|
1 | 1 | ## Opaque Session Token
|
2 | 2 |
|
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. |
4 | 4 |
|
5 | 5 | ## Description
|
6 | 6 |
|
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. |
8 | 8 |
|
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. |
10 | 10 |
|
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. |
12 | 36 |
|
13 | 37 | To query the current sessions in the key-value store:
|
14 | 38 |
|
15 |
| -`curl localhost:8010/api/3/http/keyvals/sessions` |
| 39 | +`$ curl localhost:8010/api/3/http/keyvals/sessions` |
16 | 40 |
|
17 | 41 | To delete a single session:
|
18 | 42 |
|
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` |
20 | 44 |
|
21 |
| -To delete all sessions |
| 45 | +To delete all sessions: |
22 | 46 |
|
23 |
| -`curl -X DELETE localhost:8010/api/3/http/keyvals/sessions` |
| 47 | +`$ curl -iX DELETE localhost:8010/api/3/http/keyvals/sessions` |
0 commit comments