Skip to content

fix(platform): close sign-up once a deployment has an account - #3407

Merged
yannickmonney merged 6 commits into
mainfrom
fix/closed-sign-up
Sep 17, 2026
Merged

yannickmonney merged 6 commits into
mainfrom
fix/closed-sign-up

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

The hole

POST /api/auth/sign-up/email had no backend guard: anyone who could reach the backend could create an account.

"Reach the backend" is wider than the public edge the proxy guards. backend-api is dual-homed onto the sandbox network (compose.yml, so in-sandbox connectors can call their host door), which means code running inside an agent session — a prompt-injected agent, or a client's own automation body — could create accounts on a deployment whose proxy refuses exactly that. An address a stranger takes first is also an address an operator can no longer declare for a machine account (a break-glass administrator, say).

The product already considers this closed:

  • docs/*/self-hosted/install/first-admin.md: "after the initial account, local account creation uses invitations rather than open self-service registration";
  • the login page offers the setup flow only while hasAnyUsers is false.

Only the backend disagreed.

The gate

backend/auth/sign-up-gate.ts is a pure predicate; the existing before-hook applies it on /sign-up/email:

call allowed
over HTTP, deployment has no account (setup flow, managed CLI bootstrap) yes
over HTTP, deployment has an account no — 403 SIGN_UP_CLOSED
server-side (no request): POST /api/app/users/members, provisioning, dev seed yes
over HTTP with TALE_ALLOW_OPEN_SIGN_UP=true yes (test deployments only)

The refusal happens in the before-hook: the only question the deployment answers is whether it already holds an account.

Blast radius

  • Unchanged: creating the first account; adding people through Settings → Members (server-side sign-up); invitations (Better Auth's org plugin, which needs an existing account anyway); SSO.
  • Changed: an HTTP sign-up on a deployment that already has an account now gets 403 instead of a new account. The managed CLI's fresh-bootstrap fallback (sign-up after a 401) now fails cleanly on a non-empty deployment instead of minting a second operator.
  • e2e: the Playwright specs mint accounts over HTTP (helpers/auth's signUpViaApi), so the hermetic stack sets TALE_ALLOW_OPEN_SIGN_UP=true in playwright.config.ts; tests/manual/setup.md §1A mirrors it, as that file requires.

Tests

backend/auth/auth.sign-up.test.ts: the gate's truth table, the environment parsing (only exactly true opens it), and a wiring test that drives the real auth handler over HTTP against a stub sql and asserts 403 plus that the adapter was never asked for anything beyond "does an account exist".

Local: vitest backend/auth 13 files / 88 tests, typecheck, oxlint, Knip, oxfmt --check, lint:manual (new box AUTH-B8 judges it from inside a session container), services/docs 34 files / 166 tests.

Not in this change

The sandbox network still reaches the whole API surface; this closes the route that needed no credentials. Narrowing what answers on that interface (a sandbox-only door) is an architectural change worth its own review.

`/api/auth/sign-up/email` answered anyone who could reach the backend. That is
wider than the edge the proxy guards: `backend-api` is dual-homed onto the
sandbox network so in-sandbox connectors can call their host door, so code
running inside an agent session — a prompt-injected agent, or a client's own
automation body — could create accounts on a deployment whose proxy refuses
exactly that. An address someone else takes first is also an address an
operator can no longer declare for a machine account.

The product already says this is closed: the docs say local accounts come from
invitations after the first one, and the login page offers setup only while the
deployment has no users. Only the backend disagreed.

A before-hook now refuses the path unless the call is the deployment's first
account (the setup flow and the managed CLI's bootstrap) or an administrator's
server-side call, which carries no request — `POST /api/app/users/members` and
provisioning keep working unchanged. A throwaway test deployment that needs the
open route sets TALE_ALLOW_OPEN_SIGN_UP=true; the e2e stack, whose specs mint
accounts over HTTP, sets exactly that.
The REST handlers reach the auth module by import, so the registry guard
saw the new SIGN_UP_CLOSED literal and asked for a contract row. The door
mounts no sign-up route, so the code can never leave it: list it with the
other app-only refusals instead.
… rules

The gate carried its own copy of the fresh-install probe's query, so the
login page and the backend could have disagreed about whether a deployment
is still empty, and it awaited that copy as an argument — on every
administrator-created member too, where the answer is discarded and a
transient failure would have taken the members door down with it.

One home for the query (its own module, so the auth graph does not gain the
users service's error codes), and a getter the predicate calls only on the
path whose verdict still depends on it. The refusal now leaves a log line:
a before-hook throw skips the after-hook, so nothing else recorded that
anyone tried.
Every local stack creates accounts over HTTP — the e2e workers, the manual
layer's save-auth-state, the docs screenshots, the real-Postgres integration
check — and the closed route would have stopped all of them after the first.
Only Playwright's own webServer had opted in, which its neighbouring comment
already admits a reused stack never sees, and the integration check had no
opt-in at all.

The dev orchestrator now sets it for every mode it boots (a shell override
still closes it, to rehearse the refusal), the dev compose overlay sets it
beside the seeded account that makes that stack non-empty from boot, and the
integration script sets it for itself. The e2e helper's docblock said the
opposite; it now names what keeps the route open.
A deploy whose operator cannot sign in falls back to creating the account,
which a deployment holding accounts now refuses. The refusal arrived as
"authentication failed", and the uncertainty marker journaled just before
the request then stopped every retry — over a creation that certainly never
happened.

A 403 naming the closed sign-up takes that marker back and reports what to
do instead: sign in as the break-glass administrator and restore the
operator's password.
The switch belongs in the two lists an operator reads — .env.example and the
environment reference in all three locales — beside the siblings it will be
mistaken for. The manual layer still told a tester the route accepts new
accounts, which is now true only because its own stacks open it, and the box
that judges the refusal never said which stack can show it.

Adds the error register's row for SIGN_UP_CLOSED, and corrects the auth
suite's box count (32 declared against 34 present) and the guide's total.
@yannickmonney
yannickmonney merged commit 3755216 into main Sep 17, 2026
58 checks passed
@yannickmonney
yannickmonney deleted the fix/closed-sign-up branch September 17, 2026 23:19
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