A RAG application can retrieve the right document, generate an accurate answer, and still have a serious security vulnerability.
Imagine a SaaS platform where several companies use the same AI assistant. Each company uploads internal documents, contracts, employee records, and business reports. The application stores their embeddings in a shared vector database to avoid maintaining separate infrastructure for every customer.
Now imagine an employee from Company A asks:
"Show me the latest financial report."
The retriever finds a highly relevant report. The LLM reads it and produces a convincing answer.
There is just one problem: the report belongs to Company B.
This is not a hallucination problem. It is an authorization failure.
The model did exactly what the application asked it to do. The security boundary failed before the model ever received the prompt.
This is one of the most important challenges in production RAG systems: enforcing tenant isolation, document-level permissions, and permission revocation throughout the entire retrieval pipeline.
Why Multi-Tenant RAG Needs More Than Tenant IDs
A multi-tenant application serves multiple customers using shared application code, infrastructure, and sometimes databases.
In a traditional application, an authorization check might look like this:
- Authenticate the user.
- Identify the tenant they belong to.
- Check whether they can access the requested resource.
- Return the resource only when permission is granted.
RAG introduces another layer. The application does not always request a document by its ID. It searches an entire collection using semantic similarity.
That creates a different security challenge.
A document can be relevant to a user's question without being accessible to that user.
For example, consider a company with three departments:
| Department | Documents | Access |
|---|---|---|
| Finance | Budgets, invoices, financial reports | Finance team |
| HR | Employee records, salary information | HR team |
| Engineering | Architecture, source code, technical reports | Engineering team |
All three departments might use the same internal AI assistant and the same vector database.
A finance employee should not retrieve an HR salary report simply because its content is semantically similar to their question.
This distinction matters: relevance determines what the retriever finds. Authorization determines what the user is allowed to receive.
A secure RAG system must enforce both.
1. Carry Access Permissions Into Every Vector Chunk
One of the biggest mistakes in RAG architecture is applying access control to the original document but losing that information during chunking.
Consider a document uploaded to the application:
document_id: report_101
tenant_id: company_A
department: finance
allowed_groups: ["finance_team"]
classification: confidential
The ingestion pipeline splits this document into smaller chunks and generates embeddings.
Document
|
v
Chunk 1 -> Embedding
Chunk 2 -> Embedding
Chunk 3 -> Embedding
If the vector database stores only the text and embeddings, the retriever may no longer have enough information to enforce the original document permissions.
The solution is to carry the document's access-control metadata into every generated chunk.
For example:
{
"chunk_id": "chunk_101_01",
"document_id": "report_101",
"tenant_id": "company_A",
"allowed_groups": ["finance_team"],
"classification": "confidential",
"acl_version": 12
}
The next chunk should inherit the same security metadata.
This allows the retrieval system to evaluate not only whether a chunk matches the user's question, but also whether the user has permission to access it.
There is another important detail: permissions can be inherited from folders, departments, or parent documents. The ingestion pipeline must resolve that inheritance correctly rather than copying incomplete permissions.
Do not treat access-control metadata as optional information. It is part of the security boundary of every chunk.
OWASP's RAG Security Cheat Sheet specifically recommends preserving access-control metadata at the chunk level and enforcing authorization during retrieval.
2. Enforce Tenant Isolation Before Retrieval
Storing a tenant_id in vector metadata is useful, but it does nothing by itself.
The application must enforce that tenant boundary whenever a user performs a semantic search.
A common approach is to use metadata filtering.
Imagine the vector database contains documents belonging to multiple tenants:
Shared Vector Collection
Company A
├── Finance report
├── Product documentation
└── Internal policies
Company B
├── Financial statements
├── Employee handbook
└── Technical documentation
Company C
├── Customer records
└── Business reports
When a user from Company A sends a query, the application must add a mandatory tenant filter to the vector search.
Conceptually:
results = vector_store.search(
query_embedding=query_embedding,
filter={
"tenant_id": "company_A"
}
)
The filter restricts the search to Company A's records.
However, this example only handles tenant isolation. It does not yet enforce department-level or individual document permissions.
A real authorization filter must also account for the user's current roles, groups, classification level, and any document-specific restrictions.
Shared collections or separate collections?
There is no single storage strategy that fits every multi-tenant application.
Shared collection with metadata filtering
Multiple tenants share one collection. Every vector contains tenant metadata, and searches include mandatory tenant filters.
This works well when many customers have relatively small datasets and the vector database provides reliable filtered retrieval.
Separate collections or namespaces
Each tenant receives a separate logical storage boundary.
This can simplify isolation and make tenant-specific management easier, but it introduces operational overhead as the number of tenants grows.
Dedicated shards or infrastructure
Large or highly sensitive tenants may require dedicated shards, collections, or even separate vector database deployments.
Qdrant, for example, documents payload-based partitioning, user-defined sharding, and tiered multitenancy as different approaches to this problem.
The decision depends on tenant count, data volume, isolation requirements, performance, and operational cost.
One important distinction: metadata filtering is logical isolation, not automatically infrastructure-level isolation. The application must not assume that a filter alone provides the same security boundary as separate infrastructure.
3. Apply Document-Level Authorization at Query Time
Tenant isolation prevents Company A from retrieving Company B's documents.
But what about two employees inside the same company?
A finance manager may have access to financial reports, while an engineering employee should only access engineering documentation.
A tenant filter cannot solve this problem.
The application needs document-level authorization.
A useful way to design this is to separate identity, authorization, and retrieval.
Step 1: Authenticate the user
The application validates the user's session or access token.
It identifies the user and obtains their verified tenant membership.
The tenant must come from trusted authentication and membership data, not from a freely editable request parameter.
Step 2: Resolve current permissions
An authorization service evaluates the user's current groups, roles, document permissions, and other applicable policies.
For example:
User: employee_42
Tenant: company_A
Groups:
- finance_team
Allowed classifications:
- internal
- confidential
These are illustrative authorization attributes. A real system should resolve them from trusted identity and policy data.
Step 3: Build a retrieval scope
The application constructs a mandatory filter using the verified tenant identity and the authorization decision.
Conceptually:
retrieval_scope = {
"tenant_id": current_user.tenant_id,
"allowed_groups": permission.groups,
"allowed_classifications": permission.classifications
}
Step 4: Search only within the authorized scope
results = vector_store.search(
query_embedding=query_embedding,
filter=retrieval_scope
)
The exact filter syntax depends on the vector database. The important requirement is that these conditions are constructed by trusted backend code and cannot be overridden by the user's query.
Step 5: Validate the returned documents
For systems with strict revocation requirements, check the current authorization state for the returned document IDs before assembling the context.
Only authorized content should move into the reranker and LLM context.
This second check is particularly useful when indexed permission metadata might lag behind the source authorization system.
A strong architecture does not ask the LLM whether someone should see a document. That decision belongs to the authorization layer, before the document reaches the model.
4. Permission Revocation: The Part Most Systems Underestimate
Granting access is relatively straightforward.
A user joins a department, receives a role, or gets permission to read a document. The application updates the authorization records, and subsequent searches can include that content.
Revoking access is more complicated.
Consider this situation:
An employee belongs to the finance department and can access its internal reports. They ask the RAG assistant a question, and the vector database retrieves several finance documents.
A few minutes later, the employee is removed from the finance group.
Their access has been revoked in the identity system.
But what happens to the RAG system?
The vector database may still contain



