Skip to content

Commit 88230d0

Browse files
committed
Set status to provisional, include only goals and non-goals
1 parent 77eb226 commit 88230d0

File tree

1 file changed

+0
-281
lines changed

1 file changed

+0
-281
lines changed

docs/proposals/authentication-filter.md

Lines changed: 0 additions & 281 deletions
Original file line numberDiff line numberDiff line change
@@ -20,284 +20,3 @@ This new filter should eventually expose all forms of authentication avaialbe th
2020

2121
- Design for all forms of authentication
2222
- An Auth filter for GRPC, TCP and UDP routes
23-
24-
## Introduction
25-
26-
This document focus expliclty on Authentiaction (AuthN) and not Authorization (AuthZ). Authentiaction (AuthN) defines the verification of identiy. It asks the question, "Who are you?". This is different from Authorization (AuthZ), which preceeds Authentication. It asks the question, "What are you allowed to do".
27-
28-
This document also focus on Basic Authentication. Other authentication methods such as JWT and OAuth are mentioned, but are not part of the CRD design. These will be covered in future design and implementation tasks.
29-
30-
31-
## Use Cases
32-
33-
- As an Application Developer, I want to secure access to my APIs and Backend Applications.
34-
- As an Application Developer, I want to enforce authenticaiton on specific routes and matches.
35-
36-
### Understanding NGINX authentication methods
37-
38-
| **Authentication Method** | **OSS** | **Plus** | **NGINX Module** | **Details** |
39-
|-------------------------------|--------------|----------------|----------------------------------|--------------------------------------------------------------------|
40-
| **HTTP Basic Authentication** ||| [ngx_http_auth_basic](https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html) | Requires a username and password sent in an HTTP header. |
41-
| **JWT (JSON Web Token)** ||| [ngx_http_auth_jwt_module](https://docs.nginx.com/nginx/admin-guide/security-controls/authentication/#jwt-authentication) | Tokens are used for stateless authentication between client and server. |
42-
| **OpenID Connect** ||| [ngx_http_oidc_module](https://nginx.org/en/docs/http/ngx_http_oidc_module.html)| Allows authentication through third-party providers like Google. |
43-
44-
## API, Customer Driven Interfaces, and User Experience
45-
46-
When designing a means of configuring authentication for NGF, we can consider these approaches:
47-
48-
1. An `AuthenticationFilter` CRD which is responsible for providing a specification for each form of authentication within a single resource.
49-
2. Indvidual CRDs responsbile for each authentication method. e.g. `BasicAuthFilter`, `JWTAuthFIlter`, etc...
50-
51-
This document will cover examples of both, including the pros and cons of each.
52-
53-
### 1. Single AuthenticationFilter
54-
55-
```yaml
56-
apiVersion: gateway.nginx.org/v1alpha1
57-
kind: AuthenticationFilter
58-
metadata:
59-
name: basic-auth
60-
spec:
61-
type: Basic
62-
basic:
63-
secret: basic-auth-users # Secret containing htpasswd data
64-
key: htpasswd # key within the Secret
65-
realm: "Restricted" # Optional. Helps with logging
66-
onFailure: # Optional. These setting may be defaults.
67-
statusCode: 401
68-
wwwAuthenticate: 'Basic realm="Restricted"'
69-
responseBody: 'Unauthorized'
70-
```
71-
72-
| **Pros** | **Cons** |
73-
|-------------------------------|--------------|
74-
| Single Resource to manage | Resource updates may be difficult |
75-
| | May require lots of internal logic |
76-
77-
### 2. Individual Filter for each Auth method
78-
79-
```yaml
80-
apiVersion: gateway.nginx.org/v1alpha1
81-
kind: BasicAuthFilter
82-
metadata:
83-
name: basic-auth
84-
spec:
85-
secret: basic-auth-users # Secret containing htpasswd data
86-
key: htpasswd # key within the Secret
87-
realm: "Restricted" # Optional. Helps with logging
88-
onFailure: # Optional. These setting may be defaults.
89-
statusCode: 401
90-
wwwAuthenticate: 'Basic realm="Restricted"'
91-
responseBody: 'Unauthorized'
92-
```
93-
94-
| **Pros** | **Cons** |
95-
|-------------------------------|--------------|
96-
| Versioning per-resource is much easier | Multiple resources to manage |
97-
| Easier to map to `graph` in go code | |
98-
99-
### Example integration
100-
101-
Secret referenced by Filter
102-
103-
```yaml
104-
apiVersion: v1
105-
kind: Secret
106-
metadata:
107-
name: basic-auth-users
108-
type: Opaque
109-
stringData:
110-
htpasswd: |
111-
admin:$apr1$ZxY12345$abcdefghijklmnopqrstuvwx/
112-
user:$apr1$AbC98765$mnopqrstuvwxyzabcdefghiJKL/
113-
```
114-
115-
HTTPRoute that will reference this filter
116-
117-
```yaml
118-
apiVersion: gateway.networking.k8s.io/v1
119-
kind: HTTPRoute
120-
metadata:
121-
name: api-basic
122-
namespace: default
123-
spec:
124-
parentRefs:
125-
- name: gateway
126-
hostnames:
127-
- api.example.com
128-
rules:
129-
- matches:
130-
- path:
131-
type: PathPrefix
132-
value: /v2
133-
filters:
134-
- type: ExtensionRef
135-
extensionRef:
136-
group: gateway.nginx.org
137-
kind: BasicAuthFilter
138-
name: basic-auth
139-
backendRefs:
140-
- name: backend
141-
port: 80
142-
```
143-
144-
Generated NGINX config
145-
146-
```nginx
147-
# ------------------------------------------
148-
# http context
149-
# ------------------------------------------
150-
http {
151-
# NGF-managed upstream populated from Kubernetes Endpoints
152-
upstream backend_default {
153-
server 10.0.0.10:80;
154-
server 10.0.0.11:80;
155-
}
156-
157-
server {
158-
listen 80;
159-
server_name api.example.com;
160-
161-
# ------------------------------------------
162-
# Location generated for HTTPRoute rule: PathPrefix /v2
163-
# ------------------------------------------
164-
location /v2 {
165-
# Injected by BasicAuthFilter "basic-auth"
166-
auth_basic "Restricted";
167-
auth_basic_user_file /etc/nginx/secrets/basic-auth-users/htpasswd;
168-
169-
# Optional: customize failure per filter onFailure
170-
# Ensures a consistent body and explicit WWW-Authenticate header
171-
error_page 401 = @basic_auth_failure;
172-
173-
# Optional: do not forward client Authorization header to upstream
174-
proxy_set_header Authorization "";
175-
176-
# NGF standard proxy headers
177-
proxy_set_header Host $host;
178-
proxy_set_header X-Real-IP $remote_addr;
179-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
180-
proxy_set_header X-Forwarded-Proto $scheme;
181-
182-
# Pass traffic to upstream
183-
proxy_pass http://backend_default;
184-
}
185-
186-
# Internal location for custom 401 response
187-
location @basic_auth_failure {
188-
add_header WWW-Authenticate 'Basic realm="Restricted"' always;
189-
return 401 'Unauthorized';
190-
}
191-
}
192-
}
193-
```
194-
195-
![reference-1](/docs/images/authentication-filter/basic-auth-filter/reference-1.png)
196-
197-
## Testing
198-
199-
- Unit tests
200-
- Functional tests to validate behavioural scenarios when referncing filters in different combinations. The details of these tests are out of scope for this document.
201-
202-
## Security Considerations
203-
204-
### Validation
205-
206-
If we chose to go forward with creation of our own `AuthenticationFilter`, it is important that we ensure all configurable fields are validated, and that the resulting NGINX configuration is correct and secure
207-
208-
All fields in the `AuthenticationFilter` will be validated with Open API Schema.
209-
We should also include [CEL](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-rules) validation where required.
210-
211-
## Alternatives
212-
213-
The [External AuthFilter](docs/proposals/external-auth-filter.md) document proposes a means to integrate with the expermintal feature [HTTPExternalAuthFilter](https://gateway-api.sigs.k8s.io/reference/spec/#httpexternalauthfilter) available in the HTTPRoute specification.
214-
Please refer to that proposal for details on how that approach may be implemented.
215-
216-
## Additional considerations
217-
218-
### Path Type Behaviour
219-
220-
The `auth_basic` directive can be applied at the `http`, `server` and `location` contexts in NGINX.
221-
As the intention is to provide this capabilitiy as a filter, which is attached at the `rules[].filters` level, this implementation aims to keep this behaviour at the `location` level.
222-
223-
As Filters are attached at the rule level, they are applied to every request that matches any of the rule’s match entries.
224-
If a match uses `PathPrefix`, the filter applies to the entire prefix subtree (the prefix and all subsequent subpaths under it). If a match uses `Exact`, the filter applies only to that exact path.
225-
226-
Given this behaviour, we may need to consider to construct the final `http.conf` file given combinations of `Exact` and `PathPrefix` path types.
227-
228-
Example HTTPRoute
229-
<details>
230-
<summary> >> (click to expand) << </summary>
231-
232-
```yaml
233-
apiVersion: gateway.networking.k8s.io/v1
234-
kind: HTTPRoute
235-
metadata:
236-
name: api-with-basic-auth
237-
namespace: default
238-
spec:
239-
parentRefs:
240-
- name: gateway
241-
hostnames:
242-
- api.example.com
243-
rules:
244-
# Rule 1: Protect /v1 and a nested /v1/admin path
245-
- matches:
246-
- path:
247-
type: PathPrefix
248-
value: /v1
249-
- path:
250-
type: PathPrefix
251-
value: /v1/admin
252-
filters:
253-
- type: ExtensionRef
254-
extensionRef:
255-
group: gateway.nginx.org
256-
kind: BasicAuthFilter
257-
name: basic-auth
258-
backendRefs:
259-
- name: service-v1
260-
port: 80
261-
262-
# Rule 2: Protect all /v2 paths
263-
- matches:
264-
- path:
265-
type: PathPrefix
266-
value: /v2
267-
filters:
268-
- type: ExtensionRef
269-
extensionRef:
270-
group: gateway.nginx.org
271-
kind: BasicAuthFilter
272-
name: basic-auth
273-
backendRefs:
274-
- name: service-v2
275-
port: 80
276-
277-
# Rule 3: Protect an exact path with the same filter
278-
- matches:
279-
- path:
280-
type: Exact
281-
value: /reports
282-
filters:
283-
- type: ExtensionRef
284-
extensionRef:
285-
group: gateway.nginx.org
286-
kind: BasicAuthFilter
287-
name: basic-auth
288-
backendRefs:
289-
- name: reports-svc
290-
port: 8080
291-
```
292-
293-
</details>
294-
295-
### Potential HTTPRoute behaviour
296-
297-
An authentication based filter may be referenced by multiple HTTPRoutes, and multiple rules within those routes.
298-
299-
A HTTPRoute that is already deployed, and references an authentication based filter that does `not` exist, may remain unchanged and continue to serve the previous working config.
300-
301-
A HTTPRoute that is already deployed, and references an authentication based filter that has been delete, should update the NGINX configuration to reflect the removal of the filter.
302-
303-
A new HTTPRoute that has yet to be deployed, and is referencing a filter that does `not` exist may be `rejected` when attempting to apply it.

0 commit comments

Comments
 (0)