Skip to content

[M2.3b3] Bind fleet records to existing organizations - #79

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3b3-fleet-organization-links
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3b3-fleet-organization-links

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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

  • M2.3b3 acceptance and orphan-migration cases covered
  • PostgreSQL regression suite and API checks pass
  • SPEC and PLAN updated
  • No new application mutation requiring an audit event
  • No implicit server deletion or arbitrary ownership assignment

@samuelmbabhazi samuelmbabhazi changed the title [M2.3b3] Bind fleet records to verified organization ownership [M2.3b3] Bind fleet records to existing organizations Nov 5, 2026
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3b2-tenant-isolation branch from 9106db3 to dae86da Compare November 5, 2026 12:44
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.3b2-tenant-isolation to main November 5, 2026 12:44
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3b3-fleet-organization-links branch from 8df85ae to d52e4d3 Compare November 5, 2026 12:45
@samuelmbabhazi
samuelmbabhazi merged commit ced2439 into main Nov 5, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3b3-fleet-organization-links branch November 5, 2026 12:45
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
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)
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