Skip to content

Commit ec3e2b5

Browse files
committed
NGINX Plus R16
1 parent 086a012 commit ec3e2b5

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ Review the following files copied from the GitHub repository so that they match
8989

9090
## Support
9191

92-
The reference OpenID Connect implementation at the root of the GitHub repository is supported for NGINX Plus subscribers.
92+
All reference OpenID Connect implementations within the GitHub repository are supported for NGINX Plus subscribers.
9393

9494
## Other use cases
9595

96-
Subdirectories within the GitHub repository contain sample implementations for alternative OpenID Connect use cases. These are not supported.
96+
Subdirectories within the GitHub repository contain variations of the reference implementation for alternative OpenID Connect use cases.
9797

98-
* **opaque_session_token** - proof of concept implementation that sends a random string to the client rather than the JWT
98+
* **opaque_session_token** - Uses the NGINX Plus key-value store to hold the ID Token, sending a random string to the client as the session token. The session token is then exchanged for the ID Token on each request. This use case is valuable when the ID Token contains sensitive information that should not reach the client.

opaque_session_token/README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
## Opaque Session Token
22

3-
This is a proof of concept implementation of NGINX Plus as relying party for OpenID Connect authentication.
3+
This is a variation on the reference implementation of NGINX Plus as relying party for OpenID Connect authentication.
44

55
## Description
66

7-
This is a variation of the reference OpenID Connect implementation. It does not send a JWT to the client as a session cookie. The ID Token is stored in the NGINX Plus key-value store and a random value is sent as a session cookie.
7+
This use case varies from the top-level reference implementation at the step when the ID Token received from the IdP. Instead of sending the ID Token to the client as a session cookie, the ID Token is saved to the NGINX Plus [key-value store](http://nginx.org/en/docs/http/ngx_http_keyval_module.html). A random string is sent to the client as the session cookie and acts as the _key_ to the key-value store.
88

9-
When the client presents the session cookie, that value is used to obtain the ID Token from the key-value store. The ID Token is then validated with `auth_jwt` as usual before the client request is proxied to the backend.
9+
Subsequent requests to protected resources are authenticated by exchanging the session cookie for the ID Token in the key-value store. JWT validation is performed on each request, as normal, so that the ID Token validity period is enforced.
1010

11-
This proof of concept implementation is not suitable for production use because expired tokens are not removed from the key-value store.
11+
## Installation
12+
13+
OpenID Connect with Opaque Session Token requires NGINX Plus R16 or later to be installed. Installation is as per the instructions in the top-level of the GitHub repo, and using the files found in this directory.
14+
15+
## Configuration
16+
17+
Configuration is as per the instructions in the top-level of the GitHub repo. The key-value store may additionally be configured, within **frontend.conf**, e.g.:
18+
19+
```nginx
20+
keyval_zone zone=sessions:1M state=state_sessions.json timeout=601m sync;
21+
```
22+
23+
Each of the `keyval_zone` parameters are described below.
24+
25+
* **zone** - Specifies the name of the key-value store and how much memory to allocate for it. Each session will typically occupy 1-2KB, depending on the size of the JWT, so scale this value to exceed the number of unique users that may authenticate.
26+
27+
* **state** (optional) - Specifies where all of the ID Tokens in the key-value store are saved, so that sessions will persist across restart or reboot of the NGINX host. The NGINX Plus user account, typically **nginx**, must have write permission to the directory where the state file is stored. Consider creating a dedicated directory for this purpose.
28+
29+
* **timeout** - Expired tokens are removed from the key-value store after the `timeout` value. This should be set to value slightly longer than the JWT validity period. JWT validation occurs on each request, and will fail when the expiry date (`exp` claim) has elapsed. If JWTs are issued without a JWT then set `timeout` to the desired session duration. If JWTs are issued with various validity periods then set `timeout` to exceed the longest period.
30+
31+
* **sync** (optional) - If deployed in a cluster, the key-value store may be synchronized across all instances in the cluster, so that all instances are able to create and validate authenticated sessions. Each instance must be configured to participate in state sharing with the [zone_sync module](http://nginx.org/en/docs/stream/ngx_stream_zone_sync_module.html) and by adding the `sync` parameter to the `keyval_zone` directive above.
32+
33+
## Session Management
34+
35+
The [NGINX Plus API](http://nginx.org/en/docs/http/ngx_http_api_module.html) is enabled in **openid_connect.server_conf** so that sessions can be created. The API can be used to manage the current set of active sessions.
1236

1337
To query the current sessions in the key-value store:
1438

15-
`curl localhost:8010/api/3/http/keyvals/sessions`
39+
`$ curl localhost:8010/api/3/http/keyvals/sessions`
1640

1741
To delete a single session:
1842

19-
`curl -X PATCH '{"<session ID>":null}' localhost:8010/api/3/http/keyvals/sessions`
43+
`$ curl -iX PATCH '{"<session ID>":null}' localhost:8010/api/3/http/keyvals/sessions`
2044

21-
To delete all sessions
45+
To delete all sessions:
2246

23-
`curl -X DELETE localhost:8010/api/3/http/keyvals/sessions`
47+
`$ curl -iX DELETE localhost:8010/api/3/http/keyvals/sessions`

opaque_session_token/frontend.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ js_include conf.d/openid_connect.js;
1313
js_set $requestid_hash hashRequestId;
1414
js_set $auth_token getAuthToken;
1515

16-
keyval_zone zone=sessions:1M; # state=state_sessions.json;
17-
keyval $cookie_auth_token $session_jwt zone=sessions;
16+
keyval_zone zone=sessions:1M state=state_sessions.json timeout=1h; # CHANGE timeout to JWT validity period
17+
keyval $cookie_auth_token $session_jwt zone=sessions; # Exchange cookie for JWT
1818

1919
# The frontend server - reverse proxy with OpenID Connect authentication
2020
#
@@ -33,7 +33,7 @@ server {
3333

3434
location / {
3535
# This site is protected with OpenID Connect
36-
auth_jwt "" token=$session_jwt;
36+
auth_jwt "" token=$session_jwt; # Obtain JWT from key-value store
3737
auth_jwt_key_file $oidc_jwt_keyfile;
3838

3939
# Absent/invalid OpenID Connect token will (re)start auth process

opaque_session_token/openid_connect.server_conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
proxy_pass http://127.0.0.1:$server_port/api/3/http/keyvals/sessions;
7373
}
7474

75-
location /api {
75+
location /api/ {
7676
api write=on;
77-
allow 127.0.0.1;
77+
allow 127.0.0.1; # Only the NGINX host may call the NIGNX Plus API
7878
deny all;
7979
}
8080

0 commit comments

Comments
 (0)