Skip to content
Yassir Kachri

Enterprise RAG

Identity-Aware RAG: Authorization Belongs Inside Retrieval

In regulated firms, the RAG failures that matter start with identity. How one signed identity drives relationship-based scope inside vector search and row-level security in SQL, with every control failing closed.

Yassir Kachri Updated 7 min read

Most enterprise RAG programs start with a demonstration that works: a few dozen PDFs, a vector index, and a fluent, sourced answer in front of the executive committee. Production adds what the demonstration never had to handle: several tenants, information barriers, a general ledger, and a regulator who will ask who saw what.

My position is that in a regulated firm, authorization has to be an input to retrieval, applied inside the vector search and inside the database. In the reference case of my book, every access failure came from treating authorization as a filter on results, or from deciding it somewhere other than the data engine at query time.

In the reference case, every access failure came from where authorization was decided

The reference case is AegisFin Corp, a fictional regulated M&A advisory and wealth management firm. Every figure in this article comes from that case. Its first assistant ran as a pilot for nine weeks with 340 users. Then a junior analyst asked a routine question and received the proposed offer price of a live acquisition that sat behind an information barrier. The system logged prompts and answers but not which chunks had reached which user, so every pilot user had to be treated as exposed.

Exhibit 1 Four failures in the reference case, none of them caused by the language model
FailureMeasured effectRoot cause
Barrier breachOffer price of a live deal shown to an analyst who had never been wall-crossedA filter after retrieval let through a chunk with no deal identifier; no record of the chunks served
Starved answersFor analysts staffed on one to three deals, no authorized chunk for 31% of 400 golden-set questions (first authorized hit at median rank 118)Search ran over the whole collection, then filtered
Stale entitlementsA walled deal stayed in the analyst’s token for 29 hours; 11 queries retrieved 17 of its chunks, 4 of them material non-public informationScope read from a token minted from a nightly directory sync
Revocation lagA revoked memo still retrievable 19 days later; 2,140 chunks from 37 deleted or re-permissioned documents still servedThe loader only appended, and no delete was ever checked in the index

Source: AegisFin Corp reference case (fictional), Production-Grade Enterprise RAG Architecture, Vol. 1. Rows 1 and 4 come from the pilot, rows 2 and 3 from a later limited release.

Filtering after retrieval failed in three ways

The pilot did what most prototypes do. It ran a nearest-neighbor search for the top 40 chunks across the whole collection, then dropped the ones the caller was not allowed to see.

That filter failed open on missing data. It only tested chunks that carried a deal identifier, and the leaked memo had arrived through an email connector that stamped a tenant and nothing else. In a later limited release, the first prototype built on a proper authorization service kept the same shape and checked each of the 40 hits. The answers starved instead, because the caller’s chunks often ranked below the top 40, and the 40 checks added 410 milliseconds at p95. That prototype also leaked before it filtered: a “related documents” sidebar rendered hit titles ahead of the check and exposed deal names.

Entitlements have to come from a graph the engines consult on every request

A token is a poor place for entitlements. In a later limited release, the identity provider still minted deal lists into tokens from directory groups that synchronized nightly. Compliance placed an analyst behind a barrier at 09:12, and the token kept listing the walled deal for 29 more hours. A managing director covering 212 deals needed a 9.1 KB token, above the gateway’s 8 KB header limit. The hotfix, a wildcard for the role, let a red-team token for a managing director in another region read deals outside that region.

In the target design, the gateway verifies the token’s signature and forwards only the subject and the tenant. Any entitlement claim is discarded. The orchestrator then asks a relationship-based authorization engine (OpenFGA in the reference stack; SpiceDB expresses the same model) for every deal the caller may read. A user qualifies by being staffed on the deal or by being the managing director for its region, and an information barrier overrides every grant. The lookup bypasses the engine’s check cache, so a barrier written at 09:12 applies to the query at 09:12.

One resolved scope drives two enforcement points

Once the deal list is resolved, the same scope is enforced by the engine that holds each kind of data:

  • Document path. The deal list becomes a payload filter that the vector store applies inside its nearest-neighbor traversal. Results are drawn only from authorized chunks, so unauthorized ones can no longer push them out of the top k, and an unauthorized chunk never reaches application memory.
  • Analytical path. The same list is signed into a transaction-local context. Every tenant table runs with FORCE ROW LEVEL SECURITY, so even the table owner is subject to the policies, and PostgreSQL verifies the signature before any policy compares a row. The context dies at commit, so a pooled connection cannot carry it to the next client.

Both properties of the analytical path answer failures from the prototype. A session-level setting behind a transaction-mode connection pooler served three rows of one tenant’s fees to another tenant’s managing director, and a document in a data room induced the SQL generator to write its own setting. A forged, edited or expired context returns zero rows, and the check costs less than a millisecond. Dual-path RAG describes the analytical path in full.

Exhibit 2 One signed identity, one scope resolution, two engine-level enforcement points

HR and identity events and the Compliance barrier register write a relationship graph. A question arrives with a signed token; the gateway verifies it and drops entitlement claims. Scope resolution checks tenant membership and reads the deal list fresh within its time budget, then the deal list drives a filter inside the vector store's nearest-neighbor traversal and a signed transaction-local context for forced row-level security in PostgreSQL. An empty, late or truncated scope issues no query at all

Source: Author's diagram of the authorization plane in Production-Grade Enterprise RAG Architecture, Vol. 1.

Every control should fail closed, with explicit limits

Exhibit 3 Each control has a starting limit and a defined behavior on failure; none of them widens scope
ControlRecommended starting valueBehavior on failure or limit breach
Scope resolution250 ms budget, fresh read; 1,000 or more deals is treated as a failureRefuse the request
SQL scopeForced row-level security on a signed, transaction-local contextReturn zero rows
Unknown sensitivity labelNever defaulted to “internal”Quarantine the document
Latency budget exceeded2,500 ms p95 for document answersDegrade the answer; never widen scope

Source: Author's reference design, Production-Grade Enterprise RAG Architecture, Vol. 1.

A missing key, a slow authorization call or a probe that throws is treated as a violation, and the request is refused. The reference design budgets about 35 milliseconds at p95 for the governance controls on the request path, 1.4% of the 2,500 millisecond budget (35 / 2,500), and staging measurements kept the whole authorization plane under 2% of it.

Revocation has to reach the index in minutes

Compliance moved the leaked memo out of every pilot user’s reach within two hours of the escalation. Nineteen days later, a red team still retrieved its offer-price chunks with the original analyst’s token, because the nightly loader only appended. The reference design sets a revocation-to-purge objective of 15 minutes. Change data capture writes a tombstone before deleting, deletes by document identifier, and drops the document from its manifest only after a count proves that zero points remain. The index epoch should advance only after that verification. Release gates for enterprise RAG shows what happened when a refactor moved the epoch bump ahead of it.

Recording what each answer used makes exposure measurable

Before any sentence is released, an audit record commits with who asked, the evidence that reached the model (by hash), the model, and the policy and index epochs. If something goes wrong, “who saw it?” becomes a query against that trail. In the pilot, nobody could answer it, and the firm had to collect attestations from all 340 users.

I put identity first in any RAG design review for a regulated firm, because it is the property that is hardest to retrofit. Scope has to be stamped on every chunk at ingestion. After that, each request resolves it from a consistent graph, and the engines that hold the data enforce it.