Skip to content

[M2.3a] Define tenant permissions and last-owner policy - #76

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3a-rbac-policy
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3a-rbac-policy

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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

  • Test-first suite: 30 tests, including all 19 permissions across five roles, protected environments, absent/foreign membership, malformed contexts, unknown permissions/roles, duplicate bindings, scope inheritance, and ownership changes. V8 reports 100% statements/branches/functions/lines for the policy module.
  • Workspace lint, typechecks and TypeScript tests pass; API/web builds pass; Go tests and buf lint pass.
  • No new dependencies, framework imports in domain code, generated-code edits or application shell invocation.

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

  • M2.3a acceptance criteria recorded and task checked
  • Lint, TS tests, Go tests, buf lint and builds pass
  • Authorization denial and privilege-escalation cases tested
  • No new secret exposure or application shell execution
  • SPEC/PLAN updated; no persistence mutation to audit

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.2e4c-identity-finish branch from 9d4a296 to 017b200 Compare November 5, 2026 12:43
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.2e4c-identity-finish to main November 5, 2026 12:43
@samuelmbabhazi
samuelmbabhazi merged commit 1be8664 into main Nov 5, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3a-rbac-policy branch November 5, 2026 12:43
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant