GebSecure Docs v0.1.0

Architecture · All ADRs

ADR 0003 — Tenant isolation: RLS + composite foreign keys + explicit filters

Architecture decision record — status: Accepted.

Status: Accepted

Context#

A cross-tenant data leak is the most damaging failure a multi-tenant security product can have. One missing WHERE org_id = … must not be enough to cause it.

Decision#

Three independent layers:

  1. PostgreSQL row-level security on every tenant table, keyed on the app.org_id GUC set per transaction (Database.tenant() / tenantLazy()). Services connect as gebsecure_app, which is neither table owner nor BYPASSRLS.
  2. Composite foreign keys (org_id, parent_id) so a row can never reference another tenant's row (e.g. a project in another org's workspace).
  3. Explicit org_id filters in every repository query.

Pre-tenant lookups (credential resolution, OAuth state, Slack interactions) use narrow SECURITY DEFINER functions that return only what is needed to establish the tenant. Cross-tenant jobs (worker, retention, internal admin) use the owner connection through db.system() — a deliberately greppable call site.

Consequences#

  • (+) Tests prove RLS blocks cross-tenant reads and writes even when a query omits its filter.
  • (−) Every new tenant table must call gs_enable_tenant_rls(); enforced in migration review.