# RAG authorization lab

Everything here is synthetic and fictional: 240 generated documents, 12 users, 72 queries. It exists to show a mechanism, not to measure any production system.

Used by two posts:

- /the-index-remembers-what-the-source-forgot/
- /relevance-is-not-authorization/

## Part 1: retrieval eval and ACL drift (no gateway needed)

```bash
python3 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
python corpus.py          # writes corpus.json (deterministic, seed 20261117)
python rag_eval.py        # no-drift and after-drift tables, writes results.json
python drift_seeds.py     # repeats the drift with 10 different random choices
python example.py         # one revoked-user query, stale index vs live recheck
python tier_share.py      # which tiers fill the unfiltered top 5
```

Embeddings: BAAI/bge-small-en-v1.5 through fastembed. Search: exact cosine over numpy, so there is no approximate-search noise in the numbers. Captured output is in `evidence/`.

## Part 2: gateway and token freshness (open source agentgateway)

Run on 2026-11-17 against the open source standalone binary, version 1.7.0, git revision 26f5aebe99a36a037fe54f8080a608aca5547e15 (`evidence/agentgateway-version.json`). Linux x86_64.

```bash
cd gw
python mint.py                              # creates keys/idp.pem and keys/idp.jwks.json (do not commit the key)
python mcp_server.py &                      # retrieval MCP server on 127.0.0.1:18081
agentgateway -f gateway.yaml &              # gateway on 127.0.0.1:3000
python demo.py                              # revoke, then compare old and new tokens
python probe2.py                            # denial shape, then token expiry at several ages (about 70 seconds)
```

`mcp` is pinned below 2 because the server uses `mcp.server.fastmcp`, which the 2.x SDK renamed.
