Skip to content

Commit 1b1665a

Browse files
committed
Add non-goals, test and security considerations. Move preface down to Alternatives section
1 parent 2a7f803 commit 1b1665a

File tree

1 file changed

+91
-22
lines changed

1 file changed

+91
-22
lines changed

docs/proposals/authentication-filter.md

Lines changed: 91 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,6 @@
33
- Issue: https://github.com/nginx/nginx-gateway-fabric/issues/4052
44
- Status: Provisional
55

6-
## Preface
7-
8-
The Gatewy API currently has an `implementable` HTTP Auth mechanism exposed using the `ExternalAuth` field in the `HTTPRoute` resource. This uses Envoy's `ext_authz` protocol to reach out to an External Service to both `Authenticate` and `Authorize` requests.
9-
10-
See https://gateway-api.sigs.k8s.io/geps/gep-1494/ for more details
11-
12-
This GEP also describes a [two phased approach](https://gateway-api.sigs.k8s.io/geps/gep-1494/#why-two-phases), which includes starting first with a Filter at the `rule` level, and then providing a top level Policy attachment that can be overridden by lower level Auth Filters.
13-
14-
From initial discussion, we decided to go forward with exposing our own authentication filter.
15-
16-
This was decided for the following reasons:
17-
- Given the timeline of `ExternalAuth` eventually being supported and implented by all other Gateway API implementations, it may be many months before this enchancement is available on the main channel within the Gateway API
18-
- Exposing our own form of authentication through an authenticaiton filter does not exclude the possibility of eventually supporting the `ExternalAuth` field
19-
- Given the expressed complexity of the [two phased approach](https://gateway-api.sigs.k8s.io/geps/gep-1494/#why-two-phases), `ExternalAuth` has the potential to go through may iterations before becoming stable
20-
- Recent conversations with the Gateway API maintainers suggest that implementation of `ExternalAuth` is still speculative
21-
226
## Summary
237

248
Design and implement a means for users of NGINX Gateway Fabric to enable authenticaiton on requests to their backend applications.
@@ -32,6 +16,10 @@ This new filter should eventually expose all forms of authentication avaialbe th
3216
- Authentication failures return appropriate status by default (e.g., 401/403)
3317
- Ensure response codes are configurable
3418

19+
## Non-Goals
20+
21+
- Design for all forms of authentication
22+
- An Auth filter for GRPC, TCP and UDP routes
3523

3624
## Introduction
3725

@@ -53,7 +41,7 @@ This document also focus on Basic Authentication. Other authentication methods s
5341
| **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. |
5442
| **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. |
5543

56-
## Design and Proposal
44+
## API, Customer Driven Interfaces, and User Experience
5745

5846
When designing a means of configuring authentication for NGF, we can consider these approaches:
5947
1. An `AuthenticationFilter` CRD which is responsible for providing a specification for each form of authentication within a single resource.
@@ -203,11 +191,89 @@ http {
203191
}
204192
```
205193

206-
## Reference Flow Diagram
207-
208194
![reference-1](/docs/images/authentication-filter/basic-auth-filter/reference-1.png)
209195

210-
## Path Type Behaviour
196+
## Testing
197+
198+
- Unit tests
199+
- Functional tests to validate behavioural scenarios when referncing filters in different combinations. The details of these tests are out of scope for this document.
200+
201+
## Security Considerations
202+
203+
### Validation
204+
205+
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
206+
207+
All fields in the `AuthenticationFilter` will be validated with Open API Schema.
208+
We should also include [CEL](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation-rules) validation where required.
209+
210+
211+
## Alternatives
212+
213+
The Gatewy API currently has an `implementable` HTTP Auth mechanism exposed using the `ExternalAuth` filter in the `HTTPRoute` resource using the [HTTPExternalAuthFilter](https://gateway-api.sigs.k8s.io/reference/spec/?h=externalauth#httpexternalauthfilter). This uses Envoy's `ext_authz` protocol to reach out to an External Service to both `Authenticate` and `Authorize` requests.
214+
215+
See https://gateway-api.sigs.k8s.io/geps/gep-1494/ for more details
216+
217+
This GEP also describes a [two phased approach](https://gateway-api.sigs.k8s.io/geps/gep-1494/#why-two-phases), which includes starting first with a Filter at the `rule` level, and then providing a top level Policy attachment that can be overridden by lower level Auth Filters.
218+
219+
From initial discussion, we decided to go forward with exposing our own authentication filter.
220+
221+
This was decided for the following reasons:
222+
- Given the timeline of `ExternalAuth` eventually being supported and implented by all other Gateway API implementations, it may be many months before this enchancement is available on the main channel within the Gateway API
223+
- Exposing our own form of authentication through an authenticaiton filter does not exclude the possibility of eventually supporting the `ExternalAuth` field
224+
- Given the expressed complexity of the [two phased approach](https://gateway-api.sigs.k8s.io/geps/gep-1494/#why-two-phases), `ExternalAuth` has the potential to go through may iterations before becoming stable
225+
- Recent conversations with the Gateway API maintainers suggest that implementation of `ExternalAuth` is still speculative
226+
227+
Example HTTPRoute using [HTTPExternalAuthFilter](https://gateway-api.sigs.k8s.io/reference/spec/?h=externalauth#httpexternalauthfilter)
228+
229+
```yaml
230+
apiVersion: gateway.networking.k8s.io/v1
231+
kind: HTTPRoute
232+
metadata:
233+
name: api-with-external-auth
234+
namespace: default
235+
spec:
236+
parentRefs:
237+
- name: gateway
238+
hostnames:
239+
- api.example.com
240+
rules:
241+
- matches:
242+
- path:
243+
type: PathPrefix
244+
value: /api
245+
filters:
246+
- type: ExternalAuth
247+
externalAuth:
248+
protocol: HTTP
249+
backendRef:
250+
# BackendObjectReference: defaults to core group and kind=Service if omitted
251+
name: ext-authz-svc
252+
port: 8080
253+
http:
254+
# Prepend a prefix when forwarding the client path to the auth server
255+
path: /authorize
256+
# Additional request headers to send to the auth server (core headers are always sent)
257+
allowedHeaders:
258+
- X-Request-Id
259+
- X-User-Agent
260+
- X-Correlation-Id
261+
# Headers from the auth server response to copy into the backend request
262+
allowedResponseHeaders:
263+
- X-Authz-Trace
264+
- WWW-Authenticate
265+
- Set-Cookie
266+
forwardBody:
267+
# Buffer and forward up to 16 KiB of the client request body to the auth server
268+
maxSize: 16384
269+
backendRefs:
270+
- name: backend-svc
271+
port: 80
272+
```
273+
274+
## Additional considerations
275+
276+
### Path Type Behaviour
211277

212278
The `auth_basic` directive can be applied at the `http`, `server` and `location` contexts in NGINX.
213279
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.
@@ -218,6 +284,9 @@ If a match uses `PathPrefix`, the filter applies to the entire prefix subtree (t
218284
Given this behaviour, we may need to consider to construct the final `http.conf` file given combinations of `Exact` and `PathPrefix` path types.
219285

220286
Example HTTPRoute
287+
<details>
288+
<summary> >> (click to expand) << </summary>
289+
221290
```yaml
222291
apiVersion: gateway.networking.k8s.io/v1
223292
kind: HTTPRoute
@@ -278,9 +347,9 @@ spec:
278347
- name: reports-svc
279348
port: 8080
280349
```
350+
</details>
281351

282-
283-
## Potential HTTPRoute behaviour
352+
### Potential HTTPRoute behaviour
284353

285354
An authentication based filter may be referenced by multiple HTTPRoutes, and multiple rules within those routes.
286355

0 commit comments

Comments
 (0)