Skip to content

feat(auth): let the operator make an account and set a password - #149

Merged
aRustyDev merged 2 commits into
mainfrom
feat/operator-password-reset
Nov 13, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
feat/operator-password-reset

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

A person who forgot their password had no way back in: nothing changes a password except sign-up and the test-only seed, and the sign-in screen now says "ask your admin" (#145, D-037). Q-F7 decided "the admin makes the user with a temporary password" and nothing implemented it. This does (WP2 of the locked-out-recovery plan).

  • POST /internal/operator/users makes an account; POST /internal/operator/users/password sets a new password. JSON {email, password}, 204 with no body.
  • A door of its own, OperatorAdmin in thrust-api, not the test routes (those can wipe every row): its own switch THRUST_OPERATOR_ROUTES (off unless set), its own header and token, x-operator-token and THRUST_OPERATOR_TOKEN, at least 32 characters or every call is refused, compared in constant time. The test routes' token opens nothing there; the operator's opens no test route; a session is no way in. 404 for everything while the switch is off.
  • A reset ends every session of that user, leaves a deactivated user deactivated, gives a no-password (SSO) account one, and touches nobody else. 400/404/409 follow the sign-up rules (D-023).
  • One audit line per success, for the root to log (operator set a password: user <id>): the action and the user id, never the password or the email.
  • Core: admin_create_user, admin_set_password; the checks and insert of sign-up are one private function both use. Port: Database::set_password_hash, in the memory and Postgres adapters.
  • Runbook: "Recover a locked-out user" in docs/src/architecture/infra.md. D-038, the Q-F7 note, G-32.

Measured

  • Hermetic: cargo nextest run --profile ci --workspace 3616 passed, 4 skipped; doctests; clippy (native, and the Worker for wasm32) and fmt clean; check-deps, check-acceptance-list, check-web-diff, check-topology.
  • New tests, generative first: core (12: two properties, a model_ sequence against a reference of who has which password and which sessions are alive, with a coverage control, and the pinned edges); the router as the roots mount it (32 cases: a property over switch x configured token x carried header, with its own coverage control); the memory adapter (8, exhaustive); the generated selfhosted model gets a SetPassword op that reads all three seeded users back, run against a Postgres container.
  • The contract suite, scripts/contract.sh <cell> main, 68 of 68 on all four cells (native-memory, native-pg, worker-memory, worker-cf; EXPECT_MAIN 65 to 68, three new tests).
  • Controls, each planted bug fails the tests aimed at it: no strength check, sessions left alive, the hash written to every user, the test routes' token accepted (four new rows in scripts/mutants.sh, each run by hand on native-memory: 1 or 2 operator tests failed, exit 101); the switch ignored, a prefix comparison of the token, no minimum token length (the router test); an UPDATE with no WHERE in the Postgres adapter (the generated model, 1 of 2 failed, no socket error).
  • The runbook, run as written against a local thrust-server (19 checks): create, reset, the old password refused, the new one accepted, and neither the token nor either password on curl's command line (a wrapper wrote down its arguments; a control with the token in a normal -H is caught) or in the server's log, nor the email. My first version of the "no token on the command line" check could not fail (its trace was never captured); this is the replacement.

Not measured

  • Nothing was run against a deployed Worker. Its asset config must send /internal/operator/* to the Worker (scripts/worker-dev.sh lists /internal/* in run_worker_first; the production config is not in this repo).
  • This PR's CI has not run: the worker-cf e2e cell, deny (no lockfile change), mutants as a whole (only the four new rows, by hand).
  • The docs were not built: mdbook-mermaid is not installed here. The new link is infra.md#recover-a-locked-out-user.
  • No browser journey signs in through the stock app with a temporary password (the sign-in journey does not use these routes).

Differs from the plan

  • No rate limiter, which the plan listed. The Worker's limiter takes three key classes; the one that would fit, signin:, is a namespace an anonymous sign-in can write to, so it would let anyone use up the operator's allowance; a fourth class is an adapter and binding change. The token's minimum length is the control, and the route does no work before the token matches. D-038 says so.
  • Small things I touched on the way: scripts/contract.sh honours THRUST_MOCK_IDP_PORT like its other port overrides (pick_port's lsof stalled for minutes under a load average near 800); scripts/stage2-contract.sh skips the three tests (a deployed Worker has no operator routes, so its count stays 59).

Before you merge

  • Turning it on in production is yours to do and is not in this PR: THRUST_OPERATOR_ROUTES=1 and a THRUST_OPERATOR_TOKEN secret. The product hostname is public (Q-0090.3), so until the Access phase the token is the only gate: keep the switch off when nobody is using it.
  • The temporary password stays the person's password until POST /auth/change-password/ exists (WP3, next, after this merges).

Refs: #46

🤖 Generated with Claude Code

aRustyDev and others added 2 commits November 13, 2026 15:49
Nothing could change a password except sign-up and the test-only seed, so a person who forgot theirs had no way back in, and the
sign-in screen now says "ask your admin" (D-037). Q-F7 decided the admin makes the user with a temporary password; this builds it.

Two routes, POST /internal/operator/users and /internal/operator/users/password, behind a new OperatorAdmin extractor. It is a
door of its own and not the test routes, which can wipe every row: its own switch (THRUST_OPERATOR_ROUTES, off unless set), its own
header and token (x-operator-token, THRUST_OPERATOR_TOKEN, at least 32 characters or every call is refused, compared in constant
time). The test routes' token opens nothing there and the operator's opens no test route. 204 with no body, 400/404/409 as the
sign-up rules say, 404 for everything while the switch is off. A reset ends every session of the user, leaves an inactive account
inactive and gives an account that has no password one. One audit line per success names the action and the user id, never the
password or the email.

Core: admin_create_user and admin_set_password, with the checks and the insert of sign-up factored into one private function so the
two cannot drift. Port: Database::set_password_hash, in the memory and Postgres adapters.

No rate limiter, on purpose (D-038): the Worker's limiter takes three key classes and the one that would fit, `signin:`, is a namespace an
anonymous sign-in can write to, so it would let anyone use up the operator's allowance. The token's length is the control.

Tests: generative first (core properties and a model sequence with a coverage control, a property over switch x token x header at the
router, the generated adapter model with a new SetPassword op), three contract tests on all four targets (EXPECT_MAIN 65 -> 68).
Planted bugs, each failing the tests aimed at it: no strength check, sessions left alive, the hash written to every user, the test
routes' token accepted (four new rows in scripts/mutants.sh), the switch ignored, a prefix comparison and no minimum token length
(the router test), and an UPDATE with no WHERE in the Postgres adapter (the model). scripts/stage2-contract.sh skips the three
tests (a deployed Worker has no operator routes). scripts/contract.sh also honours THRUST_MOCK_IDP_PORT like its other port
overrides, because pick_port's lsof stalled for minutes under load.

Runbook: "Recover a locked-out user" in docs/src/architecture/infra.md, run as written against a local thrust-server.

Refs: #46
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
#148 rewrote the G-31 row of docs/src/testing/status.md, the row this branch's G-32 row follows, so the two edits conflicted.
Resolved as main's G-31 row followed by this branch's G-32 row; nothing else conflicted. The resolved file differs from origin/main by
the one G-32 line, and from this branch's previous tip by #148's change to the G-31 row.

Refs: #46
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit 39ca5e1 into main Nov 13, 2026
35 checks passed
@aRustyDev
aRustyDev deleted the feat/operator-password-reset branch November 13, 2026 22:09
aRustyDev added a commit that referenced this pull request Nov 13, 2026
Main gained #149 (the operator's routes) and #148. The one conflict was crates/thrust-api/src/lib.rs, in two places where #149 added the operator's handlers and routes beside the three this branch deletes: kept both operator routes and the operator block, dropped the slice's sign-in and sign-out routes, and kept this branch's comment on what is left of the identity routes. #149's contract tests sign in through Plane's `/auth/sign-in/`, so nothing there called the deleted routes.

Checked on native-memory after the merge: main 68 of 68 (main's 65 and #149's three; this branch changes no count), sweeper 3 of 3, csrfoff 6 of 6, clippy clean on the workspace.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant