Skip to content

Commit 338ef35

Browse files
os-warrenclaude
andauthored
fix(auth)!: a boot outside development mode retires what the development seed issued (#36699)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8Nxmrq3P2eHj4WzMaPKLjA1)_ Fixes #35184 Supersedes #36311: this branch carries that PR's commits (head `c1e7347cc1`, merged onto current `main`) and adds one hardening commit. The card thread can push only its own branch, so the takeover lands here. Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none — no skill states what a boot outside development mode does to a seeded account's credentials. `skills/**` names the development seed only as `os dev --seed-admin` (`skills/objectstack-platform/references/operations.md`); checked at `origin/main`. ## 维护者速读 - 用户能看到什么变化:不在开发模式的服务器每次启动、开始接请求之前,会结束开发种子建的管理员和演示账号在开发期拿到的会话、API key 和令牌,包括这些账号以别人身份开的会话;只针对仍是种子密码的这些账号,运维改过密码的账号和管理员自建的账号不受影响,开发模式下什么都不变。 - 为什么做:开发种子凭据加固的第三项(#34717 裁决里留作跟进的那一项):离开开发模式后,开发种子签发的东西不再继续起作用。 - 出错会怎样:拿开发库直接上生产的部署,这些账号的旧会话和 key 会失效,需要运维改密后重新登录、重新发 key;结束不干净时服务器拒绝启动并说明是哪些账号。 - 要你做什么:收窄类改动,L1/L2 之后由你合并。 ## What changes **The rule (ruling item 3 on #34717, the card's text): when a deployment leaves development mode, nothing the development seed issued keeps acting for an account that carries the development seed stamp.** Development mode is `NODE_ENV=development` (`isDevelopmentMode`, the predicate the #34717 refusals use). No switch. From #36311 (unchanged, see that PR for the full account): - `dev-seed-credential-retirement.ts` (new), `retireDevSeedCredentials`: outside development mode, one indexed read for stamped accounts, the in-force filter (`isDevSeedCredentialInForce`), then per account the revocation `os user set-password` uses (`revokeSessionsAndApiKeys`: sessions tombstoned, keys revoked, authorized apps, device sign-ins, linked sign-in accounts, registered OAuth apps, SCIM credentials), outstanding reset tokens (`endOutstandingResetTokens`), and sessions in a host `secondaryStorage` (read back). - Wiring: one `kernel:ready` hook in `auth-plugin.ts`, independent of `registerRoutes`; it settles before `kernel:listening` opens the socket. - Fail closed: anything that does not land fails the boot with one sentence naming the accounts and the remedy. - Docs (`content/docs/deployment/self-hosting.mdx`), changeset (`patch`, `!`, BREAKING section, ADR-0087 `not-required`), census shard regenerated. New in this PR: - **The sessions a seed account opened acting as another account are retired too** (`retireSessionsOpenedAs`), tombstoned exactly as the account's own (same reason, counted in `sessions`, same fail-closed rule). A further security item is with the owner seat. - `forced-reset-revocation.ts`: `isLiveSession` is exported for reuse (no behaviour change). - Docs and changeset name the new item; the self-hosting sentence about `os user set-password` now says what that command ends (the account's own sessions, keys and grants) instead of "the same credentials". - Census shard regenerated on current `main` (`node scripts/tenant-audit-census.mjs --write`). **Read first (by risk):** 1. `packages/plugins/plugin-auth/src/dev-seed-credential-retirement.ts`: `retireDevSeedCredentials` and `retireSessionsOpenedAs`. 2. `packages/plugins/plugin-auth/src/auth-plugin.ts`, the `kernel:ready` hook: it runs on every boot outside development. 3. `packages/plugins/plugin-auth/src/dev-seed-credential-retirement.test.ts`, cases 1–3. **Two-minute check:** `pnpm --filter @objectstack/plugin-auth exec vitest run src/dev-seed-credential-retirement.test.ts` shows 6 cases green. ## Why #35184 (p1): credentials the development seed issued kept acting after the deployment left development mode. ## Verification Branch `claude/project-thread-grxa1f`, head `fb3c2cc478`, on `origin/main` `115d38788e`. - **Red first.** The new assertion was added to case 1 before the fix and run at the merged head (`035b1fdfe`): case 1 red, 5 others green. After the fix: 6/6 green. Removing the new call is that same red. - **Suites** (under `scripts/pm/os-verify-lock.sh`): `dev-seed-credential-retirement`, `dev-seed-credential-production`, `dev-seed-credential` (3 files, 26 passed) on the port before the fix; then `dev-seed-credential-retirement`, `api-key-restore-guard`, `forced-reset-revoke-reason-vocabulary`, `scim-deactivation-reconcile-user`, `session-tombstone`, `admin-impersonate-endpoint` (6 files, 128 passed) after it. `pnpm --filter @objectstack/plugin-auth build && … typecheck`: exit 0, `check:test-typecheck` OK. - **Derived gates:** `node scripts/pm/dispatch-gates.mjs --commands` derived 110, all run: 104 exit 0; `check-empty-changeset` exit 1 by design (the DELIBERATE CORRECTION below); `check-tenant-audit-census` and its self-test exit 1 on the first pass (shard drift from the new write site), regenerated, both re-run exit 0; NOT MEASURED (exit 3, prerequisite): `check-plugin-teardown-shape --self-test` (needs an unshallow clone), `check:skill-examples`, `check:dual-build-cjs-loads` (need packages built). CI carries those three. - **Overlap:** see Acceptance notes. - **Dogfood battery:** not run locally for this round; CI's Dogfood Regression Gate reads it. #36311's battery (484 files passed, 0 failed) was on the code before the new commit. ## Acceptance notes - **Which accounts.** The in-force reading from #36311 stands: an account whose password was set since the seed holds a credential the seed did not issue and is untouched; retiring on the bare column would end operator-era credentials at every restart. - **Revoke reason.** `admin_password_reset`, as in #36311; a dedicated reason is follow-up #36313. - **`.changeset/dev-seed-credential-production-refusal.md`** (unreleased, from #34717) is corrected: see `## DELIBERATE CORRECTION`. - **Test file weight.** The six two-boot cases read about 11.4 s of test time locally (case 1 gained one sign-in and one request); #36311 read 9.98 s. Over the 10 s file line; splitting the file would duplicate its two-boot harness, so it is kept as one and declared here. - **Overlap** (`overlap-check.mjs` at this head, #36311 excluded): `.changeset/dev-seed-credential-production-refusal.md` conflicts with #35129; the generated census shard conflicts with #34738 (whoever lands second regenerates it). `auth-plugin.ts` with #36690 merges cleanly. - The production-readiness page is not edited; the card names the self-hosting checklist. ## DELIBERATE CORRECTION This PR rewrites two lines in a pending release note it did not add: `.changeset/dev-seed-credential-production-refusal.md`, in the note's last paragraph. That paragraph's label and its last sentence named the boot-time retirement as a follow-up. This PR ships it, so left unchanged the note would publish two false lines. `check-empty-changeset` stays red by design; the dispatching seat confirms by its own record. 1. The paragraph's bold label - Before: "**Not ended at boot:**" - After: "**Ended by `os user set-password`, and at boot:**" 2. The paragraph's last sentence - Before: "Ending them at boot is follow-up #35184." - After: "In the same release, a boot outside development mode also retires them: see the note "a boot outside development mode retires what the development seed issued" (#36699)." ## 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` is read from CI's Lint job, not run locally. - [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. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbX8ecPYZVemPRBFSrY --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e5213e7 commit 338ef35

8 files changed

Lines changed: 840 additions & 18 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(auth)!: a boot outside development mode retires what the development seed issued
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. What moves is what a boot outside development mode does to the credentials the development seed's accounts were issued: no metadata, registry key or authored value changes, so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** for a deployment that serves a database `os dev` seeded. At every boot outside development mode (`NODE_ENV` is not `development`), before the server serves a request, the platform retires what each account the development seed created (its admin and the stack's `demoStaff`) was issued, while that account still has the password it was seeded with: its sessions (including any it opened acting as another account), its API keys, the apps authorized to it and its device sign-ins, its outstanding password-reset links, any sign-in account linked to it, the OAuth applications it registered (disabled) and the SCIM credentials it minted (revoked). It is the revocation `os user set-password` performs, plus the sessions the account opened as another account, without setting a password, and with a host `secondaryStorage` it also ends the sessions held there.
13+
14+
- FROM: a session, an API key or an authorized app the seed's admin or a demo account was issued under `os dev` kept working on a server outside development mode, until an operator ran `os user set-password` on that account.
15+
- TO: the boot retires them. A retired session's next request is unauthenticated, a retired key is refused `403 API_KEY_REVOKED`, and both carry the reason `admin_password_reset`, so only a platform administrator restores such a key. The log names each account and what was retired. When the retirement cannot complete, the boot fails with an error naming the accounts.
16+
17+
**Not moved.** A boot in development mode retires nothing. An account the seed did not create is never read. An account whose password was set since the seed (by `os user set-password`, by an administrator or by its own reset) holds a credential the seed did not issue and is untouched, and so is every credential it was issued after that. A database with no account the seed created costs one indexed read per boot.
18+
19+
The fix: set each seeded account's password with `os user set-password <email>` before serving the database outside development mode (the refusals added in the previous release already require it to sign in), then sign in and issue new keys.

