Repository navigation
[M2.3b3] Bind fleet records to existing organizations - #79
Merged
Merged
Conversation
5 tasks done
samuelmbabhazi
force-pushed
the
feat/m2.3b2-tenant-isolation
branch
from
November 5, 2026 12:44
9106db3 to
dae86da
Compare
samuelmbabhazi
changed the base branch from
feat/m2.3b2-tenant-isolation
to
main
November 5, 2026 12:44
samuelmbabhazi
force-pushed
the
feat/m2.3b3-fleet-organization-links
branch
from
November 5, 2026 12:45
8df85ae to
d52e4d3
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
) ## Task M2.3c1, stacked on #79 (`feat/m2.3b3-fleet-organization-links`). ## What changed and why Add `PrismaUnitOfWork.runTenant` so tenant repositories and audit writes use one transaction-local organization context. Same-tenant nested commands join their caller; changed-tenant or overlapping sibling scopes are rejected before they can race on connection settings. Context is cleared before returning to an outer identity transaction and on transaction completion. Before each tenant operation, validate the login/effective database roles, role memberships, table RLS flags and row-security setting. Refuse privileged logins, ownership, public-schema DDL and tenant-table TRUNCATE/TRIGGER access, including privileges reachable through non-inherited roles. Validate canonical UUIDv7 tenant ids and replace driver errors with an opaque storage-unavailable error. ## Validation - 20 real PostgreSQL tests use a separate restricted login and cover concurrent requests, pooled reuse, nested transactions, rollback, sibling-scope conflicts, invalid ids, privileged sessions hidden behind SET ROLE and changes to database privileges/RLS configuration. - All 124 PostgreSQL integration tests pass. - API, web and domain lint, typechecks, unit tests and builds pass. Go tests and buf lint passed earlier in this session; their sources are unchanged. ## Security considerations Setting a tenant context is not an authorization grant; live membership/resource policy checks remain required in the application adapters. This foundation does not expose tenant HTTP routes. Runtime-role provisioning and repositories continue in M2.3c2. Existing unscoped identity/audit unit-of-work behavior is retained and covered by the full integration suite. No dependency, secret, application shell call or new unaudited command is added. ## Checklist - [x] M2.3c1 acceptance and transaction isolation tests covered - [x] Separate restricted-login tests, including unsafe role memberships - [x] Lint, types, tests and builds pass - [x] SPEC and PLAN updated - [x] No new application mutation requiring an audit event
5 of 6 tasks
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
… RLS (#99) ## Task Review follow-up for #79 (M2.3b3) and #81 (M2.3c2a). Refs #22 ## What changed - `deploy/postgres/runtime-role.sql`: the runtime role now gets only SELECT and INSERT on `data_encryption_keys` and `installation_keys`, like `audit_events`. No code updates or deletes these rows: both stores only use `findUnique` and `create`, and SPEC 9 says rotation inserts new rows. - `runtime-role.integration.spec.ts`: UPDATE and DELETE on both key tables must now be rejected for the runtime login. - PLAN: new task **M2.3g**, row-level security for `nodes`, `join_tokens`, `node_certificates` and `audit_events`, with cross-tenant lookups moved to a separate reviewed role. It must land before any node, join-token or audit read endpoint. - SPEC 16: open question describing the gap and what the cross-tenant role must cover. ## Why - With UPDATE or DELETE, an injection or logic bug in the API could delete or overwrite wrapped data-encryption keys, making every secret of an environment unrecoverable, or replace the CA and confirmation keys. - The fleet and audit tables carry `organization_id` but only repository filters protect them. SPEC 4 requires both layers, and the gap was not tracked anywhere (#79 even marked the database isolation task done). ## How it was tested - `nx run-many -t lint typecheck -p api` in a clean worktree: clean. - The runtime-role integration test needs PostgreSQL. It could not run locally (no Docker in the sandbox), and GitHub Actions is blocked by the account spending limit. CI must pass before merge. ## Security considerations Least privilege for key material. No change to tenant tables. The RLS gap is documented and scheduled, not fixed here, because it needs a design decision on the cross-tenant role (enrollment by join-token hash happens before any tenant context exists). ## Checklist - [x] Lint and typecheck pass locally - [x] Integration test extended - [x] No new shell invocation and no new secret exposure path - [x] Audit events: not applicable - [x] PLAN and SPEC updated - [ ] CI green (blocked by billing)
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.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
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