Repository navigation
Commit b5765be
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgA9Z648v7EcnvTMWpmnkjL3)_
domain:server#2 · os-bill · session_01Utp6Cbvcmv8YWFhFJwzjKL
## 维护者速读
- 改了什么:Setup → 认证里清空一个设置(或"恢复默认"整组重置)后,运行值当场回到部署自己声明的值(插件选项 /
`auth:configure`,没声明就回内置默认),不再要重启。覆盖全部 33 个认证设置:锁定阈值、每人最大会话、密码策略、会话时长、强制
MFA、API 密钥期限、限流、Google、受众策略等;IP 白名单(#30203)并入同一机制。
- 为什么改:清空后界面显示默认值,但运行时一直沿用上次存的值,直到重启(实测:锁定阈值 3、最大会话 2
清空后仍生效)。管理员以为已经恢复默认,其实没有。
- 风险与回滚:收窄一处(Clause-② `yes (narrowing)`):部署声明"邮箱密码登录关"、在 Setup 里打开、再关掉了
Google,此时清空"邮箱密码登录"会被拒存(400
`SETTINGS_VALIDATION`),因为清空现在真的会把它关掉、导致无人能登录。其余清空只是开始生效。环境变量锁定的设置不受影响。回滚即撤本
PR。
-
先看:`packages/plugins/plugin-auth/src/auth-settings-declared.ts`(回落表,每个键走哪一片);`auth-plugin.ts`
的 `applySettings` 新增回落段与受众回落;`sign-in-method-floor.ts` 清空按声明值判的一行。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/auth-settings-clear.pin.test.ts`,预期 17/17 通过,其中第一组断言锁定阈值清空后当场回到声明的
7。
- 需要你做的:无,席位落地。
Fixes #30312
Clause-②: yes (narrowing) — one save an administrator could make before
is now refused at the auth settings save door with the existing
`SETTINGS_VALIDATION` / `invalid_value` field error at
`email_password_enabled`: clearing that toggle on a deployment that
itself declared email and password off, when nothing else signs anyone
in after the save. Before, that clear was saved and changed nothing at
runtime; now a clear applies, and that one would lock everyone out. No
error code, settings key or export is added or removed.
Metadata-protocol: none
Skills-docs: none — no file under `skills/**` teaches the auth settings
namespace, its clear or the sign-in floor.
## Why
`PUT /api/settings/auth` with a key set to `null` (the console's clear),
or the namespace reset, answers saved, and the key resolves `source:
'default'`. Every `if (isExplicit(key))` branch in `applySettings`
skipped such a key, so the running value kept the last stored one until
a restart. Re-measured first on `dbf53efe`, real `AuthPlugin` +
`SettingsService`: `lockout_threshold` 3 and
`max_concurrent_sessions_per_user` 2 stayed 3 / 2 after `setMany(…,
null)`; a reset left `lockout_threshold` 4. Only `allowed_ip_ranges` had
a reset arm (#30203, PR #30309).
## What changes
- **One mechanism, not thirty `else` arms.** `auth-settings-declared.ts`
holds two pieces of data. `captureDeclaredAuthOptions` takes, once in
`init()` after `auth:configure` and before the manager is built, the
deployment's own value of every option an `auth.*` key drives.
`AUTH_SETTING_RESTORE` names, for each of the 33 keys of the shipped
auth manifest, the piece its declared value goes back through.
- **The restore arm in `applySettings`.** The pass keeps the set of keys
the running config last took from the store. A key in that set that now
resolves `source: 'default'` is restored in the same pass, through the
same piece a save of it rides, so the manager judges a restore as it
judges a save:
- plain options (membership policy, password complexity / classes /
history / expiry, MFA grace, the four API-key keys, session idle /
absolute / concurrent, lockout pair, `allowed_ip_ranges`) ride the plain
patch;
- `emailAndPassword` fields (`email_password_enabled`, `signup_enabled`,
`require_email_verification`, `password_min_length`,
`password_max_length`) are each their own refusable piece; the
verification flag restores as the deployment's declaration (#20389), as
at boot;
- `password_reject_breached` is its own `plugins` piece;
- `mfa_required` restores as a save of the declared value would apply: a
declared on is one piece with `plugins.twoFactor`, a declared off clears
the requirement and leaves the enrollment path standing, exactly as an
explicit off does;
- `session_expiry_days` / `session_refresh_days` merge over the declared
`session` block (a stored field overrides its declared twin; before, a
stored field replaced the whole block);
- the rate-limit pair and the Google trio restore whole once none of
their keys is stored; the audience restores whole once
`audience_posture` is not stored, through the same merged-result
validation (a sibling still stored without a posture is IGNORED, as
before).
- A key whose restore the manager refuses stays owed and is retried on
the next pass. A key the store never gave a value is never touched (boot
restores nothing). Env overrides resolve `source: 'env'` and are
unaffected.
- **`allowed_ip_ranges`** moves onto the same table;
`declaredAllowedIpRanges` / `allowedIpRangesFromSettings` are gone. Its
#30203 pins pass unchanged (an undeclared list restores to `undefined`,
which the gate reads as open, as `[]` was).
- **The sign-in floor (`sign-in-method-floor.ts`, file surface widened
by the seat).** The floor read a cleared `email_password_enabled` as on
(the manifest default). With clears now applying, a deployment that
declared email and password off could clear the toggle into a lockout.
Measured before the floor change: declared off + Google, Setup sets
email/password on, then Google off, then clears the toggle → 200, and
the running config ends `emailPassword.enabled: false` with no provider.
The floor now takes an optional `declaredEmailPasswordEnabled()` reader
(from `bindAuthSettings`) and judges a cleared toggle at the
declaration; the same clear is refused 400 and nothing changes. With
another way in standing, the clear saves and applies.
## Tests
`packages/plugins/plugin-auth/src/auth-settings-clear.pin.test.ts`, 17
cases, on #30203's composition (real `AuthPlugin`, real
`SettingsService` with the shipped auth manifest, real settings routes
for the save-door cases):
1. The restore table names exactly the shipped manifest's keys.
2. Plain options: the measured case (declared `lockoutThreshold: 7` back
to 7; undeclared max sessions back to `undefined`); password classes +
API-key max expiry; a pass about one stored key applies only that key's
option (`applyConfigPatch` spy).
3. Refusable pieces: `emailAndPassword` fields; breached-password flag;
`mfa_required` to a declared off (enrollment stays) and to a declared on
(with `twoFactor`); the floor refuses the clear with no other way in
(code, field, `invalid_value`, runtime unchanged) and lets it through
with Google standing.
4. Groups: session merge; rate-limit pair; Google; audience (all three
cleared; posture alone cleared with siblings stored).
5. Namespace reset across families; an env-pinned
`OS_AUTH_LOCKOUT_THRESHOLD` survives a reset.
Ablations, each through `scripts/ablation-replace.mjs` (anchor 1 → 0,
restored to the HEAD blob, `git diff HEAD` empty; tests import `src/`,
no dist in the path):
| Ablated | Red |
| --- | --- |
| A1 plain-patch arm | 7 (incl. all three #30203 clear pins) |
| A2 `emailAndPassword` arm | 3 |
| A3 `plugins` arm | 1 |
| A4 session arm | 1 |
| A5 `mfa_required` declared-off arm | 1 |
| A6 `mfa_required` declared-on arm | 1 |
| A7 rate-limit group | 2 |
| A8 Google group | 1 |
| A9 audience restore | 2 |
| A10 floor reads a clear at the declaration | 1 |
| A11 store tracking (restore every unstored key) | 1 (the spy pin) |
## Acceptance notes
- With one rate-limit key cleared and the other stored, the explicit
branch keeps building the limit with its built-in fallbacks (10 / 60)
for the cleared half, not the declared `rateLimit`; unchanged from
before.
- A deployment that declared `mfaRequired: true` while
`OS_AUTH_TWO_FACTOR=false` restores to its own contradictory boot state
on a clear; the gate's once-per-process warning (#30201) names it. Not
filed: boot already lands there.
## Verification
Readings under `scripts/pm/os-verify-lock.sh`, shared box. **Landing
head `c22645eb`**: `8b9f159f` plus a merge of `origin/main` at
`f506b79d` (29 commits, among them PR #30449 for #30300). One hand
resolution, in `auth-plugin.ts`: #30449's one-line
`registerSignInMethodFloor(…, this.signInMethodFloorDeps(…), …)` taken,
and this PR's `declaredEmailPasswordEnabled` reader moved into that
shared constructor (read only by the save floor's batch fallback; the
SSO-provider delete floor and the boot report judge the running config).
Delta contract review PASS, comment 6659465418.
On `c22645eb`, one run under the verify lock (`VERDICT command-exit 0`,
every step exit 0): closure build of `dogfood^...` and
`service-settings^...`; full dogfood Test Files 419 passed, 3 skipped
(422), Tests 3492 passed, 36 skipped (3528); `@objectstack/plugin-auth`
test 225/225 files, 3991 passed, 10 skipped (4001); plugin-auth
typecheck exit 0 (`check:test-typecheck` OK);
`@objectstack/service-settings` test 68/68 files, 1156/1156;
service-settings typecheck exit 0.
Earlier readings, kept for the record: code head `f58be8f5`; `8b9f159f`
was that plus a merge of `origin/main` (23 commits, none touching
`auth-plugin.ts`, `sign-in-method-floor.ts` or `service-settings`).
<details><summary>Suites and typecheck</summary>
- On `8b9f159f`: `pnpm --filter '@objectstack/plugin-auth^...' build &&
pnpm --filter @objectstack/plugin-auth test && pnpm --filter
@objectstack/plugin-auth run typecheck`: `VERDICT command-exit 0`; Test
Files 225 passed (225), Tests 3971 passed, 10 skipped (3981);
`check:test-typecheck: OK`. (A first run after the merge, before
rebuilding the closure, read a stale `@objectstack/spec` dist and failed
`public-feature-registry.test.ts` on main's new `emailDelivery` flag;
the rebuilt run above is green.)
- On `f58be8f5`: the same suite 225/225 files, 3966 passed; `pnpm lint`:
exit 0.
- The new file alone: 17/17. Ablations as in the table above.
</details>
<details><summary>Full dogfood battery (owed by the narrowing
arm)</summary>
On `f58be8f5`: `pnpm --filter '@objectstack/dogfood^...' build && pnpm
--filter @objectstack/dogfood test` (no shard, no path): `VERDICT
command-exit 0`, held the lock 40m35s; 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 --repo
objectstack-ai/objectstack` derived 64 commands on `f58be8f5`; each run
with its exit code recorded before any pipe. `--ran`: 64 derived, 63
run, 1 NOT-MEASURED, 0 UNRUN. NOT MEASURED: `pnpm
check:dual-build-cjs-loads` (exit 3, PREREQUISITE NOT MET: it needs a
whole-workspace build; CI runs it). `check-plugin-teardown-shape
--self-test` first exited 3 (shallow clone, pinned fixture commit), then
0 after fetching that commit. Every other command exited 0.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZPLJKSBMtARXMHc4W)_
<!-- signed: domain:server#2 · os-bill ·
session_01Utp6Cbvcmv8YWFhFJwzjKL -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent fb1ab89 commit b5765be
5 files changed
Lines changed: 670 additions & 29 deletions
File tree
- .changeset
- 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
| |||
554 | 561 | | |
555 | 562 | | |
556 | 563 | | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
561 | 575 | | |
562 | | - | |
563 | | - | |
564 | | - | |
| 576 | + | |
565 | 577 | | |
566 | 578 | | |
567 | 579 | | |
| |||
801 | 813 | | |
802 | 814 | | |
803 | 815 | | |
804 | | - | |
| 816 | + | |
805 | 817 | | |
806 | 818 | | |
807 | 819 | | |
| |||
2070 | 2082 | | |
2071 | 2083 | | |
2072 | 2084 | | |
| 2085 | + | |
| 2086 | + | |
2073 | 2087 | | |
2074 | 2088 | | |
2075 | 2089 | | |
| |||
2161 | 2175 | | |
2162 | 2176 | | |
2163 | 2177 | | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
2164 | 2190 | | |
2165 | 2191 | | |
2166 | 2192 | | |
| |||
2369 | 2395 | | |
2370 | 2396 | | |
2371 | 2397 | | |
2372 | | - | |
2373 | | - | |
2374 | | - | |
2375 | 2398 | | |
2376 | 2399 | | |
2377 | 2400 | | |
| |||
2393 | 2416 | | |
2394 | 2417 | | |
2395 | 2418 | | |
2396 | | - | |
2397 | | - | |
2398 | | - | |
2399 | | - | |
| 2419 | + | |
| 2420 | + | |
2400 | 2421 | | |
2401 | 2422 | | |
2402 | | - | |
2403 | | - | |
2404 | | - | |
2405 | | - | |
2406 | 2423 | | |
2407 | 2424 | | |
2408 | 2425 | | |
| |||
2477 | 2494 | | |
2478 | 2495 | | |
2479 | 2496 | | |
2480 | | - | |
2481 | | - | |
2482 | | - | |
2483 | | - | |
2484 | | - | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
2485 | 2571 | | |
2486 | 2572 | | |
2487 | 2573 | | |
| |||
2497 | 2583 | | |
2498 | 2584 | | |
2499 | 2585 | | |
| 2586 | + | |
2500 | 2587 | | |
2501 | 2588 | | |
2502 | 2589 | | |
| |||
2508 | 2595 | | |
2509 | 2596 | | |
2510 | 2597 | | |
2511 | | - | |
2512 | | - | |
2513 | | - | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
2514 | 2604 | | |
2515 | 2605 | | |
2516 | 2606 | | |
| |||
2548 | 2638 | | |
2549 | 2639 | | |
2550 | 2640 | | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
2551 | 2659 | | |
2552 | 2660 | | |
2553 | 2661 | | |
| |||
2601 | 2709 | | |
2602 | 2710 | | |
2603 | 2711 | | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
2604 | 2717 | | |
2605 | 2718 | | |
2606 | 2719 | | |
| |||
0 commit comments