Skip to content

Commit 2a431c1

Browse files
authored
Adds JWT Authn User Docs (#991)
Signed-off-by: danehans <[email protected]>
1 parent 1b26380 commit 2a431c1

File tree

6 files changed

+157
-0
lines changed

6 files changed

+157
-0
lines changed

docs/latest/dev/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ Now you are able to view the running Envoy configuration by navigating to `127.0
126126

127127
There are many other endpoints on the [Envoy admin interface][] that may be helpful when debugging.
128128

129+
### JWT Testing
130+
131+
An example [JSON Web Token (JWT)][jwt] and [JSON Web Key Set (JWKS)][jwks] are used for the [request authentication][]
132+
user guide. The JWT was created by the [JWT Debugger][], using the `RS256` algorithm. The public key from the JWTs
133+
verify signature was copied to [JWK Creator][] for generating the JWK. The JWK Creator was configured with matching
134+
settings, i.e. `Signing` public key use and the `RS256` algorithm. The generated JWK was wrapped in a JWKS structure
135+
and is hosted in the repo.
136+
129137
[Quickstart]: https://github.com/envoyproxy/gateway/blob/main/docs/user/quickstart.md
130138
[make]: https://www.gnu.org/software/make/
131139
[Github Actions]: https://docs.github.com/en/actions
@@ -137,3 +145,8 @@ There are many other endpoints on the [Envoy admin interface][] that may be help
137145
[gateway-dev]: https://hub.docker.com/r/envoyproxy/gateway-dev/tags
138146
[mac_connect]: https://github.com/chipmk/docker-mac-net-connect
139147
[Envoy admin interface]: https://www.envoyproxy.io/docs/envoy/latest/operations/admin#operations-admin-interface
148+
[jwt]: https://tools.ietf.org/html/rfc7519
149+
[jwks]: https://tools.ietf.org/html/rfc7517
150+
[request authentication]: https://gateway.envoyproxy.io/latest/user/authn.html
151+
[JWT Debugger]: https://jwt.io/
152+
[JWK Creator]: https://russelldavies.github.io/jwk-creator/

docs/latest/user/authn.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Request Authentication
2+
3+
This guide provides instructions for configuring [JSON Web Token (JWT)][jwt] authentication. JWT authentication checks
4+
if an incoming request has a valid JWT before routing the request to a backend service. Currently, Envoy Gateway only
5+
supports validating a JWT from an HTTP header, e.g. `Authorization: Bearer <token>`.
6+
7+
## Installation
8+
9+
Follow the steps from the [Quickstart](quickstart.md) guide to install Envoy Gateway and the example manifest.
10+
Before proceeding, you should be able to query the example backend using HTTP.
11+
12+
## Configuration
13+
14+
Allow requests with a valid JWT by creating an [AuthenticationFilter][] and referencing it from the example HTTPRoute.
15+
16+
```shell
17+
kubectl apply -f https://raw.githubusercontent.com/envoyproxy/gateway/latest/examples/kubernetes/authn/jwt.yaml
18+
```
19+
20+
The HTTPRoute is now updated to authenticate requests for `/foo` and allow unauthenticated requests to `/bar`. The
21+
`/foo` route rule references an AuthenticationFilter that provides the JWT authentication configuration.
22+
23+
Verify the HTTPRoute configuration and status:
24+
25+
```shell
26+
kubectl get httproute/backend -o yaml
27+
```
28+
29+
The AuthenticationFilter is configured for JWT authentication and uses a single [JSON Web Key Set (JWKS)][jwks]
30+
provider for authenticating the JWT.
31+
32+
Verify the AuthenticationFilter configuration:
33+
34+
```shell
35+
kubectl get authenticationfilter/jwt-example -o yaml
36+
```
37+
38+
## Testing
39+
40+
Ensure the `GATEWAY_HOST` environment variable from the [Quickstart](quickstart.md) guide is set. If not, follow the
41+
Quickstart instructions to set the variable.
42+
43+
```shell
44+
echo $GATEWAY_HOST
45+
```
46+
47+
Verify that requests to `/foo` are denied without a JWT:
48+
49+
```shell
50+
curl -sS -o /dev/null -H "Host: www.example.com" -w "%{http_code}\n" http://$GATEWAY_HOST/foo
51+
```
52+
53+
A `401` HTTP response code should be returned.
54+
55+
Get the JWT used for testing request authentication:
56+
57+
```shell
58+
TOKEN=$(curl https://raw.githubusercontent.com/envoyproxy/gateway/main/examples/kubernetes/authn/test.jwt -s) && echo "$TOKEN" | cut -d '.' -f2 - | base64 --decode -
59+
```
60+
61+
__Note:__ The above command decodes and returns the token's payload. You can replace `f2` with `f1` to view the token's
62+
header.
63+
64+
Verify that a request to `/foo` with a valid JWT is allowed:
65+
66+
```shell
67+
curl -sS -o /dev/null -H "Host: www.example.com" -H "Authorization: Bearer $TOKEN" -w "%{http_code}\n" http://$GATEWAY_HOST/foo
68+
```
69+
70+
A `200` HTTP response code should be returned.
71+
72+
Verify that requests to `/bar` are allowed __without__ a JWT:
73+
74+
```shell
75+
curl -sS -o /dev/null -H "Host: www.example.com" -w "%{http_code}\n" http://$GATEWAY_HOST/bar
76+
```
77+
78+
## Clean-Up
79+
80+
Follow the steps from the [Quickstart](quickstart.md) guide to uninstall Envoy Gateway and the example manifest.
81+
82+
Delete the AuthenticationFilter:
83+
84+
```shell
85+
kubectl delete authenticationfilter/jwt-example
86+
```
87+
88+
## Next Steps
89+
90+
Checkout the [Developer Guide](../dev/README.md) to get involved in the project.
91+
92+
[jwt]: https://tools.ietf.org/html/rfc7519
93+
[AuthenticationFilter]: https://github.com/envoyproxy/gateway/blob/main/api/v1alpha1/authenticationfilter_types.go
94+
[jwks]: https://tools.ietf.org/html/rfc7517

docs/latest/user_docs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ Learn how to deploy, use, and operate Envoy Gateway.
1818
user/tcp-routing
1919
user/udp-routing
2020
user/grpc-routing
21+
user/authn
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"keys":[{"kty":"RSA","n":"u1SU1LfVLPHCozMxH2Mo4lgOEePzNm0tRgeLezV6ffAt0gunVTLw7onLRnrq0_IzW7yWR7QkrmBL7jTKEn5u-qKhbwKfBstIs-bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyehkd3qqGElvW_VDL5AaWTg0nLVkjRo9z-40RQzuVaE8AkAFmxZzow3x-VJYKdjykkJ0iT9wCS0DRTXu269V264Vf_3jvredZiKRkgwlL9xNAwxXFg0x_XFw005UWVRIkdgcKWTjpBP2dPwVZ4WWC-9aGVd-Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbcmw","e":"AQAB","alg":"RS256","use":"sig"}]}

examples/kubernetes/authn/jwt.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apiVersion: gateway.envoyproxy.io/v1alpha1
2+
kind: AuthenticationFilter
3+
metadata:
4+
name: jwt-example
5+
spec:
6+
type: JWT
7+
jwtProviders:
8+
- name: example
9+
remoteJWKS:
10+
uri: https://raw.githubusercontent.com/envoyproxy/gateway/main/examples/kubernetes/authn/jwks.json
11+
---
12+
apiVersion: gateway.networking.k8s.io/v1beta1
13+
kind: HTTPRoute
14+
metadata:
15+
name: backend
16+
spec:
17+
parentRefs:
18+
- name: eg
19+
hostnames:
20+
- "www.example.com"
21+
rules:
22+
- backendRefs:
23+
- group: ""
24+
kind: Service
25+
name: backend
26+
port: 3000
27+
weight: 1
28+
filters:
29+
- extensionRef:
30+
group: gateway.envoyproxy.io
31+
kind: AuthenticationFilter
32+
name: jwt-example
33+
type: ExtensionRef
34+
matches:
35+
- path:
36+
type: PathPrefix
37+
value: /foo
38+
- backendRefs:
39+
- group: ""
40+
kind: Service
41+
name: backend
42+
port: 3000
43+
weight: 1
44+
matches:
45+
- path:
46+
type: PathPrefix
47+
value: /bar

examples/kubernetes/authn/test.jwt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.NHVaYe26MbtOYhSKkoKYdFVomg4i8ZJd8_-RU8VNbftc4TSMb4bXP3l3YlNWACwyXPGffz5aXHc6lty1Y2t4SWRqGteragsVdZufDn5BlnJl9pdR_kdVFUsra2rWKEofkZeIC4yWytE58sMIihvo9H1ScmmVwBcQP6XETqYd0aSHp1gOa9RdUPDvoXQ5oqygTqVtxaDr6wUFKrKItgBMzWIdNZ6y7O9E0DhEPTbE9rfBo6KTFsHAZnMg4k68CDp2woYIaXbmYTWcvbzIuHO7_37GT79XdIwkm95QJ7hYC9RiwrV7mesbY4PAahERJawntho0my942XheVLmGwLMBkQ

0 commit comments

Comments
 (0)