Repository navigation
Commit 9052363
feat(plugin-auth): an IdP group mapping says whether it matches a current group of its source (#32186)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLcR66HDKGmkegYSEN3PSwY)_
Fixes #32121
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:`sys_idp_group_mapping` 多了三个只读列:`match_status`(已匹配 / 未匹配任何当前组 /
不适用)、`matched_group_id`、`match_changed_at`,`all` 列表视图显示匹配状态。plugin-auth
在 SCIM 组的创建、改名(PATCH/PUT)、删除和映射保存时自动更新它们,每次启动再全量对账一次。
- 为什么改:IdP 把组改名后,成员的授权会立刻失效(正确的 fail-closed),但映射行上什么也看不出来;cloud 的 SCIM
控制台(cloud#4278 第 4 项)需要显示「不匹配任何当前组」。
- 风险与回滚:只描述、不决定授权:谁拿到哪个权限集完全不变,不匹配的映射仍然什么也不授予。更新失败不会让 SCIM 请求失败(只记 error
日志,下次写入或重启时自愈)。回滚即还原本 PR,三个列留空无害。
-
先看:`packages/plugins/plugin-auth/src/idp-group-mapping-match.ts`(钩子与对账,重点看
`onGroupUpdate` 的跳过条件和 `refresh` 的 catch),`auth-plugin.ts` 里
kernel:ready 的注册与启动对账,`sys-idp-group-mapping.object.ts` 的三个新字段。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2 src/scim-group-projection.test.ts -t "rename the
group"`,预期 1 例通过(改名后 `unmatched` 且无授权,改回后 `matched` 且授权恢复)。
- 需要你做的:无,席位落地。
## What changes
- **`sys_idp_group_mapping`** (`packages/platform-objects`): three new
read-only fields in a `Match` group. `match_status` (select: `matched`,
`unmatched`, `not_applicable`), `matched_group_id` (the `sys_scim_group`
id it matches, empty when none), `match_changed_at` (when either last
changed). `match_status` joins the `all` list view's columns. The data
API stays `apiMethods: ['list']`, so nothing outside plugin-auth can
write them.
- **`idp-group-mapping-match.ts`** (new, `plugin-auth`): judges each
mapping with the projection's own matcher (`mappingMatchesGroup`), so
"matches" means exactly what the grant path means. Engine after-hooks
keep the answer current:
- `sys_scim_group` `afterInsert` / `afterDelete`, and `afterUpdate` when
`display_name`, `external_id` or `connection_id` moved, re-judge that
connection's mappings;
- `sys_idp_group_mapping` `afterInsert`, and `afterUpdate` when a key
column moved, re-judge the row's source; an SSO row is marked
`not_applicable`.
- A row is written only when its answer changed, so the mapping's
history shows real transitions only, and a membership change writes
nothing.
- A failure is caught and logged at `error` (consequence + how it
heals), never thrown: a SCIM write that 500s is retried by the IdP
forever.
- **`auth-plugin.ts`**: binds the trigger at `kernel:ready` beside the
other identity triggers, then runs `refreshAllMappingMatches` once, so
rows saved before this release read right after the upgrade.
- **Translations**: regenerated with the repo's extractor (`os i18n
extract … --locales=zh-CN,ja-JP,es-ES,zh-Hant,ar,fr,pt-BR,ru,de,ko
--fill=default --source-hashes`), new leaves translated in all ten
locales, then extracted again so the source-hash companions settle.
### Why engine hooks and not only the projection
Measured on the vendor (`@better-auth/scim` 1.7.12): `roles.map` is
called from `buildDesiredGrants`, which returns early when the group has
no members, so an empty group's create or rename never reaches the
projection. Every vendor group write (`create`, `update`,
`incrementOne`, `delete`) ends in an ObjectQL engine call by id through
`objectql-adapter.ts`, so an after-hook sees all of them, inside the
SCIM request's ambient engine transaction. Pinned by the empty-group
case below.
### Field names
The card suggested `matched_group_id` + `matched_at`. I kept
`matched_group_id` and used `match_changed_at` in place of `matched_at`:
one timestamp answers both "matched since" and "matches nothing since",
where `matched_at` is empty exactly when the console needs a date.
`match_status` carries the three-way answer the card asks for (an SSO
mapping reads "not applicable") so a list view can filter on it without
combining `source_kind` and an empty id.
## Tests
New top-level `describe`s in the shared harness
`scim-group-projection.test.ts` (real `AuthManager.handleRequest` over
`@better-auth/scim`, real ObjectQL over better-sqlite3; the trigger is
bound in the pool's boot, so every existing case there now runs with it
too):
- rename the group (SCIM `PATCH replace displayName`) → `unmatched`,
`matched_group_id` empty, `match_changed_at` set, member's grant gone;
rename back → `matched`, grant back (the card's test);
- a mapping saved before its group exists reads `unmatched`; a
memberless group push makes it `matched`; `DELETE /Groups` makes it
`unmatched`;
- a mapping by external id keeps its answer when only the display name
changes (`PUT`);
- a membership change writes nothing to the mapping row;
- an SSO-sourced row reads `not_applicable`;
- the boot sweep rights a row with empty match columns and a second
sweep writes nothing;
- a failure to write the mapping never fails the SCIM rename: the rename
lands, the grant follows, one `error` line names the connection;
- `AuthPlugin` registers the five hooks under one package id at
`kernel:ready` and the sweep reads the mappings.
### Ablations (each mutation via `scripts/ablation-replace.mjs`,
restored to HEAD, `git diff HEAD` empty after each)
| # | mutation | case | result |
|---|---|---|---|
| A1 | rethrow inside the hook's `catch` | failure never fails the SCIM
write | red: `SCIM PATCH /Groups rename failed: expected 500 to be less
than 300` |
| A2 | drop the `afterUpdate` hook on `sys_scim_group` | rename →
unmatched | red: `expected { status: 'matched', … } to match object {
status: 'unmatched', groupId: null }` |
| A3 | drop `settle`'s no-change guard | boot sweep | red: `a second
sweep finds nothing to write: expected 1 to be +0` |
| A4 | drop the `afterDelete` hook on `sys_scim_group` | memberless
group / delete | red: `expected { status: 'matched', … } to match object
{ status: 'unmatched', groupId: null }` |
A1's first attempt was refused by the tool (the replacement contained
the anchor, so it ran nothing); it was re-run with a different anchor
and went red as above. Not pinned behaviourally: the `onGroupUpdate`
column filter is an efficiency guard (with it removed, `settle` still
writes nothing on a membership change), so no case can tell it apart.
## Acceptance notes
- Fail-closed is unchanged: no line of `scim-group-projection.ts` or of
the grant path moved.
- A raw driver write below the engine is not seen by the hooks; the boot
sweep corrects it at the next start (said in the module header).
- File surface: besides the order's named files, `auth-plugin.ts` (the
`kernel:ready` registration, the only place plugin-auth binds engine
hooks) and the new module that holds the group lifecycle path. Two more,
each forced by a gate or a test this change moved:
- `durability-swallow-repair.test.ts`: its SCIM-stamp case captured the
LAST `afterInsert` handler `AuthPlugin` registers, so the new hooks
displaced it (`expected "vi.fn()" to be called at least once`). It now
captures the handler registered under the plugin's own package id, which
is the stamp; its assertions are unchanged.
- `content/docs/permissions/tenant-audit-census.mdx` and
`docs/audits/2026-08-tenant-audit-write-call-sites.counts.md`: the new
engine write is one more census site (293, was 292; undecidable 90,
provably carrying none 11). Generated sections rewritten by `node
scripts/tenant-audit-census.mjs --write`; the seven prose figures the
gate holds to the census edited to the numbers it printed. That includes
the historical "over-claim" paragraph (67 → 68, 10 → 11), which the gate
binds to the live counts. The site mirrors its sibling `delete` in
`idp-group-mapping-admin.ts` (same row shape: `undecidable`, `PROVABLY
NONE`).
## Verification
Head `8eeae2b2c0` (branch merged with `origin/main` at `cc8c4b0f4e`, no
conflicts, nothing on this surface moved upstream).
- Full `npx turbo run build --concurrency=2` on the merged head: 120 of
120 tasks successful (os-verify-lock `VERDICT command-exit 0`), then
`pnpm --filter @objectstack/plugin-auth typecheck` exit 0 in the same
locked run. `@objectstack/platform-objects` typecheck exit 0 (before the
merge; the merge touched neither package).
- `pnpm --filter @objectstack/platform-objects test`: 120 files, 1934
tests passed (before the merge).
- `pnpm --filter @objectstack/plugin-auth test` (before the merge): 254
of 255 files passed, 1 failed (the `durability-swallow-repair.test.ts`
capture described above). After the fix,
`src/durability-swallow-repair.test.ts` +
`src/scim-group-projection.test.ts`: 2 files, 52 tests passed. The merge
touched no plugin-auth file.
- `npx eslint --no-inline-config` on every touched `.ts` file: exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands` on `8eeae2b2c0`: 108
families, every one run, every one `exit 0`; `--ran` reconciliation: 108
derived, 108 run, 0 NOT-MEASURED, 0 UNRUN. Includes `check:i18n`,
`check:i18n-stale-fill`, `check-tenant-audit-census`,
`check:durability-log-level`, `check:startup-registry-verdict`,
`check:engine-double-contract`, `check:doc-authoring`,
`check:issue-citations`, `check:published-files`.
- CI families outside the derived set (artifact roster, wide-population
families, type-check lanes, Test Core shards, dogfood): read from this
PR's check-runs; not re-run locally. No full dogfood run: the title has
no `!` and the Clause-② line carries the `(widening)` arm.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzetdgRBVhsymYB8BWh
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 93ff5dd commit 9052363
19 files changed
Lines changed: 771 additions & 24 deletions
File tree
- .changeset
- content/docs/permissions
- docs/audits
- packages
- platform-objects/src
- apps/translations
- identity
- 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
164 | | - | |
| 163 | + | |
| 164 | + | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
| 220 | + | |
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
237 | 237 | | |
238 | | - | |
| 238 | + | |
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
| 310 | + | |
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
315 | | - | |
| 314 | + | |
| 315 | + | |
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2777 | 2794 | | |
2778 | 2795 | | |
2779 | 2796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2777 | 2794 | | |
2778 | 2795 | | |
2779 | 2796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2777 | 2794 | | |
2778 | 2795 | | |
2779 | 2796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2777 | 2794 | | |
2778 | 2795 | | |
2779 | 2796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2777 | 2794 | | |
2778 | 2795 | | |
2779 | 2796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2777 | 2794 | | |
2778 | 2795 | | |
2779 | 2796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2774 | 2774 | | |
2775 | 2775 | | |
2776 | 2776 | | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2777 | 2794 | | |
2778 | 2795 | | |
2779 | 2796 | | |
| |||
0 commit comments