Secure AI Engineering

RAG Security Architecture: Protecting Enterprise Data From LLM Applications

Retrieval-augmented generation has become the default way to connect LLMs to enterprise knowledge, and the most common way for AI features to expose data they shouldn't. This article presents a security architecture for RAG: trust zones, permission synchronisation, tenant isolation, secure prompt assembly and auditing.

By EthicalHat Research · · 3 min read
Infographic: Trust zones in a secure RAG architecture

Retrieval-augmented generation (RAG) has become the standard pattern for enterprise AI assistants this year: index internal documents, retrieve relevant passages for each question, and let a model answer with them. It is effective, and it creates a new path to enterprise data that sits outside the controls built around the original systems.

Most RAG security problems we see are not exotic AI attacks. They are architectural: permissions that are not carried through, indexes that mix data that should never mix, and retrieval that trusts the service account instead of the user.

Principle: the RAG system must never widen access

The core security requirement is simple to state: a user must never be able to obtain, through the AI assistant, information they could not access directly in the source system. Everything in the architecture should serve that requirement.

Zone 1: sources

Systems of record (document management, wikis, ticketing, CRM, file shares) remain the authority for both content and permissions. The RAG system is a derived copy and must follow their rules, including deletions and permission changes.

Zone 2: ingestion

The ingestion pipeline reads from sources, chunks content, creates embeddings and writes to the index. It typically needs broad read access, which makes it high-value.

  • Run ingestion with dedicated, read-only credentials per source.
  • Carry access control metadata (users, groups, roles, sensitivity labels) onto every chunk.
  • Classify content and exclude categories that should never be indexed, such as credentials, highly sensitive HR or legal material, or regulated data without appropriate controls.
  • Sanitise: strip hidden text and active content where possible, and flag documents containing instruction-like text.
  • Propagate deletions and permission changes promptly, with periodic full reconciliation.

Zone 3: the index

Vector databases and search indexes hold chunk text, embeddings and metadata, and should be protected like the data they contain:

  • authentication and network isolation, with no direct access from clients,
  • encryption at rest,
  • access logging for queries and administrative actions, and
  • segregation where risk demands it: separate indexes (or separate deployments) per tenant, per region or per sensitivity level, rather than relying only on metadata filters.
flowchart TB
  subgraph Sources
    S1[SharePoint]
    S2[Confluence]
    S3[Ticketing]
  end
  Sources -->|read-only creds| ING[Ingestion<br/>chunk, classify,<br/>attach ACLs]
  ING --> IDX1[(Index: internal-general)]
  ING --> IDX2[(Index: restricted<br/>separate deployment)]
  U[User] --> APP[Assistant API<br/>authenticated]
  APP --> RET[Retriever<br/>filters by user's groups<br/>& clearance]
  RET --> IDX1
  RET -->|only if cleared| IDX2
  RET --> GEN[Prompt assembly<br/>delimited, cited]
  GEN --> LLM[LLM] --> APP
  APP --> AUD[(Audit log:<br/>user, query, chunks)]

Zone 4: retrieval

This is where most oversharing happens. Retrieval must be evaluated as the user, not as the application:

  • resolve the user's identity and group memberships at query time,
  • apply them as filters in the index query, so unauthorised chunks are never returned,
  • enforce tenant boundaries in every query, and
  • cap the number and size of results.

Post-filtering, where results are retrieved first and then removed from what the model sees, is risky: bugs or ranking changes can let restricted content slip through, and it wastes retrieval capacity.

Zone 5: generation

  • Treat retrieved chunks as untrusted content: delimit them and instruct the model to use them only as reference material.
  • Do not give a RAG assistant tools with side effects unless those actions are separately authorised and confirmed.
  • Return citations so users can verify answers and see where information came from.
  • Apply output checks for sensitive data patterns where appropriate.

Multi-tenancy

For SaaS providers adding RAG features, tenant isolation is critical. Options, in increasing strength:

  1. a shared index with mandatory tenant filters in every query,
  2. separate namespaces or collections per tenant, and
  3. separate index deployments per tenant or tenant tier.

Whichever you choose, test cross-tenant retrieval explicitly and continuously.

Auditing

Log, for every question: the user, the query, the chunks retrieved (by ID and source) and the answer. This supports investigations ("who could have seen this document through the assistant?"), detection of abuse such as systematic extraction attempts, and compliance.

Testing the architecture

  • Users at different permission levels ask for the same restricted information.
  • Documents are removed or re-permissioned at the source, and the assistant is checked for stale access.
  • Cross-tenant queries are attempted.
  • Documents containing injected instructions are indexed, and the assistant's behaviour is observed.
  • Direct access to the vector database and ingestion services is attempted from untrusted networks.

The bottom line

RAG is powerful because it makes enterprise knowledge easy to reach. A secure RAG architecture makes sure it is only easy for the right people: permissions carried from the source, filtering at query time, segregation where risk demands it, untrusted handling of retrieved text and a full audit trail.

Our agentic AI security team builds permission-aware RAG systems, and our application security testing verifies them against oversharing and cross-tenant leakage.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.