Skip to content

feat: decision items #88-3 / #105 / #110 — client_id logout, coverage ratchet, key rotation - #176

Merged
wangrh0909 merged 5 commits into
masterfrom
feat/decision-items
Sep 7, 2026
Merged

wangrh0909 merged 5 commits into
masterfrom
feat/decision-items

Conversation

@voidvec

@voidvec voidvec commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Implements the three user-ratified decision items (A/B/B). Recommendations were re-verified by an adversarial review on current master before implementation — all three confirmed; #110-C (defer) noted as degenerate since key rotation is the last remaining IAM-M1 item.

#88-3 — end_session client_id identification (decision A)

RP-Initiated Logout 1.0 §2.1 allows the RP to identify itself via client_id when id_token_hint is absent. The aud-candidate chain now seeds from client_id, so the post_logout_redirect_uri must still be registered for that client (same validateRedirectUri gate — no open redirect; the forced-logout surface is unchanged since a parameterless end_session already terminated sessions). Neither hint nor client_id → the existing 400 envelope.

  • 3 new integration cases (registered→302, unregistered→400, neither→400) + 2 regressions green
  • openapi: client_id query param + description updates; SDKs regenerated

#105 — local coverage ratchet gate (decision B)

measure_coverage.py gains --json and --ratchet BASELINE; coverage.yml gates the existing gcov job:

  • fail when a non-exempt library drops >0.5pp below baseline (trunc-to-0.1pp current)
  • libs with <200 instrumented lines exempt (anti-flake)
  • baseline lib missing from the run fails (lost instrumentation ≠ pass)
  • new libs pass until the next deliberate re-baseline; absent baseline = seed mode (prints JSON, passes)
  • zero external services — consistent with the api-diff/oasdiff/spec-governance self-contained gate style

The committed baseline lands in a follow-up commit seeded from this PR's own CI run.

#110 — signing-key rotation keystore (decision B)

JwkManager becomes a multi-key store:

  • oidc.signing_keystore_dir: <kid>.pem files + active_kid marker file; filename = kid
  • signing uses the active kid; verification routes on the JWT header kid across all loaded keys (absent kid tries all, RFC 7515 §4.1.4); JWKS publishes every key
  • keystore takes precedence over single-key env/path sources; a configured-but-broken directory is a hard startup failure (never a silent different-key fallback)
  • rotation = documented 3-restart procedure (publish → switch → retire after max token TTL) — configuration-guide §9 rewritten from the F-029 to-do into the runbook
  • GET /api/admin/oidc/keys reports the live keystore (keys[] + active/published status + active_kid) instead of the hardcoded stub; endpoint scripts (sh/ps1) assert the new shape; ConfigManager's production key check accepts the keystore
  • 7 new keystore unit tests (shared-PEM rotation semantics, precedence, all structural failure modes) — JwkManagerTest 44/44

Verification

  • full_test 8/8 (incl. EndpointTests_OutOfProcess after the script update)
  • all 8 static gates green (arch-guard / migration-check / api-diff --force: private-member + internal-static signature changes with no released consumer / naming / macro-bool / parity / openapi validate / spec-governance)
  • oasdiff: clean (client_id param is additive-optional)
  • JwkManagerTest 44/44; end_session suite green

Fixes #88
Fixes #105
Fixes #110

…ation, coverage ratchet gate, signing-key rotation keystore

