FDE Times dataFDE jobs open 913▼15 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 63Companies hiring 200Remote-friendly 24%Median US pay $200kTop hirer Databricks 106
中文VI

The newspaper of the Forward Deployed Engineer

Guides

A chatbot that leaks the payroll has a retrieval bug

Permissions must be checked before text reaches the prompt, and choosing between RBAC, ABAC, ReBAC and PBAC decides whether a client's access rules survive intact.

ShareLinkedInFacebookX

In brief

  • In RAG, permissions must be enforced at the retrieval step so the pipeline only returns documents the person asking is allowed to see.
  • RBAC is easy to audit but prone to role sprawl; ABAC needs fewer policies because it matches on attributes; PBAC puts rules in a policy engine so they are easy to version and audit.
  • When documents live in Drive, Confluence or SharePoint, sync both the content and the permissions, and keep both in step with the source system.
Comparison table of four authorisation models. RBAC: access granted by role; the cost is a growing number of roles. ABAC: by department tag and clearance level; labels must be clean. ReBAC (highlighted): by shared folder; the relationship graph must be kept in sync. PBAC: by central rules; needs a policy engine.
When a client says "we use roles", it is not necessarily RBAC: if access hinges on who a folder is shared with, model it with ReBAC. Source: the article's synthesis of documentation from OpenFGA, Auth0, AWS and Ping Identity.

Week two at a client site. The internal chatbot demo has gone smoothly, until a salesperson asks about this year’s bonus policy and the bot quotes a passage straight from the executive payroll.

The model did nothing wrong. It answered the question it was asked, using the documents the retrieval step handed it. The failure is that the pipeline had no idea who was asking, or what that person was allowed to see.

Every FDE building RAG or agents for enterprises runs into this. The client already has an authorization model, sometimes explicit, more often implicit in SharePoint or Confluence. The job is to carry that model into the AI application without dropping a single rule.

Why is the hole in retrieval?

The OpenFGA documentation states the requirement plainly: document-level permissions must be applied in the pipeline so that RAG returns only content the user is permitted to see. In other words, the authorization decision has to happen before any text enters the model’s context.

Once a passage is in the prompt, any instruction along the lines of “do not reveal confidential information” is merely a request. So the real engineering question is which model you use to replicate the client’s permissions, and where you filter.

One rule, four ways to describe it

Stay with the same company and try writing the rule “only the executive team may see the payroll” in each model. Each one asks a different question about the same permission.

The most familiar is RBAC: permissions are assigned by role in the organization, and each role is a set of permissions applied to users, as Auth0 defines it. For the payroll, you create an “Executive team” role and you are done. Auditing is simple too.

Trouble starts when rules acquire context. Say the client has 5 departments, 4 seniority levels and 3 regions; if each combination needs its own role, you have 60 roles before counting projects.

This is the “role explosion” Ping Identity warns about, and AWS points to a further drawback: every time a new resource appears, you have to update policies to grant access to it.

If the client’s documents are already labeled with department and sensitivity level, ABAC is far tidier. A single rule such as “the requester’s department matches the document’s department, and their seniority is high enough for its sensitivity level” replaces all 60 roles, because the decision rests on attributes of the person, the resource and the environment.

AWS says this approach needs fewer policies and scales automatically with new resources. The price is clean labels: one payroll file someone forgot to tag is a leak.

Many clients label nothing, though. Their permissions live in who the “Payroll” folder is shared with, which is a relationship. ReBAC models exactly that: access derives from relationships between users, groups and documents, and you have to describe the whole relationship graph. Google’s Zanzibar is often cited as the template.

PBAC answers a different question altogether: where do the rules live, and who owns them? Every decision is routed through a policy engine with rules written in a declarative language, so the security team can write, version and audit them, and change permissions quickly without reviewing roles across the whole organization.

