Blog

RAG Access Control: Retrieve Only What the User May Read

Design RAG permissions across identity, retrieval, caches and citations. Review tenant boundaries, revocation and eight access-control tests.

RAG Access Control: Retrieve Only What the User May Read

Imagine a support assistant serving two customers. Both have a document called “renewal terms”. A user from customer A asks about renewal, and the search service retrieves customer B's document because it is the closest semantic match. The answer may be fluent and accurately sourced—and still disclose information to the wrong person.

This is a hypothetical failure scenario, not a report about String AI or a customer incident. The engineering question is concrete: which documents is this authenticated user allowed to retrieve before any content reaches a model? Retrieval-augmented generation, or RAG, adds source material to a model's context. That makes retrieval authorization part of the application's data boundary.

Separate model access from document access

A model API key answers whether a workload can call an endpoint. It does not, by itself, decide whether a user may read an internal contract. A service account that can read an entire search index is also not evidence that every user of the application may read every document.

Microsoft's document-level access overview distinguishes approaches to restricting search results by document permissions. The supported mechanisms depend on the data source and integration. Treat that as a design choice to verify, rather than assuming that adding a vector database has inherited the source system's permissions.

The related String AI guide to multi-tenant applications covers customer keys and usage attribution. Here the focus is narrower: the documents, chunks and derived answers that a particular caller may see. These recommendations do not claim that a String AI API key automatically enforces permissions in your knowledge base.

Build the access scope from authenticated identity

Establish the caller on the server, then resolve their tenant and permitted groups or document scopes from an authoritative policy source. A browser-supplied tenant ID can identify a requested workspace, but the backend must verify membership. A model-generated tool argument should never grant membership.

OWASP's authorization guidance recommends denying access by default and checking permissions on every request. For a retrieval endpoint, a practical application is to reject an unresolved identity or unavailable policy decision rather than retrying the query without a filter.

Keep user-selected search constraints separate from mandatory access constraints. A user can narrow results by product or date; that selection must not replace the server's tenant and permission restrictions. When users switch workspaces, recompute the authorized scope instead of changing only a label in the interface.

Carry permissions through ingestion and retrieval

A document may become many chunks, each with its own identifier. Plan how those chunks retain their source document, tenant and access metadata. A chunk without usable access metadata should not silently become public. That is a recommended default policy, not a universal database behavior.

Microsoft's security-filter pattern uses indexed identity strings to filter results. Its documentation explicitly explains that the string filter is not itself authentication. The application must establish the correct identity and apply the filter consistently.

Amazon Bedrock's retrieval configuration documentation describes metadata filtering. A filter can restrict matching records; its existence does not prove that a client is authorized to choose the filter values. Confirm operator support and behavior for the backend you actually use.

Upload and indexing: Associate each source and chunk with a verified access scope. Evidence to inspect: Chunk metadata and rejected missing-scope records.

Retrieval request: Combine mandatory permissions with user search constraints. Evidence to inspect: Effective server-side predicate.

Hybrid retrieval: Apply the same permissions to keyword and vector branches. Evidence to inspect: Candidate IDs from both paths.

Reranking and generation: Send only authorized candidates beyond the trusted retrieval boundary. Evidence to inspect: Document IDs entering those stages.

Source download: Authorize the current user again. Evidence to inspect: Download result under different identities.

“Before generation” is not precise enough if an external reranker or debug service already receives unfiltered text. Identify each component allowed to process the data and enforce the boundary before disclosure. These checkpoints form a review checklist, not an implementation of a security system.

A tenant filter alone may still be too broad

Within a customer organization, an employee handbook might be widely readable while a pricing exception or HR file is restricted. If that distinction exists in the source system, tenant isolation alone cannot represent it.

For a simplified application policy, eligibility might require a matching tenant, a current document state, and either explicitly tenant-wide visibility or an allowed user/group match. Define these rules in your authorization layer, including how explicit denials override grants if your source system supports denials. Do not flatten a richer source policy into a permissive list without reviewing what is lost.

