Skip to content

feat(cli): rename the deploy operator and declare a break-glass administrator - #3406

Merged
yannickmonney merged 4 commits into
mainfrom
feat/cli-operator-email-break-glass
Sep 17, 2026
Merged

yannickmonney merged 4 commits into
mainfrom
feat/cli-operator-email-break-glass

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Why

A managed deployment (tale deploy --bundle) signs in as its identity operator on every run, with the password alone. Two consequences:

  • An organization cannot enforce two_factor_policy without breaking its own deploys. A password sign-in of a TOTP-enabled operator is answered with a challenge, and an operator with neither factor is held at the enrolment wall once its grace period ends. The CLI stopped at both with one generic message.
  • The operator's user id anchors the retained state: the bootstrap journal, the email-attestation journal, managed native client intents (operatorUserId), operator-owned skills (skillOwner: "operator", which has no ownership transfer) and API keys. So a new account cannot take over deploys of an existing deployment.

The way out keeps the operator account but gives it a machine address. It holds a passkey, which satisfies the policy without challenging the password sign-in. People sign in with their own accounts and choose either factor. A separate break-glass administrator covers the case where the operator is unavailable.

Interface

Deployment spec identity:

  • migrateEmailFrom (literal address): the retained operator's previous sign-in address. Requires bootstrap: "fresh" and must differ from identity.email.
  • breakGlass: { email, passwordHash }:
    • email is a literal or a required env reference, distinct from the operator's current and previous address;
    • passwordHash is a required env reference to a Better Auth 1.6 hash (<32 hex>:<128 hex>).
      The host resolves both into private provisioning stdin only; the bundle carries the variable names.
  • tale auth hash-password prints that hash from stdin (or a hidden prompt with confirmation). It refuses a password that fails the platform's default password policy and prints nothing but the hash.

Operator address migration

  1. Read the retained account's current address backend-locally. It must be the declared or the previous one, and no other account may hold the declared one.
  2. Sign in with it and prove the retained user id.
  3. Journal migratingEmailFrom in bootstrap.json, then rename the account through Better Auth's internal adapter. The write is scoped with runWithAdapter, so only this exact update passes, guarded by email = previous; a concurrent change is refused, not overwritten.
  4. End every session of the account and read back.
  5. Rewrite the journal, sign in again with the new address and prove the same user id.
  6. A declared operator attestation re-verifies the new address; the completed journal of the previous address is admitted exactly once.
  7. A replay after an interruption finds the address already moved and finishes without a second rename. Keeping migrateEmailFrom declared afterwards is harmless.

Break-glass administrator

After the managed organization is selected, the backend converges on the declaration:

  • An absent account is created with a verified address. break-glass.json binds its id as soon as the user row exists, before its single credential account holding the declared hash is linked. The platform's adapter runs without transactions, so this binding is what makes a partial creation resumable.
  • A credential write (first link or replacement) is journaled as credentialPending beforehand and cleared only after the account's sessions are proven ended. A run that dies between the write and the sweep still ends the old sessions on replay.
  • An unbound account at the address is adopted only when it is this deployment's own interrupted creation: a pending journal and no provider account at all. Any other account is refused, and so are the operator and a different account holding a bound address.
  • Membership converges through the organization-scoped member doors (/api/app/members?orgId=…, …/:memberId/role?orgId=…): add as admin, or set admin. An owner is never touched.
  • The deployment never signs in as this account. The ready proof must name it, and the host checks that.

Refusals (new)

  • The deploy operator has TOTP enabled; a managed deploy signs in with its password alone, so the operator must hold a passkey and no TOTP.
  • The deploy operator has no second factor and its two-factor enrolment grace period has ended; register a passkey for it.
  • Operator address and break-glass refusals name the conflict (another holder, a missing account, a retained binding) and never echo credentials.

Tests

  • New suites operator-address.test.ts and break-glass.test.ts drive real Better Auth 1.6.30 (internal adapter, adapter scoping, transactions) over its memory adapter.
  • identity.test.ts, email-attestation.test.ts, apply.test.ts and fresh-inputs.test.ts cover admission, journaling, replay, receipts and private-input custody.
  • password-hash.test.ts / hash-password.test.ts cover the helper, and tests/hash-password.test.ts runs it as a subprocess against source and the compiled binary (verifyPassword accepts its output).