‎.changeset/dev-seed-credential-production-refusal.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Metadata-protocol: none
2424

2525
**Not detected:** a database seeded before this release with a custom seed password carries no mark and no well-known password. Set a new password with `os user set-password` on each account it seeded before serving it outside development mode.
2626

27-
**Not ended at boot:** this release refuses the development seed password and every new session for a seeded account still on it. Sessions and API keys a seeded account was issued before the server left development mode are ended by `os user set-password`; run it on each seeded account before serving the database. Ending them at boot is follow-up #35184.
27+
**Ended by `os user set-password`, and at boot:** this release refuses the development seed password and every new session for a seeded account still on it. Sessions and API keys a seeded account was issued before the server left development mode are ended by `os user set-password`; run it on each seeded account before serving the database. In the same release, a boot outside development mode also retires them: see the note "a boot outside development mode retires what the development seed issued" (#36699).

‎content/docs/deployment/self-hosting.mdx‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,28 @@ serve a database `os dev` wrote, set each seeded account's password on the
646646
server with [`os user set-password`](/docs/deployment/cli#os-user-set-password)
647647
first; the refusal names that command.
648648

649-
What this release refuses is the seed password and every new session for a
650-
seeded account still on it. Sessions and API keys a seeded account was issued
651-
before the server left development mode are ended by `os user set-password`
652-
(with any sign-in account linked to it and any app authorized to it; the
653-
OAuth applications it registered are disabled and the SCIM credentials it
654-
minted are revoked), so
655-
run it on each seeded account before serving the database; ending them at boot
656-
is follow-up #35184.
649+
Nothing the development seed issued keeps acting once the deployment leaves
650+
development mode. At every boot outside development mode, before the server
651+
serves a request, it retires what each seeded account still on its seed
652+
password was issued: its sessions, including any it opened acting as another
653+
account, its API keys, the apps authorized to it and
654+
its device sign-ins, its outstanding password-reset links, any sign-in account
655+
linked to it, the OAuth applications it registered (disabled) and the SCIM
656+
credentials it minted (revoked). A retired session or key answers exactly as a
657+
revoked one does, and the log names each account and what was retired. When
658+
the host supplies a `secondaryStorage` that holds the sessions, the server ends
659+
them there too, which `os user set-password` cannot reach. An
660+
account whose password was set since the seed (by `os user set-password`, by
661+
an administrator, or by its own reset) holds a credential the seed did not
662+
issue and is untouched, as is every account the seed did not create. A boot in
663+
development mode retires nothing. There is no switch.
664+
665+
If the retirement cannot complete (the database refuses a read or a write),
666+
the server does not start, and the error names the accounts; fix the database
667+
access, or run `os user set-password` on each of them, and start it again.
668+
`os user set-password` itself ends the account's own sessions, keys and
669+
grants when it sets the password, and from then on the boot leaves that
670+
account alone.
657671

658672
### A seeded directory opens no bootstrap window
659673

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

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

1515
| Measure | Value |
1616
|---|---:|
17-
| Write call sites | 108 |
17+
| Write call sites | 110 |
1818
| Object name statically decidable | 60 |
19-
| Object name chosen at run time | 48 |
19+
| Object name chosen at run time | 50 |
2020
| Object name spelled inline | 47 |
2121
| Object name spelled through a `const` | 13 |
22-
| Object name is an `object: string` parameter | 3 |
23-
| Object name is some other run-time expression | 45 |
22+
| Object name is an `object: string` parameter | 4 |
23+
| Object name is some other run-time expression | 46 |
2424
| Against a tenancy-enabled object | 58 |
2525
| Against an object declaring tenancy off | 2 |
26-
| Threading a tenant context | 64 |
26+
| Threading a tenant context | 66 |
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 |
31-
| Threading a decidably elevated (`isSystem`) context | 46 |
31+
| Threading a decidably elevated (`isSystem`) context | 48 |
3232
| Threading a decidably non-elevated context | 0 |
3333
| Threading a context of undecidable elevation | 47 |
34-
| Receiver carried a readable engine type | 80 |
34+
| Receiver carried a readable engine type | 81 |
3535
| Receiver erased, placed by the object NAME | 26 |
36-
| Receiver erased, placed by an `object: string` PARAMETER | 1 |
36+
| Receiver erased, placed by an `object: string` PARAMETER | 2 |
3737
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 1 |
3838

3939
## Subtractions the census could NOT defend — enforced
@@ -74,6 +74,8 @@ a row or a number here — fix the code, or the census, and regenerate.
7474
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `update` | `sys_user` | enabled | elevated | 1 |
7575
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `insert` | `sys_user_permission_set` | enabled | elevated | 1 |
7676
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `insert` | `sys_user_position` | enabled | elevated | 1 |
77+
| `packages/plugins/plugin-auth/src/dev-seed-credential-retirement.ts` | `delete` | `object` | undecidable | elevated | 1 |
78+
| `packages/plugins/plugin-auth/src/dev-seed-credential-retirement.ts` | `update` | `SystemObjectName.SESSION` | undecidable | elevated | 1 |
7779
| `packages/plugins/plugin-auth/src/dev-seed-credential.ts` | `update` | `SystemObjectName.USER` | undecidable | elevated | 1 |
7880
| `packages/plugins/plugin-auth/src/ensure-default-organization.ts` | `insert` | `object` | undecidable | elevated | 1 |
7981
| `packages/plugins/plugin-auth/src/ensure-default-organization.ts` | `update` | `sys_member` | enabled | elevated | 1 |

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import { authIdentityManifest } from './manifest.js';
130130
import { scheduleLegacySsoSecretMigration } from './sso-client-secret.js';
131131
import { reportSsoProvidersWithNonBareDomainEntries } from './sso-stored-domain-entries.js';
132132
import { reportSsoProviderAccessSweep } from './sso-provider-lifecycle.js';
133+
import { retireDevSeedCredentials, type DevSeedRetirementEngine } from './dev-seed-credential-retirement.js';
133134
import {
134135
directSignInNetworkRefusal,
135136
isDirectSignInDoorNavigation,
@@ -1822,6 +1823,23 @@ export class AuthPlugin implements Plugin {
18221823
}
18231824
});
18241825

1826+
// Outside development mode: retire what the development seed issued to
1827+
// every stamped account still on its seed password, on `kernel:ready`, so
1828+
// it has settled before `kernel:listening` opens the socket. Registered
1829+
// independently of `registerRoutes`: a retired session or key must not act
1830+
// through any door. A retirement that does not complete THROWS and fails
1831+
// the boot (`dev-seed-credential-retirement.ts`).
1832+
ctx.hook('kernel:ready', async () => {
1833+
let ql: DevSeedRetirementEngine | undefined;
1834+
try { ql = ctx.getService<DevSeedRetirementEngine>('objectql'); } catch { ql = undefined; }
1835+
const authManager = this.authManager;
1836+
await retireDevSeedCredentials({
1837+
engine: ql,
1838+
authContext: async () => (authManager ? await authManager.getAuthContext() : undefined),
1839+
logger: ctx.logger,
1840+
});
1841+
});
1842+
18251843
// Dev-only: provision a known, loginable platform admin on an empty DB.
18261844
// Registered as its own kernel:ready hook (independent of registerRoutes)
18271845
// so it runs whenever the runtime boots in development.

0 commit comments

Comments
 (0)