Repository navigation
[M2.3c2a] Separate database runtime and migration privileges - #81
Merged
Merged
Conversation
4 tasks done
samuelmbabhazi
force-pushed
the
feat/m2.3c1-tenant-transactions
branch
from
November 5, 2026 12:45
4cab3ff to
d90d39d
Compare
samuelmbabhazi
changed the base branch from
feat/m2.3c1-tenant-transactions
to
main
November 5, 2026 12:45
samuelmbabhazi
force-pushed
the
feat/m2.3c2a-runtime-database-role
branch
from
November 5, 2026 12:46
840011a to
2fcc9a0
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
…#82) ## Task M2.3c2b1, stacked on #81 (`feat/m2.3c2a-runtime-database-role`). ## What changed and why Allow an authenticated account to discover its own organizations before selecting a tenant. SELECT-only RLS policies expose only its memberships and organization metadata, and only while the account is active and verified. Project/environment contents, role bindings and tenant writes remain inaccessible in discovery mode. Add `runAccountDiscovery` with a transaction-local account setting. Tenant and account scopes are mutually exclusive, preserve same-scope nesting and clear both settings on exit. A caller cannot switch account or scope within an active transaction context. The identity must come from authentication, never a caller-selected account parameter. ## Validation - Eight restricted-login PostgreSQL tests cover independent account discovery, disabled/pending/unknown accounts, private resource contents, write denial, nested-scope rejection, cleanup, current account status and immediate membership removal. - Existing restricted-role fixtures receive only the user columns needed by the account-status policy, preserving their lack of credential access. - All 136 PostgreSQL integration tests pass, including concurrent last-owner protection and pooled transaction isolation. - API lint, types, 103 unit tests and build pass. Workspace web/domain, Go and buf checks passed earlier in this session; their sources are unchanged. ## Security considerations No security-definer function or RLS bypass is added. Discovery does not expose other members, grant tenant write permissions or substitute for live application authorization. No tenant HTTP route is exposed by this slice; scoped repositories and authorization adapters follow. Account-status checks use existing identity columns. No dependency, application shell call, secret or new domain mutation is introduced. ## Checklist - [x] M2.3c2b1 acceptance and cross-account boundaries covered - [x] PostgreSQL regression suite and API checks 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.3c2a, stacked on #80 (
feat/m2.3c1-tenant-transactions).What changed and why
Separate the administrative migration URL from the API runtime URL. Add explicit restricted-role provisioning, a loopback-only development setup command and deployment instructions. Runtime grants exclude migration tracking, public-schema creation and tenant DDL; audit events allow SELECT/INSERT only. Existing credentials are never rewritten.
Create the queue schema during migration and disable pg-boss schema creation at runtime. Provisioning transfers only existing queue objects inside
shipkeep_jobs, preserving queued work while leaving tenant tables under administrative ownership. A disposable restricted-login app fixture enables future tenant acceptance tests.Validation
Security considerations
The runtime group is NOLOGIN and has no elevated role attributes or memberships. The SQL provisioning script operates on a dedicated Shipkeep database and must run transactionally as its administrator. It never globally reassigns administrative objects. Development setup accepts only matching loopback databases and a separate
shipkeep_applogin, refuses production mode, and prints no credentials or driver diagnostics. No application shell invocation or new runtime domain command is introduced. M2.4 retains the remaining audit guarantees/export/UI scope.Existing development
.envfiles must explicitly adopt the two URLs; this PR does not rewrite them. Production operators must apply migrations, then runtime grants, and configure a private login before exposing tenant routes.Checklist