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: Debugging · Diagnose failures. 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.

Debugging · Diagnose failures

Diagnose failures · Consistent authorization across RAG and derived data

Objectives of this level: Locate a concrete cache/citation bypass before an explanation, then preserve a same-input repair trace.

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.

Exact starting state and failure events

First complete implementation, then use a separate copy of rag_acl_student.py. Save rag_acl_lab.py as rag_acl_lab.py. This is a disclosed diagnostic rehearsal, not an unseen-failure assessment. Start with:

{
  "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
        }
      ]
    }
  }
}

Change session-fin groups to [] and auth_version to 8; leave documents, ranked rows and cache unchanged. The observed events are:

[
  {
    "step": "membership_revoke",
    "session": "session-fin",
    "auth_version": 8,
    "groups": []
  },
  {
    "step": "cache",
    "cache_auth_version": 7,
    "cache_hit": true,
    "body": "finance summary 90",
    "current_acl_checked": false
  },
  {
    "step": "citation",
    "document": "d-fin",
    "body": "finance budget 90",
    "entry_acl_checked": false
  }
]

The observed fragments are cache: return state['cache'][request['cache_id']]['body'] and citation: return state['documents'][request['ref']['id']]['body']. Neither fragment checks current authority. Distinguish a stale cache generation from a direct citation bypass; clearing only cache cannot repair both paths. Do not merely hide the final answer.

Record the diagnosis before the answer

python3 rag_acl_lab.py incident > rag-acl-incident.json
python3 -c 'from pathlib import Path; Path("rag_acl_debug_student.py").open("x").write(Path("rag_acl_student.py").read_text())'

An already-green module is your positive control. The copy command refuses an existing debug filename. Inject one observed bypass into rag_acl_debug_student.py, adapting the fragment to your variable names, then run:

python3 rag_acl_lab.py grade --module rag_acl_debug_student.py --out rag-acl-debug-before.json --seed 41

Retain its failing grade as a known-fault experiment. Save the initial diagnosis.md before repair: revoked identity/version facts, first incorrect body-release entry, competing cause and evidence needed. Repair your debug copy and save repair.diff. Keep the original diagnosis, failing output and repaired output together.

python3 rag_acl_lab.py grade --module rag_acl_debug_student.py --out rag-acl-debug-after.json --seed 41
python3 rag_acl_lab.py explain --diagnosis diagnosis.md --diff repair.diff

Use seed 41 for both before/after. The optional explain command requires nonempty diagnosis and diff and records their hashes; file presence is not semantic diagnosis grading. For a stronger diagnostic exercise, an instructor chooses a changed entry or version sequence before giving you the log, then evaluates your initial reasoning. Public logs, a supplied correct solution or a disclosed one-line guard removal do not count as independent diagnosis.

Preserve positive evidence and the boundary

The repaired module must still serve session-dev’s d-dev and initial session-fin’s valid summary. Then recheck all five entries after revocation, source/ACL version changes and revoke→regrant. Grade reports point to which entry failed and the imported code hash. This exercise tests returned/context items before any external sender. It does not test actual embeddings, model output hiding, third-party logs, earlier remote disclosures or physical deletion.

code example

Version mismatch is not always membership loss

A still-authorized user can present an old source or ACL ref after a document update. Inspect the two recorded versions before blaming session groups; the contract deliberately invalidates stale references.

Acceptance task for this level

Save the initial causal diagnosis, a failing known-fault copy, repair diff and same-seed report; perform any instructor-changed diagnostic input before viewing optional explain.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

The cache was cleared but d-fin is still readable by citation. What follows?

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.