Separate indexes per tenant can help constrain retrieval and operations. They still need correct routing, credentials and document rules within each tenant. A shared index needs consistently enforced filtering. Choose the design for the actual policy and operational requirements; neither layout replaces authorization checks.

Recheck caches, conversations and citations

Suppose an authorized manager asks a question and the answer is cached by question text alone. A colleague with fewer permissions asks the same question. Reusing the cached answer could bypass the careful retrieval checks applied to the first request.

Our recommended review is to scope retrieval and answer caches to the relevant tenant and authorization context, and to define how policy changes invalidate them. Including a user ID alone does not solve a later permission revocation for that same user. A policy revision or current authorization check may be required, depending on the cache design.

Conversation history needs the same attention. Revoking a document does not erase text already shown to a user, but the application can prevent newly unauthorized excerpts from being resent as model context or exposed through a shared conversation. Define how workspace changes, history exports and shared links interact with permissions.

A citation is another read path. Test whether opening its URL requires current authorization. Hiding a link in the interface does not protect a publicly reachable file. OWASP's RAG security guidance treats access controls and isolation across the retrieval pipeline as security concerns; include derived content in your own review, not only the original files.

Make revocation a measurable operation

Document deletion, group removal and tenant offboarding can take time to propagate through an index and caches. Define the maximum acceptable delay and the mechanism that prevents stale access during that interval. If immediate revocation is required, an asynchronous reindex alone is not enough; use a current policy check or another designed control before returning content.

Record access-policy versions and source identifiers in operational traces where appropriate. Avoid logging full retrieved documents by default. The purpose of a trace is to explain which decision allowed a retrieval, without creating another broadly readable copy of the content. See what to log from LLM API calls for related logging boundaries.

Also define the failure behavior. A permission service timeout, malformed access metadata or filter error should produce a controlled failure or empty authorized result according to your policy. It should not trigger a broader search to make the assistant look helpful.

Test access decisions as well as answer quality

Use synthetic documents containing unique marker strings and at least two tenants. Add two users within one tenant who have different document permissions. These are proposed acceptance tests for your application; no tests against real customer data are implied here.

  1. Ask the same question as both tenants. Check candidate IDs, reranker input, model context, answer text and citations for the other tenant's markers.
  2. Change a tenant or group identifier in the request. Confirm that server-side identity checks determine the effective scope.
  3. Create a document with missing access metadata. Confirm the configured deny behavior.
  4. Exercise keyword search, vector search and any fallback independently. Verify that no branch drops the mandatory restriction.
  5. Warm the cache with a more privileged user, then repeat the question with a less privileged user and after revocation.
  6. Revoke access during an active conversation. Check subsequent turns, shared-history access, exports and source downloads.
  7. Make the policy service unavailable. Confirm that retrieval does not broaden its scope.
  8. Change a document's permissions and verify behavior within the defined revocation window, including all of its chunks.

A model refusing to repeat a secret is not a passing retrieval test if that secret already entered its context. Inspect the data path as well as the visible answer. Start with one document type and a small permission matrix, prove the complete path, then expand the integration.

Frequently asked questions

Can a system prompt enforce document permissions?

A prompt can guide behavior, but the application should enforce access before restricted content is disclosed to a component or user outside its permitted scope. Asking the model to ignore unauthorized text does not remove that text from the request.

Is metadata filtering sufficient?

It is a useful mechanism when the metadata is correct, the caller's scope is trusted and every read path applies the policy. It does not establish user identity or keep permissions synchronized on its own.

Does this prevent prompt injection?

No. Authorized documents can still contain hostile instructions. Permission enforcement and the treatment of retrieved text as untrusted input address different problems, and both require attention.

Editorial note: AI assisted drafting; technical claims were checked against the linked official documentation. The scenario and acceptance tests are illustrative application-design guidance, not a certification of any deployed service.