Skip to content

feat(authz): resource-scope authorization model (#43) - #49

Merged
voidvec merged 20 commits into
masterfrom
feat/resource-scope-authorization-43
Aug 14, 2026
Merged

voidvec merged 20 commits into
masterfrom
feat/resource-scope-authorization-43

Conversation

@voidvec

@voidvec voidvec commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the full resource-scope authorization model per the design doc §10.1 decisions. Replaces the minimal F-010 path→scope mapping with a single declarative registry, fine-grained <resource>:read|write scopes, per-requirement scope implication, a unified insufficient_scope emitter, data-driven Tier-2 admin-role check, and a discovery endpoint.

RFC compliance

Requirement Basis Implementation
insufficient_scope → 403 RFC 6750 §3.1 Single InsufficientScopeResponder shared by both filters
WWW-Authenticate scope attr (multi-scope space-join) RFC 6750 §3 buildInsufficientScopeChallenge — R1 fix
userinfo M2M → 401 invalid_token (not 403) OIDC Core §5.3 Handler-level split — R2 fix
OpenAPI scope binding OpenAPI 3.0.3 x-required-scopes extension (bearer scheme has no scope semantics) — R3
Scope implication (admin → leaf scopes) RFC 6749 §3.3 Per-requirement impliedBy, no hardcoded graph

Changes by layer

Foundation (libs/drogon/authz/ — new):

  • ResourceScopeRegistry — (path,method)→scopes registry with exact-template + prefix-fallback matching; bidirectional startup consistency check (LOG_FATAL on gap or orphan)
  • ScopeResolver — satisfies() with per-requirement implication; multi-scope challenge builder
  • InsufficientScopeResponder — single RFC 6750 §3.1 emitter

Controllers (7 controllers migrated from static-init struct → initApiDocs()):

  • UserAdmin, ClientAdmin, TokenAdmin, RoleScopeAdmin, Audit, UserSelfService, OrganizationController
  • Each declares granular <resource>:read|write scopes, impliedBy={"admin"}

Filters:

  • OAuth2AuthFilter + AuthorizationFilter switched from hardcoded requiredScopeForPath → registry.lookup() + satisfies()

Data model + DB-driven Tier-2 (§5.5):

  • V006 rewritten: dropped read/write; seeded OIDC + admin + 9 resource scopes
  • isAdminScope() deleted; engine takes a scopeRequiresAdmin predicate backed by oauth2_scopes.requires_admin_role (loaded at startup)
  • dev_backend_client.sql seed updated to new vocabulary

Discovery:

  • GET /api/admin/scopes/resources — scope→resource matrix
  • OpenAPI x-required-scopes + x-scope-implied-by extensions

Frontend:

  • ConsentPage.vue scope descriptions updated
  • ScopesPage.vue BUILTIN_SCOPES expanded
  • ApplicationDetailPage.vue unchanged (data-driven, auto-adapts)

Test infrastructure (方案 A):

  • Out-of-process endpoint tests (59 OAuth2 + 52 Admin) integrated into ctest via EndpointTests_OutOfProcess wrapper — no more silent omissions

Test results

Environment ctest Endpoint tests Frontend
Windows 452/452 ✅ 59/59 + 52/52 ✅ tsc + build + e2e 26/26 ✅
WSL 456/457 ✅ (SdkSmoke=drogon_ctl missing) 59/59 + 52/52 ✅ —

Breaking changes (⚠️ security hardening, per §3)

  • Legacy bare read/write scopes removed (decision refactor: repo structure reorganization (P0-P12) #2: no deployed tokens)
  • Admin routes now require concrete <resource>:read|write (the admin super-scope still satisfies all via implication)
  • ScopeDecisionEngine::evaluateScope signature changed (added scopeRequiresAdmin predicate)

Version

This PR does not bump the version. Per the versioning policy, version bump is done on master after merge (chore(release): v1.2.0). Recommended: MINOR — feat: + security hardening §3 (no deployed users to break).

Closes #43.

Replace the minimal path->scope mapping (F-010) with a full per-resource
authorization model: a single declarative registry of (path,method)->scopes,
fine-grained <resource>:read|write scopes, per-requirement scope implication,
a unified insufficient_scope emitter, data-driven Tier-2 admin-role check,
and a discovery endpoint.

Foundation (libs/drogon/authz/):
- ResourceScopeRegistry: (path,method)->scopes with exact-template +
  prefix-fallback matching; bidirectional startup consistency check
  (LOG_FATAL on orphan or missing-entry).
- ScopeResolver: satisfies() with per-requirement impliedBy (admin
  super-scope satisfies leaf scopes); multi-scope WWW-Authenticate
  challenge (RFC 6750 §3 space-delimited).
- InsufficientScopeResponder: single RFC 6750 §3.1 emitter shared by both
  filters (R1: scope attr always present + space-joined).

Controller declarations (Option A):
- 7 controllers migrated from static-init docs struct -> initApiDocs()
  (also fixes SIOF defect 1.1) with granular scopes + impliedBy=admin.
- Both filters switch from hardcoded requiredScopeForPath to
  registry.lookup() + satisfies().

Data model + DB-driven Tier-2 (§5.5):
- V006 rewritten: drop legacy read/write; seed OIDC + admin + 9
  <resource>:read|write scopes (requires_admin_role=true on admin family).
- isAdminScope() deleted; engine takes a scopeRequiresAdmin predicate.
- OAuth2Plugin loads admin-scope set from oauth2_scopes.requires_admin_role
  at startup (async Mapper+Criteria); AuthorizationService holds it.
- dev_backend_client.sql seed updated to new vocabulary.

RFC compliance fixes:
- R2: userinfo M2M rejection split to 401 invalid_token (was conflated
  with 403 insufficient_scope) per OIDC Core §5.3.
- R3: OpenAPI emits x-required-scopes + x-scope-implied-by extensions
  (bearer scheme scope arrays have no OpenAPI semantics).

Discovery (Phase 4):
- GET /api/admin/scopes/resources returns the scope->resource matrix.
- OpenAPI per-operation x-required-scopes populated from EndpointInfo.

Frontend:
- ConsentPage.vue scopeDescriptions updated (drop read/write, add
  resource-scoped labels).
- ScopesPage.vue BUILTIN_SCOPES expanded to protect new system scopes.
- ApplicationDetailPage.vue unchanged (data-driven, auto-adapts).

Tests:
- ScopeResolverTest: 8 cases (exact/implied/OIDC-non-implication/
  All/Any/empty/multi-scope-challenge).
- ScopeDecisionEngineTest rewritten for predicate-based engine signature.
- ClientCredentialsScopeValidationTest rewritten for new vocabulary.
- OidcBatch2/3 tests updated (R2 status + new scope names).
- route_manifest golden updated (+1 discovery route).

Tracks: issue #43. Design doc:
docs/productization-evolution/in-progress/resource-scope-authorization-design.md
Three test adjustments surfaced by running full_test with a live
PostgreSQL + Redis:

1. OidcBatch3 admin-scope test: WWW-Authenticate scope attr is now the
   concrete required scope ("clients:read"), not the former blanket
   "admin" — the registry returns per-resource requirements.

2. OidcBatch2 userinfo M2M test: revert to 403 insufficient_scope (not
   401). The M2M token lacks `openid`, so the filter-layer scope gate
   rejects first; the R2 handler-level 401 path only fires when an M2M
   token happens to carry `openid` (defense-in-depth edge case).

3. OpenAPI path-method fingerprint baseline: +2 new routes
   (GET /api/admin/dashboard, GET /api/admin/scopes/resources).

All 451 ctest cases pass serially (-j1).
The out-of-process endpoint tests (Step 6/7 of full_test) had two stale
scope references after the V006 rewrite dropped bare read/write:

- Test 8b insufficient-scope check: scope="admin" -> scope="audit:read"
  (/api/admin/dashboard now requires the concrete audit:read scope, not
  the former blanket "admin" prefix).
- Test 10 client_credentials: scope=read -> scope=tokens:read (the
  legacy "read" scope no longer exists).

Both .ps1 (Windows) and .sh (WSL/Linux) versions updated.
Verified: 59/59 OAuth2 + 52/52 Admin endpoint tests pass.
The ResourceScopeRegistry consistency check caught a missed controller:
/api/admin/organizations routes (list/create/getBySlug) were auth-gated
by AuthorizationFilter but had no scope requirement declared, causing
LOG_FATAL at startup. This was silent on Windows (spdlog FATAL did not
abort) but crashed the WSL/Linux server with "Resource deadlock avoided".

- Migrate OrganizationController from static-init docs struct to
  initApiDocs() (also removes dead /api/orgs OpenAPI entries that had
  no backing ADD_METHOD_TO routes).
- Declare roles:read / roles:write on the 3 org-admin routes, impliedBy
  admin.
- Wire initApiDocs() call in main.cc + test_main.cc.
- Update OpenAPI path-method fingerprint baseline (drop 3 /api/orgs,
  add 3 /api/admin/organizations).

Windows: 451/451 ctest + 59/59 + 52/52 endpoint tests pass.
Two fixes for the out-of-process endpoint test wrapper:

1. run-endpoint-tests.sh: `pkill -f authforge-server` was self-kill --
   the wrapper's own argv contains "--server-exe /path/authforge-server",
   so pkill -f matched and SIGTERM'd the wrapper script itself (0.00s
   "Subprocess terminated" with zero output). Replaced with
   `fuser -k 5555/tcp` which targets the port occupant (always the
   server), never the wrapper.

2. tests/CMakeLists.txt: dropped DEPENDS OAuth2Tests -- it prevented
   `ctest -R EndpointTests` from running in isolation (ctest kills the
   test immediately if its dependency is not in the run set). RUN_SERIAL
   + the wrapper's own port cleanup are sufficient.

Windows ctest #452 still passes (59/59 + 52/52).
@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.

…ts, v1.1.0

Update all tracking documents to reflect work completed since the
previous progress update (2026-08-12):

Completed since last update:
- #43 resource-scope authorization model fully implemented (f04d3ba)
- benchmark M2-M4: S3-S6 scenarios + 40 result JSONs + SUMMARY.md
  load-bearing verification (QPS ⚠️ near-target, P99 ✅ low-concurrency,
  memory ❌ needs redefinition, cold-start ⏳ pending)
- #42 Phase 2 token cache shipped (14f69e3)
- #41/#45/#46 all fixed; v1.1.0 tagged
- All GitHub issues #21-#46 closed

Documents updated:
- progress-status.md: Phase 0 ~85%, #43 → done, all issues closed,
  benchmark承重裁决 table added, v1.1.0 milestone recorded
- next-phase-implementation-plan.md: removed completed tiers (B1/C1/C2),
  refocused on spec governance (A1), user mgmt (A2), blog/README (A3),
  Backchannel Logout (B1), social link/unlink (B2), Phase 1 SDK/docs (C1-C3)
- iam-architecture-audit.md: RBAC section updated for #43 fine-grained
  scope model; performance line updated with Phase 0 measurements;
  version bumped to v1.1.0
- productization-research.md: §3.1 risk banner + perf table + §3.2
  selling points annotated with actual benchmark numbers (replacing
  '工程估算' with 'Phase 0 实测验证')
- resource-scope-authorization-design.md: moved to done/, status →
  Implemented; benchmark-facility-design.md: milestones → M1-M4 done
- README.md: index updated for #43 move + all status changes
…43)

