Skip to content

Self-serve workspace provisioning for founders (backend) #1402

Backlog

Description

@athvin

Why

Today a workspace (a tenant) exists only if a super admin provisions it in the operator console ((admin)/admin/tenants/new). The owner wants a person with no workspace to be able to create one themselves, right after signing in with Google, and to land in it as its admin on a free allowance.

This ticket is the backend half of the founder path only. Members joining an existing workspace never reach it (see #1400).

What the user sees

The user sees nothing directly; #1403 is the UI. The /welcome flow submits a workspace name, the kind of data (people or accounts), and acceptance of the terms. Then it watches real provisioning progress until the workspace is ready.

How

  1. Pull out a shared provisioning helper. frontend/src/app/api/admin/orgs/route.ts POST (L65-96) currently does these steps inline:

    • calls er-server POST /v1/orgs with the operator token;
    • runs mintServiceKeys (frontend/src/lib/bff/admin.ts), which seals viewer, steward and admin keys into org_credentials;
    • inserts orgs_registry;
    • writes the org.provision audit row.

    Move those steps into one server-only helper. The operator route then calls that helper, with no change in behaviour.

  2. POST /api/auth/signup/workspace.

    • Requires: a valid pending-identity cookie from First-sign-in router: join an existing workspace vs found a new one #1400 that is not staff.
    • Before anything is created, re-check on the server that:
      • no pending invite matches the email (if one does, redirect to /join);
      • this Google sub hasn't already founded a workspace (one self-serve workspace per person).
    • Input: the workspace display name (2–60 characters), the entity type (person or account, the only supported models; see launch-readiness.md), and terms_accepted = true.
    • Steps:
      1. Derive the slug: lowercase, ASCII, hyphens. Refuse reserved words (admin, app, api, login, welcome, join, docs and every top-level route) and taken slugs. Suggest -2 on a clash.
      2. Create the user (no password), the identity and terms_accepted_at, in one transaction, then commit.
      3. Call the shared provisioning helper with the entity type.
      4. Insert org_members(role=admin).
      5. Set the free allowance with the operator PATCH /v1/orgs/{org}/allowance (set_allowance, rust/crates/er-server/src/lib.rs:6463). The value comes from ERWEB_SIGNUP_FREE_ALLOWANCE.
      6. Write user_onboarding(kind=founder) for First-run state and the tour offer, per user per workspace #1404.
      7. Call createSession.
      8. Write the audit row org.self_serve_provision with the actor and the slug.
  3. GET /api/auth/signup/status?org=. It reports the real phases in order:

    • registered: the registry row exists;
    • provisioning: er-server reports org state provisioning;
    • config_ready: config v1 exists;
    • dataset_ready: the default dataset exists;
    • keys_ready: the sealed credentials exist;
    • active.

    The UI moves forward only on these, which is the motion rule that bans progress filled in between polls. Poll every 1s, with a timeout.

  4. When something fails. If provisioning fails or times out:

    • Mark the registry row failed, and show "We couldn't finish setting up your workspace — try again".
    • "Try again" re-runs provisioning for the same slug.
    • Never leave a membership pointing at an org that doesn't exist.
  5. Abuse controls.

    • One workspace per person.
    • A global daily cap, ERWEB_SIGNUP_DAILY_CAP (default 25). Past the cap, the copy says "We're at capacity for new workspaces today — try tomorrow", and the event is audited.
    • A WAF rate rule on /api/auth/signup/*.
    • Signup requires Google; there is no password signup.
  6. Feature flag. ERWEB_SELF_SERVE_SIGNUP_ENABLED, read by the router in First-sign-in router: join an existing workspace vs found a new one #1400.

  7. Prerequisite to verify first. er-server returns 503 from auto-provisioning unless ER_PROVISION_MODE is set (rust/crates/er-server/src/provision.rs:18). Whether prod sets it is unverified. Check it in the prod er-server env by name, and if it's missing, set it to postgres in the chart values before anything else.

Acceptance criteria

  • On the dev cluster, a signup goes from registered to active. Measure and record the p50 and p95 over 10 runs in this ticket. Cinematic login, /welcome (founder) and /join (member) screens #1403's scene is tuned to that number.
  • A person who already founded a workspace is refused a second one.
  • A person with a pending matching invite is redirected to /join and never gets a workspace. Test this by calling the endpoint directly.
  • Reserved and taken slugs are refused with a suggestion.
  • The daily cap is enforced, and resets the next UTC day.
  • A forced provisioning failure leaves no membership for a missing org, and "Try again" succeeds.
  • The operator console's "new tenant" still works unchanged through the shared helper; its existing tests stay green.
  • The new org's allowance reads back as the configured value from GET /v1/orgs/{org}/usage.
  • ER_PROVISION_MODE is confirmed in prod by name.

Out of scope

Depends on

#1398 and #1400. This ticket blocks #1403 and #1406.

Where to start

  • frontend/src/app/api/admin/orgs/route.ts.
  • frontend/src/lib/bff/admin.ts.
  • rust/crates/er-server/src/lib.rs: create_org at L1175 and provision_org at L967.
  • rust/crates/er-server/src/provision.rs.
  • frontend/src/components/admin/new-tenant.tsx.

Estimate: 1.5 engineer-weeks.


Part of the E31 epic (#1396) (linked as parent). Decisions recorded 2026-11-28 with the owner.

Activity

  1. added
    post-mvp
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    post-mvp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions