Repository navigation
feat(tenants): add opt-in organisations, teams and verified workspaces - #70
Conversation
ORGANISATIONS_ENABLED (off by default) adds a two-level organisation and team hierarchy with stable opaque IDs, roles, caps and deactivation instead of deletion. Administrators manage it under /admin/organisations with If-Match revisions and audit rows. Each account has at most one server-side workspace binding; /v1/workspaces lists the caller's memberships and /v1/workspaces/switch changes the binding only after a membership check. A new first post-authentication hook resolves the verified TenantContext and refuses a missing or deactivated workspace with 404 or 403 before any storage, cache, claim or provider call. Caller headers never choose a workspace. Native Worker generations, knowledge and Realtime resolve the same context, only after the key matches. Accounts without a binding stay in the legacy namespace (migration 0033).
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
multillm-proxy | 0cfdf92 | Oct 09 2026, 07:58 AM |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
de9a471
into
integrate/gateway-waves-1-6
Summary
Adds optional organisations and teams with a workspace identity the server verifies. With
ORGANISATIONS_ENABLEDunset oroff(the default), every route, response, account read, key record and storage operation is byte-for-byte unchanged, the new routes return 404, and every request keeps the legacy tenant context with an empty namespace.ORGANISATIONS_ENABLED. Empty means off; a malformed value is off with one warning that leaves the value out.active/deactivatedstatus and integer revisions.admin,billingormember. These roles grant nothing on the gateway administrator dashboard.tenant_limit_reached). Nothing is deleted; rows are deactivated.GET/POST /admin/organisations,GET/PATCH /admin/organisations/<org_id>;GET/POST /admin/organisations/<org_id>/teams,PATCH /admin/organisations/<org_id>/teams/<team_id>;GET /admin/organisations/<org_id>/members,PUT /admin/organisations/<org_id>/members/<principal>.If-Match: missing returns 428, stale returns 412. Every change writes an audit row.GET /v1/workspaceslists the caller's active memberships.POST /v1/workspaces/switchchanges the caller's own binding only after a membership check.X-OrgorX-Teamnever choose a workspace.tenant_context_hookruns first after authentication. A missing workspace returns 404workspace_not_found, and a deactivated workspace or revoked membership returns 403workspace_forbidden, before any storage, cache, claim, admission or provider call.0033). Missing tables with the flag on return 503tenant_storage_unavailablefor every authenticated request; there is no silent fallback.Details are in
docs/tenant-hierarchy.md.Wiring
app.pymountsroutes/tenants.py.services/gateway_extensions.pyregisterstenant_context_hookfirst in the named order.services/auth_service.pygets two call sites: the workspace is resolved after the key is verified and before key-usage metadata is written.worker/managed-state-dispatch.mjsroutes the private/v1/managed-state/tenantsdomain toworker/tenants-d1.mjs; it accepts only the internal origin and returns 404 while off.Review fix
The first version resolved a workspace for every account that shared the caller's 8-character key prefix, before the key was compared. Another account's deactivated workspace could then deny the caller, and the error became a 503-style failure. Resolution now happens only after the key matches, and tests cover two accounts sharing a prefix.
Shared registrations
tests/test_tenant_hierarchy_worker.mjsintest:worker.worker/tenants-d1.mjsin the edge module inventory, and the eight routes inroutes/tenants.pyin the Flask route inventory.ORGANISATIONS_ENABLEDin the Container env keys.tests/test_d1_integration.mjsnow starts its Worker withnodejs_compat, aswrangler.jsoncdoes in production.worker/tenants-d1.mjsimportsnode:crypto, and without the flag the integration Worker failed to start.tenant_organisations,tenant_teams,tenant_memberships,tenant_bindingsandtenant_auditinREQUIRED_D1_TABLES.Stack
This is the bottom of the Wave 7 stack (migration 0033), based on
integrate/gateway-waves-1-6(#69). Tenant governance (0034), SAML federation (0035), SCIM provisioning (0036), the credits ledger (0037) and payment billing (0038) stack on it in that order.Tests
tests/test_tenant_hierarchy.pyandtests/test_tenant_hierarchy_worker.mjscover:test_registered_native_protocols_preserve_bytesintests/test_output_schema_validation.py, only appears in the full run: it passes alone and after the tenant tests, and passed in the full run of every layer stacked on this one. ruff, mypy and bandit are clean.npm run test:worker: 1,793 passed.npm run test:integration: 7 passed.cf:migrations:checkreports 33 contiguous, additive migrations.test:deploy, free routes, client headers and thewrangler deploy --dry-runbundle all pass.tests/test_frontend_build.mjsfails locally because@tailwindcss/cliis not installed. It fails the same way on main.Apply the migration before enabling the flag:
npx wrangler d1 migrations apply multillm-intelligence --remote. For standalone SQLite, apply0033_tenant_hierarchy.sqlto the account database.CI notes
python/nodejobs: the dependency-audit steps fail on every branch, including main. fix(deps): clear the CI dependency audit advisories #42 fixes that.AdmissionCoordinatorDurable Object migration, whichwrangler versions uploadcannot apply. This is expected untilwrangler deployruns on main.This is part of Wave 7. The README line comes with the Wave 7 integration PR.