feat: tenant administration from the Studio, for instance administrators #23

Merged
crapougnax merged 1 commit from feat/22-tenant-administration into develop 2026-11-16 20:46:16 +00:00
Member

Closes #22

What

  • Service TenantAdministration (src/instance/tenant-admin.ts): list and create tenants, rename, suspend, reactivate, list members, add a member with roles, replace the roles, remove a member, list the accounts of the instance. It never deletes a tenant.
  • Routes under /api/admin/tenants and /api/admin/accounts, through one guard (src/lib/tenant-admin-api.ts).
  • Tenants tab in the settings dialog (TenantAdminPanel.tsx).
  • Each change is logged with the identifier of the account that made it.

Security

  • The routes accept the instance role admin only. They are refused under a tenant URL, where roles are those held in the tenant: an administrator of a tenant cannot create tenants nor see the accounts of the instance.
  • A body must be declared as JSON, so a form posted from another site cannot reach them (the session cookie is also SameSite=Lax).
  • The account list gives identifier, login, e-mail, name and state; never a password hash nor claims.
  • The application role of the database now writes the tenant registry (tenants: SELECT, INSERT, UPDATE; tenant_memberships: plus DELETE), which it could only read. It was already able to write the account table, roles included, so this does not give a compromised application a power it lacked, but the registry is no longer read-only for it.

Deployment

Run yarn admin migrate again: it applies the new grants. An instance whose migrations run at each start gets them by itself.

Verified

  • yarn test: 69 tests pass, 7 new (service on the in-memory store, the guard, the body reader) and the grant test updated.
  • End to end on the production build, with a throwaway PostgreSQL and the restricted application role:
    • administrator: create (201), taken slug (409), reserved slug (400), form-encoded body (415), list accounts, add a member, list members, suspend, rename and reactivate, remove a member (204);
    • the member then enters /t/acme/…; once the tenant is suspended or the member removed, it gets 404;
    • instance curator: 403; anonymous: 401;
    • the same account, made administrator of the tenant: 404 under /t/acme/api/admin/tenants, 403 on /api/admin/tenants.
  • In a browser: the Tenants tab lists the tenant, opens it and adds a member chosen among the accounts.

Not verified

  • In the browser, only listing, opening a tenant and adding a member were clicked through; creation, renaming, suspension, role change and removal were exercised through the routes only.

Out of scope

Per-tenant git repository, storage and AI provider: next part of the multi-tenant work. Until then, configuring a tenant means its name, its state and its members.

🤖 Generated with Claude Code

Closes #22 ## What - **Service** `TenantAdministration` (`src/instance/tenant-admin.ts`): list and create tenants, rename, suspend, reactivate, list members, add a member with roles, replace the roles, remove a member, list the accounts of the instance. It never deletes a tenant. - **Routes** under `/api/admin/tenants` and `/api/admin/accounts`, through one guard (`src/lib/tenant-admin-api.ts`). - **Tenants tab** in the settings dialog (`TenantAdminPanel.tsx`). - Each change is logged with the identifier of the account that made it. ## Security - The routes accept the instance role `admin` only. They are refused under a tenant URL, where roles are those held in the tenant: an administrator of a tenant cannot create tenants nor see the accounts of the instance. - A body must be declared as JSON, so a form posted from another site cannot reach them (the session cookie is also `SameSite=Lax`). - The account list gives identifier, login, e-mail, name and state; never a password hash nor claims. - **The application role of the database now writes the tenant registry** (`tenants`: SELECT, INSERT, UPDATE; `tenant_memberships`: plus DELETE), which it could only read. It was already able to write the account table, roles included, so this does not give a compromised application a power it lacked, but the registry is no longer read-only for it. ## Deployment Run `yarn admin migrate` again: it applies the new grants. An instance whose migrations run at each start gets them by itself. ## Verified - `yarn test`: 69 tests pass, 7 new (service on the in-memory store, the guard, the body reader) and the grant test updated. - End to end on the production build, with a throwaway PostgreSQL and the restricted application role: - administrator: create (201), taken slug (409), reserved slug (400), form-encoded body (415), list accounts, add a member, list members, suspend, rename and reactivate, remove a member (204); - the member then enters `/t/acme/…`; once the tenant is suspended or the member removed, it gets 404; - instance curator: 403; anonymous: 401; - the same account, made administrator of the tenant: 404 under `/t/acme/api/admin/tenants`, 403 on `/api/admin/tenants`. - In a browser: the Tenants tab lists the tenant, opens it and adds a member chosen among the accounts. ## Not verified - In the browser, only listing, opening a tenant and adding a member were clicked through; creation, renaming, suspension, role change and removal were exercised through the routes only. ## Out of scope Per-tenant git repository, storage and AI provider: next part of the multi-tenant work. Until then, configuring a tenant means its name, its state and its members. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat: tenant administration from the Studio, for instance administrators (#22)
All checks were successful
Build and Publish OCI Image / Build & Push ARM64 OCI Image (pull_request) Successful in 3m27s
e44e39e9d1
Administrators of the instance create tenants, rename, suspend and reactivate
them, and manage their members from a Tenants tab of the settings dialog, backed
by JSON routes under /api/admin. The routes refuse anyone else, and are not
served under a tenant URL: an administrator of a tenant is not an administrator
of the instance.

The application role of the database now writes the tenant registry, which it
could only read; it still cannot delete a tenant. Run the migration command
again to apply the new grants.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
crapougnax merged commit e32aa3131a into develop 2026-11-16 20:46:16 +00:00
crapougnax deleted branch feat/22-tenant-administration 2026-11-16 20:46:16 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
modaka/studio!23
No description provided.