Skip to content

[M2.3c1] Scope tenant transactions and reject unsafe database roles - #80

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

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3c1-tenant-transactions

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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

  • M2.3c1 acceptance and transaction isolation tests covered
  • Separate restricted-login tests, including unsafe role memberships
  • Lint, types, tests and builds pass
  • SPEC and PLAN updated
  • No new application mutation requiring an audit event

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3b3-fleet-organization-links branch from 8df85ae to d52e4d3 Compare November 5, 2026 12:45
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.3b3-fleet-organization-links to main November 5, 2026 12:45
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3c1-tenant-transactions branch from 4cab3ff to d90d39d Compare November 5, 2026 12:45
@samuelmbabhazi
samuelmbabhazi merged commit 27f7b87 into main Nov 5, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3c1-tenant-transactions branch November 5, 2026 12:45
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
## 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

- All 128 PostgreSQL integration tests pass, including four new full-app
restricted-login tests: account registration/verification with audit,
tenant transactions, forbidden audit/DDL operations, queue preservation
on repeated provisioning and unsafe-role rejection.
- The development setup command was exercised against a disposable
PostgreSQL instance: initial creation, rerun, real login and
unsafe-configuration rejection passed.
- API lint, typechecks, 103 unit tests and build pass; tooling ESLint
passes. Workspace web/domain checks, Go tests and buf lint passed
earlier in this session; their sources are unchanged.

## 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_app`
login, 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 `.env` files 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

- [x] M2.3c2a acceptance covered with a real restricted login
- [x] PostgreSQL regression suite and API/tooling checks pass
- [x] Development setup tested on a disposable database
- [x] SPEC, PLAN, README and deployment instructions updated
- [x] No automatic password overwrite, secret output or application
shell call
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