Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0ee480e
feat(openid-connect): support stateless session revocation
Hockenba Aug 27, 2026
cf2cc5e
refactor(openid-connect): expose session revocation backend
Hockenba Aug 28, 2026
7572d22
fix(openid-connect): avoid unconditional revocation default
Hockenba Aug 28, 2026
0c3c35c
for lua-resty-openidc changes
Hockenba Sep 2, 2026
cac900b
update to newest openidc with my commit
Hockenba Sep 5, 2026
a56f816
Merge apache/master into feat/openid-connect-stateless-session-revoca…
Hockenba Sep 7, 2026
e9022c1
in memory cache config options
Hockenba Sep 15, 2026
5c1b46d
Merge branch 'master' of https://github.com/apache/apisix into feat/o…
Hockenba Sep 18, 2026
56083de
chore(deps): bump lua-resty-session to 4.3.0-1
Hockenba Nov 9, 2026
df39083
Merge branch 'master' of https://github.com/apache/apisix into feat/o…
Hockenba Nov 9, 2026
b420af1
fix(openid-connect): disable revocation error cache with the lookup c…
Hockenba Nov 9, 2026
ddcf668
test(openid-connect): cover revocation cache TTL normalization
Hockenba Nov 9, 2026
6afeda5
test(openid-connect): move revocation TTL test into the revocation suite
Hockenba Nov 9, 2026
07ecd1f
docs(openid-connect): explain the revocation lookup cache
Hockenba Nov 9, 2026
f494d1e
chore(openid-connect): drop the library version from a comment
Hockenba Nov 9, 2026
ad249f3
fix(openid-connect): override the revocation error TTL only where it …
Hockenba Nov 9, 2026
5ecfa78
chore(openid-connect): reword the revocation error TTL comments
Hockenba Nov 9, 2026
dfccf89
test(openid-connect): open the cached session in a separate request
Hockenba Nov 9, 2026
8641cc6
fix(openid-connect): address revocation review feedback
Hockenba Nov 16, 2026
9a90e3a
docs(openid-connect): describe lineage revocation in the session limi…
Hockenba Nov 17, 2026
aae225d
refactor(openid-connect): rely on the session and openidc fixes inste…
Hockenba Nov 17, 2026
48a3d2a
test(openid-connect): replay across workers in the fail-open/closed r…
Hockenba Nov 17, 2026
d278942
test(openid-connect): drop stub tests covered by real-service tests
Hockenba Nov 17, 2026
9f059bf
Merge branch 'apache:master' into feat/openid-connect-stateless-sessi…
Hockenba Nov 17, 2026
32f20cb
refactor(openid-connect): name the revocation store error check
Hockenba Nov 17, 2026
8cef328
refactor(openid-connect): use lua-resty-session to recognize revocati…
Hockenba Nov 18, 2026
1a35b65
refactor(openid-connect): match the revocation store error message again
Hockenba Nov 18, 2026
cf85818
test(openid-connect): replay the cookie issued by a refresh after logout
Hockenba Nov 18, 2026
cd0cad4
docs(openid-connect): define the revocation cache size variable with …
Hockenba Nov 18, 2026
db414b0
feat(openid-connect): create the session revocation storage once per …
Hockenba Nov 18, 2026
96ed640
refactor(openid-connect): create the revocation storage with the docu…
Hockenba Nov 18, 2026
f6a3cb4
fix(openid-connect): keep the revocation storage of up to 512 routes …
Hockenba Nov 18, 2026
ed4da6a
feat(openid-connect): share one revocation storage between routes tha…
Hockenba Nov 18, 2026
1b97fda
docs(openid-connect): routes with the same redis share a revocation c…
Hockenba Nov 18, 2026
5a976cd
test(openid-connect): turn the lookup cache off where the refreshed c…
Hockenba Nov 18, 2026
101ec52
refactor(openid-connect): pass the session configuration to the libra…
Hockenba Nov 19, 2026
ef973ee
docs(openid-connect): document the revocation error cache size variable
Hockenba Nov 19, 2026
628b9f1
docs(openid-connect): shorten the revocation notes
Hockenba Nov 19, 2026
354ff08
docs(openid-connect): drop an upgrade note that does not apply to a n…
Hockenba Nov 19, 2026
c8a4de5
docs(openid-connect): drop the same upgrade note from the Chinese docs
Hockenba Nov 19, 2026
8a00848
fix(openid-connect): name the session revocation cache entries by rou…
Hockenba Nov 19, 2026
91592d5
refactor(openid-connect): pass the session configuration to the libra…
Hockenba Nov 19, 2026
257e131
docs(openid-connect): routes with the same redis share the revocation…
Hockenba Nov 19, 2026
b734659
refactor(openid-connect): inline the revocation store error check
Hockenba Nov 19, 2026
281b1dc
docs(openid-connect): revocation markers live only in Redis
Hockenba Nov 19, 2026
4f7452f
Merge remote-tracking branch 'apache/master' into feat/openid-connect…
Hockenba Nov 19, 2026
ed2bdd5
Merge remote-tracking branch 'apache/master' into feat/openid-connect…
Hockenba Nov 20, 2026
32a9d73
test(openid-connect): retry a logout that failed on a Redis write; do…
Hockenba Nov 23, 2026
860f3bb
test(openid-connect): retry a logout that wrote only the lineage mark
Hockenba Nov 23, 2026
2002786
test(openid-connect): let TEST 7 allow the lineage mark of any ID
Hockenba Nov 24, 2026
9b91085
Merge remote-tracking branch 'apache/master' into feat/openid-connect…
Hockenba Nov 24, 2026
bd32fa7
test(openid-connect): use resty.redis for the ACL commands in TEST 7
Hockenba Nov 24, 2026
54f6b37
test(openid-connect): check the presented session id mark, widen the …
Hockenba Nov 24, 2026
2236517
test(openid-connect): always delete the ACL user of TEST 7
Hockenba Nov 24, 2026
a6eae16
docs(openid-connect): shorter revocation docs; clearer test names
Hockenba Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies = {
"api7-lua-resty-jwt = 0.2.6-0",
"lua-resty-hmac-ffi = 0.06-1",
"lua-resty-cookie = 0.4.1-1",
"lua-resty-session = 4.2.0-1",
"lua-resty-session = 4.3.0-1",
"lua-resty-openapi-validator = 1.0.6-1",
"opentracing-openresty = 0.1-0",
"lua-resty-radixtree = 2.9.2-0",
Expand Down
52 changes: 51 additions & 1 deletion apisix/plugins/openid-connect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,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,
description =
"Worker-local TTL in seconds for successful revocation "
.. "lookups. 0 disables. Default is 5.",
},
revocation_error_cache_ttl = {
type = "integer",
minimum = 0,
description =
"Worker-local TTL in seconds for revocation store errors. "
.. "0 disables. Default is 5.",
},
},
required = {"secret"},
["if"] = {
Expand All @@ -306,6 +332,19 @@ local schema = {
["then"] = {
required = {"redis"},
},
allOf = {
{
["if"] = {
required = {"revocation"},
},
["then"] = {
required = {"redis"},
properties = {
storage = { const = "cookie" },
},
},
},
},
additionalProperties = false,
},
realm = {
Expand Down Expand Up @@ -1467,6 +1506,17 @@ local function authenticate(plugin_conf, ctx)
return 401
end

-- in closed fail mode an unreachable revocation store fails opening
-- or destroying the session: reject and keep 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
Expand Down
40 changes: 39 additions & 1 deletion docs/en/latest/plugins/openid-connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ The `openid-connect` Plugin supports the integration with [OpenID Connect (OIDC)
| session.absolute_timeout | integer | False | | | Absolute session lifetime in seconds. Forwarded to lua-resty-session as `absolute_timeout`. |
| session.cookie.lifetime | integer | False | | | Deprecated. Mapped to `session.absolute_timeout` at runtime when `absolute_timeout` is not set. Use `session.absolute_timeout` instead. |
| session.storage | string | False | cookie | ["cookie", "redis"] | Session storage method. |
| session.redis | object | False | | | Redis configuration when `storage` is `redis`. |
| session.revocation | string | False | | ["redis"] | Session revocation backend. Set to `redis` to enable revocation for cookie sessions. Requires `session.redis` and cannot be used when `session.storage` is `redis`. |
| session.revocation_fail_mode | string | False | open | ["open", "closed"] | When the revocation store is unreachable, `open` treats the session as not revoked, while `closed` rejects session open and destroy operations. |
| session.revocation_cache_ttl | integer | False | 5 | | Worker-local TTL in seconds for successful revocation lookups. `0` disables. |
| session.revocation_error_cache_ttl | integer | False | 5 | | Worker-local TTL in seconds for revocation store errors. `0` disables. |
| session.redis | object | False | | | Redis connection. Required when `storage` is `redis`, or when `revocation` is `redis`. |
| session.redis.host | string | False | 127.0.0.1 | | Redis host. |
| session.redis.port | integer | False | 6379 | | Redis port. |
| session.redis.username | string | False | | | Redis username. |
Expand Down Expand Up @@ -357,6 +361,40 @@ spec:

See [Implement Authorization Code Grant](../tutorials/keycloak-oidc.md#implement-authorization-code-grant) for a complete example to use the `openid-connect` Plugin to integrate with Keycloak using the authorization code flow.

### Cookie Session Revocation

Cookie sessions are stored by the client and cannot normally be invalidated individually by APISIX. To enable server-side revocation, set `session.revocation` to `redis` and configure a Redis denylist:

```json
"session": {
"secret": "your-session-secret-min-16-chars",
"storage": "cookie",
"revocation": "redis",
"revocation_fail_mode": "closed",
"revocation_cache_ttl": 5,
"revocation_error_cache_ttl": 1,
"redis": {
"host": "127.0.0.1",
"port": 6379,
"prefix": "oidc:session"
}
}
```

`revocation_fail_mode` defaults to `open`, which keeps accepting sessions when the revocation store is unavailable; `closed` rejects session open and destroy instead. Each worker caches lookups for `revocation_cache_ttl` seconds and store errors for `revocation_error_cache_ttl` seconds, so not every request calls Redis. Set both to `0` to check Redis on every request. Omit `revocation` to disable revocation.

A logout takes effect at once on the worker that handled it, and on other workers when their cached entry expires, so `revocation_cache_ttl` bounds how long a revoked session can still be accepted elsewhere. Routes with the same `session.redis` settings share their cache in each worker.

Each worker caches up to 1024 lookups and 1024 store errors. To change that, define the nginx variables `$session_revocation_cache_size` and `$session_revocation_error_cache_size` in an `http` configuration snippet, for example `map $host $session_revocation_cache_size { default 4096; }`. Workers read them once, so a change needs a reload.

#### Logout behavior and limitations

- **Logout revokes every cookie of the same login.** Each save of the session, such as a token renewal or rolling refresh, gives it a new session ID; logout revokes them all, including cookies refreshed before or after the logout. A new login is not affected.
- **Cookies issued before lineage IDs existed are revoked one by one.** A cookie saved by a `lua-resty-session` version without lineage IDs, and still valid after an upgrade, is revoked by its own session ID only; its older copies expire at their timeout.
- **In `open` mode (the default), a logout can succeed without revoking anything.** If Redis is unavailable during logout, the cookie is cleared but no marker is written, so a copied cookie stays valid until it times out. Use `closed` if you rely on revocation: the failed write is reported and the session is kept.
- **Revocation markers live only in Redis.** If Redis loses its data, revoked cookies are accepted again until they expire. Use persistence if logouts must survive a restart.
- In `closed` mode, requests with a cookie session get `503` while Redis is unavailable.

### Authorization Code Flow with PAR and DPoP

To use Pushed Authorization Requests (PAR), set `par.enabled` to `true`. If `par.endpoint` is not configured, the Plugin uses the PAR endpoint from the well-known discovery document.
Expand Down
40 changes: 39 additions & 1 deletion docs/zh/latest/plugins/openid-connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ import TabItem from '@theme/TabItem';
| session.absolute_timeout | integer | 否 | | | 会话绝对生存时间(秒)。作为 `absolute_timeout` 透传到 lua-resty-session。 |
| session.cookie.lifetime | integer | 否 | | | 已弃用。当未设置 `session.absolute_timeout` 时,运行时会将该值映射到 `session.absolute_timeout`。请改用 `session.absolute_timeout`。 |
| session.storage | string | 否 | cookie | ["cookie", "redis"] | 会话存储方式。 |
| session.redis | object | 否 | | | `storage` 为 `redis` 时的 Redis 配置。 |
| session.revocation | string | 否 | | ["redis"] | 会话吊销后端。设置为 `redis` 可为 Cookie 会话启用吊销功能。必须配置 `session.redis`,且不能在 `session.storage` 为 `redis` 时使用。 |
| session.revocation_fail_mode | string | 否 | open | ["open", "closed"] | 当吊销存储不可用时,`open` 将会话视为未吊销,`closed` 则拒绝打开和销毁会话。 |
| session.revocation_cache_ttl | integer | 否 | 5 | | 成功吊销查询的 worker 本地缓存 TTL(秒)。`0` 禁用。 |
| session.revocation_error_cache_ttl | integer | 否 | 5 | | 吊销存储错误的 worker 本地缓存 TTL(秒)。`0` 禁用。 |
| session.redis | object | 否 | | | Redis 连接配置。当 `storage` 为 `redis`,或 `revocation` 为 `redis` 时必填。 |
| session.redis.host | string | 否 | 127.0.0.1 | | Redis 主机。 |
| session.redis.port | integer | 否 | 6379 | | Redis 端口。 |
| session.redis.username | string | 否 | | | Redis 用户名。 |
Expand Down Expand Up @@ -356,6 +360,40 @@ spec:

详见[实现授权码授权](../tutorials/keycloak-oidc.md#实现-authorization-code-grant),获取使用 `openid-connect` 插件与 Keycloak 集成并使用授权码流程的完整示例。

### Cookie 会话吊销

Cookie 会话存储在客户端,APISIX 通常无法单独将其失效。要启用服务端吊销,请将 `session.revocation` 设置为 `redis` 并配置 Redis 拒绝列表:

```json
"session": {
"secret": "your-session-secret-min-16-chars",
"storage": "cookie",
"revocation": "redis",
"revocation_fail_mode": "closed",
"revocation_cache_ttl": 5,
"revocation_error_cache_ttl": 1,
"redis": {
"host": "127.0.0.1",
"port": 6379,
"prefix": "oidc:session"
}
}
```

`revocation_fail_mode` 默认为 `open`,即吊销存储不可用时继续接受会话;`closed` 则会拒绝打开和销毁会话。每个 worker 会将查询结果缓存 `revocation_cache_ttl` 秒、将存储错误缓存 `revocation_error_cache_ttl` 秒,因此并非每个请求都访问 Redis。将两者都设为 `0` 即可让每个请求都查询 Redis。省略 `revocation` 即不启用吊销。

登出在处理该请求的 worker 上立即生效,在其他 worker 上则在其缓存条目过期后生效,因此 `revocation_cache_ttl` 限定了已吊销的会话在其他 worker 上仍可能被接受的最长时间。使用相同 `session.redis` 配置的路由在每个 worker 中共享同一份缓存。

每个 worker 最多缓存 1024 条查询结果和 1024 条存储错误。如需调整,请在 `http` 配置片段中定义 nginx 变量 `$session_revocation_cache_size` 和 `$session_revocation_error_cache_size`,例如 `map $host $session_revocation_cache_size { default 4096; }`。worker 只读取一次,因此修改后需要重新加载。

#### 登出行为与限制

- **登出会吊销同一次登录产生的所有 Cookie。** 会话每次保存(例如令牌续期或滚动刷新)都会生成新的会话 ID;登出会将它们全部吊销,包括在登出之前或之后刷新得到的 Cookie。新的登录不受影响。
- **在引入谱系 ID 之前签发的 Cookie 只能逐个吊销。** 由不支持谱系 ID 的 `lua-resty-session` 版本保存、升级后仍然有效的 Cookie 只会按其自身的会话 ID 吊销,它较早的副本会在超时后失效。
- **在 `open` 模式(默认)下,登出可能在没有吊销任何内容的情况下成功。** 如果登出时 Redis 不可用,Cookie 会被清除但不会写入吊销标记,因此被复制的 Cookie 在超时之前仍然有效。依赖吊销功能时请使用 `closed`:写入失败会返回错误,且会话会被保留。
- **吊销标记只保存在 Redis 中。** 如果 Redis 丢失数据,已吊销的 Cookie 在过期之前会再次被接受。如果登出必须在重启后仍然有效,请启用持久化。
- 在 `closed` 模式下,Redis 不可用时携带 Cookie 会话的请求会收到 `503`。

### 使用 PAR 和 DPoP 的授权码流程

如需使用 Pushed Authorization Requests (PAR),请将 `par.enabled` 设置为 `true`。如果未配置 `par.endpoint`,插件将使用 well-known 发现文档中的 PAR 端点。
Expand Down
Loading
Loading