Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Consistent authorization across RAG and derived data

Enforce authorization throughout retrieval, reranking, context assembly, caching, and source access.

Learning objectives: Authorization determines whether data can enter calculations, and relevance only determines the order of authorized data. All summaries, caches, and citations derived from the text must be subject to the current permissions.

Content checked: 2026-10-03 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Foundation · Understand the concepts. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Consistent authorization across RAG and derived data
Authorization determines whether data can enter calculations, and relevance only determines the order of authorized data. All summaries, caches, and citations derived from the text must be subject to the current permissions.

How does the mechanism work?

Step-by-step explanation
  1. A user has just been removed from a department group. How to deal with the cache of old answers?

    Revocation can make previously authorized derivatives unreadable under current permissions.

  2. Why is it not enough to hand over unauthorized content to the model and then hide the output?

    Trace backward from the final answer to the actual boundary where data enters computation.

  3. Should block permissions be maintained independently or should document permissions be inherited?

    Apply authorization rules to chunking and context expansion.

Foundation · Understand the concepts

Understand the principle · Consistent authorization across RAG and derived data

Objectives of this level: Derive authorized data before ranking and trace every document and derivative read entry.

Visual guide · Authorize before releasing bodies

Authorize before releasing bodies

All body access paths need current checks, including direct IDs, citations, expansion and caches. Hiding a final answer cannot undo unauthorized model input. Select the figure to open it at full size.

Fixed identity and data, not model-provided groups

This standalone standard-library exercise uses fictional server-side sessions. It performs no authentication handshake, real vector search, reranking or model request. session-dev resolves to tenant-a/user-dev/groups dev in trusted state. Request fields named tenant or groups cannot widen that identity. Complete initial state:

{
  "authority_available": true,
  "policy_version": 3,
  "sessions": {
    "session-dev": {
      "tenant": "tenant-a",
      "user": "user-dev",
      "auth_version": 4,
      "groups": [
        "dev"
      ]
    },
    "session-fin": {
      "tenant": "tenant-a",
      "user": "user-fin",
      "auth_version": 7,
      "groups": [
        "finance"
      ]
    }
  },
  "documents": {
    "d-dev": {
      "tenant": "tenant-a",
      "source_version": 1,
      "acl_version": 2,
      "groups": [
        "dev"
      ],
      "body": "development budget 10"
    },
    "d-fin": {
      "tenant": "tenant-a",
      "source_version": 1,
      "acl_version": 5,
      "groups": [
        "finance"
      ],
      "body": "finance budget 90"
    },
    "d-other": {
      "tenant": "tenant-b",
      "source_version": 1,
      "acl_version": 2,
      "groups": [
        "dev"
      ],
      "body": "other tenant budget 99"
    }
  },
  "ranked": [
    {
      "id": "d-fin",
      "source_version": 1,
      "acl_version": 5,
      "score": 0.99
    },
    {
      "id": "d-other",
      "source_version": 1,
      "acl_version": 2,
      "score": 0.98
    },
    {
      "id": "d-dev",
      "source_version": 1,
      "acl_version": 2,
      "score": 0.7
    }
  ],
  "cache": {
    "cache-fin": {
      "tenant": "tenant-a",
      "user": "user-fin",
      "auth_version": 7,
      "policy_version": 3,
      "body": "finance summary 90",
      "dependencies": [
        {
          "id": "d-fin",
          "source_version": 1,
          "acl_version": 5
        }
      ]
    }
  }
}

Derive candidates before truncation

The ranked metadata places d-fin and d-other ahead of d-dev. Neither is authorized for session-dev: the first has the wrong group, the second the wrong tenant. Filter current authorization and source/ACL versions before taking limit 1; the result is d-dev, not empty and not d-fin. These scores are fixed simulation inputs, not measured vector quality. Microsoft describes its string security-filter pattern as filtering rather than authenticating principals: Azure security filters. Here session lookup is a supplied trusted boundary, not a deployed identity system.

Run this observation in a fresh Python 3 file:

import json
identity = {"tenant": "tenant-a", "groups": ["dev"]}
rows = [("d-fin", "tenant-a", ["finance"]),
        ("d-other", "tenant-b", ["dev"]),
        ("d-dev", "tenant-a", ["dev"])]
allowed = [doc for doc, tenant, groups in rows
           if tenant == identity["tenant"] and set(groups) & set(identity["groups"])]
print(json.dumps({"allowed_document_ids": sorted(allowed), "real_vector_or_model_measurement": False}))

It prints allowed_document_ids ["d-dev"] and false for real_vector_or_model_measurement. It covers one identity filter only. Save rag_acl_lab.py as rag_acl_lab.py in a new practice directory; python3 rag_acl_lab.py guided gives the same observation (exit 0). A new process recreates all data.

Predict five entries

For session-dev, predict retrieve limit 1 → d-dev; context refs d-fin then d-dev → d-dev; by_id d-fin → empty; citation d-fin/version1/ACL5 → empty; cache-fin → empty. Now use session-fin: d-fin and cache-fin can be read initially. Remove finance membership and set auth_version to 8: all five entries must return no private body. Restoring finance membership under auth_version 9 must not revive the version-7 cache. Keep these input/prediction pairs in rag-prediction.json before guided.

Why hiding the answer is too late

An unauthorized body sent to a model or reranker has already crossed a boundary. Downloads by ID, citation handlers and saved summaries are also read paths. OWASP describes inherited access and caching risks: OWASP RAG Security. This lesson applies that principle through explicit current checks; returning no text does not prove that earlier remote copies or backups were erased.

code example

A citation is another data entry

Hiding the answer while returning an unprotected private-document URL still permits reading. The citation handler must use current identity and permissions, even when an earlier retrieval was authorized.

Acceptance task for this level

Deliver five-entry predictions for session-dev, finance revocation and finance regrant; mark the trusted identity and body-release boundaries before running guided.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

Why is filtering top-1 afterward different from filtering authorized candidates before top-1?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.