Model The question it answers Suits the client when The cost
RBAC What role does this person hold? The organization has few roles and needs simple audits Role counts balloon; new resources mean policy edits
ABAC Do the attributes of person, document and context match? Documents are already tagged by department and sensitivity Attributes must be clean and kept current
ReBAC What is this person’s relationship to the document? Access follows folders, groups and who shared what The whole relationship graph must be described and synced
PBAC What does the central rule say? The security team wants to manage rules as code Requires a policy engine and someone to maintain the rules

The practical lesson: a client saying “we use roles” does not mean they use RBAC. If their permissions come down to “who has this folder shared with them”, that is a relationship, and ReBAC is the better fit.

Example: documents that inherit folder permissions

OpenFGA offers an example very close to what turns up at client sites: a document belongs to a folder and inherits that folder’s viewers, so anyone who can view the folder can view every document in it. In OpenFGA’s modeling language the rule takes only a few lines:

model
  schema 1.1

type user

type folder
  relations
    define viewer: [user]

type document
  relations
    define parent: [folder]
    define viewer: [user] or viewer from parent

The last line holds the entire inheritance logic. Only the executive team are viewers of the “Payroll” folder, so the payroll file inside is automatically visible only to them, with no new role required.

The next step is deciding where to filter. OpenFGA describes two approaches: post-filtering, which queries the vector store first and then checks permission on each result; and pre-filtering, which first fetches the list of documents the user may view, then passes those IDs as a filter to the vector search. A pre-filter sketch:

def retrieve(user_id, question, k=8):
    allowed = fga.list_objects(
        user=f"user:{user_id}",
        relation="viewer",
        type="document",
    )
    return vector_db.search(
        query=question,
        top_k=k,
        filter={"doc_id": {"$in": allowed}},
    )

The case for pre-filtering is simple arithmetic. With post-filtering, if you take the top 8 and all 8 chunks come from confidential documents, the user gets 0 chunks even though a permitted document sits at rank 9.

Pre-filtering carries the opposite risk: the ID list can grow very long for someone who can see a great deal, so measure it on the client’s real data.

How to start from scratch at a client site

Start with discovery before writing any code. Bring a few short questions:

  • Which systems do the documents live in?
  • Who decides on permissions?
  • Are permissions tied to roles, to tags or to shared folders?
  • When someone leaves the company, in which system is their access revoked?

The answer to the last question usually reveals the source of truth you need to anchor to.

Then choose a model according to how permissions actually work, whatever name the client gives them. Folder-and-sharing permissions point toward ReBAC. Documents already labeled with department and sensitivity suit ABAC. A security team that wants to review rules as code should prompt a look at PBAC.

When documents live in Drive, Confluence or SharePoint, OpenFGA recommends syncing content into the vector database and permissions into OpenFGA, keeping both in step with the source system. That means two separate pipelines. Each needs a schedule, alerts when it drifts and a way to handle deletions.

Finally, test with real users. Take three accounts from three departments, ask the same question, and check that the sets of cited documents differ exactly as expected.

On a CV, avoid a generic “built RAG”; say you modeled document-level permissions and synced them from the source system. When interviewing for an enterprise RAG role, ask how they handle document-level permissions.

The question tells you how mature the product is, and shows them you know where these projects tend to break.

The common traps

The first trap is syncing permissions once for the demo and then forgetting them. Content that is a few days stale may go unnoticed, but permissions a few days stale mean someone who just lost access can still query the bot.

The second is letting an agent read documents through a broadly privileged service account and hoping the prompt keeps it in check. The third is handling every odd case by creating another role, the shortest route to role explosion.

The last is relying solely on post-filtering with a fixed top-k, so that users with few permissions get empty answers and conclude the bot is “bad”. That costs you the trust of precisely the largest group of users.

Whether an enterprise AI application earns trust depends less on how well it answers than on whether it stays silent at the right moment, with the right person.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
7 sources
Read next on the roadmap · Stage 5: DeploymentWhy a bare 500 error turns you into your client's night shiftRFC 9457, the 2023 successor to RFC 7807, defines machine-readable error fields so a client's operators can handle many incidents themselves.