All three ratified by an adversarial re-review on current master (post
#156/#157); recommendations A/B/B confirmed unchanged, with #110-C noted as
degenerate (key rotation is the last remaining IAM-M1 item, and the repo
ships no helm/compose signing-key carrier, so the multi-secret concern was
moot).

#88-3 (decision A): end_session accepts client_id as the RP identification
when id_token_hint is absent (RP-Initiated Logout 1.0 §2.1); the
post_logout_redirect_uri must still be registered for that client (same
validateRedirectUri gate the aud candidates use — no open redirect; session
termination semantics unchanged, and a parameterless end_session already
logged out with no proof). With neither hint nor client_id the 400 envelope
stands. 3 new integration cases + 2 regressions.

#105 (decision B): local coverage ratchet. measure_coverage.py gains --json
and --ratchet BASELINE (fail when a non-exempt library drops >0.5pp below
baseline; <200-instrumented-line libs exempt; baseline lib missing from the
run fails = lost instrumentation; new libs pass until next re-baseline;
absent baseline = seed mode printing the JSON). coverage.yml gates the
existing job (seconds of added compute). Baseline JSON is committed in a
follow-up commit seeded from the first CI run.

#110 (decision B): signing-key rotation keystore. JwkManager loads a
multi-key store (signing_keystore_dir: <kid>.pem files + active_kid
marker), signs with the active kid, verifies by routing on the JWT header
kid across all loaded keys (absent kid tries all — RFC 7515 §4.1.4), and
publishes EVERY key in JWKS. A configured-but-broken keystore is a hard
startup failure (no silent fallback to another key source); the keystore
takes precedence over the single-key env/path sources. Rotation is a
documented 3-restart procedure (publish → switch → retire; see
configuration-guide §9, rewritten from the F-029 to-do). GET
/api/admin/oidc/keys now reports the live keystore (keys[] with
active/published status) instead of the hardcoded stub; ConfigManager's
production key check accepts signing_keystore_dir; endpoint scripts assert
the new shape. 7 new keystore unit tests (44/44 in JwkManagerTest).

Sync: openapi (end_session client_id param + description, jwks multi-key
note, admin keys response) + regenerated openapi.json/Python/Go SDKs;
api-diff baseline ratified --force (private-member/static-signature changes
with no released consumer); all 8 static gates green; full_test 8/8.

Fixes #88
Fixes #105
Fixes #110
@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.

…ion-proof script assertions, JWKS cache note, workflow paths

Adversarial review verdict FIX-FIRST with one required fix (commit the
ratchet baseline before merge -- landing next, seeded from this PR's CI)
and four recommended minors, all applied:

- MINOR-1: loadPemInto rejects non-RSA keys (an EC/Ed25519 pem would
  silently vanish from the JWKS and, as active, sign ECDSA under an
  alg=RS256 header no RP can verify).
- MINOR-2: an unopenable keystore <kid>.pem is a hard init failure --
  silently skipping it would no-op rotation step 1 (Publish).
- MINOR-4: test-admin-endpoints.sh asserts exactly-one-active keyed by
  active_kid instead of keys[0].status (keys[0] is filename-sorted and may
  be a retiring 'published' key under real rotation).
- NOTE: configuration-guide §9 step 1 now says to wait out the JWKS
  Cache-Control max-age (1h) before flipping active_kid.
- MINOR-3: coverage.yml paths include tools/coverage/** so baseline-only
  PRs still run the gate they edit.

JwkManagerTest 44/44 after the hardening.
… loud and locatable

Two CI failures surfaced by this PR's runs:

1. JwkManagerTest.VerifyJwt_Expired_IsExpired_IncludingExactBoundary is a
   1-second wall-clock race (PRE-EXISTING): validClaims(0) took a FRESH
   std::time, so a tick between the test's captured now and token minting
   flipped the boundary assertion from Expired to Ok. The new explicit-base
   validClaims(offset, base) overload pins exp and the verification instant
   to the same now (25x repeat green; the added keystore tests had merely
   shifted scheduling enough to trip it).

2. The coverage pipeline has produced ZERO gcov JSON reports since its
   first run (pre-existing, masked by '|| true' + '>/dev/null'): gcov -j -p
   writes <mangled-path>.gcov.json.gz into the CURRENT directory, not next
   to the .gcda, so 'find libs' never saw them and every summarize/ratchet
   output -- including the ratchet's first seed -- was empty. The step now
   reports repo-wide vs libs/ counts, relocates cwd-left reports into
   libs/, and HARD-FAILS on zero instead of masking (a permanently-empty
   gate is worse than no gate).
…I run

The gcov relocation fix produced 166/166 reports; this baseline is the
verbatim seed JSON from that run (7 libs: common 74.3, drogon 57.8,
identity 87.1, oauth2 88.8, storage-memory 97.0, storage-postgres 54.1,
storage-redis 62.2). Review MAJOR-1 resolved: the gate is armed as of
this commit -- any library dropping >0.5pp below these numbers fails CI.
@voidvec

voidvec commented Sep 5, 2026

Copy link
Copy Markdown
Owner Author

对抗评审处置完毕(FIX-FIRST 必修项 + 全部 4 个推荐 minor + 两个 CI 意外发现),HEAD ff53b15:

MAJOR-1(必修):基线已随本 PR 落地,且带出并修复了一个预先存在的管道缺陷

按计划从本 PR 自己的 CI seed——第一次 seed 输出是空基线,深挖发现这不是 ratchet 的问题:覆盖率管道自首次运行(08-28)就产出 0 份 gcov JSON 报告,gcov -j -p 把报告写进当前目录(带 # 路径前缀的文件名)而非 .gcda 旁边,find libs 从未见过它们,且 || true + >/dev/null 把这一切掩盖成了 success(历次 run 的 step summary 一直是 "0 instrumented lines")。修复:生成步骤自诊断(repo-wide vs libs/ 计数)+ 把 cwd 遗留报告归位到 libs/ + 零输出硬失败。修复后 166/166 报告,seed 出真基线并提交(7 库:common 74.3 / drogon 57.8 / identity 87.1 / oauth2 88.8 / storage-memory 97.0 / storage-postgres 54.1 / storage-redis 62.2)。基线提交后的第一轮门控模式 CI 已实证通过:[ratchet] OK: no library dropped more than 0.5pp below baseline。

MINOR(4/4 已修,c913383a)

  • M1 RSA guard:loadPemInto 拒绝非 RSA 钥(EC/Ed25519 会从 JWKS 消失且以 active 身份签出无人能验的 ECDSA-under-RS256)。
  • M2 unopenable pem 硬失败:不再静默跳过(否则轮换步骤 1 静默 no-op)。
  • M4 sh 断言防轮换:改为"恰一个 active 且其 kid == active_kid"(keys[0] 只是文件序首个,真实轮换下可能是 published)。
  • M3 workflow paths:tools/coverage/** 已入触发路径。
  • NOTE(JWKS cache):§9 步骤 1 已补"等满 JWKS max-age(1h)再翻 active_kid"。

评审之外的 CI 发现(均已修,90a19cd6)

  1. Windows matrix 挂出一个既有 1 秒竞态 flake:VerifyJwt_Expired_IncludingExactBoundary 的 validClaims(0) 另取新鲜 std::time,跨秒即从 Expired 翻成 Ok——新增 validClaims(offset, base) 显式基重载把 exp 与验证时刻钉到同一 now,25x repeat 压测绿(本 PR 新增测试只是挪动了调度时序让它显形)。
  2. 即上述 gcov 管道缺陷(详见 MAJOR-1)。

未处理(按评审 NOTE 级放行)

active_kid 前导空白不对称(fail-closed 方向,信息里有 marker 值)、--json --ratchet 组合(当前无调用方)、CategoryB_JwkManagerRaceTest 引用旧代码的历史注释。

验证

full_test 8/8;JwkManagerTest 44/44;8 项静态门全绿;oasdiff 干净;CI 13 pass + SDK smoke 收尾中;ratchet 门控模式首跑 OK。

@voidvec voidvec left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review — #88-3 / #105 / #110-B

Reviewed ff53b15a against master (merge-base 6435f781; the checked-out tree matches the remote head commit exactly). Overall: architecture is sound, fail-closed behavior is consistent, test coverage is strong — no [CRITICAL]/[MAJOR] blockers. Four inline comments below; everything else:

[NIT] keystore unit tests leave $TEMP/jwkstore_* dirs behind across runs (writeKeystoreDir/makeKeystoreDir use a counter prefix and the leading remove_all prevents contamination, so correctness is unaffected) — optional teardown cleanup.

[INFO] admin GET /api/admin/oidc/keys response is a breaking schema change (flat kid/kty/alg/key_status → keys[] with per-key status: active|published + active_kid + key_count). Scripts/SDK/docs are in sync, so it is a controlled break — worth one line in the CHANGELOG for external admin integrators.

[INFO] the ratchet baseline is seeded from this PR's own CI run, so the gate only binds from the next PR onward (documented decision). Before merge, a quick sanity check that no lib (esp. oauth2, +334 lines) regressed vs master would be nice since there is no master baseline to diff against — oauth2 88.8% includes all new code plus the 7 keystore tests, so it looks healthy.

[INFO] no-session end_session with a verified hint fans out backchannel logout from hintSub (SessionController.cc 2023-2027). Post-#78 this requires a valid, unexpired id_token, so it is not a new surface — flagging the tradeoff (id_token secrecy matters here) for the record; consider a decision note.

I also compared the push vs pull_request path filters in coverage.yml: the asymmetry (push lacks the script/workflow/CMake entries) is pre-existing on master, not introduced by this PR — this PR adds tools/coverage/** symmetrically to both triggers. No action needed here.

Conclusion: no blockers; the two [MINOR]s are cheap consistency fixes worth doing before merge, #3 could be a follow-up.

Comment thread apps/server/openapi.yaml
(RP-Initiated Logout 1.0 §2.1). The post_logout_redirect_uri must be
registered for this client (#88-3).'
in: query
name: client_id

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MINOR] client_id is documented here for the GET variant (#88-3), but the POST /oauth2/end_session variant in this same file was not updated: it still only declares id_token_hint/post_logout_redirect_uri/state, and its 400 description still reads "missing hint for a supplied post_logout_redirect_uri". Since GET and POST are registered to the same endSession handler (SessionController.cc 1876-1888) reading req->getParameters(), POST + client_id actually works in the implementation — the gap is spec/SDK-side (generated Python/Go POST clients won't expose the parameter). Suggest declaring client_id on the POST variant too and unifying the 400 text, then re-running the SDK regen.

const bool hasEnvKey = keyEnv && std::strlen(keyEnv) > 0;
const bool hasEnvPath = keyPathEnv && std::strlen(keyPathEnv) > 0;
if (!hasEnvKey && !hasEnvPath && configKeyPath.empty())
if (!hasEnvKey && !hasEnvPath && configKeyPath.empty() && configKeystoreDir.empty())

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MINOR] configKeystoreDir now counts as a valid production signing-key source (#110-B), but the production-gate tests in tests/unit/config/ConfigManagerTest.cc only cover env and signing_key_path. This branch is the gate for keystore deployments — a misconfiguration slips past validate() and only hard-fails later when OAuth2Plugin exits. Suggest one test: plugins → OAuth2Plugin → config.oidc.signing_keystore_dir non-empty ⇒ validate() == true.

Comment thread scripts/measure_coverage.py Outdated
)
continue
base_pct = float(entry["pct"])
if tot[lib] < MIN_LINES:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MINOR] The exemption is keyed on the current run's instrumented-line count. If a library that has thousands of lines in the baseline loses most of its data in a run (test crash / partial instrumentation) and lands below MIN_LINES, it gets exempted instead of failing; only a library that vanishes entirely from tot fails today. Suggest basing the exemption on the baseline total: if base_total >= MIN_LINES but the current total collapses below MIN_LINES, that should FAIL — exempt only when the baseline total itself is < MIN_LINES.

Comment thread libs/oauth2/src/jwk/JwkManager.cc Outdated
if (!item.is_regular_file())
continue;
const std::string filename = item.path().filename().string();
if (filename.size() <= 4 || filename.substr(filename.size() - 4) != ".pem")

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT] Suffix check is case-sensitive — an operator naming a key <kid>.PEM (Windows) silently gets it skipped, and the active_kid marker trimming only strips trailing whitespace (291-297), so a leading space would mismatch too. Both end in a hard fail (safe direction), just potentially confusing log output. Optional: case-insensitive suffix match, trim both ends of the marker line, and state the conventions (lowercase .pem, no leading whitespace) in the hard-fail messages.

…ir gate test, baseline-keyed ratchet exemption, keystore filename hardening, changelog

Review round 2 (no blockers; 3 MINOR + 1 NIT + INFOs, all addressed):

- MINOR-1: openapi declares client_id on the POST /oauth2/end_session
  variant too (the handler reads it already) and the 400 text is unified
  across GET/POST; SDKs regenerated.
- MINOR-2: ConfigManager production-gate test for oidc.signing_keystore_dir
  as a standalone key source (misconfiguration now fails validate() with
  the signing-key message instead of only at plugin exit).
- MINOR-3: the ratchet exemption is keyed on the BASELINE total, not the
  current run's -- a library whose instrumented lines collapse below
  MIN_LINES while its baseline was above now FAILS with an explicit
  'partial instrumentation' message (synthetic scenarios verified:
  healthy=OK, collapse=FAIL, baseline-tiny=exempt).
- NIT: keystore .pem suffix match is case-insensitive AND opens the ACTUAL
  filename (opening kid+'.pem' on a case-sensitive FS would have turned a
  detected .PEM into a hard fail); active_kid marker trims both ends.
- INFO: CHANGELOG [Unreleased] records the admin /api/admin/oidc/keys
  response-shape change for external integrators plus the two features.

Verified: build green, JwkManagerTest 44/44, new config gate test + hint
end_session regression green, all static gates + governance + oasdiff clean.
@voidvec

voidvec commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

评审第二轮处置完毕(3 MINOR + 1 NIT 全修,INFO 逐条回应),HEAD 7463a9a:

MINOR(3/3 已修)

M1 POST 变体缺 client_id 声明 — openapi 的 POST /oauth2/end_session 现在声明 client_id(实现侧本就经 req->getParameters() 生效),GET/POST 的 400 文案统一为 "neither id_token_hint nor client_id supplied…";Python/Go SDK 已再生成(POST 客户端现在暴露该参数)。

M2 keystore 目录缺 validate() 门测试 — 新增 Unit_P0_ConfigManager_Production_ConfigOidcKeystoreDir_Passes:仅配 oidc.signing_keystore_dir 的生产配置过 validate();配置错误现在停在带 signing-key 语义的早期报错,而不是等到 plugin exit。

M3 豁免键在当前运行总行数上 — 已改为键在基线总行数:基线 ≥ MIN_LINES 而当前塌缩到 < MIN_LINES 直接 FAIL(消息明说 "partial instrumentation or a crashed test run");只有基线本身 < MIN_LINES 的库才豁免。三个合成场景实证:healthy=OK / collapse=FAIL / baseline-tiny=exempt。

NIT(已修,含一处自查加固)

.pem 后缀大小写不敏感匹配;且打开的是真实文件名(自查发现:只改匹配不改打开,在大小写敏感 FS 上检测到的 .PEM 会变成 "cannot be opened" 硬失败);active_kid 两端 trim。约定(小写 .pem、marker 顶格)写进注释与报错语境。

INFO 逐条

  • CHANGELOG:已加 [Unreleased] 段——admin keys 响应形状变化(标注 ⚠️ Breaking (admin API) 并指路 JWKS 取钥材料)+ POST client_id + 两个 feature 条目;release 时 cliff 策展可见。
  • 基线自证:oauth2 88.8% 含全部新增 334 行 + 7 个 keystore 测试,是本 PR 自己的 run 造出的基线(无 master 基线可对比——这正是管道此前空转的后果,现已 armed,下一 PR 起有硬基线)。
  • hintSub backchannel(无 session + 已验 hint → 按 hint sub 通知):同意是 [High] Unauthenticated cross-user forced logout: /oauth2/end_session trusts unverified id_token_hint sub for backchannel fan-out #78 后既有权衡非新增面;作为决策注记已在本评论留档(id_token 保密性 = 该面的边界条件)。不改代码。
  • $TEMP/jwkstore_ 残留*:接受为 NIT 不处理(remove_all 前清已保证正确性;失败路径残留本身有调试价值)。
  • coverage.yml push/pull 路径不对称:确认 pre-existing,本 PR 已对称加 tools/coverage/**。

验证

构建绿;JwkManagerTest 44/44;新增 config 门测试 + hint 端到端回归绿;api-diff/naming/migration/governance/oasdiff 全绿;CI 重跑中。

@wangrh0909
wangrh0909 merged commit 2960648 into master Sep 7, 2026
16 checks passed
wangrh0909 pushed a commit that referenced this pull request Sep 7, 2026
…ion-proof script assertions, JWKS cache note, workflow paths

Adversarial review verdict FIX-FIRST with one required fix (commit the
ratchet baseline before merge -- landing next, seeded from this PR's CI)
and four recommended minors, all applied:

- MINOR-1: loadPemInto rejects non-RSA keys (an EC/Ed25519 pem would
  silently vanish from the JWKS and, as active, sign ECDSA under an
  alg=RS256 header no RP can verify).
- MINOR-2: an unopenable keystore <kid>.pem is a hard init failure --
  silently skipping it would no-op rotation step 1 (Publish).
- MINOR-4: test-admin-endpoints.sh asserts exactly-one-active keyed by
  active_kid instead of keys[0].status (keys[0] is filename-sorted and may
  be a retiring 'published' key under real rotation).
- NOTE: configuration-guide §9 step 1 now says to wait out the JWKS
  Cache-Control max-age (1h) before flipping active_kid.
- MINOR-3: coverage.yml paths include tools/coverage/** so baseline-only
  PRs still run the gate they edit.

JwkManagerTest 44/44 after the hardening.
wangrh0909 pushed a commit that referenced this pull request Sep 7, 2026
…I run

The gcov relocation fix produced 166/166 reports; this baseline is the
verbatim seed JSON from that run (7 libs: common 74.3, drogon 57.8,
identity 87.1, oauth2 88.8, storage-memory 97.0, storage-postgres 54.1,
storage-redis 62.2). Review MAJOR-1 resolved: the gate is armed as of
this commit -- any library dropping >0.5pp below these numbers fails CI.
@voidvec
voidvec deleted the feat/decision-items branch September 7, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants