Repository navigation
[M2.3b1] Persist organizations and tenant-bound resources - #77
Merged
Merged
Conversation
5 tasks done
samuelmbabhazi
force-pushed
the
feat/m2.3a-rbac-policy
branch
from
November 5, 2026 12:43
df08b09 to
aa85ccf
Compare
samuelmbabhazi
force-pushed
the
feat/m2.3b1-tenant-schema
branch
from
November 5, 2026 12:44
8eecc56 to
5bac68c
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
…#78) ## Task M2.3b2, stacked on #77 (`feat/m2.3b1-tenant-schema`). ## What changed and why Force PostgreSQL row security on organizations, memberships, projects, environments and role bindings. A transaction-local organization context scopes reads and writes; missing context denies access. Deferred constraint triggers require every surviving organization to retain an owner and permit atomic ownership transfers. A serialized organization write prevents concurrent owner removals, including stale snapshots at REPEATABLE READ. Checks retain their stored tenant when a caller changes context before commit. Migration refuses pre-existing ownerless organizations. ## Validation - All 98 real PostgreSQL integration tests pass, including eight new isolation/concurrency tests and the six tenant-schema tests. - Restricted-role tests cover all five tables, foreign reads/updates/deletes, missing-context and foreign writes, table-owner FORCE RLS, context restoration, ownership transfer, organization deletion and concurrent last-owner protection at two isolation levels. - API lint/typechecks pass. Workspace TypeScript tests/builds, Go tests and buf lint passed in this session; their sources are unchanged by this SQL slice. ## Security considerations The trigger runs with invoker privileges, a fixed search path and qualified table names. No security-definer bypass, new dependency, secret or application shell invocation is added. This slice exposes no tenant endpoint or application mutation. M2.3c must enforce a restricted runtime database role and transaction context before tenant routes are enabled; superusers and BYPASSRLS roles still bypass PostgreSQL RLS. Fleet foreign keys remain tracked in M2.3b3. ## Checklist - [x] M2.3b2 acceptance and malicious cross-tenant cases covered - [x] Concurrent last-owner removals tested against real PostgreSQL - [x] Lint, types and integration suite pass - [x] SPEC, threat model and PLAN updated - [x] No new application mutation requiring an audit event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
M2.3b1, stacked on #76 (
feat/m2.3a-rbac-policy). This slice adds storage constraints; M2.3b2 adds RLS and last-owner database guards before tenant routes are exposed.What changed and why
Add organizations, memberships, projects, environments and role bindings to Prisma and SQL. Composite foreign keys include organization and parent project identifiers, rejecting cross-tenant and sibling-project references even outside application validation. A NULLS NOT DISTINCT index prevents duplicate project-wide bindings as well as duplicate environment bindings. User deletion is restricted while memberships remain.
Constrain roles, configuration-write modes, environment kinds, failover policies, names and slugs. Projects default to pull-request writes; environments default to protected with no automatic failover. Existing fleet references are tracked separately in M2.3b3 so orphan records are not silently assigned to an arbitrary organization.
Validation
Security considerations
No new endpoint, permission grant or runtime tenant query is exposed. Foreign-key isolation is not a substitute for RLS; tenant read/write policies and concurrent ownership protection remain required in M2.3b2 before HTTP access. No domain state changes are initiated by application code in this slice, so no new audit event path is needed. No dependencies, secrets or application shell calls are added.
Checklist