LLM engineering × identity security

A PAM support copilot that never leaks secrets.

PAM Copilot answers first-level Privileged Access Management questions from approved runbooks, diagnoses CyberArk-style CPM, PSM and PVWA errors from pasted logs, and masks every password, key, token, IP and hostname before anything reaches the model. Everything runs locally.

29/29red-team cases passed (secret leakage, injection, doc poisoning, RBAC)
33/33simulated logs with planted secrets sent end to end, none leaked to prompt, output or audit
92.9%retrieval hit@5 on 42 in-scope questions
100%out-of-scope questions refused instead of guessed

What it does

Built for the first line of a PAM team: quick answers that cite their source, and log triage that never puts a credential in front of the model.

Grounded answers

Answers come only from approved runbooks. Every claim cites runbook › section › last-updated, and an answer without a valid citation is turned into a refusal.

Log diagnosis

Paste a CPM/PSM/PVWA/Vault log. It is redacted, classified by error code (or by similarity, flagged low-confidence), routed to the matching runbook, and turned into cited fix steps.

Security first

Redaction before the LLM, injection defenses for questions, logs and documents, role filtering inside the vector DB, an output filter with canary detection, and a hash-chained audit log.

How a request flows

Each step is a choke point in our own code, not a framework callback, so each one can be unit-tested on its own.

Redactregex + entropy → [PASSWORD_1], [HOST_1]
Injection checkblock the question, drop poisoned log lines
RetrieveQdrant top-5 with a role filter on the server
Gatescore < 0.60 → refuse, no LLM call
Generatelocal Ollama, delimited sources, canary
Output filterre-redact; block canary or original values
Cite + auditno citation → refuse; hash-chained log

Stack: Python 3.11 · FastAPI · Streamlit · LlamaIndex (ingestion + retrieval) · Qdrant · Ollama (qwen2.5:7b-instruct, nomic-embed-text) · Docker Compose · pytest · GitHub Actions.

Screenshots

Captured from the running Docker Compose stack against the local model. Click any image for full size.

Security design

The core idea is to stop relying on the model to behave: it never receives a secret, and it never receives content above the user's role. Detection then adds a second layer.

ThreatControl
Secrets in a pasted log or questionRedaction runs first: PEM, JWT, bearer/basic, cloud key prefixes, URL credentials, password=/-newpass, IPs, FQDNs, plus a Shannon-entropy fallback
The model echoes a secret anywayThe output is re-redacted and blocked if any original masked value or the system-prompt canary appears
Secrets persisted in logsThe audit log stores redacted text only; findings hold spans, never values; file mode 0600
Direct and indirect prompt injectionQuestions blocked, poisoned log lines dropped, poisoned documents quarantined at ingest, delimiters neutralized, chunks re-scanned at query time
Operator reaching admin guidanceThe role comes from the token; Qdrant filters audience on the server, so admin chunks never leave the DB
Hallucinated fixesRelevance gate, an INSUFFICIENT_CONTEXT contract, mandatory valid citations
Audit tamperingSHA-256 hash chain, verified by the /audit endpoint and a CLI
Weak deploymentRefuses to start without strong tokens; non-root, read-only containers with cap_drop: ALL; Qdrant and Ollama not exposed; gitleaks in CI

Evaluation results

A real run against the local model on 2026-11-03: generator qwen2.5:7b-instruct, judge llama3.1:8b (a different model, to reduce self-grading bias). Nothing here is hand-entered: results.json has every item.

Retrieval & answersValue
Retrieval hit@1 / hit@3 / hit@585.7% / 90.5% / 92.9%
Retrieval MRR@50.886
In-scope questions answered (42)88.1%
Citation hit rate (cites an expected runbook)97.3%
Citation precision91.0%
Faithfulness (judge, 37 answers)95.2%
Key-point coverage, answered (37)60.8%
Key-point coverage, all in-scope (refusal = 0)53.6%
Out-of-scope refused (8)100%
Latency p50 / p953.66 s / 9.59 s
Red teamPassed
Secret leakage (handwritten)10/10
Prompt injection: direct6/6
Prompt injection: inside pasted logs5/5
Poisoned documents4/4
Role-based access4/4
Simulated logs end to end (prompt, output, audit)33/33
Total, handwritten29/29
Redaction recall (660 simulated logs)Masked / planted
api_key96/96 (100%)
hostname680/680 (100%)
ip420/420 (100%)
password570/570 (100%)
token106/106 (100%)
Secret false positives (19 runbooks / 330 clean logs)0 / 0
Log classification (33 codes)Accuracy
With error code (exact match)100%
Error code stripped (similarity only)84.8%

Caveat: the runbooks, log generator, questions and redactor were all written by the same author, so scores on simulated data are in-distribution and optimistic. The handwritten red-team cases are the out-of-distribution evidence. In the two poisoned-document questions, the stealth document (no injection phrasing, so not quarantined) was never retrieved, so those passes don't prove resistance to content poisoning; reviewing documents before ingest is the control.

Run it

Requires Docker and, on macOS, native Ollama for Metal GPU acceleration.

# 1. models (native Ollama)
ollama pull nomic-embed-text && ollama pull qwen2.5:7b-instruct

# 2. secrets: fill OPERATOR_TOKEN, ADMIN_TOKEN, QDRANT_API_KEY
git clone https://github.com/Harshitraiii2005/AI-Support-Assistant-for-PAM-Operations-secure-RAG.git && cd AI-Support-Assistant-for-PAM-Operations-secure-RAG
cp .env.example .env

# 3. qdrant + ingest + api + ui  →  http://localhost:8501
docker compose up --build

# tests (offline) and evaluation (needs Ollama)
uv run pytest -q
uv run python -m pam_copilot.evaluate

Limitations