RAG access control: testing document permissions and tenant isolation
Design and test authorization across RAG retrieval, citations, caches, exports, and permission changes using a practical synthetic document matrix.
Treat retrieval as a data-access decision
A retrieval-augmented application can expose information before it produces its final answer. Retrieved passages, citations, previews, conversation history, and debugging records are all possible data surfaces. Start with the question: which principal may access which document for which operation? Define this independently of model behavior. A system prompt that asks the assistant to respect permissions does not establish an application authorization boundary. Write down the actual enforcement points from the original document store to the generated response, including the services and caches that receive content along the way.
Build a permission model before indexing documents
Represent tenant, document identity, access policy, and relevant group membership with application-controlled metadata. Preserve the relationship between each chunk and its parent document when parsing, splitting, and reindexing. Decide what happens when required permission metadata is absent or cannot be resolved. The intended behavior should deny access until the application can make a valid decision. Document how the index learns about document creation, deletion, and permission changes. A chunk detached from its parent policy is a maintenance problem even if the first demonstration uses only public documents.
Derive identity from a trusted application session
The server should determine the user and tenant context from its authenticated session or another verified identity mechanism. Do not accept a tenant identifier supplied in a prompt, query parameter, or client-generated search filter as sufficient authority. Construct retrieval constraints from the validated context and apply authorization before content enters the model context. Where a second verification step is used after retrieval, it must still prevent unauthorized content from reaching downstream components. Review service-account permissions too: a broadly privileged retrieval service needs narrow, tested application checks at every path that can return content.
Worked example: a synthetic permission matrix
Create tenant Cedar and tenant Harbor, with one public document, one tenant-only document, and one restricted-group document in each. Use distinctive invented phrases in every document so a tester can identify the origin of a returned passage without using real confidential material. Test a Cedar ordinary user, a Cedar restricted-group user, a Harbor user, and an unauthenticated request. State the expected document set for each principal before executing queries. This matrix is a proposed test design. It gives the team a concrete way to compare intended permissions with actual retrieval, citation, and export behavior.
Check citations, previews, and document downloads
An answer may omit restricted text while its citation title, snippet, or download URL still reveals it. Apply access checks when opening the referenced document, not only when generating the initial search result. Avoid handing out a durable public URL for content that requires ongoing authorization. Review previews, copied citations, conversation exports, and shared conversation views using the same permission matrix. Test direct document identifiers as well as search queries. A result that looks secure in the main chat window can still expose content through a separate endpoint that was not included in the original retrieval review.
Scope caches to the authorization context
Inventory caches for search results, retrieved passages, generated answers, and document previews. Determine whether their keys include the permission context needed to keep responses separate. A cache entry created for an authorized user must not be reused for a different principal merely because the query text matches. Plan invalidation for revoked access and changed document policies. If the design uses short-lived permission snapshots, state the allowed freshness window and test its behavior. Keep sensitive retrieved text out of routine diagnostic records unless there is a justified purpose, appropriate access control, and a bounded retention period.
Test revocation and stale indexes explicitly
Run a query as an authorized user, remove that user from the relevant group, then repeat the query and follow any previous citations. Test deletion and permission changes while a document is being reindexed. Include renamed documents and regenerated chunk identifiers so the test covers the update path as well as initial ingestion. Define the expected response when the identity service or policy source is unavailable. Document any eventual-consistency window honestly and decide whether it is acceptable for the information involved. A successful initial access check does not establish that later revocation works.
Separate authorization tests from answer-quality tests
Use deterministic document-access assertions for the permission boundary and separate human or model-assisted evaluation for relevance and answer quality. Verify which document identifiers reached the retrieval response and model context, rather than inferring authorization solely from the wording of the final answer. Keep synthetic test phrases and fixtures isolated from real customer material. Include positive cases to show that permitted users can still complete their tasks. A policy repair that blocks every document avoids disclosure but does not establish that the intended application remains functional.
Make permission regressions a release blocker
Version the permission matrix, synthetic corpus, expected outcomes, and deployment configuration. Require the same checks when changing the embedding model, vector store, chunking process, cache layer, or authorization integration. Log enough metadata to investigate which principal and policy decision produced a retrieval without copying unnecessary document contents into logs. Assign an owner to respond to a failed isolation check and retain a way to disable the affected retrieval path. The release record should show both that unauthorized access is denied and that authorized retrieval still returns the documents needed for the supported workflow.