Skip to content

feat(auth): OIDC Back-Channel Logout 1.0 notifier + admin config - #50

Closed
voidvec wants to merge 9 commits into
masterfrom
feat/backchannel-logout-b1
Closed

voidvec wants to merge 9 commits into
masterfrom
feat/backchannel-logout-b1

Conversation

@voidvec

@voidvec voidvec commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

What

Real OIDC Back-Channel Logout 1.0 — replaces the LoggingBackchannelLogoutNotifier stub. On logout the OP finds every relying party with an active session for the user and a registered backchannel_logout_uri, and POSTs a signed logout_token to each (fire-and-forget). Includes the full config path (admin API + admin UI) and endpoint test coverage.

Design doc: docs/productization-evolution/in-progress/backchannel-logout-design.md.

Key finding (verified)

oauth2_access_tokens.user_id stores the public subject (public_sub), identical to the userId notify() receives (TokenService.cc:172,343) and to the id_token sub. So no subject mapping is needed — query tokens by user_id and use it as the logout_token sub.

Changes

  • libs/oauth2 — LogoutToken: pure buildLogoutTokenClaims() (iss/sub/aud/iat/exp/jti/events, no nonce per §2.4) + generateJti().
  • libs/drogon — BackchannelLogoutNotifier (Adapter layer): notify() chains two async Mapper queries (active tokens → distinct client_ids → clients with a URI; no JOIN) then dispatch() signs + POSTs per-RP, fire-and-forget, auditing each. enable_shared_from_this; per-Mapper try-catch that always reaches the callback.
  • IdentityAssembly — wires the real notifier; deletes the logging stub + SessionController's dead stub.
  • DiscoveryController — backchannel_logout_supported=true, backchannel_logout_session_supported=false (subject-scoped, no sid).
  • ClientManagementService — create/update read+validate+persist backchannel_logout_uri (https; empty-on-update clears to NULL); get/list surface it. RuleSet — validateBackchannelLogoutUri() (https per §2.3; honors the auth.allow_http_redirect_uri dev hatch; loopback NOT exempt). openapi.yaml — requestBody schemas for POST/PUT /api/admin/clients.
  • Admin UI — backchannel_logout_uri field in ApplicationDetailPage (Auth Config tab) + ApplicationsPage create modal.
  • IOAuthHttpClient / DrogonOAuthHttpClient — ungated from WITH_SOCIAL.

logout_token

RS256 JWT (same OP key/kid as id_token). Claims: {iss, sub, aud=clientId, iat, exp=iat+120, jti, events={"http://schemas.openid.net/event/backchannel-logout":{}}}; no nonce. POSTed as application/x-www-form-urlencoded logout_token=<jwt>.

