Skip to content

feat(platform): let the operator name who may create an organization - #3413

Merged
larryro merged 4 commits into
mainfrom
feat/organization-creators-allowlist
Sep 18, 2026
Merged

larryro merged 4 commits into
mainfrom
feat/organization-creators-allowlist

Conversation

@larryro

@larryro larryro commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Why

Better Auth's organization plugin lets every signed-in user create an organization, and a managed deployment answered that with the opposite extreme: the CLI's proxy policy refused POST /api/auth/organization/create for everyone and answered the capability probe {"canCreate":false} session-free, so neither the owner nor the operator could open a second workspace, and nothing the deployment declared could change it. platform.tale.dev is such a deployment.

An allowlist is the right shape for this — the same one TALE_DEPLOYMENT_CONFIG_ADMINS already uses for who may write the deployment config — and it has to be judged by the backend: the edge cannot know who is asking, and backend-api is reachable from the sandbox network the edge never sees (the argument #3407 made for accounts).

What changes

Backend — one predicate, two doors. TALE_ORGANIZATION_CREATORS names the sign-in addresses that may create an organization (commas, semicolons or spaces; matched case-insensitively; the grammar is shared with TALE_DEPLOYMENT_CONFIG_ADMINS through one parser, backend/lib/email-allowlist.ts).

  • Unset keeps the previous behaviour: any signed-in user may create. A workspace deployment or an own Compose file that never heard of the variable is unchanged.
  • Set, a listed address passes without a database read; anyone else is refused with 403 ORGANIZATION_CREATION_FORBIDDEN once the deployment holds an organization, and the refusal is logged ([organizations] refused …) because a before-hook throw is the only record the operator gets.
  • The first organization is always allowed — the setup flow's, or the managed bootstrap's — so setup is unaffected by any list.
  • A set but empty value closes creation to everyone after the first organization.
  • A server-side call (no request) always passes, like the sign-up gate.

The gate runs in Better Auth's before-hook for /organization/create (the caller comes from getSessionFromCtx; a caller without a session is left to the endpoint's own 401). GET /api/app/organizations/capabilities answers the same predicate per caller, so the app shows Create organization exactly when the door would open; the UI needed no change — it already keys on canCreate and already carries the forbidden-creation copy in en/de/fr.

CLI — a declaration instead of a blanket refusal. The deployment specification takes organizations.creators: 1–64 distinct addresses, literal or environment references that preparation resolves; two spellings of one address are refused as a duplicate. Declared, the CLI writes TALE_ORGANIZATION_CREATORS into the runtime environment (a managed key — an environment entry cannot set it), omits the two organization rules from the proxy policy (the sign-up refusal stays), records organizationCreatorsDeclared in the runtime bundle so readRuntimeBundle checks the policy against the declaration, and includes the list in the receipt's input hash only when declared, so every earlier receipt keeps its hash. Undeclared, nothing changes: the edge refuses everyone as before and the variable is removed if an earlier declaration wrote it.

Docs and manual layer. Environment reference (en/de/fr), the first-administrator page (en/de/fr), the CLI install page's managed section (en/de/fr, #managed-organization-creators), the CLI readme, .env.example, manual box AUTH-B9 with its automation and error-code register rows.

Proof

  • backend/auth/organization-creation-gate.test.ts — the truth table (server-side call, no list, listed, unlisted with/without an organization, empty list, no address) and that the database is asked only when its answer matters.
  • backend/auth/auth.organization-create.test.ts — the real auth handler: a caller without a session gets the endpoint's 401, never the gate's 403, and no list means no organization read.
  • backend/domains/organizations/routes.test.ts — the capability per caller (listed, unlisted, first organization, empty list) and the existing unmanaged case unchanged.
  • backend/integration-check.ts — against real Postgres: a settings-door member not on the list reads canCreate: false and is refused with the code; the listed owner (matched case-insensitively) reads true and creates.
  • CLI: inputs.test.ts (resolution, refusals), runtime-env.test.ts (write, remove, managed-key refusal), runtime-prepare.test.ts (policy with and without the declaration), apply.test.ts (the list reaches the runtime environment and stays out of the native identity). 147 tests across the six deployment suites pass; the platform server suites touched pass (6 files / 40 tests); tsc --noEmit clean in both workspaces; docs suite 34 files / 166 tests; lint:manual and check-guide on the auth suite clean.

Known limits

  • A managed deployment that declares no creators keeps today's edge-only refusal: a signed-in session on the sandbox network could still reach the backend's open create door there, as before this change. Declaring a list closes it in the backend too.
  • The browser round for AUTH-B9 (the picker entry disappearing, the forbidden page) is manual; the register row says so.
  • Better Auth 1.6.30 also offers allowUserToCreateOrganization(user); the before-hook was chosen so the refusal carries our code and a log line and follows the sign-up gate's shape.

Better Auth's organization plugin lets every signed-in user create one, and
a managed deployment closed the door at its edge for everyone instead. The
backend now judges each caller against TALE_ORGANIZATION_CREATORS: unset
keeps the previous open behaviour, a listed address passes, an unlisted one
is refused with 403 ORGANIZATION_CREATION_FORBIDDEN once the deployment
holds an organization, and the first organization (the setup flow's, or the
managed bootstrap's) always passes. The capabilities route answers the same
predicate per caller, so the UI shows the create door exactly when it would
open. The list shares its grammar with TALE_DEPLOYMENT_CONFIG_ADMINS.
A deployment specification may name organization creators
(organizations.creators: sign-in addresses, literal or environment
references). The CLI writes them to the runtime's managed
TALE_ORGANIZATION_CREATORS and stops refusing organization creation at the
proxy, leaving the backend to judge each caller against the list; without
the declaration the edge refuses everyone as before and the variable is
removed. The list is part of the receipt's input hash only when declared,
so earlier receipts keep their hash.
…tgres

A member the settings door created is not on TALE_ORGANIZATION_CREATORS:
its capability reads false and its create answers 403
ORGANIZATION_CREATION_FORBIDDEN, while the listed owner — matched
case-insensitively — reads true and creates. The variable is restored
afterwards so no later case inherits the list.
TALE_ORGANIZATION_CREATORS joins the environment reference and the first
administrator page in English, German and French, the CLI install page and
the CLI readme gain the managed organizations.creators declaration, the
.env.example block states the unset/set/empty semantics, and the manual
layer carries AUTH-B9 with its automation and error-code register rows.
@larryro
larryro merged commit 8398e1f into main Sep 18, 2026
56 checks passed
@larryro
larryro deleted the feat/organization-creators-allowlist branch September 18, 2026 10:34
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