Skip to content

security: require auth to create a tenant (POST /v1/tenants) - #33

Open
doctatortot wants to merge 1 commit into
ourmem:mainfrom
doctatortot:fix/authenticate-tenant-creation
Open

security: require auth to create a tenant (POST /v1/tenants)#33
doctatortot wants to merge 1 commit into
ourmem:mainfrom
doctatortot:fix/authenticate-tenant-creation

Conversation

@doctatortot

Copy link
Copy Markdown
Contributor

Problem

POST /v1/tenants is mounted on public_routes — outside the auth_middleware route_layer. create_tenant creates a tenant and returns its id as a working API key, so any client that can reach the server can mint an active tenant + key with a single unauthenticated request. On a self-hosted LAN deployment that is every device on the network; tenant isolation is only as strong as "who can obtain a key," and today anyone can.

Change

Move the route onto authed_routes so a caller must present a valid X-API-Key to create another tenant. /health and the GitHub webhook (HMAC-verified in its own handler) stay public. One-file change, +8/−1.

Tradeoff

This yields an "any active tenant may mint another tenant" model rather than true admin-gating. For a single-operator instance that closes the real exposure (anonymous minting). A follow-up could gate create_tenant behind a dedicated bootstrap/admin token from an env var if per-instance admin control is wanted.

Bootstrap note

Existing tenants are unaffected. After this change the first tenant on a fresh instance must be seeded out-of-band (admin token or direct store insert), since there is no longer an anonymous creation path.

`POST /v1/tenants` is mounted on `public_routes`, i.e. outside the
`auth_middleware` route_layer. `create_tenant` creates a tenant and returns its
id as a working API key, so any client that can reach the server can mint an
active tenant + key with a single unauthenticated request. On a self-hosted
LAN deployment that is every device on the network; the memory store's tenant
isolation is only as strong as "who can obtain a key," and right now anyone can.

Move the route onto `authed_routes` so a caller must present a valid `X-API-Key`
to create another tenant. `/health` and the GitHub webhook (HMAC-verified in its
own handler) stay public.

Tradeoff: this yields an "any active tenant may mint another tenant" model
rather than true admin-gating. For a single-operator instance that closes the
real exposure (anonymous minting). If per-instance admin control is wanted,
a follow-up could gate `create_tenant` behind a dedicated bootstrap/admin token
from an env var instead of the shared auth layer.

Bootstrap note: existing tenants are unaffected. After this change the first
tenant on a fresh instance must be seeded out-of-band (admin token or a direct
store insert), since there is no longer an anonymous creation path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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