Repository navigation
[M2.3a] Define tenant permissions and last-owner policy - #76
Merged
Merged
Conversation
5 tasks done
samuelmbabhazi
force-pushed
the
feat/m2.2e4c-identity-finish
branch
from
November 5, 2026 12:43
9d4a296 to
017b200
Compare
samuelmbabhazi
changed the base branch from
feat/m2.2e4c-identity-finish
to
main
November 5, 2026 12:43
samuelmbabhazi
force-pushed
the
feat/m2.3a-rbac-policy
branch
from
November 5, 2026 12:43
df08b09 to
aa85ccf
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
## 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 - Six real PostgreSQL tests cover migration reapplication, scoped uniqueness, cross-tenant insert/update rejection, sibling-project rejection, null-scope uniqueness, invalid states, safe defaults and cascade boundaries. - All 84 existing PostgreSQL integration tests passed with the migration. The first full run exposed an ambiguous fixture (a duplicate-name error preceded the intended foreign-key rejection); the fixture now uses a distinct name and all six new tests pass on rerun. - Prisma formatting/generation, API/web unit tests and builds, lint and typechecks pass. Shared domain tests, Go tests and buf lint passed in this session; their sources are unchanged by this slice. ## 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 - [x] M2.3b1 checked; remaining isolation/integration work explicit in PLAN - [x] PostgreSQL constraints and malicious cross-resource references tested - [x] Lint, typechecks, unit tests and builds pass - [x] No new secret exposure or application shell execution - [x] SPEC/PLAN updated; no runtime mutation to audit
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.3a, stacked on #75 (
feat/m2.2e4c-identity-finish). This is the pure authorization foundation; persistence, HTTP enforcement and organization screens remain tracked separately in PLAN.What changed and why
Add a default-deny tenant policy implementing SPEC 7 across the closed permission vocabulary. It validates resource hierarchy and scope, rejects unknown roles/capabilities, bounds resource grants to their project/environment, and requires current protection metadata for deploy, secret write and container exec. An explicit environment binding overrides inherited project access; an environment-only grant allows parent navigation but no sibling access or project administration.
Add a membership-change policy that prevents organization admins from granting/changing ownership and preserves the last owner. The caller must serialize changes under an organization lock; this pure function does not provide database concurrency protection. Destructive actions still require the separate M2.5 confirmation contract.
Split M2.3 into reviewable plan tasks and document conservative defaults in SPEC/Open questions. No HTTP route uses the new policy yet; existing tenant-token capabilities remain denied until the live adapter lands.
Validation
Security considerations
The integration adapter must load current membership, actual resource ancestry and environment protection from the database. A policy allow is neither proof of token scope nor a consumed destructive-action confirmation. No persistence or mutation was introduced, so no new audit event is required in this slice. API enforcement, tenant isolation and concurrent last-owner checks remain explicit follow-up acceptance tasks.
Checklist