Mental model
Securing the primary PostgreSQL database with Row-Level Security (RLS) solves only one slice of multi-tenant AI confidentiality. Because enterprise AI features duplicate and derive knowledge continuously across dense vector indexes, Redis semantic caches, LLM prefix memory, agent working logs, third-party tool credentials, observability traces, and offline evaluation exports, every downstream derivative store must propagate and enforce verified tenant identity cleanly end-to-end.
Learning outcomes
- Trace every secondary derivative AI artifact (
embeddings,BM25,semantic caches,semantic memory,OTel traces,evaluation sets) for cross-tenant leakage pathways. - Enforce immutable server-derived tenant scoping (
never accepting client-supplied JSON IDs) paired with PostgreSQLRLSand vector partition namespaces. - Isolate OAuth tool credentials, prompt prefix caches, and human customer-support diagnostic exports strictly under per-tenant boundaries.
Theory
Most real multi-tenant AI breaches bypass primary SQL locks cleanly through unguarded auxiliary stores: teams enable Postgres RLS on documents, then write shared cached embeddings into Redis keyed purely by query text, pool global tool API keys with multi-org admin scope, or log unredacted prompt payloads straight into shared team analytics dashboards! Complete defense treats tenant identity as an unbreakable invariant across all six boundaries:
| AI Platform Store | Typical Cross-Tenant Breach | Enforced Isolation Pattern | Operational Check |
|---|---|---|---|
| Primary Relational Store | Unfiltered SELECT missing tenant predicate | Mandatory PostgreSQL SET LOCAL app.tenant_id + FORCE ROW LEVEL SECURITY | Automated dual-tenant integration suite asserts 0 leaked rows |
| Vector & Lexical Indexes | Global top-K search scores Tenant B chunks before filter | Physical per-tenant table partitions / namespaces OR pre-filtered SQL scans | Continuous chaos probe injecting cross-tenant strings asserts empty [] |
| Semantic Query Cache | User in Tenant B hits Tenant A's cached FAQ reply | Key strictly on sha256(tenant_id, acl_group_hash, index_epoch, query) | Zero shared global cache pools unless explicit public doc namespace |
| Tool Credential Broker | Shared static "god-mode" SaaS API token read by agent tool | Short-lived brokered token minted strictly for current calling user's org | Token scope limited cleanly to target tenant workspace |
| Telemetry & Evals | Support trace exports copy Tenant A PII straight to public CI test files | Default prompt/payload scrubbing + opt-in encrypted trace buckets | Fail CI if un-anonymized customer domains enter git fixtures |
sql-- Defense-in-depth PostgreSQL multi-tenant vector + relational isolationALTER TABLE tenant_knowledge_chunks ENABLE ROW LEVEL SECURITY;ALTER TABLE tenant_knowledge_chunks FORCE ROW LEVEL SECURITY;CREATE POLICY tenant_isolation_policy ON tenant_knowledge_chunksUSING (tenant_id = current_setting('app.verified_tenant_id', true))WITH CHECK (tenant_id = current_setting('app.verified_tenant_id', true));-- Application connection handler MUST set verified context per transaction:-- BEGIN; SET LOCAL app.verified_tenant_id = '...'; ... COMMIT;
Trade-offs
Full physical silo isolation (dedicated encrypted database, dedicated HNSW index cluster, and isolated worker queue per enterprise customer) provides near-zero cross-tenant blast radius and trivial regional residency compliance (EU vs US hosting), at dramatically higher idle RAM cost and operational upgrade complexity across hundreds of small tenants. Logical isolation (PostgreSQL RLS + tenant-keyed partitions + scoped Redis namespaces + strict automated cross-tenant negative suites) slashes hardware waste and simplifies platform scaling cleanly for multi-tenant SaaS while demanding rigorous discipline never to introduce an un-scoped shared cache or admin tool helper.
Failure modes and misconceptions
- Trusting Client-Supplied Tenant Headers or Model Arguments: Letting an LLM tool accept
tenant_id="acme"cleanly as a generated parameter lets indirect prompt injection query sibling organizations effortlessly. - Shared Global Prefix/Semantic Response Caches: Caching answers solely on normalized text lets Tenant B discover secret acquisition names queried minutes ago inside Tenant A cleanly.
- Unrestricted Multi-Tenant Worker Credentials: Running an MCP/tool server holding an organization-wide super-admin API key relies purely on prompt instructions for isolation.
- Copying Customer Traces Verbatim Into Eval Golden Sets: Exporting failed prod traces directly onto shared developer test fixtures without redaction or tenant approval turns ops debugging into a privacy breach.
Decision scenario
A multi-tenant B2B knowledge platform serves 50 regulated financial firms on shared infrastructure. Postgres tables already use tenant_id, yet engineering just noticed semantic query caching shares Redis hashes cleanly globally, eval engineers exported unredacted trace CSVs into staging, and an assistant MCP connector holds one shared Zendesk master key. Design concrete remediation across caches, credentials, vector indexes, traces, and CI isolation gates cleanly.
Which shared AI caches and secondary artifacts can still leak confidential customer records across tenants even after PostgreSQL Row-Level Security is strictly enforced?