Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/35184-dev-seed-retire-at-boot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/plugin-auth': patch
---

fix(auth)!: a boot outside development mode retires what the development seed issued

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- 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. -->

**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.

- 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.
- 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.

**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.

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.
2 changes: 1 addition & 1 deletion .changeset/dev-seed-credential-production-refusal.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
'@objectstack/plugin-auth': patch
'@objectstack/platform-objects': patch
Expand All @@ -24,4 +24,4 @@

**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.

**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.
**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).
30 changes: 22 additions & 8 deletions content/docs/deployment/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,28 @@ serve a database `os dev` wrote, set each seeded account's password on the
server with [`os user set-password`](/docs/deployment/cli#os-user-set-password)
first; the refusal names that command.

What this release refuses is the 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`
(with any sign-in account linked to it and any app authorized to it; the
OAuth applications it registered are disabled and the SCIM credentials it
minted are revoked), so
run it on each seeded account before serving the database; ending them at boot
is follow-up #35184.
Nothing the development seed issued keeps acting once the deployment leaves
development mode. At every boot outside development mode, before the server
serves a request, it retires what each seeded account still on its seed
password was issued: 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). A retired session or key answers exactly as a
revoked one does, and the log names each account and what was retired. When
the host supplies a `secondaryStorage` that holds the sessions, the server ends
them there too, which `os user set-password` cannot reach. 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, as is every account the seed did not create. A boot in
development mode retires nothing. There is no switch.

If the retirement cannot complete (the database refuses a read or a write),
the server does not start, and the error names the accounts; fix the database
access, or run `os user set-password` on each of them, and start it again.
`os user set-password` itself ends the account's own sessions, keys and
grants when it sets the password, and from then on the boot leaves that
account alone.

### A seeded directory opens no bootstrap window

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ a row or a number here — fix the code, or the census, and regenerate.

| Measure | Value |
|---|---:|
| Write call sites | 108 |
| Write call sites | 110 |
| Object name statically decidable | 60 |
| Object name chosen at run time | 48 |
| Object name chosen at run time | 50 |
| Object name spelled inline | 47 |
| Object name spelled through a `const` | 13 |
| Object name is an `object: string` parameter | 3 |
| Object name is some other run-time expression | 45 |
| Object name is an `object: string` parameter | 4 |
| Object name is some other run-time expression | 46 |
| Against a tenancy-enabled object | 58 |
| Against an object declaring tenancy off | 2 |
| Threading a tenant context | 64 |
| Threading a tenant context | 66 |
| Provably carrying none (options read, no context key) | 15 |
| …and decidably tenancy-enabled | 3 |
| Options argument unreadable | 29 |
| …and decidably tenancy-enabled | 16 |
| Threading a decidably elevated (`isSystem`) context | 46 |
| Threading a decidably elevated (`isSystem`) context | 48 |
| Threading a decidably non-elevated context | 0 |
| Threading a context of undecidable elevation | 47 |
| Receiver carried a readable engine type | 80 |
| Receiver carried a readable engine type | 81 |
| Receiver erased, placed by the object NAME | 26 |
| Receiver erased, placed by an `object: string` PARAMETER | 1 |
| Receiver erased, placed by an `object: string` PARAMETER | 2 |
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 1 |

## Subtractions the census could NOT defend — enforced
Expand Down Expand Up @@ -74,6 +74,8 @@ a row or a number here — fix the code, or the census, and regenerate.
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `update` | `sys_user` | enabled | elevated | 1 |
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `insert` | `sys_user_permission_set` | enabled | elevated | 1 |
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `insert` | `sys_user_position` | enabled | elevated | 1 |
| `packages/plugins/plugin-auth/src/dev-seed-credential-retirement.ts` | `delete` | `object` | undecidable | elevated | 1 |
| `packages/plugins/plugin-auth/src/dev-seed-credential-retirement.ts` | `update` | `SystemObjectName.SESSION` | undecidable | elevated | 1 |
| `packages/plugins/plugin-auth/src/dev-seed-credential.ts` | `update` | `SystemObjectName.USER` | undecidable | elevated | 1 |
| `packages/plugins/plugin-auth/src/ensure-default-organization.ts` | `insert` | `object` | undecidable | elevated | 1 |
| `packages/plugins/plugin-auth/src/ensure-default-organization.ts` | `update` | `sys_member` | enabled | elevated | 1 |
Expand Down
18 changes: 18 additions & 0 deletions packages/plugins/plugin-auth/src/auth-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import { authIdentityManifest } from './manifest.js';
import { scheduleLegacySsoSecretMigration } from './sso-client-secret.js';
import { reportSsoProvidersWithNonBareDomainEntries } from './sso-stored-domain-entries.js';
import { reportSsoProviderAccessSweep } from './sso-provider-lifecycle.js';
import { retireDevSeedCredentials, type DevSeedRetirementEngine } from './dev-seed-credential-retirement.js';
import {
directSignInNetworkRefusal,
isDirectSignInDoorNavigation,
Expand Down Expand Up @@ -1811,6 +1812,23 @@ export class AuthPlugin implements Plugin {
}
});

// Outside development mode: retire what the development seed issued to
// every stamped account still on its seed password, on `kernel:ready`, so
// it has settled before `kernel:listening` opens the socket. Registered
// independently of `registerRoutes`: a retired session or key must not act
// through any door. A retirement that does not complete THROWS and fails
// the boot (`dev-seed-credential-retirement.ts`).
ctx.hook('kernel:ready', async () => {
let ql: DevSeedRetirementEngine | undefined;
try { ql = ctx.getService<DevSeedRetirementEngine>('objectql'); } catch { ql = undefined; }
const authManager = this.authManager;
await retireDevSeedCredentials({
engine: ql,
authContext: async () => (authManager ? await authManager.getAuthContext() : undefined),
logger: ctx.logger,
});
});

// Dev-only: provision a known, loginable platform admin on an empty DB.
// Registered as its own kernel:ready hook (independent of registerRoutes)
// so it runs whenever the runtime boots in development.
Expand Down
Loading
Loading