Commit 8dcf607
* feat(plugin-auth): break-glass 守卫的 delete 半边 —— 最后一个管理员也删不掉 (#5941)
#5892 / PR #5939 只守住了 ban(`sys_user.banned = true`,`beforeUpdate`)。
删除这条路径今天没有任何一段代码判断「管理员还剩几个」:`auth-manager.ts`
那段 HTTP 守卫判的是「最后一个本地 credential 持有人」,目标不持本地密码
(enforced SSO 下 IdP 托管 / SCIM JIT provision 出来的管理员)时整段跳过,
于是 SCIM `DELETE /Users/{id}` / `/admin/remove-user` 可以把环境最后一个
管理员的行删掉,环境从此无人可管。
本次把同一条不变量装到 `sys_user` 的 `beforeDelete` 上,与 ban 半边同形状、
同一份管理员枚举:装在写上而不是端点上(SCIM adapter、admin remove-user、
导入、脚本都覆盖),by-id 与谓词/multi(含无谓词的清表 multi)都守,对
`isSystem` 同样生效(真正会锁死的正是 system 那条),并且 fail-closed ——
枚举读不出来或超出 maxScan 一律拒绝。
实测(写进了模块头注释):`beforeDelete` 的 by-id 派发给 `input.id`,
谓词/multi 派发把行域谓词放在 `input.options.where`;`ctx.previous`
(引擎 #5272 预取 + objectql 的 `sys_fetch_previous_delete` 内建)只在 by-id
形状上绑定,批量派发上是 undefined ——守卫因此完全不消费它,只解析目标 id 集。
拒绝走 `PERMISSION_DENIED` + 403,信息按调用方实际执行的动作措辞
(「Refusing to delete '…'」),并给出 ADR-0024 D5.2 依据与修复办法;
`withValidationErrorMapping` 逐方法包装,#5939 加的 403 arm 原样覆盖 `delete`。
模块随之更名为 `last-admin-guard.ts` / `registerLastAdminGuard`(原
`last-admin-ban-guard.ts`,同一个未发布周期内加入):它现在注册两个钩子,
旧名字会低估它装了什么。
⛔ 未动 `auth-manager.ts:1239-1300` 的 fail-open HTTP 守卫段(分诊明令,
它继续守自己的 credential 版不变量,两层并存)。撤销管理员「身份」的第三条
写法(改/删 `sys_member` 行、撤 `admin_full_access` 授权)另开 #5978。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JwwiU9bjhwy2SWj13ho8uv
* docs(plugin-auth): 精确化守卫读取 `input.options.where` 与 HookContext 契约表的关系
#5964 刚把 `HookEvent` 的枚举注释对齐到契约表的「谓词不在 `input` 上」。
两句都对,但要分清:钩子拿不到的是 composed `ast`(生效谓词);`before*`
期间 `input.options` 仍是调用方那只 engine options 包(engine.ts 5516→5517 /
6137→6152 之后才重建成 DriverOptions),`where` 与 `multi` 都在 —— 守卫读的
正是它。中间件只收窄不放宽,所以把调用方谓词当目标集是上界近似,对
fail-closed 守卫恰是安全方向。契约表那两处 `before` 行的措辞另记为 #5997。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JwwiU9bjhwy2SWj13ho8uv
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent f192981 commit 8dcf607
5 files changed
Lines changed: 655 additions & 115 deletions
File tree
- .changeset
- packages/plugins/plugin-auth/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
988 | 988 | | |
989 | 989 | | |
990 | 990 | | |
991 | | - | |
| 991 | + | |
992 | 992 | | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
1002 | 1003 | | |
1003 | 1004 | | |
1004 | 1005 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
0 commit comments