Repository navigation
feat(platform): let the operator name who may create an organization - #3413
Merged
Merged
Conversation
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.
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.
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/createfor 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_ADMINSalready uses for who may write the deployment config — and it has to be judged by the backend: the edge cannot know who is asking, andbackend-apiis reachable from the sandbox network the edge never sees (the argument #3407 made for accounts).What changes
Backend — one predicate, two doors.
TALE_ORGANIZATION_CREATORSnames the sign-in addresses that may create an organization (commas, semicolons or spaces; matched case-insensitively; the grammar is shared withTALE_DEPLOYMENT_CONFIG_ADMINSthrough one parser,backend/lib/email-allowlist.ts).ORGANIZATION_CREATION_FORBIDDENonce 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 gate runs in Better Auth's before-hook for
/organization/create(the caller comes fromgetSessionFromCtx; a caller without a session is left to the endpoint's own 401).GET /api/app/organizations/capabilitiesanswers 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 oncanCreateand 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 writesTALE_ORGANIZATION_CREATORSinto the runtime environment (a managed key — anenvironmententry cannot set it), omits the two organization rules from the proxy policy (the sign-up refusal stays), recordsorganizationCreatorsDeclaredin the runtime bundle soreadRuntimeBundlechecks 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 boxAUTH-B9with 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 readscanCreate: falseand is refused with the code; the listed owner (matched case-insensitively) readstrueand creates.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 --noEmitclean in both workspaces; docs suite 34 files / 166 tests;lint:manualandcheck-guideon the auth suite clean.Known limits
AUTH-B9(the picker entry disappearing, the forbidden page) is manual; the register row says so.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.