Skip to content

Commit 7c36f52

Browse files
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
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth): a directory deactivation suspends the AI service accounts the person is accountable for, and a re-activation resumes none
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
**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, with its own reason, `Accountable owner deactivated by the directory`, so it reads apart from `Accountable owner left the organization`. Nothing is revoked: the account's keys are refused while it is suspended and work again after a resume. An account already suspended keeps its own reason.
11+
12+
**Resume.** A re-activation lifts the person's ban only, so the accounts stay suspended. `POST /api/v1/auth/service-account/resume` answers `409 RESOURCE_CONFLICT` while the accountable owner is still deactivated by the directory. Once the owner is re-activated, or a new owner is named (`set-owner`), an administrator of the account's organization or a platform administrator resumes it.
13+
14+
**Unchanged.** An administrator's own ban of the owner leaves the owner's accounts as they are. The person's local password is not changed by this release.
15+
16+
**If the suspension does not finish.** The deactivation still lands: the person is disabled and the SCIM request succeeds. The server logs one `error` line naming the person, how many accounts were and were not suspended, and the remedy (suspend each account whose `accountable_user_id` is that person). The next SCIM write that leaves the person inactive runs the suspension again.

‎content/docs/ai/agents.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ SKILL.md download (`GET /api/v1/mcp/skill`), and API-key minting.
132132
- **`set-owner`** (an administrator) names another member as the
133133
accountable owner. When the owner leaves the organization, the account is
134134
suspended, and it is not resumed until an administrator names a new owner.
135+
When the organization's directory (SCIM) deactivates or deletes the owner,
136+
the account is suspended too, a re-activation of the owner does not resume
137+
it, and `resume` refuses until the owner is re-activated or a new owner is
138+
named.
135139
- **`retire`** (an administrator) ends its membership and revokes every key
136140
for good; the account's record stays, so what it wrote still names it.
137141

