feat(db): route tenant-scoped service queries through begin_with_tenant #186
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/pms-256-rls-guc-plumbing"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Step 1 of 9 toward fail-closed RLS (parent PMS-255). Every tenant-scoped read and write across the 20 PSA modules now runs inside a transaction that has set the
app.current_tenantGUC viaDatabase::begin_with_tenant, so the RLStenant_isolationpolicy can later be flipped fail-closed. The policy stays fail-open in this PR, so there is no behavior change yet: this only guarantees the GUC is always present.begin_with_tenantnow takesimpl Into<Uuid>(newFrom<TenantId> for Uuid) so call sites pass either type unchanged, andTenantTransactionderefs tosqlx::PgConnectionso the standard&mut *txidiom yields a sqlx executor (sqlx 0.8 has noExecutor for &mut Transaction). Standalone pooled reads were wrapped in read-only tenant txs; standalone pooled writes were wrapped in tenant txs with an explicitcommit()(a pooledexecuteauto-commits, a transaction must not be dropped uncommitted). ExistingWHERE tenant_id = $Nfilters are kept for defense in depth.Cross-function-boundary writes were threaded through new service methods so the worker/route layers stay GUC-correct:
CalendarService::claim_reminder,SlaService::claim_sla_notification,ReportsService::run_custom(withcustom::runnow taking aPgExecutor), and the auth login/logout out-of-band audit writes.Deliberate exceptions (no single tenant to bind, or tables RLS does not cover) are kept on the pool and catalogued in
dev-docs/audits/pms-256-rls-guc-audit.md: thetenantstable itself, cross-tenant provisioning copies, cross-tenant background-worker sweeps, pre-tenant-resolution identity lookups (login/reset/portal/bootstrap),sla_targets/notification-template tables that have notenant_idcolumn, and the genericaudit_writehelper. The doc also lists the two follow-ups for PMS-255.2 (rmm sync-worker id-only writes need a tenant threaded in;rehome_user_between_tenantsneeds the source-vs-destination GUC decided).Verified:
just checkclean;cargo test --lib(117) andcargo test --docpass; all integration test binaries pass except the twotests/settings.rsmodule-gating tests, which fail identically on unmodifiedmainin this environment and are outside CI's integration set.#PMS-256
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com