Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
27 changes: 27 additions & 0 deletions .changeset/dev-seed-credential-production-refusal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@objectstack/plugin-auth': patch
'@objectstack/platform-objects': patch
'@objectstack/cli': patch
---

fix(auth)!: a server outside development mode refuses a development seed credential, and `os user set-password` sets a new one on the server

Clause-②: yes (narrowing) — narrowed: on a server whose `NODE_ENV` is not `development`, a password sign-in that submits the development seed password (`admin123`, or the value `OS_SEED_ADMIN_PASSWORD` sets) is refused on every account, and an account the development seed created opens no session while its stored password is still the one it was seeded with. Widened: the `os user set-password` command, the `sys_user.dev_seed_credential` column, and new `@objectstack/plugin-auth` exports `setOperatorPassword`, `findAccountByEmail`, `operatorPasswordRefusal`, `OPERATOR_PASSWORD_MIN_LENGTH`, `OPERATOR_PASSWORD_MAX_LENGTH` and the types `OperatorPasswordResetEngine`, `OperatorPasswordResetOutcome`, `OperatorPasswordResetRefusalReason`.
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) No authorable key, accepted value or metadata type is added, removed or renamed; a system column is added; nothing stored is rewritten: the moved answer is whether a server outside development mode accepts a development seed credential at sign-in. The one-line fix for a refused account is in the body: set a new password on the server with os user set-password. -->

**BREAKING** for a deployment that serves, outside development mode, a database `os dev` seeded, or any account whose password is the development seed password. Such a sign-in is refused. Set a new password on the server with `os user set-password <email>`; the refusal names the command. A server in development mode (`os dev`) is unchanged.

**The rule: a server outside development mode never accepts a development seed credential.** Development mode is `NODE_ENV=development`, the condition the development seed itself runs under. The rule lives in the auth plugin, so `os start`, `os serve`, the image and a custom host all apply it.

- **The seed password is refused at sign-in, on any account.** A password sign-in with the development seed password answers `403 PERMISSION_DENIED`, and its message names `os user set-password`. It is decided on the submitted password alone, before any account is read, so every address gets the same answer. This covers the seeded admin, the stack's `demoStaff`, any other account on that password, and a database seeded by an earlier release.
- **The accounts the development seed creates are marked.** `os dev`'s admin and each `demoStaff` account carry `sys_user.dev_seed_credential`: a one-way digest of the password hash the seed stored, never the password. The column is never returned on reads, and any password change stops it matching.
- **A marked account still on its seed password opens no session**, on any sign-in door (password, emailed link, one-time code, passkey, social or SSO, impersonation), whatever password it was seeded with, `os dev --admin-password` included. A password check never confirms that seed password: a password sign-in answers it as a wrong password.
- **No password change is offered at sign-in.** Whoever signed in first could perform it. The way out is the operator's reset on the server.

**`os user set-password <email>`** sets the account's password in the project database. It reads the new password from a terminal prompt (twice, not echoed) or from standard input with `--password-stdin`, never from the command line, and takes `--database-url` like the other one-shot commands. It checks that the new password is not a development seed password and is 8 to 128 characters long; the deployment's own password policy and password history are not applied. It writes nothing on a refusal. It deletes the account's outstanding password-reset links and codes from the project database before the new password lands. It clears the account's development seed mark and any sign-in lock, records the change time, and ends every session and revokes every API key of the account, as an administrator's forced reset does. It asks for no password change at the next sign-in. It writes the project database only: a secondary storage the host configures for the auth service is out of its reach, for the reset links and the sessions alike. With one configured, run the command with the server stopped, or restart the server afterwards; a secondary storage kept outside the server process outlives a restart and is cleared of the account's entries by hand.

**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.
41 changes: 41 additions & 0 deletions content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,47 @@ for its own keys.
- A bundle proves what its checkpoints hold. Rows of a sealed window that no checkpoint
lists (`late` and unsealed) are carried as the writing run found them.

#### `os user set-password`