Tests (all green locally, full 8-step pipeline)

  • Unit: LogoutTokenTest (U1–U3) — exact claim set/no nonce, exp=iat+ttl, jti uniqueness. BackchannelLogoutNotifierTest (D1–D6) — per-client fan-out with matching aud/sub, skip empty URI, transport failure audited + others still notified, non-200=failure/200=success, RS256 signature verifies against the signing key (kid matches), completion-after-dispatch. Unit_P0_Validation_BackchannelLogoutUri_AllScenarios — scheme policy incl. loopback-not-exempt.
  • Endpoint suites (sh+ps1): admin Tests 44–46 (set/read/clear lifecycle; non-https 400 via ftp:// since test configs enable the http dev hatch; create-with-uri + read-back + cleanup) and discovery Test 3 asserts both backchannel flags. Admin suite 52→55 tests.
  • Full local pipeline: 462/462 ctest after the seeded-client fix (api-service was a frontend mock id — tests now target vue-client).

Follow-ups (not blocking)

  • Full e2e POST-to-RP integration test (needs a mock RP listener; dispatch logic is unit-covered D1–D6).
  • sid issuance (clients with backchannel_logout_session_required=true — documented gap); cross-client token revocation on logout; configurable HTTP timeout/retry; RP response-body validation; RFC 7591 backchannel_logout_uri.

Safety

Default config (no client has a backchannel_logout_uri) → zero POSTs, identical to prior behavior.

The outbound-HTTP port (IOAuthHttpClient) and its Drogon adapter
(DrogonOAuthHttpClient) were only compiled under WITH_SOCIAL because their
sole consumer was social login. OIDC Back-Channel Logout (B1) is a core
feature that needs the same postForm() transport to deliver logout_tokens,
so the port + adapter can no longer be social-gated.

- Drop the #ifdef WITH_SOCIAL guards from IOAuthHttpClient.h and
  DrogonOAuthHttpClient.{h,cc} (FakeOAuthHttpClient was already ungated).
- Move IOAuthHttpClient.h out of the social-only header group in
  libs/identity/CMakeLists.txt so it is a declared public header regardless
  of WITH_SOCIAL. DrogonOAuthHttpClient.cc was already always compiled by
  the GLOB; its body now defines symbols unconditionally.

No behavior change for social builds; non-social builds now also provide the
port + adapter.
First slice of B1 (OIDC Back-Channel Logout 1.0): the real notifier and the
pure logout_token claim builder, with full unit coverage. Wiring into the
logout flow + admin/UI config follow in subsequent commits.

- libs/oauth2: LogoutToken.{h,cc} -- pure buildLogoutTokenClaims() (iss/sub/
  aud/iat/exp/jti/events, no nonce per spec §2.4) + generateJti(). Unit tests
  assert the exact claim set, exp=iat+ttl, and jti uniqueness.
- libs/drogon: BackchannelLogoutNotifier -- the real Adapter-layer
  IBackchannelLogoutNotifier. notify() chains two async Mapper queries (active
  tokens for the user -> distinct client_ids -> clients with a
  backchannel_logout_uri, no JOIN per db-operations.md) then dispatch().
  dispatch() signs a per-RP logout_token and POSTs it fire-and-forget,
  auditing each attempt; logout responses are never blocked by RP round-trips.
  enable_shared_from_this + per-Mapper try-catch that always reaches the
  callback.
- libs/drogon/test: dispatch unit tests (D1-D6) with an ephemeral-key
  JwkManager + FakeOAuthHttpClient + FakeAuditSink, including RS256 signature
  verification of the logout_token against the signing key.

Not yet wired into IdentityAssembly (still uses the logging stub).
- IdentityAssembly: replace the LoggingBackchannelLogoutNotifier stub with
  the real BackchannelLogoutNotifier (dbClient + plugin signing key/issuer/
  audit sink + the shared DrogonOAuthHttpClient). Move oauthHttpClient
  construction out of the WITH_SOCIAL block so the notifier always has a
  transport (social reuses the same instance).
- SessionController: delete the dead sendBackchannelLogoutNotifications()
  stub; the sessionManager_==null branch (memory/no-DB configs, where there
  are no clients to notify) now just responds.
- DiscoveryController: advertise OIDC Back-Channel Logout 1.0 support --
  backchannel_logout_supported=true, backchannel_logout_session_supported=
  false (subject-scoped logout_tokens, no sid).
The backchannel_logout_uri column (V015) was writable nowhere -- admin API,
RFC 7591 registration, and the admin UI all ignored it, so the notifier added
in the previous commit could never be exercised in production. This wires the
write/read path through the client admin service.

- RuleSet: new validateBackchannelLogoutUri() -- OIDC §2.3 https requirement
  (empty == not configured), honoring the auth.allow_http_redirect_uri dev
  hatch; loopback NOT exempt (server-to-server).
- ClientManagementService: createClient/updateClient read, validate (https),
  and persist backchannel_logout_uri (empty on update clears it to NULL);
  getClient/listClients surface backchannel_logout_uri (+ session_required on
  the detail endpoint).
- openapi.yaml: add requestBody schemas (with backchannel_logout_uri) to
  POST/PUT /api/admin/clients -- these operations previously had none.
…s row

Mark Backchannel Logout backend as delivered on feat/backchannel-logout-b1
(notifier + logout_token builder + admin config + discovery + unit tests
D1-D6), and record that the admin-UI forms are ready but blocked by a Mimosa
false-positive on pre-existing mock-api.ts fixtures, and that integration
tests are pending (need PostgreSQL).
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@voidvec

voidvec commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

Code Review — Back-Channel Logout (feat/backchannel-logout-b1)

代码已逐文件核对(LogoutToken.cc / BackchannelLogoutNotifier.cc / SessionManager.cc / IdentityAssembly.cc / DiscoveryController.cc / 迁移 V015 / ClientManagementService.cc / RuleSet.cc)。整体实现扎实、规范对齐良好,未发现必须阻塞合入的崩溃级 bug。 以下是经代码验证的结论与建议项。

已验证正确的关键点

  • logout_token claim 集合完全符合 OIDC Back-Channel Logout 2.4:iss/sub/aud(=client_id)/iat/jti/events(含规范 URN 空对象),且无 nonce、无 sid(当前 OP 不签发 session id,省略是正确选择)。测试 LogoutTokenTest U1-U3 已覆盖。
  • 目标筛选正确:Query1 用 revoked=false OR revoked IS NULL + expires_at > now 过滤(BackchannelLogoutNotifier.cc:84-89),与 TokenManagementService::listTokens 一致;clientIds 为空时直接完成回调、不发起查询,安全。
  • 每 client 仅发一次:clientIds 为 std::set 去重,按 client 扇出,符合规范“每 RP 一个 logout_token”要求。
  • 触发链完整:SessionController::logout → sessionManager->logout → notifier_->notify(已替换旧 LoggingBackchannelLogoutNotifier 桩,死 stub sendBackchannelLogoutNotifications 已删除);IdentityAssembly.cc:120 已注入真实 curl 通知器。
  • Discovery 广告正确:backchannel_logout_supported:true / backchannel_logout_session_supported:false,并对需要 sid 的 RP 做了 documented gap 说明。

建议修(非阻塞)

  1. jti 跨 RP 复用(BackchannelLogoutNotifier.cc:91):jti 在 notify() 中只生成一次,所有 RP 的 logout_token 共享同一 jti。2.4 要求每个 logout_token 的 jti 唯一(防重放)。当前按 audience 隔离通常可接受,但严格合规应每个收件人单独 generateJti()。
  2. 缺少 typ:"logout+jwt" 头:规范建议 logout_token 的 JOSE 头带 typ:"logout+jwt"(与本项目 userinfo 校验要求 typ:"at+jwt" 立场一致)。部分严格 RP 会据此拒绝。建议在 buildLogoutTokenClaims/签名处加入。
  3. 无重试/队列(已知限制,可接受):dispatch() 立即完成 fire-and-forget 回调,transport 失败仅审计不重试。作为 best-effort 设计可接受,但建议在文档中明确“通知不保证送达”。

结论

可合入。上述 1/2 为合规增强建议,3 为设计说明。无必须修项。

- ApplicationDetailPage (Auth Config tab): editable Backchannel Logout URI,
  loaded from getClient and sent on save (only when changed).
- ApplicationsPage (create modal): optional Backchannel Logout URI field,
  included in the create payload.
…overy endpoint tests

- ValidatorTest: Unit_P0_Validation_BackchannelLogoutUri_AllScenarios —
  https valid, empty valid (not configured), scheme-less/ftp invalid; http
  expectations read from the live config because the test env enables
  auth.allow_http_redirect_uri (dev hatch honored by the validator). Loopback
  http is NOT free (unlike redirect_uri) — gated by the same hatch.
- Admin endpoint suite (sh+ps1): Test 44 backchannel_logout_uri
  set/read/clear lifecycle; Test 45 non-https scheme rejected 400 (ftp:// —
  plain http is not a reliable negative under the dev hatch); Test 46 create
  client with backchannel_logout_uri + read-back + cleanup. ps1 $total 52→55.
- OAuth2 endpoint suite (sh+ps1): Test 3 discovery now asserts
  backchannel_logout_supported=true and backchannel_logout_session_supported
  =false (subject-scoped logout_tokens, no sid).
Test 44/45 hit /api/admin/clients/api-service, which is a frontend e2e MOCK
id — no such client exists in the seed data, so Test 44's first PUT returned
404 (Test 45 passed only because scheme validation (400) fires before the
client lookup). Target the seeded vue-client instead; the lifecycle test
restores it (clears to NULL) immediately.
voidvec added a commit that referenced this pull request Aug 14, 2026
…1 delivery

Restores the memory-verdict updates lost when the working tree was
switched to feat/user-management-crud-v2 (the previous edits were never
committed), and syncs all tracking docs with the newly delivered work:

Memory verdict (⚠️ → ✅, re-applied across 4 docs):
- SDK embedding scope measured 2026-08-13: third-party-host-smoke
  (pure SDK) peak working set 2.5 MB / private 0.6 MB / binary 12 MB;
  full-stack-host-smoke (SDK+Drogon) also 2.5 MB peak
- 50-120MB claim conservatively MET — actual SDK logic layer far below
- docker stats 2.4GB is a different scope (container: pools + shared
  libs + page cache), not comparable to the SDK claim

Newly delivered work synced:
- A2 user management CRUD — IMPLEMENTED (PR #52): pagination, search,
  createUser, updateUser expansion, deleteUser soft-delete (V024)
- D1 Backchannel Logout — BACKEND DELIVERED (PR #50): notifier +
  logout_token JWT + admin API + discovery + unit tests D1-D6;
  frontend blocked by Mimosa false-positive, integration tests pending
- Phase 2 completion raised ~25% → ~45%; Phase 0 raised ~85% → ~90%
- IAM audit: user mgmt + backchannel logout rows updated to delivered
- next-phase plan: completed-tiers table extended, A2/B1 sections
  marked delivered, dependency graph + risk matrix + decision items
  updated (decisions 1-3 now resolved)
@voidvec

voidvec commented Aug 14, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #61 — same content rebased onto current master (post #52), plus the admin-UI forms and the endpoint/unit test coverage that landed after this PR was opened. Closing in favor of the clean branch.

@voidvec voidvec closed this Aug 14, 2026
@voidvec
voidvec deleted the feat/backchannel-logout-b1 branch August 14, 2026 11:02
voidvec added a commit that referenced this pull request Aug 15, 2026
…1 delivery

Restores the memory-verdict updates lost when the working tree was
switched to feat/user-management-crud-v2 (the previous edits were never
committed), and syncs all tracking docs with the newly delivered work:

Memory verdict (⚠️ → ✅, re-applied across 4 docs):
- SDK embedding scope measured 2026-08-13: third-party-host-smoke
  (pure SDK) peak working set 2.5 MB / private 0.6 MB / binary 12 MB;
  full-stack-host-smoke (SDK+Drogon) also 2.5 MB peak
- 50-120MB claim conservatively MET — actual SDK logic layer far below
- docker stats 2.4GB is a different scope (container: pools + shared
  libs + page cache), not comparable to the SDK claim

Newly delivered work synced:
- A2 user management CRUD — IMPLEMENTED (PR #52): pagination, search,
  createUser, updateUser expansion, deleteUser soft-delete (V024)
- D1 Backchannel Logout — BACKEND DELIVERED (PR #50): notifier +
  logout_token JWT + admin API + discovery + unit tests D1-D6;
  frontend blocked by Mimosa false-positive, integration tests pending
- Phase 2 completion raised ~25% → ~45%; Phase 0 raised ~85% → ~90%
- IAM audit: user mgmt + backchannel logout rows updated to delivered
- next-phase plan: completed-tiers table extended, A2/B1 sections
  marked delivered, dependency graph + risk matrix + decision items
  updated (decisions 1-3 now resolved)
wangrh0909 pushed a commit that referenced this pull request Aug 16, 2026
…1 delivery

Restores the memory-verdict updates lost when the working tree was
switched to feat/user-management-crud-v2 (the previous edits were never
committed), and syncs all tracking docs with the newly delivered work:

Memory verdict (⚠️ → ✅, re-applied across 4 docs):
- SDK embedding scope measured 2026-08-13: third-party-host-smoke
  (pure SDK) peak working set 2.5 MB / private 0.6 MB / binary 12 MB;
  full-stack-host-smoke (SDK+Drogon) also 2.5 MB peak
- 50-120MB claim conservatively MET — actual SDK logic layer far below
- docker stats 2.4GB is a different scope (container: pools + shared
  libs + page cache), not comparable to the SDK claim

Newly delivered work synced:
- A2 user management CRUD — IMPLEMENTED (PR #52): pagination, search,
  createUser, updateUser expansion, deleteUser soft-delete (V024)
- D1 Backchannel Logout — BACKEND DELIVERED (PR #50): notifier +
  logout_token JWT + admin API + discovery + unit tests D1-D6;
  frontend blocked by Mimosa false-positive, integration tests pending
- Phase 2 completion raised ~25% → ~45%; Phase 0 raised ~85% → ~90%
- IAM audit: user mgmt + backchannel logout rows updated to delivered
- next-phase plan: completed-tiers table extended, A2/B1 sections
  marked delivered, dependency graph + risk matrix + decision items
  updated (decisions 1-3 now resolved)
voidvec added a commit that referenced this pull request Aug 17, 2026
CHANGELOG for v1.2.0 (61 commits since v1.1.0): #43 resource-scope
authorization model, A2 user-management CRUD (PR #52), B1 back-channel
logout backend (PR #50), A1 OpenAPI spec governance M0 + breaking-change
gates (PR #63), benchmark M2-M4 load-bearing verdicts (PR #48), and the
#53-#60 user-admin hardening batch (PR #62).

Per the release SOP (docs/backend/versioning-and-release.md §11.1):
draft via `git cliff --unreleased --tag v1.2.0 --prepend`, then
hand-curated (themed sections, security-hardening migrations, noise
removed). Version SSoT already bumped to 1.2.0 in e5548ec; api-diff and
the new spec-governance gate verified OK on the release ref.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant