Skip to content

[M2.3b2] Enforce tenant row isolation and concurrent owner protection - #78

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3b2-tenant-isolation
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3b2-tenant-isolation

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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

  • M2.3b2 acceptance and malicious cross-tenant cases covered
  • Concurrent last-owner removals tested against real PostgreSQL
  • Lint, types and integration suite pass
  • SPEC, threat model and PLAN updated
  • No new application mutation requiring an audit event

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3b1-tenant-schema branch from 8eecc56 to 5bac68c Compare November 5, 2026 12:44
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.3b1-tenant-schema to main November 5, 2026 12:44
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3b2-tenant-isolation branch from 9106db3 to dae86da Compare November 5, 2026 12:44
@samuelmbabhazi
samuelmbabhazi merged commit 839b523 into main Nov 5, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3b2-tenant-isolation branch November 5, 2026 12:44
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
## Task

M2.3b3, stacked on #78 (`feat/m2.3b2-tenant-isolation`).

## What changed and why

Require every fleet node and enrollment token to reference an existing
organization. Organization deletion is restricted while either kind of
record remains, so it cannot silently cascade into servers, certificates
or enrollment history. Abort migration on legacy orphan references with
an opaque diagnostic; do not invent owners, move servers or delete
records. Seed a real organization and verified owner in the existing
enrollment acceptance fixture.

## Validation

- Six PostgreSQL tests cover rejected orphan inserts/updates, deletion
restrictions and failed migration preservation for both fleet tables.
- Real CA-backed enrollment still passes. All 104 PostgreSQL integration
tests pass with the new migration.
- Prisma format/generation, API lint/typechecks and 103 API unit tests
pass. Go tests and buf lint passed earlier in this session; their
sources are unchanged.

## Security considerations

This adds referential integrity only. Runtime fleet
authorization/transactions belong to the separate M1.2 stack; tenant
context and restricted database-role enforcement continue in M2.3c. No
endpoint, automatic cleanup, new application mutation, dependency,
secret or shell invocation is added. Existing installations with orphan
records require explicit reconciliation with their verified owners
before upgrading.

## Checklist

- [x] M2.3b3 acceptance and orphan-migration cases covered
- [x] PostgreSQL regression suite and API checks pass
- [x] SPEC and PLAN updated
- [x] No new application mutation requiring an audit event
- [x] No implicit server deletion or arbitrary ownership assignment
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