Code review finding: header comment still described the deleted
isAdminScope() prefix-matching semantics, contradicting the .cc which
states it was replaced by the DB-driven scopeRequiresAdmin predicate.
…cold-start observed pass

Two承重假设 corrections after methodology review:

Memory (50-120MB claim):
- docker stats measures container RSS (Drogon framework + 25 PG / 20 Redis
  connection pools + shared library COW pages + page cache), NOT the SDK
  logic layer the claim refers to
- Verdict changed from ❌ to ⚠️ (口径不匹配 = wrong metric, not a failure)
- Correct measurement: use examples/third-party-host/ PSS (smem) or
  explicit 'OAuth2 logic layer' scoping

Cold start (~5s target):
- No script has a 5s timeout; 5s is the TARGET not a timeout
- setup.sh health-gate already observed /health/ready returning 200 in ~4s
  (including PG+Redis startup), meeting the ~5s target
- Verdict changed from ⏳ 未测 to ✅ 观测达成

Updated across: SUMMARY.md, progress-status.md, productization-research.md,
next-phase-implementation-plan.md
@voidvec

voidvec commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

Code Review — Resource-Scope Authorization (#43)

代码已逐文件核对(ResourceScopeRegistry.cc/.h / ScopeResolver.h / InsufficientScopeResponder.h / OAuth2AuthFilter.cc / AuthorizationFilter.cc / main.cc 接线 / EndpointInfo / OidcBatch3 集成测试 / route_manifest.txt)。设计清晰、启动期一致性校验(LOG_FATAL)能有效防止漏配,未发现 authz 绕过类必须修 bug。 结论与建议如下。

已验证正确的关键点

  • 路径匹配正确:templateMatches(ResourceScopeRegistry.cc:103-110)将 {param} 段视为通配,能正确把具体请求路径(如 /api/admin/users/123)匹配到模板条目;同时已用 route_manifest.txt 核对 getHandlersInfo() 返回 {param} 模板格式,与 EndpointInfo.path 一致,一致性校验的精确 == 比较成立。
  • ScopeResolver::satisfies 正确:All 用 std::all_of,Any 用 std::any_of,并支持 impliedBy 超集(admin 满足 clients:read 等)。与测试期望一致。
  • 403 + RFC 6750 3.1 challenge 正确:respondInsufficientScope 返回 403 并带 WWW-Authenticate: Bearer realm=..., error="insufficient_scope", scope="<reqmt.scopes>";测试 ApiAdmin_TokenWithoutAdminScope 断言 scope="clients:read" 与实现一致。
  • 双层门独立:admin 路由经 AuthorizationFilter 先过 scope 门、再过 RBAC role 门;scope 缺失即 403,与 RBAC 解耦(测试 ApiAdmin_TokenWithoutAdminScope 验证:admin 用户有 role 但无 scope 仍 403)。
  • 启动期 loud-fail:runConsistencyCheck 对未声明 scope 的 /api/admin/*、/api/me、/oauth2/userinfo 路由 LOG_FATAL,能防止漏配(已核对 userinfo 在 TokenEndpointController 声明 requiredScopes={"openid"})。

建议修(非阻塞)

  1. EndpointInfo 无 ScopeMatch 字段:buildFromEndpoints(ResourceScopeRegistry.cc:205)硬编码 ScopeMatch::All。若未来某端点需要 Any 语义,目前无法表达。建议在 EndpointInfo 增加 ScopeMatch scopeMatch = ScopeMatch::All; 并由 buildFromEndpoints 读取。
  2. 覆盖式校验仅限固定前缀:runConsistencyCheck 的 coverage 方向只 gate /api/admin/*、/api/me、/oauth2/userinfo。注册在其它前缀但本应 scope 门控的路由不会触发 LOG_FATAL。属设计取舍,建议在设计文档显式说明“只有这三个前缀享有启动期强制校验”。
  3. orphan 校验不含 prefix 条目:snapshot() 只遍历 registry()(精确条目),prefix 条目不参与 orphan 检查,目前安全;若将来加入 prefix 条目的强约束,需同步扩展 snapshot。

结论

可合入。无必须修项;1 为前瞻性增强,2/3 为文档/范围说明。建议补一条单元测试覆盖“scope 缺失返回 challenge 的 scope 属性为具体所需 scope(而非超集)”以固化当前正确行为。

)

Three CI/build blockers fixed:

1. Migration immutability (CI migration_check M5): V006 is baselined and
   cannot be modified. Restored V006 to original; the scope catalog change
   moves to a new forward-only V023__resource_scopes.sql (INSERT-only per
   M3/M4 -- legacy read/write rows stay as inert orphans, no DELETE FROM).

2. CMake configure-time crash (WSL full-test.sh): set_tests_properties ran
   unconditionally but add_test was guarded by EXISTS(server_binary) which
   is false at configure time (before build). Fixed by tracking
   registration in a variable and dropping the EXISTS check (the binary is
   validated at test-run time, not configure time).

3. Updated migration baseline.json (23 entries, V001..V023).
ScopeDecisionEngine.h (isAdminScope removed, evaluateScope/evaluateScopes
signature change) and AuthorizationService.h (constructor gained
adminScopes param with default) are internal engine interfaces, not
end-user-facing SDK API. Per versioning §3, security hardening advances
within MINOR without MAJOR. --force applied for verified non-public-
surface breaking change.
CI naming_validator requires [Category]_[Priority]_[Module]_[Feature]_
[Scenario]. Renamed Unit_ResourceScope_* -> Unit_P0_Authz_*.
CI -Werror=unused-parameter: scopeResources(req, callback) does not use
req (read-only discovery). Added (void)req;
Root cause: the server process inherited the wrapper's stdout/stderr pipe
from ctest. After the wrapper exited (all tests passed), ctest kept waiting
for pipe EOF because the server still held the write end open -> timeout.

Fix: redirect server stdout/stderr to a temp log file. Also: disown +
SIGTERM grace + SIGKILL + wait-reap in cleanup.

Verified on WSL: Passed in 9.52s (was Timeout at 90s).
@voidvec

voidvec commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

代码评审 — PR #49 feat(authz): resource-scope authorization model (#43)

结论:建议合并,但需先修复 3 项必改项(M1 / M2 / M4)。

总体评价:设计质量很高。单一声明式 ResourceScopeRegistry 作为 (path,method)→scopes 的唯一真相源,两个过滤器(用户路由 OAuth2AuthFilter、管理路由 AuthorizationFilter)统一走 lookup()+ScopeResolver::satisfies()``;Tier-2 管理员判定数据驱动(读 oauth2_scopes.requires_admin_role);统一 insufficient_scope发射器;启动双向一致性检查(LOG_FATAL)。代码规范整体遵守良好(无 CoroMapper、异步用shared_from_this()、无 emoji、错误码字符串化、敏感值走 env)。测试矩阵庞大(ctest 451–457、端点测试 59+52、前端 26 e2e)。**未发现**任何能导致用户数据泄露或越权的实时漏洞,admin超范围作用被正确隔离(userinfo //api/me的impliedBy为空,不会被admin` 命中)。

必改项(合并前)

[M1][Medium] R2(userinfo M2M→401)实际未生效

  • 位置:libs/drogon/src/filters/OAuth2AuthFilter.cc:96-117 + libs/drogon/src/controllers/TokenEndpointController.cc:183,1928
  • 问题:/oauth2/userinfo 在注册表中声明 requiredScopes={"openid"}(无 impliedBy)。过滤器在处理器之前执行:对缺少 openid 的 M2M(client_credentials)令牌,satisfies() 返回 false → 过滤器直接回 403 insufficient_scope。TokenEndpointController 里的 401 invalid_token 分支(line 1928,针对 client: subject)仅当令牌同时携带 openid 才到达,对常见 M2M 情形是死代码。PR 描述声称“R2: M2M→401 invalid_token”,但作者提交日志也自承“revert to 403… handler-level 401 仅在 M2M 恰好带 openid 时触发”——声明与实现不符。
  • 影响:非安全漏洞(两者都拒绝),但属于 RFC 6750 / OIDC Core §5.3 错误分类与互操作问题,且 PR 文案误导。
  • 修复:二选一——(a) 从注册表 scope 门中排除 /oauth2/userinfo,让处理器独占 M2M-vs-openid 拆分判定;(b) 在过滤器内识别 client:/M2M subject 时对 userinfo 改发 401 invalid_token。并相应修正测试与 PR 描述。

[M2][Medium] 一致性检查在 Windows 上静默失效

  • 位置:libs/drogon/src/authz/ResourceScopeRegistry.cc:318,353(LOG_FATAL)
  • 问题:PR 提交记录明确写道“This was silent on Windows (spdlog FATAL did not abort) but crashed the WSL/Linux server”。即 LOG_FATAL 在 Windows 上不会终止进程,导致“缺失 scope 声明 = 静默安全缺口”这一本该被 loud-fail 拦住的场景,在 Windows 开发/测试平台上完全不生效,提供 False 安全感——本 PR 最关键的防护机制之一跨平台不可靠。
  • 修复:在 LOG_FATAL 后显式 abort() / std::exit(EXIT_FAILURE)(或改用会在所有平台终止的硬失败封装),确保 loud-fail 一致。

[M4][Medium] ResourceScopeRegistry 缺单测(安全网逻辑未覆盖)

  • 位置:tests/unit/authz/ScopeResolverTest.cc:113-116(注释承认 registry 未单测)
  • 问题:ScopeResolver 有 8 个用例,但最关键的 ResourceScopeRegistry(模板精确匹配、前缀回退、buildFromEndpoints 过滤、runConsistencyCheck 的 LOG_FATAL 双向判定)没有单测,仅依赖集成测试正向 happy-path。一致性检查的失败分支(缺项/孤儿项触发 LOG_FATAL)完全未被测试。类已提供 clear() 测试接缝,单测可行。
  • 修复:新增 ResourceScopeRegistryTest:精确模板匹配(含 {param})、前缀回退(最长前缀优先)、buildFromEndpoints 跳过空 scope、以及一致性检查“缺失项→失败 / 孤儿项→失败 / 全通过”的判定(可用 death test 验证 LOG_FATAL 路径)。

建议尽快(可 fast-follow)

  • [M3] 一致性检查覆盖为硬编码前缀(/api/admin、/api/me、/oauth2/userinfo,见 ResourceScopeRegistry.cc:158-172 的 isAuthGatedPath),新增授权族可能漏检 → 优先从“路由→过滤器”挂载关系派生受授权路径集合,而非硬编码前缀。
  • [M5] discovery 端点 snapshot()(ResourceScopeRegistry.cc:269-290)仅遍历 registry(),漏报 /api/me → profile 前缀门,admin 自查时低估真实 scope 门。
  • [M6] libs/drogon/src/plugin/OAuth2Plugin.cc:371 异步回调捕获 [this] 缺“进程单例”理由注释(约定 refactor: repo structure reorganization (P0-P12) #2);回调内 if (authorizationService_) 守卫虽实际安全,但建议按值捕获服务 shared_ptr 更稳妥。

可后续清理(Low)

  • [L1] /api/me 前缀回退(registerPrefix("/api/me", {profile}))可能未检出“应更严却更松”的过度授权,因一致性检查命中前缀总是通过。
  • [L2] defaultAdminScopes() 硬编码集与 DB 种子存在漂移风险;当前 AuthorizationService 头注释“NOT YET WIRED INTO PRODUCTION”,属理论风险。一旦接线生产,建议启动断言 DB 集与默认集一致。
  • [L3] UserSelfServiceController.cc 残留空 UserSelfServiceControllerDocs 结构体与 docs_ 实例,待删。
  • [L4] getHandlersInfo() 与 EndpointInfo.path 格式一致性,孤儿方向用 == e.path 精确比较,路由格式不一致时会误报 LOG_FATAL 崩溃(本项目有过类似教训),建议测试锁定。
  • [L5] scripts/backend/run-endpoint-tests.ps1 的 finally 中 $proc 为 $null 时未处理异常(.sh 版用 fuser -k 正确)。

已澄清(非问题)

  • GET /api/admin/oidc/keys 声明 audit:read 不是 bug:V023 种子中 audit:read 描述明确包含 “OIDC key info”,控制器与数据模型一致。
  • ScopeChecker::hasScope 整体 token 匹配,无子串绕过(read≠readwrite),legacy read/write 移除安全。
  • AuthorizationFilter 的“scope + RBAC 角色双门”是纵深防御,设计正确(admin 路由需同时满足细粒度 scope 与角色)。

测试覆盖

  • 单元:ScopeResolver 8 例(精确/隐含/OIDC 不隐含/All/Any/空/单&多 scope challenge)充分;ResourceScopeRegistry 无单测(M4)。
  • 集成/端点:OidcBatch2/3、ClientCredentialsScopeValidation、route_manifest golden、OpenAPI 指纹基线随词汇更新;端点测试纳入 ctest(SKIP_RETURN_CODE 77 接线正确)。
  • 一致性检查失败路径未被任何测试断言(M4)。

规范符合度

  • 数据流异步回调+Mapper+Criteria(OAuth2Plugin.cc admin-scope 加载符合,try/catch 包裹 Mapper<> 符合 db-operations.md);命名/测试分类 Unit_P0_Authz_* 修正到位;无 emoji、错误码字符串化、敏感值走 env 均符合。仅 M6 的 [this] 注释待补。

安全判定:无实时越权或鉴权绕过,架构方向正确。上述均为正确性/健壮性/RFC 分类与测试完备性问题;M1/M2/M4 应在合并前落地,以保证“声明即事实”与该安全网的可靠性。

V006 (restored, immutable) still seeds 'read'/'write'. Other tests
running before ClientCredentialsScopeValidationTest can add 'read' to
backend-svc via admin client-scope CRUD, causing the exact-set CHECK to
fail on Linux (GCC compile-unit order differs from MSVC). Fix: DELETE
all backend-svc scopes first, then INSERT the expected 4. Immune to
test-ordering drift.
M1: userinfo no longer registry-gated -- handler exclusively owns the
    401 (M2M client: subject) vs 403 (missing openid) split per OIDC
    Core §5.3. Removed requiredScopes from userinfo EndpointInfo +
    excluded from isAuthGatedPath. Test updated to expect 401.
M2: std::abort() after LOG_FATAL in consistency check -- LOG_FATAL alone
    doesn't abort on Windows (spdlog), providing false safety.
M4: ResourceScopeRegistry unit tests (prefix fallback, longest-prefix-wins)
    using isolated /test/authz/* prefixes + clearPrefixes() test seam
    that cleans up without destroying the real registry.
M5: snapshot() now includes prefix entries so discovery endpoint does
    not under-report the scope matrix.
M6: [this] capture in OAuth2Plugin admin-scope load annotated with
    plugin-singleton rationale.
L3: removed residual empty UserSelfServiceControllerDocs struct.

Windows: 452/452 ctest pass.
…ntries

Two fixes for the consistency check crash on Windows:

1. std::abort() caused STATUS_STACK_BUFFER_OVERRUN (0xC0000409) on
   Windows MSVC -- the crash handler interfered with spdlog destructors.
   Switched to std::quick_exit(1) which terminates cleanly without
   running atexit/destructors, plus fprintf(stderr) for visibility.

2. M5's snapshot() now includes prefix entries (ANY /api/me/*), but
   the orphan check treated them as real routes -> false FATAL crash.
   Orphan check now skips method='ANY' entries (prefix catch-all gates
   are not ADD_METHOD_TO routes).

Windows full_test.bat: 8/8 PASS.
std::quick_exit is unavailable on macOS. Use conditional compilation:
Windows -> std::quick_exit (avoids STATUS_STACK_BUFFER_OVERRUN from
std::abort + spdlog destructor interference); Linux/macOS -> std::abort
(works correctly).
@voidvec
voidvec merged commit a837749 into master Aug 14, 2026
8 checks passed
voidvec added a commit that referenced this pull request Aug 14, 2026
…User, expanded updateUser (#A2)

Backend:
- listUsers: real pagination (page/per_page, total count via Mapper::count),
  search (q on username/email), filters (role via JOIN-free fan-out,
  locked derived from locked_until)
- createUser (POST /api/admin/users): PBKDF2 hash + default role assignment +
  audit log (user_create); 201 Created response
- updateUser: expanded to username, mfa_enabled, locked, org_id
  (was email + email_verified only)
- AuthorizationFilter: persist userId/scope/clientId onto request attributes
  (was only done by OAuth2AuthFilter) so admin handlers can identify the actor
- OpenAPI: added POST /api/admin/users + query params on GET list

Frontend:
- UsersPage: pagination controls, search bar, role/locked filters,
  Create User modal (username/password/email/roles)
- UserDetailPage: Info tab expanded — username, mfa_enabled, locked,
  org_id now editable (was email + email_verified only)
- mock-api: paginated GET handler + POST create mock with duplicate detection
- e2e: create-user, search-filter, duplicate-username test cases

Tests:
- AdminUserApiHttpTest: 7 new cases (create success/dup/missing, pagination,
  search, expanded update, locked filter)

Stacked on PR #49 (feat/resource-scope-authorization-43); rebase to master
after #49 merges.
@voidvec
voidvec deleted the feat/resource-scope-authorization-43 branch August 14, 2026 11:02
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.

[architecture] Full resource-scope authorization model (successor to minimal F-010 scope enforcement)

2 participants