Sets a user's password in the project database, on the server. A server that is not in
development mode never accepts a development seed credential: a sign-in with the
development seed password (`admin123`, or the `OS_SEED_ADMIN_PASSWORD` value) is refused
on every account, and an account `os dev` seeded (its admin and the stack's `demoStaff`)
opens no session while it still has the password it was seeded with, a custom
`--admin-password` included. No session is offered to change it in, because whoever signed
in first could. This command is the way out, and the refusal names it.

```bash
os user set-password admin@example.com # asks twice, unechoed
printf %s "$NEW_PASSWORD" | os user set-password admin@example.com --password-stdin
os user set-password admin@example.com --database-url "postgres://user:pass@host:5432/mydb"
```

**Options:**
- `--password-stdin` — read the new password from standard input instead of asking for it
- `--database-url <url>` — the database to write (defaults to `$OS_DATABASE_URL` / the project database)

What one run does:

- **The password never goes on the command line.** It is asked for on a terminal, or read
from standard input.
- **It checks two things about the new password:** it is not a development seed password,
and it is 8 to 128 characters long. The deployment's own password policy and password
history are not applied. An address no account holds, and an account with no password
sign-in, are refused too. A refusal writes nothing.
- **It sets the password with the hash every server verifies**, clears the account's
development seed mark and a sign-in lock, and records the change time.
- **It deletes the account's outstanding password-reset links and codes from the project
database** before the new password lands.
- **It ends every session and revokes every API key of the account**, as an
administrator's forced reset does: the sessions and keys issued under the old password do
not outlive it. It asks for no password change at the next sign-in.
- **It writes the project database only.** A secondary storage the host configures for the
auth service (a cache that can hold reset links and sessions) is out of its reach, for the
reset links and the sessions alike. With one configured, run the command with the server
stopped, or restart the server afterwards; a secondary storage kept outside the server
process outlives a restart and is cleared of the account's entries by hand.

### Build & Validate

| Command | Description |
Expand Down
14 changes: 14 additions & 0 deletions content/docs/deployment/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,20 @@ on empty development databases. That seed is hard-gated to
`NODE_ENV=development`: it is a development convenience, never a production
recovery path.

Nor does a server outside development mode **accept** a development seed
credential. A sign-in with the development seed password is refused on every
account, and an account `os dev` seeded (its admin and the stack's `demoStaff`)
opens no session while it still has the password it was seeded with. If you
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`, so
run it on each seeded account before serving the database; ending them at boot
is follow-up #35184.

### A seeded directory opens no bootstrap window

Both paths above assume the deployment's **first login** is still ahead of it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ a row or a number here — fix the code, or the census, and regenerate.

| Measure | Value |
|---|---:|
| Write call sites | 98 |
| Write call sites | 102 |
| Object name statically decidable | 58 |
| Object name chosen at run time | 40 |
| Object name chosen at run time | 44 |
| Object name spelled inline | 47 |
| Object name spelled through a `const` | 11 |
| Object name is an `object: string` parameter | 2 |
| Object name is some other run-time expression | 38 |
| Object name is some other run-time expression | 42 |
| Against a tenancy-enabled object | 56 |
| Against an object declaring tenancy off | 2 |
| Threading a tenant context | 55 |
| Threading a tenant context | 59 |
| Provably carrying none (options read, no context key) | 15 |
| …and decidably tenancy-enabled | 3 |
| Options argument unreadable | 28 |
| …and decidably tenancy-enabled | 16 |
| Threading a decidably elevated (`isSystem`) context | 38 |
| Threading a decidably elevated (`isSystem`) context | 42 |
| Threading a decidably non-elevated context | 0 |
| Threading a context of undecidable elevation | 45 |
| Receiver carried a readable engine type | 72 |
| Receiver carried a readable engine type | 76 |
| Receiver erased, placed by the object NAME | 24 |
| Receiver erased, placed by an `object: string` PARAMETER | 1 |
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 1 |
Expand Down Expand Up @@ -74,6 +74,7 @@ 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.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 |
| `packages/plugins/plugin-auth/src/forced-reset-revocation.ts` | `update` | `SystemObjectName.API_KEY` | undecidable | elevated | 1 |
Expand All @@ -94,6 +95,9 @@ a row or a number here — fix the code, or the census, and regenerate.
| `packages/plugins/plugin-auth/src/objectql-adapter.ts` | `delete` | `objectName` | undecidable | PROVABLY NONE | 5 |
| `packages/plugins/plugin-auth/src/objectql-adapter.ts` | `insert` | `objectName` | undecidable | options unreadable | 2 |
| `packages/plugins/plugin-auth/src/objectql-adapter.ts` | `update` | `objectName` | undecidable | options unreadable | 5 |
| `packages/plugins/plugin-auth/src/operator-password-reset.ts` | `delete` | `object` | undecidable | elevated | 1 |
| `packages/plugins/plugin-auth/src/operator-password-reset.ts` | `update` | `SystemObjectName.ACCOUNT` | undecidable | elevated | 1 |
| `packages/plugins/plugin-auth/src/operator-password-reset.ts` | `update` | `SystemObjectName.USER` | undecidable | elevated | 1 |
| `packages/plugins/plugin-auth/src/organization-delete.ts` | `delete` | `sys_team` | enabled | elevated | 1 |
| `packages/plugins/plugin-auth/src/organization-delete.ts` | `delete` | `sys_team_member` | enabled | elevated | 1 |
| `packages/plugins/plugin-auth/src/organization-delete.ts` | `delete` | `sys_user_permission_set` | enabled | elevated | 1 |
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
},
"storage": {
"description": "Inspect stored files: report orphaned attachments"
},
"user": {
"description": "Maintain user accounts on the server: set a password"
}
}
},
Expand Down
Loading
Loading