Repository navigation
Conversation
Add opt-in Redis-backed revocation for cookie sessions, with schema validation, documentation, and focused coverage.
Forward lua-resty-session revocation settings directly and make the fail-open default explicit.
Let lua-resty-session apply fail-open behavior only when revocation is enabled, preserving unchanged defaults for other sessions.
…penid-connect-stateless-session-revocation
…penid-connect-stateless-session-revocation # Conflicts: # apisix-master-0.rockspec
…ache lua-resty-session 4.3.0 allocates its revocation cache only when revocation_cache_ttl > 0, but reads it when either TTL is set. A zero lookup TTL with the default error TTL therefore indexed a nil cache. Force the error TTL to 0 in that case, and add a test that counts store lookups across repeated opens of one session.
The session library reads its cookie through an nginx variable that is cached per request, so saving and re-opening in one request never sees the new cookie. Split the test into a save request and open requests.
- Open the cookie session without refreshing it when a logout request is handled, so the session id that is revoked is the one in the presented cookie rather than one rotated by a rolling refresh. - Do not cache revocation store errors in open mode: lua-resty-session 4.3.0 caches them as "not revoked" under a key shared with closed configurations. Document the library workarounds and the in-place mutation of the shared session conf. - Add Keycloak/Redis tests for logout past a rolling refresh and for a fail-open store error not being replayed to a fail-closed configuration; update the build_session_opts test for the new TTL rules. - Docs (en/zh): document the cache TTL defaults, qualify the maximum-staleness claim, and describe the rotated-cookie and open-mode logout limitations.
…tations Note that releases of lua-resty-session that revoke the whole lineage of a session on logout reject every cookie descended from the same login, and that 4.3.0 only revokes the presented session id.
…ad of workarounds Drop the revocation error TTL override and the logout special-casing: with the lua-resty-session and lua-resty-openidc fixes (revocation cache allocated unconditionally and keyed per fail mode, logout opens the session without refreshing it, lineage revocation on destroy) the plugin passes the session options through unchanged. Docs: the cache TTL rows no longer carry the plugin-side restrictions, and the limitations describe lineage revocation. Tests: drop the TTL rules test, give the cache probe one stable store, and count the two lookups per open.
…egression The revocation cache is per worker, so a single replay may reach a worker that never cached the fail-open error. Replay ten times in each phase so every worker is covered.
The closed-mode 503 mapping and the cache lookups are now exercised against real Keycloak and Redis, and the cache behaviour is covered by the lua-resty-session specs, so the stub-based tests only duplicated them.
The closed-mode 503 branch now says what it matches through a function, and the docs section covers the logout behaviour as well as its limitations.
…on errors, document cache size
…route configuration
… cache; test: use the default cache ttl
…-stateless-session-revocation
…-stateless-session-revocation
|
Thanks for moving the logout and session changes upstream. Before merging this PR, could you fix partial-write recovery in lua-resty-session #217 and add a regression test for a second HTTP logout request? In the current candidate, Please extend the upstream test that currently stops at the first write error, and cover the browser-visible retry through APISIX with real Keycloak and Redis:
For this PR, please also pin mutually compatible releases containing both upstream fixes. The current CI job installed session 4.3.0, then replaced it with 4.2.0 to satisfy OpenIDC 1.9.3. Both cookie replays returned 200 on the initial run and on retry. Finally, please qualify the English and Chinese docs: cookies issued before lineage IDs existed only support per-SID revocation, and checking Redis on every request requires setting both lookup and error cache TTLs to zero. |
…cs: qualify revocation limits Add a regression test that retries a failed logout with the same cookie and checks that two cookies of one login are revoked. State in the docs that cookies issued before lineage IDs existed are revoked one by one, and that both cache TTLs have to be 0 to check Redis on every request.
Use a Redis user that may write lineage marks but not session id marks, so the first logout stores one mark and is refused, then retry it with the same cookie and check that both cookies of the login are rejected.
Addressed. Session bungle/lua-resty-session#217 · feat(*): revoke every cookie of…: destroy() now writes the lineage mark before the session ID mark, so a failure between the two writes no longer leaves a cookie that the retry would miss. Added specs for a failed lineage write, a failed session ID write, and the cached write error. Added the regression tests through APISIX with real Keycloak and Redis. TEST 6 logs in and refreshes to get two valid cookies, fails the first logout (503, cookie kept, no marks written), then retries with the same cookie and checks that both cookies are rejected. TEST 7 does the same for a partial write, using a Redis ACL that allows only the lineage mark. Docs (English and Chinese): cookies issued before lineage IDs are revoked one by one, and both cache TTLs must be 0 to check Redis on every request. Pins: waiting on the session and openidc releases. I'll bump them in this PR once they are out. |
| -- keys are "<prefix>:<cookie name>:<base64url of the mark key>", and the | ||
| -- mark keys of a lineage start with "lineage:", "bGluZWFnZTp" encoded | ||
| local prefix = "oidc:revocation:partial:" | ||
| local lineage_keys = prefix .. ":session:bGluZWFnZTp*" |
There was a problem hiding this comment.
Could you adjust this ACL pattern so TEST 7 always allows the lineage write? The last p in bGluZWFnZTp* depends on the first character of the lineage ID. For example, lineage:A encodes as bGluZWFnZTpB, while lineage:0 encodes as bGluZWFnZTow. Both are valid starts, but the ACL denies the second one. In that case the first write fails and the test never exercises the intended SID-write failure.
For the base64url IDs generated here, bGluZWFnZT[op]* covers both forms. Please check the matcher with a letter-leading and a digit-leading ID, and keep the assertion that Redis contains one lineage marker and zero SID markers after the first logout.
There was a problem hiding this comment.
Addressed.
The pattern is now bGluZWFnZT[op]*, so TEST 7 always allows the lineage write, whatever character the ID starts with. The test now checks the pattern with IDs starting with a letter, a digit, - and _, and still asserts one lineage marker and zero SID markers after the first logout.
The ACL pattern of the lineage marks depended on the first character of the lineage ID, so a digit or - denied the write the test needs to succeed. Match both encodings and check the matcher with IDs starting with a letter, a digit, - and _.
…-stateless-session-revocation
Add the ACL command to resty.redis and use ngx.base64 for the key, instead of a raw protocol client and character replacements.
…rolling window, restore Redis settings TEST 4 checks that logout marked the session id of the presented cookie, which tells opening the session apart from refreshing it. TEST 4, 6 and 7 use a 20 second rolling window so the requests after the wait cannot reach its end. TEST 6 restores the maxmemory settings it changes and makes Redis reject writes instead of evicting keys. docs: drop the trailing colon of the example prefix.
Run the scenario of TEST 7 in a function and delete the Redis user after it, whether it passes or an assertion fails.
Shorten the English and Chinese revocation section and the comments of the plugin and its revocation tests, and give the test helpers names that say what they do.
Description
Cookie sessions of the
openid-connectPlugin live in the browser, so/logoutonly cleared the cookie and a copied cookie stayed valid until it timed out. This adds opt-in Redis-backed revocation: logout revokes every cookie of that login, including ones rotated by a refresh, and later requests with any of them are rejected.session.revocation("redis") turns it on. It reusessession.redisand requiressession.storageto becookie.session.revocation_fail_modeisopen(documented default) orclosed. Inclosedmode a store error returns503and keeps the cookie, so the logout can be retried.session.revocation_cache_ttlandsession.revocation_error_cache_ttl(default5seconds) control a per-worker cache that avoids a Redis lookup on every request. Cache sizes use the nginx variables$session_revocation_cache_sizeand$session_revocation_error_cache_size.lua-resty-sessionis raised to4.3.0-1.Back-channel and front-channel logout are not part of this change.
Dependencies: this needs unreleased changes in lua-resty-session (bungle/lua-resty-session#217) and lua-resty-openidc (zmartzone/lua-resty-openidc#581, logout opens the session without refreshing it). The revocation tests fail in CI until both are released. I will bump the rockspec pins in this PR then.
Which issue(s) this PR fixes:
N/A
Test plan
t/plugin/openid-connect-revocation.t, with real Keycloak and Redis: schema cases, logout and replay, logout after a rolling refresh, fail-open and fail-closed behavior, and retry of a logout that failed on a Redis write (all writes, or only the session ID mark).t/plugin/openid-connect*.tfiles pass locally.Checklist