Skip to content

Commit 8c629b2

Browse files
fix(plugin-auth)!: a directory deactivation removes the user's local password; a re-activation restores access through SSO only (#34738)
Fixes #32115 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — no skill under `skills/**` teaches the SCIM deactivation lifecycle; `content/docs/permissions/authentication.mdx` gains the rule in this change. ## 维护者速读 - 改了什么:SCIM 目录停用(`active: false`)、删除(`DELETE /Users/{id}`)、让用户失去最后一个活跃来源的连接退役,以及目录把用户保持为停用时的任何后续写入,在 main 已有的封禁、吊销 API key、暂停 AI 服务账号、结束其注册的 OAuth 应用与 SCIM 凭证之外,现在还删除该用户的本地密码(`sys_account` 中 `provider_id = 'credential'` 的行),之后该用户读作目录托管(`idp_provisioned`)。目录重新启用(`active: true` 解除目录自己的封禁)时先删除用户此刻持有的本地密码再解封,访问只经 SSO 恢复;删除未完成则重新启用失败,用户保持停用。 - 为什么改:在案裁决(#32004 评论 6787890900,「Directory deactivation」条)写明「移除目录用户的本地密码是后一步」;API key 一半(#33075)、AI 服务账号(#33109)与注册结束(#36163)已在 main 上,本 PR 合入 main 之后只剩本地密码这一半。维护者 11-17 的「这个不用处理」只免去回填扫尾,修复本身仍欠。 - 风险与回滚:收窄(BREAKING,标题带 `!`):被目录停用过的用户重新启用后没有本地密码,需要时要在重新启用之后有意设置。不做迁移或回填。管理员封禁/解封、管理员封禁之上的 `active: true`、未被封禁用户的目录同步、末位管理员被拒的停用都不删密码。回滚 = 回退本 PR;已删除的密码行不会随回滚恢复。 - 先看:`packages/plugins/plugin-auth/src/auth-manager.ts` 的 `reconcileScimUserLifecycle`(本轮合并解决处:停用分支里 main 的注册结束之后、目录标记之前删除;重新启用分支 fail-closed);`scim-deactivation-password-removal.ts`;`scim-deactivation-reconcile-user.test.ts` 的 (l) describe。 - 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run src/scim-deactivation-reconcile-user.test.ts`,预期 60/60 通过(main 的 45 条 + 本 PR 的 15 条 (l) 用例)。 - 需要你做的:无,席位落地(收窄所需的 L2 契约复审由席位路由)。 ## What changes - **The rule.** A directory deactivation removes the user's local password; a re-activation by the directory restores access through SSO only. - On every inactive call of `AuthManager#reconcileScimUserLifecycle`, after what `main` already does there (the ban write, the API key revocation, the AI service account suspension, and the ending of the user's OAuth applications and SCIM credentials), and before the directory-managed mark, every `sys_account` row of the user with `provider_id = 'credential'` is deleted. The inactive calls are PATCH `active: false`, `DELETE /Users/{id}`, a create with `active: false`, a tombstone re-link that arrives inactive, a connection decommission pass that removes the user's last active source, and any later SCIM write while the directory holds the user inactive. The trigger is the directory's state, never the ban column. - On the `active: true` call that lifts the directory's own ban (`SCIM_DEACTIVATION_BAN_REASON`), the same writer removes any such row the user holds at that moment, inside the same SCIM transaction, before the directory-managed mark and before the unban. A re-activation after a directory deactivation therefore restores no credential from before it, a password an administrator set while the directory held the user deactivated included. - The user row, the user's other account links (SSO / OAuth) and the history that names the user are kept (ADR-0134 D3). - **Writer** `packages/plugins/plugin-auth/src/scim-deactivation-password-removal.ts` (package-internal): reads the row ids only and deletes them through the engine in the system context, attributed to the SCIM connection as a service principal (`authSystemWriteContext`). Idempotent, never throws. `complete` is a measured zero: after deleting, it re-reads and reports `complete` only when no local-password row is left; a row read without an id counts as not removed. At most 100 rows of one user per call, documented in the module header. No audit row follows a delete: `sys_account` is on the audit mirror's skip list. - **Failure posture, one per branch.** Deactivation: the ban lands first, so an incomplete removal is logged once at `error` and the deprovision still succeeds; the next inactive write runs it again. Re-activation: the ban stays until the removal is complete; an incomplete removal is logged once at `error` and fails the SCIM request, which the vendor rolls back, so the user stays deactivated until the directory retries. - **Order and the mark.** On a deactivation the removal runs after the ban, so a ban the last-administrator guard refuses throws first and removes nothing. On both branches it runs before the directory-managed mark (ADR-0135 D4), so a user whose password the removal took reads `idp_provisioned`. - **Sessions.** Unchanged: the vendor deletes the user's sessions after the callback for an inactive state. - **Unchanged, each pinned by a control:** an administrator's ban and unban; an `active: true` over an administrator's ban; an attribute sync or `active: true` for a user who is not banned; a user with no local password. - **The directory's ban reason.** A ban whose reason reads `Deactivated via SCIM` is the directory's whoever wrote it: the directory's next active write lifts it and removes the local password (docblock, changeset, docs). Reserving that string on the administrator's ban mount is not done here (L2 N4, Acceptance notes). - **Docs:** a bullet in `content/docs/permissions/authentication.mdx`, after `main`'s registration-ending bullet: the removal, the decommission door, the `idp_provisioned` mark, the re-activation half, and that no migration or backfill runs. `scim-identity-source.ts`'s header says what the mark reads after the removal. - **Changeset:** `.changeset/32115-directory-deactivation-local-password.md`, `@objectstack/plugin-auth` patch, BREAKING, ADR-0087 disposition not-required (no-migration-prescription). Its BREAKING paragraph now lists the registration ending `main` gained beside the ban, keys and AI service accounts. - **Census:** `docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins/plugin-auth.md` regenerated by `node scripts/tenant-audit-census.mjs --write` after the merge (never hand-merged): 111 sites, `main`'s 110 plus the writer's one `delete` of `SystemObjectName.ACCOUNT`. ## Tests Top-level describe in `packages/plugins/plugin-auth/src/scim-deactivation-reconcile-user.test.ts`, through `@better-auth/scim` over a real better-sqlite3 engine: "a directory deactivation removes the user's local password, and a re-activation restores access through SSO only". Its fifteen cases are now face **(l)**: `main` added its own (k) describes (an account disabled by any door keeps nothing running in its name), so the merge keeps `main`'s (k) whole and renames this PR's face; no case changed subject. - (l) `active: false` removes the local password and keeps every other link; the mark reads `idp_provisioned`; `active: true` lifts the ban and restores no password (sign-in `401 INVALID_EMAIL_OR_PASSWORD`); the delete is the SCIM connection's write (`isSystem: true`, actor `svc:scim:okta-14360`, no user credited). - (l) `DELETE /Users/{id}` removes it the same way; a re-link through the tombstone restores none. - (l) a repeated inactive write sends no delete. - (l) a deactivation over an administrator's ban removes the password too and keeps the administrator's reason. - (l) CONTROL: an administrator's ban and unban leave the password alone. - (l) CONTROL: an attribute sync or an `active: true` for a user who is not banned removes nothing; only lifting the directory's ban does (positive leg: one delete). - (l) a re-activation after a directory deactivation restores no credential from before it, the deactivated state seeded directly; attribution asserted. - (l) CONTROL: `active: true` over an administrator's ban lifts nothing and removes nothing. - (l) CONTROL: a user with no local password is a no-op. - (l) a refused deactivation of the last administrator (PATCH and DELETE) attempts no delete. - (l) a deactivation that fails after the removal rolls the removal back with the ban. - (l) a removal that cannot be written on a deactivation still bans, logs once at `error`, and the next inactive write removes it. - (l) a removal that cannot be written on a re-activation fails it (status ≥ 500), logs once, and keeps the user deactivated; the retry re-activates with no password. - (l) a removal is complete only when a re-read finds no local password. - (l) a local-password row read without an id counts as not removed. Cases changed because the behaviour changed (unchanged from the earlier rounds): "(b) active:true ⇒ the SCIM ban is lifted, and the re-activation restores no local password from before it", and the faces (a), (d), (f) and the cause cases, which set the password again after the deactivation before signing in. ## Acceptance notes - Premise re-measured on `origin/main` `f46ce5b4af`: the API-key half (#33075, `revokeDirectoryDeactivatedApiKeys`), the AI service account suspension (#33109) and the registration ending (#36163, `endScimDeactivatedRegistrations`) are on `main`; the inactive branch deletes no `credential` row and the active branch only unbans. Only the local-password half still reproduces, and it is this PR's whole delta against `main` (7 paths, +1027 / −26). - Merge of `origin/main` `f46ce5b4af` (merge commit `c7c85d60c3`, no rebase, no force push): four files conflicted. `auth-manager.ts` keeps `main`'s registration ending and runs the removal after it, before the mark; the test file keeps `main`'s new describes whole and renames this PR's face to (l); `authentication.mdx` keeps both bullets; the census shard was taken from `main` and regenerated (`f635db10e8`). - The maintainer's 「这个不用处理」 (11-17) waives only the residual backfill sweep. No migration or backfill runs: a user deactivated before this version keeps their local credential until the directory next writes that user. An administrator's unban removes nothing. - Seat answers on the round-0 questions (delta r1): the removal runs on every inactive write, a connection decommission pass included; the last-local-credential guard stays off on the SCIM path; the break-glass last-administrator guard still refuses first. - L2 nits (record 6946949332, at `1540d3a270`): N1, N2, N3 and N5 applied in round 3; N4 documented, not reserved (reserving the string adds a refusal to the administrator's ban door, outside this card); N6 and S1 belong to the ADR bookkeeping card. - ADR bookkeeping: #34820 - The connection decommission door is named from the vendor's code path (`reconcileSCIMProjectionDomainBatch` calls `identity.reconcileUser`), not driven by a case in this file. - Records on file are at `1540d3a270` (L1 ACCEPT 6946960271, L2 PASS 6946949332) and do not cover this head; the round-3 delta and this merge are unreviewed. - `scim-deactivation-reconcile-user.test.ts` now runs 60 cases (45 on `main`). Budget line `test-budget: 20` stands, re-measured LOCALLY at 60 cases (10.52 s, the slowest of four runs of the file alone, × 1.25); the line says the reading is local. ## Verification All readings on head `9d96795467` (the merge `c7c85d60c3`, the census regeneration `f635db10e8`, and the wording commit `9d96795467`) unless stated. Wall-clock figures are shared-box readings. <details> <summary>plugin-auth: red before, green after, full suite, typecheck, census</summary> - Closure build: `pnpm exec turbo run build --concurrency=2 --filter='@objectstack/plugin-auth...'` under the lock: `Tasks: 36 successful, 36 total`. - `pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/scim-deactivation-reconcile-user.test.ts`: `Tests 60 passed (60)`, four runs (tests 10.48 s, 10.09 s, 10.52 s, 10.31 s). - Red before: the same file with `auth-manager.ts` restored from `origin/main` (worktree only; blob 32d8b3f vs HEAD 10e6399): `Tests 17 failed | 43 passed (60)`, VERDICT command-exit 1. The 17 red are eleven (l) cases (the attribute-sync control among them, on its positive leg) plus (a), (b), (d), (f) and the two cause cases, whose fixtures follow the rule; the three remove-nothing controls and the last-administrator case stay green. Restored with `git checkout HEAD -- PATH`: blob 10e6399 == HEAD, `git diff HEAD` empty, `git status` clean. - `bash scripts/pm/os-verify-lock.sh -c 'pnpm --filter @objectstack/plugin-auth test'` (on `9d96795467`): `Test Files 295 passed (295)`, `Tests 6289 passed | 10 skipped (6299)`, VERDICT command-exit 0. - `pnpm --filter @objectstack/plugin-auth typecheck` after building it, under the lock: VERDICT command-exit 0; `check:test-typecheck: OK`, debt ledger unchanged. - `node scripts/check-tenant-audit-census.mjs`: `OK -- 345 write call sites certified across 18 package shard(s)`. - Ablations of the writer and of both call sites ran in round 3 on `fcc2c1cfbc` (a4–a9) and round 2 (a1–a3); the merge moved no line they mutate except the inactive-branch neighbourhood, which the red-before leg above covers. </details> <details> <summary>Gate round</summary> - `env -u OS_SKIP_DTS pnpm build --concurrency=2` under the lock: `Tasks: 120 successful, 120 total`. - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 108 commands (7 changed paths vs merge base `f46ce5b4a`); each run with stdin from `/dev/null`, its exit code captured before any pipe. - 106 exited 0 in the round. Two answered exit 3 (PREREQUISITE NOT MET, nothing measured) and exited 0 on re-run: `node scripts/check-plugin-teardown-shape.mjs --self-test` (its positive control is a pinned commit outside the shallow clone; that commit was fetched) and `pnpm check:type-check-debt` (queued behind the dogfood battery's hold on the lock; re-run under the lock: `check-type-check-coverage: OK`, `--re-measure: OK`). - `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran FILE` (each line carrying its exit code): `108 derived, 108 run, 0 NOT-MEASURED, 0 UNRUN`, a derived zero (all 108 recorded an exit code). - CI on `9d96795467`, read once: 55 check runs completed, each `success` or `skipped`, none failed. Test Core 1/10 to 10/10 and the `Test Core` aggregate, Build Core, Build Docs, Test UI, Live E2E UI, Dogfood Regression Gate, TypeScript Type Check, Lint & Repo Gates and every Lint / Type Check lane, Check Changeset, Check PR Size, Governed Surface Queue Guard, the PR-body guards, Check Documentation Links, Spec property liveness and Flag docs affected by code changes: `success`. Path-gated UI jobs, the queue verdicts and the opt-in jobs: `skipped`. </details> <details> <summary>Dogfood battery (the title carries `!`)</summary> - On `9d96795467`, after the full build above (it covers the `@objectstack/dogfood` closure): `bash scripts/pm/os-verify-lock.sh -c 'pnpm --filter @objectstack/dogfood test'` (no `OS_TEST_SHARD`, no path): `Test Files 487 passed | 3 skipped (490)`, `Tests 4126 passed | 68 skipped (4194)`, VERDICT command-exit 0, held the lock 45m38s (shared box). No failure. </details> **Seat-written update.** Seat `repo:objectstack#4` (os-justin, `session_01QSeKYpEsWWE9Y5YtSsDgqZ`) wrote this body on the maintainer's ruling in the seat session, verbatim 「一选1+」 (2026-11-24): option 1+ — the seat performs only the writes the dev session's permission classifier refused, each checked against the branch; no standing allow rule is added (evidence card #36936). Refused once in dev session `session_01QSeKYkTjJ5ybZ2ydLHnMbv`, reason `[Undermining Oversight]`: `node scripts/pm/fleet-write/dispatch.mjs --repo objectstack-ai/objectstack --actions-file FILE` carrying this `issue_patch`. The text above is the dev's, unchanged (15,575 bytes, sha256 prefix `6be7afe46bc08eda`, matching the dev's hand-off); head checked at `9d96795467`. <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkTjJ5ybZ2ydLHnMbv --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 62692b7 commit 8c629b2

