Repository navigation
Commit 7c36f52
fix(plugin-auth): a directory deactivation suspends the AI service accounts the person is accountable for, and a re-activation resumes none (#33109)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoAUvWRKPo4TS8boyLtwkTkt)_
Clause-②: no
Metadata-protocol: none
Part of #32115 (step 2: the AI service accounts of a person the
directory deactivates; step 1 was #33075, and the local-password half is
still a later step).
## 维护者速读
- 改了什么:目录(SCIM)停用或删除一个人时,这个人负责的所有 AI
服务账号都会被暂停,原因记为"负责人被目录停用"。暂停就是封禁,不吊销密钥;重新启用这个人不会恢复这些账号,要等负责人被重新启用或换了新负责人,再由管理员恢复。管理员自己封禁负责人的行为不变。
- 为什么改:按你 11-13 在席位线程里的选择,#32115 也覆盖这个人负责的 AI 服务账号,做法和"负责人离开组织"一样。这是
#32115 的第 2 步;删除本地密码那一半仍是后续一步,所以写 `Part of #32115`。
- 风险与回滚:patch 级,只改 plugin-auth(含 resume 路由台账说明)和三处文档(Clause-②
no,元数据协议不变,暂停原因写在自由文本的 `ban_reason` 里,不新增枚举值)。暂停写不进去时,停用照常生效,服务器记一条
error 日志并写明补救办法,下一次让这个人保持停用的目录写入会再试。回滚就是还原本 PR。
-
先看:`packages/plugins/plugin-auth/src/service-account-owner-leaves.ts`(和"离开组织"共用同一个暂停写入,换了原因)、`auth-manager.ts`
里 `reconcileScimUserLifecycle` 的停用分支、`service-account-lifecycle.ts` 的
resume。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
scim-deactivation-reconcile-user service-account-lifecycle`,预期全部通过。
- 需要你做的:无。这是 draft,由 security#2 席位审阅和落地;改动约 555 行,不涉及受管路径。
## What changes
**The rule.** Deactivating a person through SCIM (`active: false`), or
deleting one (`DELETE /Users/{id}`), suspends every AI service account
whose accountable owner is that person, in every organization. The
suspension is the ban the owner-left rule already writes (ADR-0151 D6),
with its own reason, `Accountable owner deactivated by the directory`.
Nothing is revoked, so the account's keys are refused while it is
suspended and work again after a resume. A re-activation lifts the
person's ban only, and the accounts stay suspended. `resume` refuses
while the owner is still deactivated by the directory. An
administrator's own ban of the owner leaves the accounts as they are.
- `service-account-owner-leaves.ts`: the owner-left suspension writer is
now one function both callers use. `suspendAccountsOfDepartedOwner`
(owner left an organization, unchanged behaviour and log lines) and the
new `suspendAccountsOfDirectoryDeactivatedOwner` (every organization,
the new reason) both call it. The writer skips an account already
suspended, so it keeps its own reason, and it returns what it suspended
and what it could not. It never throws.
- `auth-manager.ts`, `reconcileScimUserLifecycle`: the inactive branch
(a SCIM `active: false`, and the SCIM delete, which reconciles the
person as inactive) runs the suspension after step 1's key revocation.
If it does not finish, the deprovision still lands and one `error` line
names the person, the counts and the remedy. The next directory write
that leaves the person inactive runs it again.
- `service-account-lifecycle.ts`:
- The new reason is one of this family's suspension reasons, so an
administrator of the account's organization may lift it, as with
owner-left.
- `resume` answers `409 RESOURCE_CONFLICT` while the accountable owner's
ban in force carries the directory's deactivation reason, naming the two
ways forward: a new owner (`set-owner`), or the owner's re-activation.
- `auth-route-ledger.ts`: the `POST /api/v1/auth/service-account/resume`
row's note names the new suspension reason among the ones an
organization administrator may lift, and the new `409` refusal.
- Docs, rule-level lines: `permissions/authentication.mdx` (the "When
the identity provider deactivates a user" section), `ai/agents.mdx` (the
service account lifecycle doors) and `permissions/index.mdx` (the AI
service account paragraph).
## Why
The ruling of record (6787890900 on #32004, item "Directory
deactivation") is that deactivating or deleting a user through SCIM
revokes what that user can sign in with. The maintainer chose in the
seat thread on 2026-11-13 that this card also covers the AI service
accounts that user is accountable for, suspended the way an owner
leaving the organization already suspends them.
## Verification
On head `8f94ed83` (one merge of `origin/main` over `913efacd`) unless
stated. Head `3c1d57b8` adds the resume row's ledger note only: the 19
derived gates that read the ledger or scan source text
(`check:auth-mount-ledger` among them) and `check:route-ledger-census`,
plus the 7 plugin-auth files that pin ledger notes or the resume door
(165 tests), green, and ESLint on the file.
- New tests (names state the rule):
- `scim-deactivation-reconcile-user.test.ts`, describe "a directory
deactivation suspends the AI service accounts the person is accountable
for, and a re-activation resumes none", end to end through
`@better-auth/scim`. Its five cases:
- `active: false` suspends each account in two organizations with the
new reason. No key is revoked, and the keys answer
`refused:owner_banned`. Another person's account keeps running. `resume`
is refused `409` before the re-activation. After `active: true`, the
person is unbanned, the accounts stay suspended, and a platform
administrator's `resume` lets the same key be admitted again.
- `DELETE /Users/{id}` suspends the same way, and a re-link through the
tombstone resumes nothing.
- An account already suspended keeps its own reason.
- CONTROL: an administrator's ban of the owner leaves the account
running.
- A refused suspension write still bans the person and logs one error,
and the next directory write retries it.
- `service-account-lifecycle.test.ts`, describe "a directory
deactivation of the owner suspends the accounts, and resume waits for
the owner". Its six cases:
- every organization covered, and another owner's account untouched;
- an account already suspended keeps its reason, and a second pass
writes nothing;
- resume is refused for an organization administrator and a platform
administrator alike;
- after the re-activation, an organization administrator resumes it with
the owner kept, and the same key works;
- a new owner named while the old one stays deactivated, then resume;
- a refused write counted in the outcome and its message.
- Ablation (`ablation-replace.mjs` on `913efacd`, each restored with the
blob equal to HEAD and `git diff HEAD` empty):
- the suspension call in the SCIM branch replaced by an empty outcome: 3
of the 5 end-to-end pins red; the kept-reason case and the CONTROL stay
green;
- the resume refusal's condition forced false: 2 red (the unit refusal
and the end-to-end case);
- the new reason dropped from the family's reasons: 3 red (an
organization administrator can no longer lift it).
- Suites: plugin-auth 266 files, 5,037 passed and 10 skipped (on
`913efacd`); after the merge, the touched files plus
`auth-plugin.test.ts` (which `main` changed), 3 files and 193 tests,
green. `typecheck` (with test typecheck) and ESLint on the changed files
green.
- Gates: `dispatch-gates.mjs --ran` reconciled 106 derived, 106 run, 0
not measured, every exit code 0, on `913efacd`. Four of them (`spec
check:docs`, `spec check:skill-examples`, `check:dts-closure`,
`check:dual-build-cjs-loads`) were rerun after a full declaration build.
They read local build output, and the first two had read spec artifacts
older than `main`'s spec source. After the merge, the 33 node-script
gates (changeset, census, ADR-0087 against `origin/main`) and three
census or changeset families were rerun, all exit 0.
## Acceptance notes
- **Reused writer, measured.** The owner-left writer was
organization-scoped. Its loop now lives in one function that takes the
reason and an optional organization. The owner-left path keeps its
pre-check, its scope and its exact log lines; its existing tests pass
unchanged.
- **Discriminator.** "Directory-deactivated" is read the way the
platform already reads it: the owner's ban in force carries `Deactivated
via SCIM` (`user-ban-write.ts`, the reason the SCIM re-activation lifts
and the sign-in cause reports). The accounts' own ban carries the new
reason, which the SCIM re-activation does not lift.
- **Retry.** A repeated SCIM `PATCH active: false` on a person who is
already inactive does not call the vendor's reconcile. An attribute
write does, and the pin uses one.
- **Remainders, out of scope by the order:** an administrator's own ban
of the owner (unchanged), and the local-password half of the card (a
later step).
- No new value in any shipped vocabulary: `sys_user.ban_reason` is free
text.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(`packages/spec` not touched.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (ESLint on every changed
TypeScript file; the full `pnpm lint` runs in CI.)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (Not touched.)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibyho66BmvQ2CZsxoWJ
<!-- signed: security#2 · os-tesla · session_01L9qibyho66BmvQ2CZsxoWJ
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e997113 commit 7c36f52
10 files changed
Lines changed: 507 additions & 48 deletions
File tree
- .changeset
- content/docs
- ai
- permissions
- 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1251 | 1251 | | |
1252 | 1252 | | |
1253 | 1253 | | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
1254 | 1260 | | |
1255 | 1261 | | |
1256 | 1262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
258 | 263 | | |
259 | 264 | | |
260 | 265 | | |
| |||
4634 | 4639 | | |
4635 | 4640 | | |
4636 | 4641 | | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
4637 | 4653 | | |
4638 | 4654 | | |
4639 | 4655 | | |
| |||
4712 | 4728 | | |
4713 | 4729 | | |
4714 | 4730 | | |
| 4731 | + | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
4715 | 4735 | | |
4716 | 4736 | | |
4717 | 4737 | | |
| |||
4743 | 4763 | | |
4744 | 4764 | | |
4745 | 4765 | | |
| 4766 | + | |
| 4767 | + | |
| 4768 | + | |
| 4769 | + | |
| 4770 | + | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
| 4775 | + | |
| 4776 | + | |
| 4777 | + | |
| 4778 | + | |
| 4779 | + | |
| 4780 | + | |
| 4781 | + | |
| 4782 | + | |
| 4783 | + | |
| 4784 | + | |
| 4785 | + | |
| 4786 | + | |
| 4787 | + | |
4746 | 4788 | | |
4747 | 4789 | | |
4748 | 4790 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
| 281 | + | |
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| |||
0 commit comments