Access Control in RAG
Enforce document ACLs at retrieval time so users only see what they can access.
In plain words
When the AI looks things up for you, it must only look in the places you're allowed to see, which is checked before it searches, not after.
Think of it like…
A library where the librarian fetches books for you: if the librarian can enter the restricted archive and doesn't check your pass, anyone can read anything by asking nicely; the check must happen at the shelf, using your card, not in the librarian's judgement.
Where you’ve seen it
An internal assistant indexes 1,000,000 documents. A typical employee can see 2% of them. With post-filtering (retrieve the global top 10, then drop unauthorised chunks) the expected number of visible results among the top 10 is only 0.2, and the chance that none of the 10 is visible is 0.98¹⁰ = 81.7%: the assistant says "I couldn't find anything" four times out of five, and, worse, the reranker, the logs and sometimes the citations have already seen the restricted text. With pre-filtering the vector query includes acl_groups IN (user's groups) so the top 10 are chosen only from the 20,000 visible documents and always return 10 results. ACL changes arrive through source webhooks and a 15-minute sync; for high-sensitivity sources (HR, legal) the system also checks the source of truth at query time before showing a result, closing the 15-minute stale window. A CI canary test plants a document "ZEBRA-7741" readable only by group Finance and asserts that 500 queries from non-Finance users never return it, in answers, citations, caches or logs.
Words you’ll hear
- Pre-filtering vs post-filtering
- Applying permissions inside the search versus after retrieving results.
- Document ACL metadata
- Per-chunk fields (groups, users, tenant) mirroring source permissions.
- Permission sync
- Keeping the index's ACLs consistent with source systems.
- Derived-data leakage
- Exposure through summaries, caches, embeddings or citations built from restricted content.
Visual diagram
Theory & deep dive
Why filtering location matters
Post-filtering retrieves the top-k chunks from the whole corpus and removes unauthorised ones afterwards. It fails in two ways: utility (if the user can see 2% of documents, the chance that none of the global top 10 are visible is 0.98¹⁰ = 81.7%, so the assistant returns nothing or poor results) and security (restricted text has already passed through the retriever's results, rerankers, logging, telemetry and possibly prompts or error messages; result counts, scores and timing can leak that a restricted document exists). Pre-filtering applies the ACL predicate inside the vector or hybrid search (metadata filters in pgvector, Pinecone, Weaviate, Elasticsearch, OpenSearch), so only permitted chunks are candidates and top-k is computed within them.
Represent permissions on each chunk: tenant id, owner, allowed users and groups, sensitivity labels, and sometimes deny rules (explicit exclusions). At query time, resolve the user's effective groups (nested groups, roles, org-chart relations) from the identity provider and build the filter. Large group lists make filters heavy; alternatives include ACL tags (compressing permissions into a few access-set ids), per-tenant namespaces or indexes for hard isolation, or relationship-based access control (Zanzibar-style) with an authorisation service that you consult for candidate ids. Pick based on scale, change frequency and isolation requirements; the filter must be enforced by the service, never chosen by the model or the client.
User sees 2% of 1,000,000 documents. Expected visible results in a global top 10 = 0.2. P(zero visible) = 0.98¹⁰ = 81.7%. Pre-filtering over the 20,000 visible documents always returns 10 relevant results.
Freshness, derived data and testing
Freshness: permissions change (people join teams, documents are re-shared, access is revoked). Ingest ACL changes via source webhooks or change feeds, run a periodic reconciliation to catch missed events (every 15 minutes in the example), and for high-sensitivity sources verify at query time against the source system's API before showing content, accepting extra latency for safety. Plan for revocation: a document unshared at 10:00 shouldn't appear at 10:05; define the maximum acceptable staleness and test it. Handle deletion (remove chunks and embeddings) and re-embedding after content changes. Consider cross-user cache keys: semantic caches and prefix caches must include the access context, or serve only public content.
Derived data is a common blind spot: summaries, generated reports, conversation memory, embeddings of restricted text (which can leak through similarity search or inversion if exposed), analytics dashboards and citation titles or snippets that reveal restricted document names. Inherit ACLs on derived artifacts or restrict them to the strictest source. Test with canaries: plant uniquely marked documents with restricted ACLs, run many queries as unauthorised users (including adversarial ones asking about the marker), and assert zero appearances in answers, citations, caches, logs and analytics; test revocation timing and group-nesting edge cases, and cross-tenant isolation. Add audit logs (who retrieved which document, under which identity) and alert on unusual access patterns. In multi-tenant products, prefer hard isolation (separate namespaces or indexes per tenant) for the strongest guarantee.
Document with text ZEBRA-7741 is readable only by group Finance. CI runs 500 queries as non-Finance users, including "what is ZEBRA-7741?" and injection attempts. The test fails if the marker appears anywhere: answer, citation, cache entry, log line or analytics event.
How it works, step by step
Step 1 of 41. Capture source permissions
Ingest ACLs (users, groups, tenant, labels) with each chunk and map them to a common model.
- Nested groups
- resolved
When to use it & trade-offs
What it is
Access control in RAG ensures that retrieval returns only documents the requesting user is authorised to see. The authoritative permissions live in the source systems (SharePoint, Google Drive, Confluence, Slack, a CRM); the RAG system must ingest those ACLs with each chunk (as metadata such as allowed_groups, tenant_id, owner), resolve the caller's identity and group memberships at query time, and apply the permission filter inside the vector search (pre-filtering), not after it. It must also keep permissions fresh when they change, cover derived data (summaries, caches, embeddings, citations) and be tested with canary documents to prove that nothing leaks across users or tenants.
Why it matters: An enterprise assistant that can search everything becomes the easiest way to read documents people shouldn't: the HR file, the unreleased financial results, another customer's contract. The model happily summarises whatever it retrieves, so retrieval is the real security boundary. Getting this wrong is a data breach; getting it too strict makes the assistant useless. The design must put permission enforcement in the data layer, match source-system semantics and scale to large, changing ACLs.
When to reach for it
- Enterprise search assistants over mixed-permission content
- Multi-tenant SaaS with customer documents
- Regulated data such as HR, legal and finance
When to avoid or be careful
- Letting the model or client pick the tenant or ACL filter
- Caching answers without the access context
- Ignoring derived data such as summaries and citations
Permission strategies for RAG
Strengths: Correct top-k within permitted docs; no leakage through results.
Watch out: Needs ACL sync and efficient filters.
Strengths: Hard boundary; simple reasoning.
Watch out: More infrastructure; per-user ACLs within a tenant still needed.
Strengths: Simple to add.
Watch out: Empty results and leakage through scores, logs and rerankers.
Interview signals & numbers to know
When this topic comes up
- “The assistant showed me a document I shouldn't see”
- Pre-filter vs post-filter
- ACL sync lag
- Canary documents
- Namespace per tenant
Benchmarks & rules of thumb
- 0.98¹⁰ = 81.7%
- chance a post-filtered top 10 contains no visible document
- 2% of 1,000,000
- documents a typical user can see in the example
- 15 minutes
- example ACL sync interval
Common mistakes & follow-ups
Common interview mistakes
- Applying ACLs after reranking and logging the restricted text.
- Assuming group membership is static.
- Forgetting that summaries and caches inherit the sensitivity of their sources.
Likely interviewer follow-ups
- How would you enforce document permissions in a RAG system?
- Why is post-filtering a poor design?
- How do you test for cross-tenant leakage?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Access Control in RAG with generative AI interview Q&A and hands-on practice.