Tenant isolation: implementation checklist
Status: foundation implemented; authentication, membership authorization, request and job integration remain pending. The bootstrap administrator remains a PostgreSQL superuser and must not be used for application runtime.
Database access
Section titled “Database access”- Provision separate migration and runtime login roles using separately managed
credentials. The runtime role must not own tenant tables, be a superuser,
have
BYPASSRLS, create roles, or inherit a role that can bypass policies. - Run migrations explicitly as the migration role; web and worker processes must connect as the runtime role. Never expose migration credentials to them.
- Preserve existing volumes when applying the change. Provision roles on an existing database as well as on a fresh installation.
Tenant context and policies
Section titled “Tenant context and policies”- Establish verified tenant identity before accessing tenant-owned data. Set it transaction-locally on the same checked-out connection; missing context must deny access. Clear it automatically when the transaction finishes.
- Enable and force RLS on tenant-owned tables, and apply both
USINGandWITH CHECKpolicies. Add tenant-aware foreign keys where appropriate. - Do not infer tenant identity from an untrusted request parameter. Authentication, authorization and job tenant identity must be implemented before exposing tenant operations.
- Preserve policies in the database schema dump and restoration path.
Verification
Section titled “Verification”- Test with the actual runtime role, including direct SQL, no tenant context, cross-tenant read, insert, update and delete, and context cleanup after errors.
- Verify the runtime role cannot change roles or bypass RLS, and schema restoration retains the policies.
- Use a dedicated test database. Confirm test configuration cannot target the development database before running destructive database setup tasks.