7 files changed

Lines changed: 1027 additions & 26 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth)!: a directory deactivation removes the user's local password; a re-activation restores access through SSO only
6+
7+
Clause-②: yes (narrowing) — narrowed: a SCIM `active: false`, a SCIM `DELETE /Users/{id}`, a SCIM create with `active: false`, a connection decommission that leaves the user with no active source, and any later SCIM write that leaves the user inactive now also delete the user's local password (every `sys_account` row of the user with `provider_id = 'credential'`), where they left it in place, so the identity-source mark then reads the user `idp_provisioned` where the password had kept it `env_native`; and a SCIM `active: true` that lifts the directory's ban now first deletes any such row the user holds at that moment, where it lifted the ban alone, and fails (SCIM 500, the user staying deactivated) when that deletion cannot be completed. A re-activation by the directory restores no credential from before it, so a password sign-in by that user answers the ordinary `401 INVALID_EMAIL_OR_PASSWORD` until a password is set again on purpose after it.
8+
Metadata-protocol: none
9+
Skills-docs: none — no skill under `skills/**` teaches the SCIM deactivation lifecycle; `content/docs/permissions/authentication.mdx` gains the rule in this change.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed, renamed or re-shaped. The change is a runtime write on the SCIM deprovision and re-activation paths (rows of the better-auth account table), so there is nothing stored in metadata for a migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** for a deployment that provisions users through a SCIM directory: deactivating or deleting a user through SCIM, or decommissioning the last SCIM connection that holds the user active, now removes that user's local password, alongside the ban, the API key revocation, the AI service account suspension and the ending of the user's OAuth applications and SCIM credentials it already performed. A re-activation by the directory restores access through the identity provider's sign-in only: it removes any local password the user holds at that moment, one set while the user was deactivated included, before it lifts the ban, so it restores no credential from before it; when that removal cannot be completed the re-activation fails and the user stays deactivated until the directory retries. The user's other account links (SSO / OAuth) and the user row are kept. With the password gone, the user reads as directory-managed (`sys_user.source = 'idp_provisioned'`, ADR-0135 D4) where the password had kept it `env_native`, so every rule keyed on that mark applies to the user, the SSO-only mode refusals to set a local password among them.
14+
15+
Unchanged: an administrator's ban and unban (`admin/ban-user`, `admin/unban-user`) leave the local password alone; an `active: true` over an administrator's ban, and an active SCIM write for a user who is not banned, remove nothing; a deactivation the break-glass last-administrator guard refuses removes nothing.
16+
17+
A ban whose reason reads `Deactivated via SCIM`, the reason the directory's ban records, is the directory's whoever wrote it: the directory's next active write lifts it and removes the local password.
18+
19+
What to do: nothing. No migration or backfill runs: a user deactivated before this version keeps their local credential until the directory next writes that user. An administrator's unban removes nothing. A re-activation by the directory also removes a password set while the user was deactivated. A person who needs a local password after a re-activation sets one again on purpose after it (`set-initial-password`, or an administrator's Set Password where the deployment allows it; with SSO-only mode on, these doors refuse a directory-managed user other than a platform administrator setting their own).

