Phase 13, part 2: each team's own database role

A team's connections take a Postgres role that owns its schema and may
use the shared tables, nothing else: even SQL naming another team's
schema is refused. The second guard behind the search_path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:11:57 -07:00
co-authored by Claude Opus 5.5
parent 0e695ac810
commit 210b1e57fc
4 changed files with 136 additions and 10 deletions
+16 -1
View File
@@ -55,7 +55,7 @@ tools over MCP, approvals, limits and visibility, and the JSON API. Schema
39.
**Phase 13 (multi-tenant) is under way** on branch `phase13`, with a
Postgres schema per team (decided 2026-11-26); part 1 is built.
Postgres schema per team (decided 2026-11-26); parts 1–2 are built.
**Phase 12 (signing in with the Core, OIDC) is set aside for now**
(2026-11-26): before it starts, the user will share the Federated Core's
@@ -2810,6 +2810,21 @@ stand.
key, see only their own, through the pages, Search, MCP and secrets; the
main schema holds none of it.
**Part 2 built 2026-11-26** on `phase13`.
- Each team has a Postgres role named as its schema (`team_<id>`), which
owns the team's schema and every table in it (they're made as that
role), and has SELECT, INSERT, UPDATE and DELETE on the shared tables
(granted again each time the team opens, so shared tables added later
are covered), and nothing else. A team's pool takes that role on each
connection (`SET ROLE`, through pgx's after-connect hook).
- So a query naming another team's schema, or the main schema's own,
unused copies of the team tables, is refused (*permission denied*): the
second guard. Platform work that needs every team uses the main pool,
as the app's own user.
- The app's database user needs `CREATEROLE` on the multi-tenant edition
(managed Postgres gives it to the main user). Dropping a team drops its
role and what it was granted; tests leave no roles or schemas behind.
1. **Teams everywhere.**
- Every table that holds a company's data gets `team_id`, and its
unique keys include it. The settings table's key becomes