Local results (macOS arm64):

  • tools/cli: tsc --noEmit clean, oxlint clean, bun test 1212 pass / 19 skip / 1 fail. The failure is runtime-configuration.test.ts › the actual fixed reader … refuses … alternate mounts; it fails identically with this change stashed, so it's pre-existing and macOS-specific.
  • build:mac + check:bundle OK; the compiled auth hash-password subprocess suite 8/8.
  • services/docs vitest 34 files / 166 tests; bun run lint:manual OK; oxfmt --check clean.

Known limits

  • The deployment records no password-change time for the break-glass account, so an organization password rotation policy may ask it for a new password, which the next deployment sets back (documented).
  • Renaming an operator that holds a single sign-on link is refused: the link belongs to the person who signed in with it. Remove it first.
  • The backend-local suites drive real Better Auth over its memory adapter, not the platform's Postgres adapter.

Review

An independent adversarial read found four defects, fixed in fix(cli): bind the break-glass account first and never adopt a foreign one:

  • the role door needs orgId;
  • an interrupted rotation could leave old sessions;
  • a foreign account could be adopted as administrator;
  • account creation is not transactional on the platform adapter.

It also found the SSO-link case (now refused).

Docs

The CLI readme, docs/{en,de,fr}/self-hosted/install/cli-install.md (new anchored subsections plus the auth command list) and the manual automation reference.

…istrator

A managed deployment signs in as its operator with the password alone on every
run, and the operator's user id anchors the bootstrap journal, the managed
native clients, operator-owned skills and API keys. Enforcing the two-factor
policy therefore needs that account to become a machine-held one, and a second
administrator to exist for when it is unavailable.

- identity.migrateEmailFrom renames the retained operator in place: the CLI
  reads the current address backend-locally, signs in with it, journals the
  change, renames through Better Auth's internal adapter guarded by the
  previous address, ends every session of the account, signs in again and
  re-attests the new address. A replay completes without a second rename.
- identity.breakGlass declares one administrator whose password reaches the
  deployment only as a Better Auth hash. The backend creates the account or
  sets it back to exactly that credential (ending its sessions when it
  changes), a journal binds the address to one account id, and membership
  converges to admin through the native member doors without touching an
  owner. The deployment never signs in as it.
- tale auth hash-password prints that hash from stdin or a hidden prompt and
  refuses a password that fails the platform's default policy.
- A password sign-in answered with a two-factor challenge or the enrolment
  wall now names which one stopped the unattended deploy.
…hash-password

The self-hosted CLI guide (EN/DE/FR) and the CLI readme describe identity.migrateEmailFrom, identity.breakGlass, tale auth hash-password and why a managed deploy operator holds a passkey and never an authenticator app under an enforced two-factor policy. The manual automation reference names the suites that own the behaviour and what they do not prove.
…n one

Review findings on the break-glass administrator and the operator rename:

- The role door sits behind the organization-scope check like every member
  route, so the membership call now names `orgId`; without it the backend
  answered 400 and a non-admin membership could never converge. The test
  doubles now refuse a role call without it.
- A credential write is journaled (`credentialPending`) before it happens and
  cleared only after the account's sessions are proven ended, so a run that
  dies between the write and the sweep still ends the old sessions on replay.
- An unbound account at the address is adopted only when it is this
  deployment's own interrupted creation: a pending journal and no provider
  account at all. Any other account is refused instead of being made an
  administrator with its existing way in intact.
- The platform's adapter runs without transactions, so the account ID is
  bound in the journal right after the user row exists, before its
  credential; the transaction wrapper is gone.
- Renaming an operator that holds a single sign-on link is refused before
  any write: the link belongs to the person who signed in with it.
@yannickmonney
yannickmonney merged commit e56b041 into main Sep 17, 2026
56 checks passed
@yannickmonney
yannickmonney deleted the feat/cli-operator-email-break-glass branch September 17, 2026 16:32
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