‎content/docs/permissions/authentication.mdx‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,10 @@ like any banned account's, with one field added:
17741774
- `scim_deactivated` marks exactly the bans the identity provider lifts when it
17751775
sends `active: true` again. An administrator's ban that a deactivation
17761776
arrived on top of keeps the administrator's reason, and answers as an
1777-
administrator's ban.
1777+
administrator's ban. A ban whose reason reads `Deactivated via SCIM`, the
1778+
reason the directory's ban records, is the directory's whoever wrote it: the
1779+
directory's next active write lifts it and removes the user's local
1780+
password.
17781781
- A deactivation, or a `DELETE /Users/{id}`, also revokes every API key the
17791782
user owns (`revoked_reason: scim_deactivated`). A re-activation re-arms none
17801783
of them, and no one can restore them: the owner's Restore and a platform
@@ -1792,6 +1795,22 @@ like any banned account's, with one field added:
17921795
re-activation restores none of them, and a credential it revoked is reported
17931796
once in the server log at `error`
17941797
([What a ban, a deactivation or a removal ends](#what-a-ban-a-deactivation-or-a-removal-ends)).
1798+
- It also removes the user's local password. So does a connection
1799+
decommission that leaves the user with no active source: that is a
1800+
deactivation too. With the password gone the user reads as
1801+
directory-managed (`sys_user.source` is `idp_provisioned`), so the rules for
1802+
IdP-provisioned users apply, the
1803+
[SSO-only mode](#sso-only-mode-idp-provisioned-users-get-no-local-password)
1804+
refusals included. A re-activation by the identity provider restores access
1805+
through its sign-in only: the `active: true` that
1806+
lifts the deactivation removes any local password the user holds at that
1807+
moment, one set while the user was deactivated included, so a re-activation
1808+
restores no credential from before it. If that removal cannot be completed,
1809+
the re-activation fails and the user stays deactivated until the identity
1810+
provider retries. The user holds a local password again only once one is set
1811+
on purpose after the re-activation. No migration or backfill runs: a user
1812+
deactivated before this rule shipped keeps their local credential until the
1813+
directory next writes that user. An administrator's unban removes nothing.
17951814
- The cause is told only after the password verified: a wrong password is the
17961815
ordinary `401 INVALID_EMAIL_OR_PASSWORD`, whatever the account's state. It
17971816
names no connection, provider or other account.

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins/plugin-auth.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ a row or a number here — fix the code, or the census, and regenerate.
1414

1515
| Measure | Value |
1616
|---|---:|
17-
| Write call sites | 110 |
17+
| Write call sites | 111 |
1818
| Object name statically decidable | 60 |
19-
| Object name chosen at run time | 50 |
19+
| Object name chosen at run time | 51 |
2020
| Object name spelled inline | 47 |
2121
| Object name spelled through a `const` | 13 |
2222
| Object name is an `object: string` parameter | 4 |
23-
| Object name is some other run-time expression | 46 |
23+
| Object name is some other run-time expression | 47 |
2424
| Against a tenancy-enabled object | 58 |
2525
| Against an object declaring tenancy off | 2 |
26-
| Threading a tenant context | 66 |
26+
| Threading a tenant context | 67 |
2727
| Provably carrying none (options read, no context key) | 15 |
2828
| …and decidably tenancy-enabled | 3 |
2929
| Options argument unreadable | 29 |
3030
| …and decidably tenancy-enabled | 16 |
3131
| Threading a decidably elevated (`isSystem`) context | 48 |
3232
| Threading a decidably non-elevated context | 0 |
33-
| Threading a context of undecidable elevation | 47 |
34-
| Receiver carried a readable engine type | 81 |
33+
| Threading a context of undecidable elevation | 48 |
34+
| Receiver carried a readable engine type | 82 |
3535
| Receiver erased, placed by the object NAME | 26 |
3636
| Receiver erased, placed by an `object: string` PARAMETER | 2 |
3737
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 1 |
@@ -115,6 +115,7 @@ a row or a number here — fix the code, or the census, and regenerate.
115115
| `packages/plugins/plugin-auth/src/scim-connection-service.ts` | `insert` | `sys_scim_connection_credential` | enabled | PROVABLY NONE | 1 |
116116
| `packages/plugins/plugin-auth/src/scim-connection-service.ts` | `update` | `sys_scim_connection_credential` | enabled | elevated | 2 |
117117
| `packages/plugins/plugin-auth/src/scim-deactivation-key-revocation.ts` | `update` | `SystemObjectName.API_KEY` | undecidable | context, elevation undecidable | 1 |
118+
| `packages/plugins/plugin-auth/src/scim-deactivation-password-removal.ts` | `delete` | `SystemObjectName.ACCOUNT` | undecidable | context, elevation undecidable | 1 |
118119
| `packages/plugins/plugin-auth/src/scim-group-projection.ts` | `delete` | `sys_user_permission_set` | enabled | PROVABLY NONE | 1 |
119120
| `packages/plugins/plugin-auth/src/scim-group-projection.ts` | `insert` | `sys_user_permission_set` | enabled | elevated | 1 |
120121
| `packages/plugins/plugin-auth/src/scim-identity-source.ts` | `update` | `sys_user` | enabled | context, elevation undecidable | 1 |

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

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ import {
275275
directoryRevokedCredentialsMessage,
276276
endRegistrationsOfARemovedAccount,
277277
} from './removed-account-registrations.js';
278+
import {
279+
removeDirectoryDeactivatedLocalPassword,
280+
scimDeactivationPasswordRemovalIncompleteMessage,
281+
scimReactivationPasswordRemovalIncompleteMessage,
282+
} from './scim-deactivation-password-removal.js';
278283
// [objectstack-ai/cloud#3606, ruling A] `/oauth2/revoke` for an MCP access
279284
// token: the answer `handleRequest` gives after the provider's, through
280285
// `answerOAuthTokenRevocation` below.
@@ -4987,14 +4992,16 @@ export class AuthManager {
49874992
* the vendor's session hook auto-lifts an expired ban and would admit a
49884993
* principal the IdP still holds deactivated, and this callback is not
49894994
* re-invoked until the IdP mutates that user again.
4990-
* - `active: true` on a row banned WITH that reason ⇒ `applyUserUnban`.
4991-
* A ban carrying any other reason was placed by an administrator and is
4995+
* - `active: true` on a row banned WITH that reason ⇒ the user's local
4996+
* password is removed, then `applyUserUnban` (the password paragraph
4997+
* below). A ban carrying any other reason was placed by an administrator and is
49924998
* not the IdP's to lift: an attribute sync (every SCIM PUT carries
49934999
* `active: true`) must not silently re-admit a user banned for cause.
49945000
* Known collision, documented rather than reserved: an administrator
49955001
* who types the reason `Deactivated via SCIM` on the admin mount
49965002
* produces a ban this rule reads as the IdP's, so an `active: true`
4997-
* lifts it. Reserving the string on the admin mount would change that
5003+
* lifts it, and removes the user's local password with it. Reserving the
5004+
* string on the admin mount would change that
49985005
* surface, which is not this hook's to do.
49995006
* - Anything else is a no-op. The callback is contractually idempotent
50005007
* ("Implementations must be idempotent") and the vendor invokes it on
@@ -5085,6 +5092,30 @@ export class AuthManager {
50855092
* an arm that does not finish is reported once at `error` too, and the next
50865093
* inactive write retries it.
50875094
*
5095+
* An inactive state also removes the user's local password: every
5096+
* `sys_account` row of the user with `provider_id = 'credential'`
5097+
* (`scim-deactivation-password-removal.ts`, the same ruling's later step). It
5098+
* runs on every inactive call after the suspension and the ending of the
5099+
* user's registrations, and before the mark; it is idempotent: nothing to
5100+
* remove means no write. A refused last-administrator ban throws before it,
5101+
* so that refusal removes nothing. A removal that does not finish never
5102+
* fails the deprovision (the ban already landed); it is reported once at
5103+
* `error`.
5104+
*
5105+
* A re-activation by the directory restores access through SSO only: the
5106+
* `active: true` call that lifts the directory's own ban runs the same
5107+
* removal first, so the re-activation restores no local password from before
5108+
* it, one set while the directory held the user deactivated included. There
5109+
* the removal fails closed, the mirror of the inactive branch: the ban is the
5110+
* state that keeps a password from signing in, so it is lifted only once the
5111+
* removal is complete. A removal that does not finish is reported once at
5112+
* `error` and fails the SCIM request; the vendor rolls the request back, the
5113+
* user stays deactivated, and the directory's retry runs it again. The
5114+
* removal comes before the unban in code order too, so even a driver without
5115+
* a real transaction never reaches the unban first. An `active: true` over an
5116+
* administrator's ban, any active call for a user who is not banned, and an
5117+
* administrator's ban and unban leave the password alone.
5118+
*
50885119
* [ADR-0135 D4] This callback also writes the directory-managed mark
50895120
* (`sys_user.source = 'idp_provisioned'`, `scim-identity-source.ts`) on every
50905121
* call — fail-closed and first on an active state, best-effort and after the
@@ -5120,10 +5151,13 @@ export class AuthManager {
51205151
// so the mark commits with the SCIM write or not at all.
51215152
//
51225153
// Its failure posture depends on the state, and the ORDER is the contract:
5123-
// - active: the mark is written FIRST and fails closed — a mark that
5124-
// cannot be written fails the SCIM request, the vendor rolls the create
5125-
// back, and the IdP retries; no SCIM user is created unmarked.
5126-
// - inactive (a deactivation, a DELETE, a create with `active: false`):
5154+
// - active: the mark is written before any ban column and fails closed —
5155+
// a mark that cannot be written fails the SCIM request, the vendor rolls
5156+
// the create back, and the IdP retries; no SCIM user is created
5157+
// unmarked. Only a re-activation that lifts the directory's ban writes
5158+
// before it: the local-password removal, which fails closed too.
5159+
// - inactive (a deactivation, a DELETE, a create with `active: false`, a
5160+
// connection decommission that leaves the user no active source):
51275161
// the deprovision write goes FIRST and the mark after it is best-effort,
51285162
// so a refused mark can never leave a deprovisioned account enabled. A
51295163
// refusal is logged and swallowed; the boot backfill and the next active
@@ -5171,17 +5205,37 @@ export class AuthManager {
51715205
// OAuth applications they registered disabled, the SCIM credentials they
51725206
// minted revoked. A re-activation restores none of them.
51735207
await this.endScimDeactivatedRegistrations(engine, state.userId);
5208+
// ...and removes the user's local password, so a re-activation restores
5209+
// access through SSO only. Before the mark, which then reads the user as
5210+
// holding no local password (ADR-0135 D4).
5211+
const removal = await removeDirectoryDeactivatedLocalPassword(engine as never, state.userId);
5212+
if (!removal.complete) {
5213+
this.logScimPasswordRemovalIncomplete(scimDeactivationPasswordRemovalIncompleteMessage(state.userId, removal), removal);
5214+
}
51745215
try {
51755216
await markDirectoryProvisionedUsers(engine as never, [state.userId]);
51765217
} catch (e) {
51775218
this.logScimMarkDegradation(state.userId, e);
51785219
}
51795220
return;
51805221
}
5181-
await markDirectoryProvisionedUsers(engine as never, [state.userId]);
5182-
if (!banned) return;
51835222
// An administrator's ban is not the IdP's to lift.
5184-
if (user.banReason !== SCIM_DEACTIVATION_BAN_REASON) return;
5223+
const liftsDirectoryBan = banned && user.banReason === SCIM_DEACTIVATION_BAN_REASON;
5224+
if (liftsDirectoryBan) {
5225+
// A re-activation by the directory restores access through SSO only: the
5226+
// local password goes first, before the mark (which then reads the user
5227+
// as holding none, ADR-0135 D4) and before the unban. Fail-closed: the
5228+
// ban is lifted only once the removal is complete, so a removal that
5229+
// does not finish fails the request and the vendor rolls it back.
5230+
const removal = await removeDirectoryDeactivatedLocalPassword(engine as never, state.userId);
5231+
if (!removal.complete) {
5232+
const message = scimReactivationPasswordRemovalIncompleteMessage(state.userId, removal);
5233+
this.logScimPasswordRemovalIncomplete(message, removal);
5234+
throw new Error(message);
5235+
}
5236+
}
5237+
await markDirectoryProvisionedUsers(engine as never, [state.userId]);
5238+
if (!liftsDirectoryBan) return;
51855239
await applyUserUnban(writer, state.userId);
51865240
}
51875241

@@ -5224,6 +5278,24 @@ export class AuthManager {
52245278
else console.error(message, meta);
52255279
}
52265280

5281+
/**
5282+
* The one notice for a SCIM write whose removal of the user's local password
5283+
* did not finish (`scim-deactivation-password-removal.ts`), with the message
5284+
* for its branch. Logged at `error`. On a deprovision the account is
5285+
* disabled and the request succeeds, so nothing looks wrong while the user
5286+
* still holds a local password; on a re-activation the request fails and the
5287+
* user stays deactivated, and this line names the cause.
5288+
*/
5289+
private logScimPasswordRemovalIncomplete(
5290+
message: string,
5291+
outcome: Parameters<typeof scimDeactivationPasswordRemovalIncompleteMessage>[1],
5292+
): void {
5293+
const meta = { object: 'sys_account', removed: outcome.removed, failed: outcome.failed };
5294+
const sink = this.config.logger as { error?: (msg: string, meta?: unknown) => void } | undefined;
5295+
if (typeof sink?.error === 'function') sink.error(message, meta);
5296+
else console.error(message, meta);
5297+
}
5298+
52275299
/**
52285300
* The directory's half of the rule that an account disabled by any door
52295301
* keeps nothing running in its name (`removed-account-registrations.ts`):

0 commit comments

Comments
 (0)