Repository navigation
fix(platform): close sign-up once a deployment has an account - #3407
Merged
Merged
Conversation
`/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The hole
POST /api/auth/sign-up/emailhad 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-apiis 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";hasAnyUsersis false.Only the backend disagreed.
The gate
backend/auth/sign-up-gate.tsis a pure predicate; the existing before-hook applies it on/sign-up/email:SIGN_UP_CLOSEDPOST /api/app/users/members, provisioning, dev seedTALE_ALLOW_OPEN_SIGN_UP=trueThe refusal happens in the before-hook: the only question the deployment answers is whether it already holds an account.
Blast radius
helpers/auth'ssignUpViaApi), so the hermetic stack setsTALE_ALLOW_OPEN_SIGN_UP=trueinplaywright.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 exactlytrueopens it), and a wiring test that drives the real auth handler over HTTP against a stubsqland asserts 403 plus that the adapter was never asked for anything beyond "does an account exist".Local:
vitest backend/auth13 files / 88 tests, typecheck, oxlint, Knip,oxfmt --check,lint:manual(new boxAUTH-B8judges it from inside a session container),services/docs34 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.