BM
Bashar ModallalSOFTWARE · AI · SYSTEMS
← All field notes

AI

Permission-Aware RAG: Filter Before the Model Sees the Data

Two employees can ask the same question and need different evidence. Build RAG that enforces document permissions in retrieval, caches, and citations.

A lime access gate routes allowed document cards toward a model, leaving restricted cards outside.

Two employees ask the same procurement assistant the same question: “What approval does a rush order need?” One buys from a public catalogue. The other reviews confidential supplier contracts. They should not necessarily get the same answer, even if they work for the same company and use the same chat window. The answer depends on which evidence each employee is allowed to see.

The risky shortcut is to retrieve the most relevant passages across the company and tell the model to ignore the confidential ones. That instruction controls how a model is asked to respond; it does not control what the model receives. The same records can reach an external reranker, a trace collector, or an answer cache long before anyone sees the final text. A permission-aware RAG system, or retrieval-augmented generation system, restricts the evidence before it crosses those boundaries.

Relevance is not permission

A similarity score tells you whether a passage resembles the question. It does not tell you whether the current caller may read it. Separate three decisions: verify who is asking; decide what they may read in this tenant and operation; rank the allowed candidates. Treat the second decision as application policy, not a feature of the model.

Build a trusted scope on the server for each retrieval: session identity, verified tenant membership, current groups or assignments, and any attributes the policy actually uses. A company slug in a URL can select the tenant the user is asking for, but it does not establish membership. A tool call generated by the model can propose a search phrase, but cannot supply a trusted identity or widen the scope. OWASP’s authorization guidance recommends least privilege, default denial, and checking permissions on every request. This includes requests issued by chat tools and links returned as citations.

Give every chunk an authorization lineage

At ingestion, record the tenant, stable source ID, immutable document version, and a reference to the access policy on every derived chunk. An ACL, or access-control list, defines which principals may read a document. A principal can be a person, group, or service. Obtain these grants from the source system or a reviewed application policy. Do not copy a heading such as “staff only” into a metadata field and treat it as an authoritative grant.

Give summaries and extracted records their own provenance. A summary of two documents whose readership differs must not become available to everyone who can read only one of them. Either keep those documents separate when summarizing, or require access to all contributing sources. Missing ACL metadata is not the same thing as public access. A document intended for the public should have an explicit, reviewed public designation; an import with a missing grant should remain quarantined or unpublished until the grant is known.

Search products do not all enforce this for you. Microsoft’s security-filter documentation distinguishes application-managed principal filtering from native document authorization. A principal identifier in a filter is just a value. The application still has to authenticate the caller, derive the allowed principals from a trusted source, and apply the condition to every relevant query.

Put checks at the boundaries

Verified session          Authoritative document grants
       |                              |
       v                              v
Resolve tenant and rights --> Query within allowed scope
                                      |
                                      v
                       Recheck version and access
                                      |
                                      v
                       Rerank and build model context
                                      |
                                      v
                                  Answer
                                      |
                               citation click
                                      v
                          Fresh source-access check

The left side starts with identity. The right side supplies grants and document state. Together they constrain retrieval so that ranking has fewer, safer candidates. Before reading body text for an external reranker or building the prompt, verify that each candidate still belongs to the selected tenant, has a usable version, and is readable by the current caller. If an index is asynchronous, one design is to retrieve only opaque candidate IDs and scores within a coarse tenant filter, then authorize against current grants before fetching text from the source. Do not pass the raw search response or a discarded snippet to logging or downstream services. Use native authorization filters where suitable to improve both isolation and recall.

A store such as PostgreSQL can enforce a second layer through row-level security. Run retrieval as an application role without row-security bypass privileges and test policies using the same execution identity as production. Owners normally bypass row security unless forced to obey it; superusers and roles with the bypass attribute remain outside its restrictions. With pooled connections, bind any request-scoped authorization state to the transaction, and demonstrate that a subsequent request never inherits it. Database isolation does not protect text already copied to a separate index, cache, or object store.

