Repository navigation
Commit a93ef3e
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgWXUffkVpeZMuUzb3Fkntr9)_
Fixes #30300
Clause-②: yes (narrowing)
Metadata-protocol: none
Skills-docs: none — no file under `skills/**` teaches deleting an SSO
provider or the sign-in boot reports;
`content/docs/deployment/self-hosting.mdx` gains "No sign-in method
left".
## 维护者速读
- **改了什么**:邮箱密码登录关闭、只剩一个企业 SSO 身份提供方时,Setup 的「删除 SSO
提供方」被拒(409),不再删掉最后一条登录路;重部署后没有任何登录方式时,启动日志打一条 error,启动照常。
- **为什么改**:两扇门都在 main 上真实启动复现过:删完或重部署之后,全租户连同管理员都登录不了,而且没有任何提示。
- **风险与回滚**:只在「邮箱密码关、SSO 开、这是最后一个提供方、没有其他登录方式」时拒删,其余删除照旧;读不到提供方列表时返回 503
拒删。回滚即 revert 本 PR。
- **先看**:`sign-in-method-floor.ts` 的 `ssoProviderDeleteRefusal` 与
`resolveNoSignInMethodReport`;`auth-manager-before-hook.ts` 的
`/sso/delete-provider` 分支;`auth-plugin.ts` kernel:ready 新增的那一段。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/sign-in-method-floor.test.ts`,预期 35 条全过。
- **需要你做的**:无,席位落地。
## What changes
Two doors removed the last way to sign in without a word. Both are now
judged by the sign-in method floor that #30298 added to the auth
settings save (`sign-in-method-floor.ts`), so the three doors cannot
drift apart.
**Door 1: deleting the last identity provider.** `POST
/api/v1/auth/sso/delete-provider` (Setup's "Delete SSO Provider") is
refused in plugin-auth's global better-auth before-hook, before the
vendor deletes anything, when all of these hold:
- email and password sign-in is off;
- enterprise SSO is switched on;
- no other way in counts: a social or OIDC provider with a client ID and
secret, phone-number sign-in, or a host sign-in handoff;
- the provider being deleted is the last `sys_sso_provider` row. One
bounded read of two rows answers this.
The answer is `409` with `code: DELETE_RESTRICTED`, `lastSignInMethod:
enterprise_sso`, and a message in the caller's language (en, zh-CN,
ja-JP, es-ES). This is an existing standard code, the one an
organization delete answers when it is refused for the same kind of
reason. When the provider list cannot be read, the answer is `503
SERVICE_UNAVAILABLE`, because a guard that could not be evaluated does
not pass.
Nothing changes for an unauthenticated caller (still the vendor's
`401`), an unknown provider (still the vendor's `404`), or the vendor's
own provider-access check.
- `AuthManager.setSsoProviderDeleteFloor()` (`@internal`): `AuthPlugin`
hands the manager the judge, because the manager does not hold the host
handoff declaration or the boot credential index.
- `AuthPlugin.signInMethodFloorDeps()`: one builder of the floor's live
facts, used by the settings save, the delete, and the boot report.
**Door 2: a boot that serves no way in.** At the `kernel:ready` site
that already reports `no_sign_in_account_at_boot`, after the auth
settings are applied, a deployment that serves no sign-in method now
reports `no_sign_in_method_at_boot` at `error`. The line names the
consequence and the recovery: `OS_AUTH_EMAIL_PASSWORD_ENABLED=true` and
a restart.
- It is a positive claim only: a provider table that cannot be read
stays silent.
- It is reported in every posture and **never refuses the boot** (seat
ruling, option A). A platform-SSO tenant that signs in through a door
this plugin cannot see, such as `ssoOnlyMode`, which the floor does not
count, must keep starting.
- **Refusing such a boot is a later option, not done here.** It fits
only once every delegated path is counted.
**Docs.** `content/docs/deployment/self-hosting.mdx` gains "No sign-in
method left", covering the three doors and the recovery.
## Why
Both doors were measured on `main` bfca0ef on a real boot before any
code (report 6652003986).
- **Door 1.** With email and password off and one SAML provider as the
only way in, the delete answered `200 {"success":true}`. After sign-out,
`/sign-in/email` answered `400 EMAIL_PASSWORD_DISABLED` and
`/sign-in/sso` answered `404`.
- **Door 2.** A redeploy without the `GOOGLE_CLIENT_*` pair booted to
"Server is ready" with no sign-in line, and served no method.
## Tests
Pins added to the floor's shared harness
`packages/plugins/plugin-auth/src/sign-in-method-floor.test.ts`, as
top-level describes. There are 18 new cases, and the file has 35 in all.
- **Door 1, real composition.** `ObjectKernel` + `ObjectQLPlugin` over
in-memory SQLite, the real `SettingsServicePlugin`, the real
`AuthPlugin` with the SSO plugin, and a real sign-up and session cookie.
Email and password is turned off through `settings.setMany`, which the
floor admits while a provider row exists. Then the real `POST
/api/v1/auth/sso/delete-provider`:
- the last provider gets `409 DELETE_RESTRICTED`, the zh-CN copy under
`Accept-Language: zh-CN`, then the en copy, and the row is still there;
- CONTROL, two providers: the first delete goes through (`200`) and the
one left is then refused;
- CONTROL, email and password on: the delete goes through;
- CONTROL: an unknown provider gets the vendor's `404`, and no session
gets the vendor's `401`.
- **Door 2, the same composition.**
- `emailAndPassword.enabled: false` with no provider reports once at
`error` and the boot completes;
- the same with SSO on and no row;
- CONTROL: `GOOGLE_CLIENT_*` set reports nothing;
- recovery: `OS_AUTH_EMAIL_PASSWORD_ENABLED=true` turns email and
password back on over the stack config, and nothing is reported.
- **The judge and the report**, for faults the composition cannot make:
- an unreadable provider list gets `503` on the delete and silence at
boot;
- seven pass cases;
- the report goes to `error`, or to `warn` on a sink without `error`,
and a throwing sink does not throw.
<details><summary>Ablations (each through
<code>scripts/ablation-replace.mjs</code>, restored, worktree clean
after)</summary>
Each mutation landed (anchor 1 → 0, blob changed), the run went red as
below, and the file was restored to the HEAD blob (`git status` clean).
- **A1**, door 1 call removed from the before-hook (`await
this.assertSsoProviderDeletable(ctx);`): the last-provider refusal and
the "one left is then refused" control go red, `expected 200 to be 409`.
2 failed, 33 passed. This reproduces the bug on the test stack.
- **A2**, the boot report call removed from `kernel:ready`: both door 2
report cases go red. 2 failed, 33 passed.
- **A3**, an unreadable provider list read as "another provider
remains": the 503 case goes red. 1 failed, 17 passed (run before the
pins moved into the shared file).
- **A4**, the boot report speaks unless a provider row is `present`: the
positive-claim case goes red. 1 failed, 17 passed (same).
- **A5**, `AuthPlugin` does not hand the manager the judge: the two door
1 refusal cases go red, `{"success":true}: expected 200 to be 409`. 2
failed, 16 passed (same).
A1 and A2 were re-run against the final shared file.
</details>
## Acceptance notes
- **Clause-② re-measured: yes (narrowing).** The Claim wrote `no — the
dev re-measures`. Measured: a request accepted before (`POST
/sso/delete-provider` on the last provider, `200`) is now refused
(`409`). That is an accept-set narrowing at a public endpoint, the same
kind #30298 declared for the settings save. Hence the `!` and the
BREAKING section in the changeset. The widening half is one `@internal`
setter on the exported `AuthManager`.
- **Metadata-protocol: none.** No metadata shape or semantics change.
- **Out of scope, filed by the seat as #30352.** Setup's Register SAML
Provider bridge always answers 400 on this vendor version, so the
re-measure registered providers through the vendor's `/sso/register`.
## Verification
All readings are on head `385ecdcc`: this branch merged with
`origin/main` `7d7babb1`, which carries #30368 and #30376. Heavy runs
were under `scripts/pm/os-verify-lock.sh` on a shared box.
<details><summary>Real boot re-measure of both doors (pnpm dev,
SqlDriver better-sqlite3)</summary>
Door 1: fresh boot with `OS_SSO_ENABLED=true`, signed in as the dev
admin. Two SAML providers were registered through
`/api/v1/auth/sso/register`. `PUT /api/settings/auth
{email_password_enabled:false}` answered `200`; the floor admits it
while SSO has rows.
- `POST /api/v1/auth/sso/delete-provider {providerId:"beta-saml"}` →
`200 {"success":true}` (another provider remains).
- `POST /api/v1/auth/sso/delete-provider {providerId:"acme-saml"}` →
`409 {"code":"DELETE_RESTRICTED","message":"This is the last enterprise
SSO identity provider, and with email and password off nothing else
signs anyone in, …","lastSignInMethod":"enterprise_sso"}`.
- The same with `Accept-Language: zh-CN` → `409` with the zh-CN copy.
- `GET /api/v1/data/sys_sso_provider` → `acme-saml` still there;
`/auth/config` `features.sso: true`.
- After sign-out, `POST /api/v1/auth/sign-in/sso
{email:"someone@acme.test"}` → `200` with the IdP redirect URL.
Door 2: the database from the measurement round, with
`auth.email_password_enabled` stored `false` and Google previously
declared by env.
- The redeploy without `GOOGLE_CLIENT_*` logged `ERROR [auth]
no_sign_in_method_at_boot: this deployment serves NO way to sign in, …
Recover: set OS_AUTH_EMAIL_PASSWORD_ENABLED=true and restart … The boot
continues.`, then `✓ Server is ready`.
- `/sign-in/email` → `400 EMAIL_PASSWORD_DISABLED`.
- The recovery boot with `OS_AUTH_EMAIL_PASSWORD_ENABLED=true` logged no
such line, and `/sign-in/email` → `200`.
</details>
<details><summary>Suites, typecheck, lint</summary>
- `pnpm exec turbo run build --filter='!@objectstack/docs'
--concurrency=3` → `VERDICT command-exit 0`, 119/119 tasks.
- `pnpm --filter @objectstack/plugin-auth test` → `VERDICT command-exit
0`; Test Files 224 passed (224), Tests 3967 passed, 10 skipped (3977).
- `pnpm --filter @objectstack/plugin-auth typecheck` → `VERDICT
command-exit 0` (`check:test-typecheck: OK`, debt ledger unchanged).
- `src/sign-in-method-floor.test.ts` alone → 35/35.
- `pnpm lint` → `VERDICT command-exit 0`.
</details>
<details><summary>Full dogfood battery (owed by the narrowing
arm)</summary>
`pnpm --filter @objectstack/dogfood test` (no shard, no path), after the
whole-workspace build above → `VERDICT command-exit 0`, held the lock
33m24s. Test Files 419 passed, 3 skipped (422). Tests 3492 passed, 36
skipped (3528). No failure.
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 95 commands on
`385ecdcc`. Each was run with its exit code recorded before any pipe,
and all 95 exited 0. `--ran`: 95 derived, 95 run, 0 NOT-MEASURED, 0
UNRUN.
On the pre-merge head `e5f6926f`, two commands were non-zero:
- `check:liveness`: main's own red, fixed by #30368 and green after the
merge.
- `check-plugin-teardown-shape --self-test`: exit 3, its pinned fixture
commit missing from the shallow clone. It passed after `git fetch
--depth=1` of that commit.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(No spec change.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [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: n/a.
- [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 (the 维护者速读 block is the
maintainers' Chinese summary).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Utp6CadeYZeJahkVWxXfYx
<!-- signed: domain:server#3 · os-bill ·
session_01Utp6CadeYZeJahkVWxXfYx -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 648089d commit a93ef3e
8 files changed
Lines changed: 702 additions & 28 deletions
File tree
- .changeset
- content/docs/deployment
- 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 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
628 | 628 | | |
629 | 629 | | |
630 | 630 | | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
631 | 653 | | |
632 | 654 | | |
633 | 655 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
780 | 781 | | |
781 | 782 | | |
782 | 783 | | |
| 784 | + | |
783 | 785 | | |
784 | 786 | | |
785 | 787 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
308 | 310 | | |
309 | 311 | | |
310 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
311 | 324 | | |
312 | 325 | | |
313 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
1588 | 1589 | | |
1589 | 1590 | | |
1590 | 1591 | | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
1591 | 1608 | | |
1592 | 1609 | | |
1593 | 1610 | | |
| |||
1744 | 1761 | | |
1745 | 1762 | | |
1746 | 1763 | | |
| 1764 | + | |
1747 | 1765 | | |
1748 | 1766 | | |
1749 | 1767 | | |
| |||
5044 | 5062 | | |
5045 | 5063 | | |
5046 | 5064 | | |
| 5065 | + | |
| 5066 | + | |
| 5067 | + | |
| 5068 | + | |
| 5069 | + | |
| 5070 | + | |
| 5071 | + | |
| 5072 | + | |
| 5073 | + | |
| 5074 | + | |
| 5075 | + | |
| 5076 | + | |
| 5077 | + | |
| 5078 | + | |
| 5079 | + | |
| 5080 | + | |
| 5081 | + | |
| 5082 | + | |
| 5083 | + | |
| 5084 | + | |
| 5085 | + | |
| 5086 | + | |
| 5087 | + | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
5047 | 5094 | | |
5048 | 5095 | | |
5049 | 5096 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
114 | 121 | | |
115 | 122 | | |
116 | 123 | | |
| |||
800 | 807 | | |
801 | 808 | | |
802 | 809 | | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
803 | 816 | | |
804 | 817 | | |
805 | 818 | | |
| |||
1509 | 1522 | | |
1510 | 1523 | | |
1511 | 1524 | | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
1512 | 1542 | | |
1513 | 1543 | | |
1514 | 1544 | | |
| |||
2013 | 2043 | | |
2014 | 2044 | | |
2015 | 2045 | | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
2016 | 2071 | | |
2017 | 2072 | | |
2018 | 2073 | | |
| |||
2086 | 2141 | | |
2087 | 2142 | | |
2088 | 2143 | | |
2089 | | - | |
2090 | | - | |
2091 | | - | |
2092 | | - | |
2093 | | - | |
2094 | | - | |
2095 | | - | |
2096 | | - | |
2097 | | - | |
2098 | | - | |
2099 | | - | |
2100 | | - | |
2101 | | - | |
2102 | | - | |
2103 | | - | |
2104 | | - | |
2105 | | - | |
2106 | | - | |
2107 | | - | |
2108 | | - | |
| 2144 | + | |
2109 | 2145 | | |
2110 | 2146 | | |
2111 | 2147 | | |
| |||
0 commit comments