You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/proposals/authentication-filter.md
-281Lines changed: 0 additions & 281 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,284 +20,3 @@ This new filter should eventually expose all forms of authentication avaialbe th
20
20
21
21
- Design for all forms of authentication
22
22
- 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.
|**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
- 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