‎content/docs/permissions/authentication.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,12 @@ like any banned account's, with one field added:
12511251
administrator's are both refused `403 PERMISSION_DENIED`. The person creates
12521252
a new key under **Account → Developer → API Keys** and replaces the old one
12531253
wherever it is configured.
1254+
- It also suspends every AI service account the user is accountable for, with
1255+
the reason that the directory deactivated its owner. Nothing is revoked: the
1256+
account's keys are refused while it is suspended. A re-activation does not
1257+
resume it, and `resume` refuses while the owner is still deactivated; once the
1258+
owner is re-activated, or a new owner is named, an administrator resumes it
1259+
(see [AI service account](/docs/ai/agents#connect-your-ai-byo-ai-over-mcp)).
12541260
- The cause is told only after the password verified: a wrong password is the
12551261
ordinary `401 INVALID_EMAIL_OR_PASSWORD`, whatever the account's state. It
12561262
names no connection, provider or other account.

‎content/docs/permissions/index.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ organization or platform administrator's act; its owner or an administrator
129129
mints its API key. Its owner or an administrator suspends it (every key
130130
stops, nothing is revoked) or revokes one key; only an administrator resumes
131131
it, changes its owner or retires it. If its owner leaves the organization, it
132-
is suspended until an administrator names a new owner. It never signs in, and
132+
is suspended until an administrator names a new owner; if the organization's
133+
directory deactivates or deletes its owner, it is suspended until the owner is
134+
re-activated or a new owner is named, and then an administrator resumes it.
135+
It never signs in, and
133136
it is never counted among the administrators that keep an organization
134137
manageable. See
135138
[AI service account](/docs/ai/agents#connect-your-ai-byo-ai-over-mcp).

‎packages/plugins/plugin-auth/src/auth-manager.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ import {
255255
revokeDirectoryDeactivatedApiKeys,
256256
scimDeactivationKeyRevocationIncompleteMessage,
257257
} from './scim-deactivation-key-revocation.js';
258+
import {
259+
directoryDeactivatedOwnerSuspensionIncompleteMessage,
260+
isOwnedAccountSuspensionComplete,
261+
suspendAccountsOfDirectoryDeactivatedOwner,
262+
} from './service-account-owner-leaves.js';
258263
// [objectstack-ai/cloud#3606, ruling A] `/oauth2/revoke` for an MCP access
259264
// token: the answer `handleRequest` gives after the provider's, through
260265
// `answerOAuthTokenRevocation` below.
@@ -4634,6 +4639,17 @@ export class AuthManager {
46344639
* already landed); it is reported once at `error`. The `active: true` branch
46354640
* and an administrator's ban leave keys alone.
46364641
*
4642+
* An inactive state also suspends every AI service account the user is
4643+
* accountable for, with the reason that the directory deactivated its owner
4644+
* (`service-account-owner-leaves.ts`, the owner-left writer with its own
4645+
* reason; the maintainer's choice that this card covers those accounts). A
4646+
* re-activation lifts the user's ban only, so the accounts stay suspended
4647+
* until an administrator resumes them, and resume refuses while the owner is
4648+
* still deactivated. It runs on every inactive call after the key
4649+
* revocation, an account already suspended keeps its own reason, and a
4650+
* suspension that does not finish never fails the deprovision; it is
4651+
* reported once at `error`. An administrator's ban leaves the accounts alone.
4652+
*
46374653
* [ADR-0135 D4] This callback also writes the directory-managed mark
46384654
* (`sys_user.source = 'idp_provisioned'`, `scim-identity-source.ts`) on every
46394655
* call — fail-closed and first on an active state, best-effort and after the
@@ -4712,6 +4728,10 @@ export class AuthManager {
47124728
// a revocation that cannot land never leaves the account enabled.
47134729
const revocation = await revokeDirectoryDeactivatedApiKeys(engine as never, state.userId);
47144730
if (!revocation.complete) this.logScimKeyRevocationIncomplete(state.userId, revocation);
4731+
// ...and suspends the AI service accounts the user is accountable for; a
4732+
// re-activation resumes none of them.
4733+
const suspension = await suspendAccountsOfDirectoryDeactivatedOwner(engine as never, state.userId);
4734+
if (!isOwnedAccountSuspensionComplete(suspension)) this.logScimAccountSuspensionIncomplete(state.userId, suspension);
47154735
try {
47164736
await markDirectoryProvisionedUsers(engine as never, [state.userId]);
47174737
} catch (e) {
@@ -4743,6 +4763,28 @@ export class AuthManager {
47434763
else console.error(message, meta);
47444764
}
47454765

4766+
/**
4767+
* The one notice for a SCIM deprovision whose suspension of the user's AI
4768+
* service accounts did not finish (`service-account-owner-leaves.ts`).
4769+
* Logged at `error`: the user is disabled, so nothing looks wrong, but an
4770+
* account left unsuspended keeps running with nobody accountable for it.
4771+
*/
4772+
private logScimAccountSuspensionIncomplete(
4773+
userId: string,
4774+
outcome: Parameters<typeof directoryDeactivatedOwnerSuspensionIncompleteMessage>[1],
4775+
): void {
4776+
const message = directoryDeactivatedOwnerSuspensionIncompleteMessage(userId, outcome);
4777+
const meta = {
4778+
object: 'sys_user',
4779+
suspended: outcome.suspended.length,
4780+
failed: outcome.failed.map((f) => f.accountId),
4781+
...(outcome.readError !== undefined ? { error: outcome.readError } : {}),
4782+
};
4783+
const sink = this.config.logger as { error?: (msg: string, meta?: unknown) => void } | undefined;
4784+
if (typeof sink?.error === 'function') sink.error(message, meta);
4785+
else console.error(message, meta);
4786+
}
4787+
47464788
/**
47474789
* [ADR-0135 D4] The one notice for a directory-managed mark that could not
47484790
* be written on a SCIM deprovision, where the deprovision write has already

‎packages/plugins/plugin-auth/src/auth-route-ledger.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export const AUTH_ROUTE_LEDGER: readonly AuthRouteLedgerEntry[] = [
278278
{ route: 'POST /api/v1/auth/service-account/create-key', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — the sys_user create_service_account_key action posts it directly; mints one sys_api_key for an AI service account (userId: a sys_user row of kind agent; a person\'s id answers 404 as unknown), user_id the account and active_organization_id its one membership\'s organization (never the caller\'s, never the body\'s), signed with the same lifecycle rule as POST /keys (default life; past the ceiling 400 VALIDATION_FAILED at expires_at, with POST /keys\'s message), raw secret returned once and only its hash stored; a retired account (no membership) is refused 409. A signed-in session only (401 without one, a held session 403 with its posture): the account\'s accountable owner, an administrator of its organization (membership grade admin or owner), or a platform administrator; anyone else 403 PERMISSION_DENIED; an unreadable membership 503. ADR-0151 D4' },
279279
{ route: 'POST /api/v1/auth/service-account/register', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL — the sys_user register_service_account action posts it directly; registers an AI service account in the caller\'s current organization in one unit of work: the sys_user row (principal_kind agent, accountable_user_id the named owner or the caller, a placeholder .invalid address, source env_native), written through the data engine so its sys_user hooks judge it, and its one sys_member row as a plain member through the vendor\'s server-only addMember (a refused membership rolls the row back). The owner must be a member of the organization (400 VALIDATION_FAILED on ownerId); name required. A signed-in session only (401 without one, a held session 403 with its posture): an administrator of the current organization (membership grade admin or owner) or a platform administrator; anyone else 403 PERMISSION_DENIED; an unreadable membership 503. ADR-0151 D1' },
280280
{ route: 'POST /api/v1/auth/service-account/restore-key', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL; restores one revoked sys_api_key of an AI service account (keyId; a key that is not an account\'s answers 404 as unknown), clearing revoked_reason; the account\'s other keys are untouched. Follows the restore guard\'s reasons: organization_membership_ended and scim_deactivated are never restored, admin_password_reset and administrator_suspended by a platform administrator only (403 PERMISSION_DENIED otherwise). A signed-in session only (401 without one, a held session 403 with its posture): the account\'s accountable owner, an administrator of its organization, or a platform administrator; anyone else 403 PERMISSION_DENIED; an unreadable membership 503. ADR-0151 D6' },
281-
{ route: 'POST /api/v1/auth/service-account/resume', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL; lifts an AI service account\'s suspension (clears banned, ban_reason, ban_expires), so the same keys work again. Lifts only this family\'s suspension (that reason, or the owner-left one); any other ban (a platform administrator\'s) only a platform administrator lifts, else 403 PERMISSION_DENIED. Refused 409 RESOURCE_CONFLICT for a retired account and for one whose accountable owner is no longer a member of its organization (name a new owner first). A signed-in session only (401 without one, a held session 403 with its posture): an administrator of the account\'s organization or a platform administrator; the owner and anyone else 403 PERMISSION_DENIED; a person\'s id 404; an unreadable membership 503. ADR-0151 D6' },
281+
{ route: 'POST /api/v1/auth/service-account/resume', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL; lifts an AI service account\'s suspension (clears banned, ban_reason, ban_expires), so the same keys work again. Lifts only this family\'s suspension (that reason, the owner-left one, or the directory-deactivated-owner one); any other ban (a platform administrator\'s) only a platform administrator lifts, else 403 PERMISSION_DENIED. Refused 409 RESOURCE_CONFLICT for a retired account, for one whose accountable owner is no longer a member of its organization (name a new owner first), and for one whose accountable owner is still deactivated by the directory (name a new owner, or have the directory re-activate the owner, first). A signed-in session only (401 without one, a held session 403 with its posture): an administrator of the account\'s organization or a platform administrator; the owner and anyone else 403 PERMISSION_DENIED; a person\'s id 404; an unreadable membership 503. ADR-0151 D6' },
282282
{ route: 'POST /api/v1/auth/service-account/retire', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL; retires an AI service account in one unit of work: its sys_member rows end and every sys_api_key it holds is revoked with organization_membership_ended; the sys_user row stays. Terminal: 409 RESOURCE_CONFLICT once retired. A signed-in session only (401 without one, a held session 403 with its posture): an administrator of the account\'s organization or a platform administrator; the owner and anyone else 403 PERMISSION_DENIED; a person\'s id 404; an unreadable membership 503. ADR-0151 D6' },
283283
{ route: 'POST /api/v1/auth/service-account/revoke-key', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL; revokes one sys_api_key of an AI service account (keyId; a key that is not an account\'s answers 404 as unknown); the account\'s other keys are untouched. A platform administrator\'s revoke of a key carrying no reason records administrator_suspended; a stored reason is never overwritten. A signed-in session only (401 without one, a held session 403 with its posture): the account\'s accountable owner, an administrator of its organization, or a platform administrator; anyone else 403 PERMISSION_DENIED; an unreadable membership 503. ADR-0151 D6' },
284284
{ route: 'POST /api/v1/auth/service-account/set-owner', family: 'objectstack-mount', source: 'objectstack', disposition: 'server-only', note: 'no SDK method builds this URL; names a new accountable owner (ownerId) for an AI service account, written through the data engine so the sys_user row rules judge it (exists, a person, not the account). The new owner must be a member of the account\'s organization (400 VALIDATION_FAILED on ownerId); a retired account 409. Does not resume a suspended account. A signed-in session only (401 without one, a held session 403 with its posture): an administrator of the account\'s organization or a platform administrator; the owner and anyone else 403 PERMISSION_DENIED; a person\'s id 404; an unreadable membership 503. ADR-0151 D6' },

0 commit comments

Comments
 (0)