Repository navigation
feat(openid-connect): support stateless session revocation #13651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hockenba
wants to merge
18
commits into
apache:master
Choose a base branch
from
geico:feat/openid-connect-stateless-session-revocation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0ee480e
feat(openid-connect): support stateless session revocation
Hockenba cf2cc5e
refactor(openid-connect): expose session revocation backend
Hockenba 7572d22
fix(openid-connect): avoid unconditional revocation default
Hockenba 0c3c35c
for lua-resty-openidc changes
Hockenba cac900b
update to newest openidc with my commit
Hockenba a56f816
Merge apache/master into feat/openid-connect-stateless-session-revoca…
Hockenba e9022c1
in memory cache config options
Hockenba 5c1b46d
Merge branch 'master' of https://github.com/apache/apisix into feat/o…
Hockenba 56083de
chore(deps): bump lua-resty-session to 4.3.0-1
Hockenba df39083
Merge branch 'master' of https://github.com/apache/apisix into feat/o…
Hockenba b420af1
fix(openid-connect): disable revocation error cache with the lookup c…
Hockenba ddcf668
test(openid-connect): cover revocation cache TTL normalization
Hockenba 6afeda5
test(openid-connect): move revocation TTL test into the revocation suite
Hockenba 07ecd1f
docs(openid-connect): explain the revocation lookup cache
Hockenba f494d1e
chore(openid-connect): drop the library version from a comment
Hockenba ad249f3
fix(openid-connect): override the revocation error TTL only where it …
Hockenba 5ecfa78
chore(openid-connect): reword the revocation error TTL comments
Hockenba dfccf89
test(openid-connect): open the cached session in a separate request
Hockenba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,9 @@ local MAX_AUTH_FLOW_RESTARTS = 3 | |
| -- Session config is passed as-is to resty.session.start(); the only | ||
| -- translation is the legacy session.cookie.lifetime alias from the | ||
| -- lua-resty-session 3.x schema, which is mapped to absolute_timeout | ||
| -- when the latter is unset. | ||
| -- when the latter is unset. The revocation error cache needs the lookup cache: | ||
| -- the session library only allocates its cache when revocation_cache_ttl > 0, | ||
| -- so with the lookup cache off the error TTL is set to 0 as well. | ||
| local function build_session_opts(session_conf) | ||
| if not session_conf then | ||
| return nil | ||
|
|
@@ -68,6 +70,18 @@ local function build_session_opts(session_conf) | |
| "use session.absolute_timeout instead") | ||
| end | ||
| end | ||
| if session_conf.revocation and session_conf.revocation_cache_ttl == 0 then | ||
| local error_ttl = session_conf.revocation_error_cache_ttl | ||
| -- the error cache needs the lookup cache, so a non-zero error TTL, set | ||
| -- or defaulted by the library, cannot apply without it | ||
| if error_ttl == nil or error_ttl > 0 then | ||
| if error_ttl then | ||
| core.log.warn("session.revocation_error_cache_ttl is ignored when ", | ||
| "session.revocation_cache_ttl is 0") | ||
| end | ||
| session_conf.revocation_error_cache_ttl = 0 | ||
| end | ||
| end | ||
| return session_conf | ||
| end | ||
|
|
||
|
|
@@ -295,7 +309,33 @@ local schema = { | |
| description = "keepalive timeout in milliseconds", | ||
| }, | ||
| } | ||
| } | ||
| }, | ||
| revocation = { | ||
| type = "string", | ||
| enum = {"redis"}, | ||
| description = "Redis-backed revocation for cookie sessions.", | ||
| }, | ||
| revocation_fail_mode = { | ||
| type = "string", | ||
| enum = {"open", "closed"}, | ||
| description = | ||
| "When the revocation store is unreachable, open treats the " | ||
| .. "session as not revoked and closed rejects open/destroy.", | ||
| }, | ||
| revocation_cache_ttl = { | ||
| type = "integer", | ||
| minimum = 0, | ||
|
Hockenba marked this conversation as resolved.
Resolved
|
||
| description = | ||
| "Worker-local TTL in seconds for successful revocation " | ||
| .. "lookups. 0 disables. Default is 5 in lua-resty-session.", | ||
| }, | ||
| revocation_error_cache_ttl = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Waiting for bungle/lua-resty-session#213
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Still feel free to take a peak at to make sure that I implemented what was requested :) |
||
| type = "integer", | ||
| minimum = 0, | ||
| description = | ||
| "Worker-local TTL in seconds for revocation store errors. " | ||
| .. "0 disables. Default is 5 in lua-resty-session.", | ||
| }, | ||
| }, | ||
| required = {"secret"}, | ||
| ["if"] = { | ||
|
|
@@ -306,6 +346,19 @@ local schema = { | |
| ["then"] = { | ||
| required = {"redis"}, | ||
| }, | ||
| allOf = { | ||
| { | ||
| ["if"] = { | ||
| required = {"revocation"}, | ||
| }, | ||
| ["then"] = { | ||
| required = {"redis"}, | ||
| properties = { | ||
| storage = { const = "cookie" }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| additionalProperties = false, | ||
| }, | ||
| realm = { | ||
|
|
@@ -1467,6 +1520,17 @@ local function authenticate(plugin_conf, ctx) | |
| return 401 | ||
| end | ||
|
|
||
| -- fail-closed only: resty.session appends the store error, so match | ||
| -- the prefix. Reject without destroying the cookie. | ||
| if core.string.find(err, "unable to check session revocation") | ||
| or core.string.find(err, "unable to mark session revoked") then | ||
| if session then | ||
| session:close() | ||
| end | ||
| core.log.error("OIDC session revocation store unavailable: ", err) | ||
| return 503 | ||
| end | ||
|
|
||
| -- Recoverable authorization-callback failures: a stale state | ||
| -- (replayed or pruned callback), or the ID provider redirecting | ||
| -- back with error=temporarily_unavailable, e.g. Keycloak after | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.