Worked example 1: a rush-order question with three near matches

Consider three synthetic documents in a procurement search. The scores are illustrative, not measurements:

Document Tenant Allowed readers Similarity
Supplier terms, v4 Juniper Contract reviewers 0.96
Rush purchase guide, v2 Juniper Purchasing staff 0.82
Rush order playbook, v3 Cedar Cedar purchasing staff 0.91

Maya works in Juniper’s purchasing group but is not a contract reviewer. The guide says rush purchases above AED 5,000 require a manager’s approval. The terms describe a supplier-specific exception unavailable to her. With a trusted scope of Juniper plus purchasing staff, the system rejects the terms and the other tenant’s playbook. It sends the guide to the reranker and prompt builder. The answer cites the guide: “The purchasing guide requires manager approval above AED 5,000.” It does not reveal that an exception or an alternative policy exists.

Test the opposite direction too. Give a separate reviewer access to the terms and scope their question to the matching supplier. Their response may cite the exception, but should not apply it to unrelated purchases. A public or unassigned account with no eligible evidence should get a neutral answer such as “I couldn’t verify the rule from sources available to this session,” not a list of the restricted document titles. If you ask for the global top two and trim them afterwards, neither surviving candidate gives Maya an answer. Tenant and ACL filtering where the engine supports it allow the correct third-ranked passage to compete.

Worked example 2: permissions change after the answer is cached

A contractor has temporary access to an incident runbook. At 10:00 the assistant generates an answer, retains its citations, and warms a cache. At 10:02 a manager removes the contractor from the incident group. At 10:03 the contractor repeats the question. The text, tenant, and session are unchanged; membership is not.

A cache keyed by question alone is wrong even without revocation. A key that includes only tenant and user can still serve the 10:00 answer at 10:03. Bind reusable answers to authenticated scope and versions of the relevant policy and sources, and store the evidence IDs the answer depended on. When serving sensitive cached material, confirm that those dependencies are still authorized. If membership updates and index updates arrive through different queues, define how fresh policy decisions must be and fail closed or use a ground-truth check when that freshness cannot be established. The Zanzibar paper is a useful reference for reasoning about consistency when both content and access rules change; adopting its concepts does not give a different system the same guarantees automatically.

The old citation must also deny access when opened again. Make it resolve through an endpoint that checks current identity and document permissions rather than exposing a permanent download link. Replaying a server-held conversation is also a read: redact or omit old derived text the user can no longer read before building a new prompt. This cannot recall text that was legitimately displayed, copied, or downloaded before revocation. It can stop the system from serving that text again and from quietly sending it back to a model.

For long-running requests, define when you authorize at the start and when you validate again before text leaves the service. Decide what to do if a grant changes during streaming; you can stop further disclosure, but cannot take back bytes already sent. In stricter environments, buffer the reply and recheck before release instead of promising instant revocation of a live stream.

Test what actually crosses the boundary

Build a small fixture with two tenants, a shared-looking title, a unique marker in each restricted chunk, two roles, and a mid-session revocation. Run it against vector search, keyword and hybrid search, chat tool retrieval, history replay, citations and download routes. Stub the reranker and model so you can assert that the restricted marker never became an input, not merely that the model omitted it in the answer. Re-run with a warm cache, a delayed ACL update, and a failed identity lookup. An authorized user must still get useful evidence; a system that returns nothing passes the wrong test.

Log the authorization outcome and policy version with a trace ID, not denied passages or confidential source titles. Measure authorized recall on a small labeled set in addition to response latency, and watch for elevated empty results after index changes. Start with one connector and one restricted corpus. Expand only when every evidence path preserves the same rule: the model receives only what the current caller is allowed to read for that request.

اقرأ المقال بالعربية

YOUR TAKE

What did you think?

Choose one reaction for this article.

Was this useful?

A cookie helps limit repeat responses. Your feedback is private.

Share this noteLinkedIn ↗X ↗Email ↗

Keep exploring.