Repository navigation
Commit 30e364e
fix(auth)!: with SSO-only mode on, an IdP-provisioned user is given no local password at any door; a platform administrator may still set their own (#33177)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoASGPj15PDYEW3irdvMYnjH)_
Clause-②: yes (narrowing) — narrowed: with SSO-only mode on
(`ssoOnlyMode`, or `OS_AUTH_SSO_ONLY=true`), the four doors that write a
local password, `POST /set-initial-password`, `POST
/admin/set-user-password`, `POST /reset-password` and `POST
/phone-number/reset-password`, answer `409 RESOURCE_CONFLICT` to a user
whose `sys_user.source` is `idp_provisioned`, where they set the
password; and the two reset doors answer `503 SERVICE_UNAVAILABLE` when
the reset record they would judge cannot be read. Widened: two public
members, `AuthManager#isSsoOnlyMode()` (the read of the SSO-only switch
the manager already resolves) and the optional `ssoOnlyMode?(): boolean`
on `AdminUserEndpointDeps`. No first-party composition in this
repository turns SSO-only mode on.
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches SSO-only mode or
these four doors; `content/docs/permissions/authentication.mdx` gains
the rule in this change, and `content/docs/deployment/self-hosting.mdx`
names SSO-only mode only for the missing-credential log level, which
does not move.
Part of #32087 (item 5, the server half under ruling record 6866334319:
honour the SSO-only switch. The administrator's set-password warning and
the governed ADR-0135 D5.2 note follow as their own work, and item 4 is
its own pull request.)
## 维护者速读
- 改了什么:环境开了"仅 SSO 登录"(`ssoOnlyMode` /
`OS_AUTH_SSO_ONLY`)时,服务端在四处会生成本地密码的入口(自设初始密码、管理员"设置密码"、邮件重置、短信重置)都拒绝给公司登录系统开通的员工(`idp_provisioned`)本地密码,回
409 并写明是"仅 SSO 模式";唯一例外是平台管理员给自己设应急密码。
- 为什么改:按你 11-13 对 #32087 第 5 项选的 D:兑现已有的"仅 SSO 登录"开关,开了就真的生效;spec 里
`ssoOnlyMode` 的描述同步写明服务端现在强制的规则。
- 风险与回滚:patch 级,但对**已经开着 SSO-only
的部署**是破坏性收紧(BREAKING):升级后,身份提供方开通的员工在这四处拿不到本地密码,改为走
SSO;平台管理员仍可给自己设应急密码。没开 SSO-only
的部署、本地(`env_native`)用户、云托管环境的规则都不变;已持有本地密码的员工照常用它登录和改密码(不追溯)。重置入口在读不到重置记录时拒绝(503),不放行。两处防锁死守卫没动。回滚就是还原本
PR。
-
先看:`packages/plugins/plugin-auth/src/sso-only-local-password.ts`(共用判定与重置入口的读法)、`auth-manager-before-hook.ts`
新增的重置入口分支、`admin-user-endpoints.ts` 的 set-user-password 分支。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/sso-only-local-password.test.ts src/cloud-managed.test.ts
src/password-reset-ends-sessions.test.ts`,预期 81 个用例全部通过。
- 需要你做的:无,席位落地。
## What changes
**The rule.** With SSO-only mode on, the server gives a user whose
`sys_user.source` is `idp_provisioned` no local password at any door
that writes one without the user proving a current one. Each door
answers `409 RESOURCE_CONFLICT` (the registered code the cloud-managed
refusals answer) with a message that names SSO-only mode, and writes
nothing. One exception keeps break-glass reachable: a platform
administrator setting their own local password.
| Door | SSO-only on, IdP-provisioned user | Exception (platform
administrator, own password) | Predicate asked |
|:--|:--|:--|:--|
| `POST /set-initial-password` | 409 | allowed | the session user's
`isPlatformAdminUser` (the cloud-managed door's own) |
| `POST /admin/set-user-password` (`sys_user#set_user_password`) | 409,
another administrator as target included | allowed when the target is
the caller (the route's gate admits platform administrators only) |
`actor.id === userId` behind `gateAdmin` |
| `POST /reset-password` (emailed link) | 409 | allowed |
`isPlatformAdminUserId` (the manager's platform-admin standing) |
| `POST /phone-number/reset-password` (texted code) | 409 | allowed |
`isPlatformAdminUserId` |
- `sso-only-local-password.ts` (new): the rule, its messages and refusal
envelope, `readUserSource` (moved here from `admin-user-endpoints.ts`,
the read the cloud-managed administrator door already asked, so both
rules read one), the shared verdict `judgeSsoOnlyLocalPassword` (`allow`
/ `refuse` / `unreadable`, which fails closed as `503
SERVICE_UNAVAILABLE`, as the cloud-managed door does), and
`resolveResetDoorUserId`. The module header names both
platform-administrator predicates, where they differ, and ADR-0135
D5.2's `env_native` stamp.
- The reset doors judge only a credential the door itself would accept,
read without spending it: a live reset token, or a texted code that
matches the live stored one inside its attempt budget (better-auth's own
non-consuming predicate for that door). Any other request answers
exactly as before. When the reset record (or the user it names) cannot
be read, the reset doors fail closed with `503 SERVICE_UNAVAILABLE`
instead of handing the request on unjudged.
- `admin-user-endpoints.ts`: the set-user-password arm after the
cloud-managed arm; the deps take `ssoOnlyMode()`, read live per call.
- `auth-plugin.ts`: the set-initial-password arm after the cloud-managed
arm; `adminUserDeps` passes `ssoOnlyMode`.
- `auth-manager-before-hook.ts`: the reset-door arm, ahead of the
password complexity check so the refusal names the real reason. The host
gains `getDataEngine` and `isSsoOnlyMode`.
- `auth-manager.ts`: `isSsoOnlyMode()`, the public read of the existing
`resolveSsoOnly()`.
- `packages/spec` `AuthConfigSchema.ssoOnlyMode`: TSDoc and `.describe`
say what the server now enforces;
`content/docs/references/system/auth-config.mdx` regenerated. No key,
value or export changes.
- `content/docs/permissions/authentication.mdx`: a short "SSO-only mode:
IdP-provisioned users get no local password" section, including the
fail-closed answer and which body shape each door answers.
**Unchanged:** SSO-only mode off; environment-native users (and rows
with no source) at every door; a local password a user already holds (it
still signs in, and `/change-password` still changes it); the
cloud-managed rules, which answer first on a cloud-managed environment;
`last-admin-guard.ts` and `last-local-credential.ts`. Not doors:
`/change-password` (proves the current password), `/sign-up/email`
(SSO-only already forces sign-up off), admin create-user and
import-users (new rows only; import never changes an existing user's
password), SCIM (writes no credential), the email-OTP reset (not
mounted).
## Breaking
**BREAKING** for a deployment already running with SSO-only mode on: an
IdP-provisioned user can no longer be given a local password at the four
doors above; each answers `409 RESOURCE_CONFLICT` and writes nothing.
Such a user signs in through the identity provider; a platform
administrator can still set their own break-glass password; a deployment
that needs a managed user to hold a local password turns SSO-only mode
off. Level stays `patch` (a non-protocol change; AGENTS.md, Post-Task
Checklist step 3). The widening is two additive public members:
`AuthManager#isSsoOnlyMode()` and the optional
`AdminUserEndpointDeps.ssoOnlyMode?()`. ADR-0087 disposition:
`not-required (no-migration-prescription)`, in the changeset: no schema
key, value or type moves, and nothing stored needs a migration.
## Why
Ruling record 6866334319 on #32087, item 5 → D: when SSO-only mode is
on, the server refuses to give an IdP-provisioned user a local password
at every door, with the one break-glass exception the cloud-hosted rule
already makes; SSO-only off is unchanged; not retroactive.
## Tests
- `sso-only-local-password.test.ts` (new, the module's own pins): the
verdict table (off reads nothing; refuse; the platform-administrator
exception; environment-native and source-less rows ask no standing; fail
closed on no engine, no read surface, a throwing read); the refusal
envelope and that its code and status equal the cloud-managed ones;
`resolveResetDoorUserId` names a user only for a live token or a
matching in-budget code, reads nothing on another path, and answers
unreadable when the reset record or the user lookup has no read surface
or throws.
- `cloud-managed.test.ts` (the set doors' shared harness, a real
`AuthManager` behind `registerAuthRoutes` on Hono), new top-level
describe: per door, SSO-only on refuses the IdP-provisioned user with
409 + code + sentence and writes no credential; the IdP-provisioned
platform administrator setting their own is allowed; an administrator
setting one for another IdP-provisioned administrator is refused; an
environment-native user and an anonymous caller answer as before;
SSO-only off answers as before (CONTROL); on a cloud-managed environment
the cloud-managed refusal answers. Not retroactive: an IdP-provisioned
user holding a password still signs in and changes it, while no door
sets it anew.
- The existing leg "unmanaged with SSO-only on, both doors answer the
idp user as before" pinned the behaviour this ruling reverses. It now
asserts that the SSO-only refusal answers there, never the cloud-managed
sentence, and a new leg keeps the SSO-only-off control.
- `password-reset-ends-sessions.test.ts` (the reset doors' shared
harness, a real ObjectQL on SQLite), new top-level describe: for each
reset door, SSO-only on refuses the IdP-provisioned user (409 + code +
sentence, no credential written); a holder is refused too and their
password still signs in; the platform administrator resetting their own
is allowed; an environment-native user answers as before; an unmatched
token or a wrong code answers exactly as it does with SSO-only off; a
reset record that cannot be read (every `sys_verification` read made to
throw) answers `503 SERVICE_UNAVAILABLE` and writes no credential;
SSO-only off resets as before (CONTROL).
## Acceptance notes
- Reading confirmed by the seat before the edit: the set and reset doors
refuse an IdP-provisioned user even when one already holds a password
(the cloud-managed administrator door does the same); "not retroactive"
means an existing password keeps working.
- The reset-door refusal leaves in better-auth's flat `{ code, message
}` body, the shape those doors' other refusals (`INVALID_TOKEN`,
`INVALID_OTP`) take; the set doors answer the nested ADR-0112 envelope,
as their cloud-managed refusals do.
- The cloud mounts its own twin of `set-initial-password` from
`runSetInitialPassword`; this PR puts the SSO-only arm in this
repository's route, as the cloud-managed arm is, and a cloud-managed
environment answers the stricter cloud-managed rule first.
- Contract review 6868317289 (FAIL at `f3393c48`, must-fix ②): this head
declares the narrowing and the widening, adds `!`, the BREAKING banner,
the ADR-0087 disposition and the `Skills-docs:` line, and runs the
dogfood battery. Nits 2, 3 and 5 are taken as prose (module header,
`authentication.mdx`). Nit 4 (the request-reset doors still send a mail
or text to a user whose reset will be refused) is not in the ruling and
is left for the seat.
- Remainders, not in this PR: the administrator's set-password warning
(ui card), the governed ADR-0135 D5.2 note (kept in step with cloud
ADR-0024 D5.2), and the question of managed users who already hold a
local password.
## Verification
All readings at head `f183d45b` (round 2, after contract review
6868317289), objectstack-ai/objectstack. Round 1 readings were at
`f3393c48`.
<details><summary>Tests</summary>
- `pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2` (whole package): Test Files 267 passed (267), Tests 5075
passed, 10 skipped, exit 0.
- The three files that carry this rule's pins
(`sso-only-local-password`, `cloud-managed`,
`password-reset-ends-sessions`): 3 files, 81 tests passed.
- `pnpm --filter @objectstack/plugin-auth typecheck` (with
`check:test-typecheck`): exit 0, after a full declaration build.
- eslint over the changed `.ts` files: exit 0.
- Dogfood battery (`packages/qa/dogfood`, `vitest run`, all shards in
one process): Test Files 462 passed, 3 skipped (465); Tests 3905 passed,
42 skipped; exit 0. Run on `35395b46` plus the changeset commit; the one
later commit, `f183d45b`, changes only the module's docblock.
</details>
<details><summary>Ablation (one shot each, not kept)</summary>
- Round 1: the shared judge's refuse verdict replaced with an
unconditional allow; 9 failed, 68 passed, every refusal leg. Restored,
`git diff HEAD` empty.
- Round 2: the reset-door reader's unreadable answer (its `catch`)
replaced with "names nobody"; 3 failed: the module pin for an unreadable
record and the two reset doors' 503 pins. Restored, `git diff HEAD`
empty.
</details>
<details><summary>Gates</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 120 families derived for this diff (the
same list as round 1); all 120 run with exit codes recorded first, all
exit 0.
- `dispatch-gates --ran`: 120 derived, 120 run, 0 NOT-MEASURED, 0 UNRUN.
- `check-adr-0087-registration --base origin/main`: 1 declared-breaking
changeset, `[BREAKING+bang+clause-②-narrowing]`, `not-required
(no-migration-prescription)`, exit 0.
- `pnpm --filter @objectstack/spec check:generated`: green (round 1
regenerated `content/docs/references/system/auth-config.mdx`; round 2
does not touch `packages/spec`).
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(Description text only.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (eslint over the changed
files, exit 0.)
- [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. (`check:generated --fix` regenerated the one
it proved stale, `content/docs/references/system/auth-config.mdx`.)
- [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 by [Claude
Code](https://claude.ai/code/session_01L9qibwgMDk9yn3MZdGMqEM)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibwgMDk9yn3MZdGMqEM
<!-- signed: security#2 · os-tesla · session_01L9qibwgMDk9yn3MZdGMqEM
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent de31809 commit 30e364e
14 files changed
Lines changed: 1133 additions & 35 deletions
File tree
- .changeset
- content/docs
- permissions
- references/system
- packages
- plugins/plugin-auth/src
- spec/src/system
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
346 | 374 | | |
347 | 375 | | |
348 | 376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
94 | 100 | | |
95 | 101 | | |
96 | 102 | | |
| |||
232 | 238 | | |
233 | 239 | | |
234 | 240 | | |
| 241 | + | |
235 | 242 | | |
236 | 243 | | |
237 | 244 | | |
| |||
408 | 415 | | |
409 | 416 | | |
410 | 417 | | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | 418 | | |
438 | 419 | | |
439 | 420 | | |
| |||
1118 | 1099 | | |
1119 | 1100 | | |
1120 | 1101 | | |
1121 | | - | |
| 1102 | + | |
1122 | 1103 | | |
1123 | 1104 | | |
1124 | 1105 | | |
| |||
1136 | 1117 | | |
1137 | 1118 | | |
1138 | 1119 | | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
1139 | 1134 | | |
1140 | 1135 | | |
1141 | 1136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
| |||
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
| 165 | + | |
164 | 166 | | |
165 | 167 | | |
166 | 168 | | |
| |||
824 | 826 | | |
825 | 827 | | |
826 | 828 | | |
| 829 | + | |
827 | 830 | | |
828 | 831 | | |
829 | 832 | | |
830 | 833 | | |
831 | 834 | | |
832 | 835 | | |
| 836 | + | |
833 | 837 | | |
834 | 838 | | |
835 | 839 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
73 | 82 | | |
74 | 83 | | |
75 | 84 | | |
| |||
99 | 108 | | |
100 | 109 | | |
101 | 110 | | |
| 111 | + | |
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
106 | 116 | | |
107 | 117 | | |
| 118 | + | |
108 | 119 | | |
109 | 120 | | |
110 | 121 | | |
| |||
182 | 193 | | |
183 | 194 | | |
184 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
185 | 239 | | |
186 | 240 | | |
187 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2101 | 2101 | | |
2102 | 2102 | | |
2103 | 2103 | | |
| 2104 | + | |
2104 | 2105 | | |
2105 | 2106 | | |
2106 | 2107 | | |
| |||
2112 | 2113 | | |
2113 | 2114 | | |
2114 | 2115 | | |
| 2116 | + | |
2115 | 2117 | | |
2116 | 2118 | | |
2117 | 2119 | | |
| |||
5438 | 5440 | | |
5439 | 5441 | | |
5440 | 5442 | | |
| 5443 | + | |
| 5444 | + | |
| 5445 | + | |
| 5446 | + | |
| 5447 | + | |
| 5448 | + | |
| 5449 | + | |
| 5450 | + | |
| 5451 | + | |
| 5452 | + | |
5441 | 5453 | | |
5442 | 5454 | | |
5443 | 5455 | | |
| |||
0 commit comments