AWS Builder Center
Your company's AI assistant can leak the layoff list. Here's why, and how to build RAG that can't

Your company's AI assistant can leak the layoff list. Here's why, and how to build RAG that can't

Similarity is not permission. How enterprise RAG leaks confidential data, and a 3-layer fix on AWS: filter before retrieval, keep permissions fresh, guard the output.

Picture a company of 10,000 people. HR is quietly planning layoffs. The list sits in a Google Drive folder that only HR leadership can open.
A fresher joins and asks the internal AI assistant a normal question: "What's the company's plan for next quarter?"
The assistant answers helpfully. And in that answer is the layoff list, along with a few managers' salaries.
Nobody hacked anything. The fresher never had access to that folder. The AI did, and it shared.
This is the most common way enterprise RAG goes wrong, and it's worth understanding why it happens before talking about the fix.

Why it happens: similarity is not permission

A RAG system breaks every document into chunks, turns each chunk into an embedding vector, and stores it in a vector database. When someone asks a question, it finds the chunks whose vectors are closest to the question and hands them to the LLM.
That search answers one question only: "Is this text related to what was asked?"
It never asks the second question: "Is this person allowed to see it?"
To a vector database, the layoff spreadsheet is just more text about "next quarter". If it's relevant, it gets retrieved. Once it is in the model's context, no system prompt saying "don't reveal confidential data" is a real security boundary. Prompts can be talked around. Permissions can't.

The fixes people try first, and why they fail

  • Check permissions on every result, live, against Drive and Slack. At enterprise scale that's lakhs of files and permissions changing every minute. Calling the source system's API for every chunk of every query will crush your latency, or the API's rate limits will crush you.
  • Delete sensitive files from the index. Then the assistant is useless for HR, finance and leadership, the people who'd use it most.
  • One separate AI per team. Permissions don't follow team lines. A file can be shared with three people across two departments. You end up with dozens of indexes and still leak at the edges.

The real fix: three layers

Layer 1: Filter before you retrieve

Resolve who the user is and what they're allowed to see first. Then restrict the vector search to only those documents. A chunk the user can't access never enters the search, so it can never reach the prompt.
The detail that matters is before. If you retrieve the top 10 and filter afterwards, a bug anywhere in that filter step leaks data, and you also end up with fewer useful results. Filtering inside the search fails safe.
Large systems model permissions as a graph of relationships: user → member of group → group has access to folder → folder contains file. Google's Zanzibar paper made this approach well known. You build the graph once and answer "what can this user see?" quickly, without calling Drive or Slack on every query.

Layer 2: Keep permissions fresh

Permissions change all the time. Someone makes a file private. An employee changes team. A contractor leaves. If the index still has yesterday's permissions, it will leak yesterday's access.
The pattern here is change data capture. Listen for permission and file-change events from the source systems, stream them through an event pipeline, and update the access metadata on the indexed chunks within seconds. Revocations matter more than new files: a file that becomes private must disappear from search right away.
When the permission state is unknown or stale, fail closed. Hiding a document for a few seconds is a small inconvenience. Showing the layoff list is the end of trust in your assistant.

Layer 3: A guardrail on what goes in and comes out

Even with correct permissions, some content should never appear in an answer: salary figures, Aadhaar or PAN numbers, phone numbers, health details. A PII and sensitive-data filter on the model's input and output catches what slips through, such as a salary pasted into a widely shared Slack thread.
This is defence in depth, not a replacement for Layer 1. Redaction is pattern matching, and patterns miss things. Authorisation decides what the model is allowed to read. Redaction cleans up what it says.
Add audit logging on top: which user, which query, which chunks were retrieved, and why they were allowed. When someone asks "how did the AI know this?", you have an answer.

Building this on AWS

You don't have to build all of this from scratch. Here's how each layer maps to AWS:
Layer
What you need
AWS option
Identity
Who is asking, and their groups
Amazon Cognito (or your company IdP), passing groups in the JWT
Permission decisions
"What can this user see?" as policy, not code
Amazon Verified Permissions (Cedar policies)
Pre-retrieval filtering
Search only allowed documents
Amazon Bedrock Knowledge Bases metadata filters, or document-level ACLs on custom data sources
Freshness
React to file and permission changes
Amazon EventBridge + SQS + Lambda to update metadata and re-sync; Amazon MSK if you already run Kafka
Output safety
Block or mask PII and sensitive data
Amazon Bedrock Guardrails sensitive information filters
Edge protection
Stop abuse before it reaches your app
Amazon API Gateway, AWS WAF
Audit
Who saw what, and why
Amazon CloudWatch Logs, AWS CloudTrail
The request flow looks like this:
  1. The user signs in through Cognito. The token carries their groups.
  1. API Gateway checks the token, and a Lambda authoriser asks Verified Permissions whether this user may use the assistant at all.
  1. A middleware Lambda asks Verified Permissions which departments or document sets this user may query, and turns the answer into a metadata filter.
  1. Bedrock Knowledge Bases runs the retrieval with that filter, so the vector search only ever sees permitted chunks.
  1. Bedrock Guardrails checks the response for PII before it goes back to the user.
AWS publishes a reference architecture for close to this exact design (link below). Because the permission rules live in Cedar policies, HR can tighten access without anyone redeploying code.
If you'd rather not build the pipeline yourself, Amazon Q Business takes a different approach. It crawls the access control lists from connected sources along with the documents and filters answers per user. Its ACLs update on each sync, so how often you re-sync decides how fresh your permissions are.

Three things AWS won't do for you

  1. Verify identity in the filter. Bedrock's document-level ACLs match the user identity your app passes in. They do not authenticate that user. If your app passes the wrong email, the filter trusts it. Authentication is your job, upstream.
  1. Make metadata filtering a hard tenant boundary. Metadata filters give logical isolation inside one index. For separate customers, AWS recommends a separate knowledge base per tenant.
  1. Tell you when ACLs are misconfigured. Bedrock fails closed: a document with a broken or missing ACL is silently left out of results. That's the safe default, but it means "the AI can't find my document" bugs. Test for it.

A checklist before you ship enterprise RAG

  • Permissions are enforced inside retrieval, not in the prompt
  • Revocations propagate within seconds, and you've tested that
  • Stale or missing permission data means deny, not allow
  • The source systems stay the single source of truth for access; the vector DB only mirrors it
  • PII guardrail on output, as a second layer
  • Every retrieval is logged with user, query and chunk IDs, without copying sensitive content into the logs
  • A test suite of "can user A see user B's data?" queries runs on every deploy
I applied the same idea at small scale in my SecureRAG project (role-based metadata filtering on Lambda), and the lesson held even there: decide your access model before you chunk. Adding permission metadata later means re-indexing everything.
If you're building RAG over company data, how are you handling permission changes? Tell me in the comments. That's the part most teams get wrong.
References
  • AWS Architecture Blog: Secure multi-tenant RAG with Amazon Bedrock and Verified Permissions
  • Amazon Bedrock docs: Document-level access controls for Knowledge Bases
  • Amazon Bedrock docs: Guardrails
  • Amazon Q Business docs: Data source connector concepts
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article