Signed Audit Trails Recipe

Signed Audit Trails Recipe

Walks through setting up cryptographically signed audit trails for Claude Code tool calls using Cedar policy, Ed25519 receipts, offline verification and CI/CD integration.

Skill files5 files

references/

SKILL.md257 lines
1
---
2
name: signed-audit-trails-recipe
3
description: Step-by-step cookbook for setting up cryptographically signed audit trails on Claude Code tool calls. Use when explaining, evaluating, or demonstrating the pattern before committing to the protect-mcp runtime hooks. Covers Cedar policy, Ed25519 receipts, offline verification, tamper detection, CI/CD integration, and SLSA composition.
4
---
5
6
# Signed Audit Trails for Claude Code Tool Calls
7
8
Cookbook-style walkthrough for cryptographically signed receipts on every
9
Claude Code tool call. This is the teaching skill. For the runtime
10
implementation, install the [`protect-mcp`](../../../protect-mcp/) plugin.
11
12
## What this gives you
13
14
Every tool call (`Bash`, `Edit`, `Write`, `WebFetch`) is:
15
16
1. **Evaluated against a Cedar policy** before execution. If the policy denies
17
the call, the tool does not run.
18
2. **Signed as an Ed25519 receipt** after execution. Receipts are
19
JCS-canonical and verifiable offline by anyone with the public key.
20
21
An auditor, regulator, or counterparty can verify every receipt later
22
(Step 5). No network call, no vendor lookup, no trust in the operator.
23
24
## When to use the pattern
25
26
- **Regulated environments** (finance, healthcare, critical infrastructure)
27
where you need tamper-evident evidence of agent behavior
28
- **CI/CD pipelines** where you want to prove that a policy gate held for
29
every automated build step
30
- **Multi-party collaboration** where a counterparty wants to verify your
31
agent's behavior without trusting your operator
32
- **Compliance contexts** (EU AI Act Article 12, SLSA provenance for
33
agent-built software) where standard logging is not sufficient
34
35
## Step 1: Install the hook configuration
36
37
Install the `protect-mcp` plugin with `/plugin install protect-mcp`. Its hooks
38
run `evaluate.sh` before each tool call and `sign.sh` after it. Both scripts
39
read the hook event from stdin, because Claude Code sets no `TOOL_NAME` or
40
`TOOL_INPUT` variables. See
41
[`references/hook-wiring.md`](references/hook-wiring.md) for the hook
42
configuration and what each script passes to protect-mcp.
43
44
`protect-mcp@0.32.4 sign` does not create the signing key, and without a key the
45
receipts are unsigned. Create `./protect-mcp.key` once. The command never
46
replaces an existing key:
47
48
```bash
49
if [ ! -e ./protect-mcp.key ]; then
50
d=$(mktemp -d) && npx protect-mcp@0.32.4 init --dir "$d" && mv "$d/keys/gateway.json" ./protect-mcp.key
51
fi
52
chmod 600 ./protect-mcp.key
53
```
54
55
Give auditors the `publicKey` value from that file. Do not commit the file,
56
because it also holds the private key.
57
58
Add the private key and receipt directory to `.gitignore`:
59
60
```bash
61
echo "/protect-mcp.key" >> .gitignore
62
echo "/receipts/" >> .gitignore
63
```
64
65
## Step 2: Write a Cedar policy
66
67
Create `./protect.cedar` from the example in
68
[`references/cedar-policy.md`](references/cedar-policy.md). It allows read-only
69
tools and a short list of Bash commands, denies shell chaining and destructive
70
commands, and limits writes to the project with `..` segments denied.
71
72
## Step 3: Use Claude Code normally
73
74
Start Claude Code. Every tool call goes through both hooks:
75
76
```
77
You: Please read the README and summarize it.
78
79
Claude: I will read README.md.
80
[PreToolUse: Read ./README.md -> allow]
81
[Tool: Read executes]
82
[PostToolUse: receipt rcpt-a8f3c9d2 signed to ./receipts/]
83
84
... summary of README ...
85
```
86
87
A session of 20 tool calls appends 20 receipts to `./receipts/receipts.jsonl`.
88
89
## Step 4: Inspect a receipt
90
91
protect-mcp 0.32.4 appends each receipt as one line of
92
`./receipts/receipts.jsonl`. Print the newest one:
93
94
```bash
95
tail -n 1 ./receipts/receipts.jsonl | python3 -m json.tool
96
```
97
98
The receipt has a signed `payload` and an object `signature`. It names the
99
tool and carries a signed public key; verify against an independently trusted key. See [`references/receipt-format.md`](references/receipt-format.md)
100
for a sample and the signed fields.
101
102
## Step 5: Verify the receipts
103
104
Pass the `publicKey` value from `./protect-mcp.key` to the verifier:
105
106
```bash
107
PUB=$(node -p 'JSON.parse(require("fs").readFileSync("./protect-mcp.key")).publicKey')
108
npx @veritasacta/verify@0.11.1 --replay-chain ./receipts/receipts.jsonl --key "$PUB"
109
```
110
111
Exit codes:
112
113
| Code | Meaning |
114
|------|---------|
115
| `0` | Every receipt verified |
116
| `1` | A receipt failed verification (tampered, wrong key, or malformed line) |
117
| `2` | The receipts file could not be read |
118
119
## Step 6: Demonstrate tamper detection
120
121
Change the newest receipt's `decision` from `allow` to `deny`:
122
123
```bash
124
python3 -c "
125
import json
126
path = './receipts/receipts.jsonl'
127
lines = open(path).read().splitlines()
128
r = json.loads(lines[-1])
129
r['payload']['decision'] = 'deny'
130
lines[-1] = json.dumps(r)
131
open(path, 'w').write('\n'.join(lines) + '\n')
132
"
133
134
npx @veritasacta/verify@0.11.1 --replay-chain ./receipts/receipts.jsonl --key "$PUB"
135
```
136
137
The verifier exits with code `1` and reports which line failed. The
138
Ed25519 signature no longer matches the JCS-canonical bytes of the
139
tampered payload.
140
141
Restore the field and verification passes again.
142
143
## How the cryptography works
144
145
Two invariants make receipts verifiable offline across any conformant
146
implementation:
147
148
1. **JCS canonicalization (RFC 8785)** before signing. Keys sorted by
149
UTF-16 code units, whitespace minimized, strings not normalized. Two
150
independent implementations produce byte-identical signing payloads for the same
151
receipt content.
152
2. **Ed25519 signatures (RFC 8032)** over the canonical bytes.
153
Deterministic, fixed-size, no nonce dependency.
154
155
The verifier detects broken links between surviving receipts, including
156
interior deletion or reordering. A truncated tail and deletion or reordering
157
within the legacy portion of a mixed log can go undetected. Editing signed
158
contents still fails signature verification. Keep an externally retained
159
checkpoint or copy to check completeness.
160
161
For the formal wire format see
162
[draft-farley-acta-signed-receipts](https://datatracker.ietf.org/doc/draft-farley-acta-signed-receipts/).
163
164
## Cross-implementation interop
165
166
The receipt format has four independent implementations today:
167
168
| Implementation | Language | Use case |
169
|----------------|----------|----------|
170
| [protect-mcp](https://www.npmjs.com/package/protect-mcp) | TypeScript | Claude Code, Cursor, MCP hosts |
171
| [protect-mcp-adk](https://pypi.org/project/protect-mcp-adk/) | Python | Google Agent Development Kit |
172
| [sb-runtime](https://github.com/ScopeBlind/sb-runtime) | Rust | OS-level sandbox (Landlock + seccomp) |
173
| APS governance hook | Python | CrewAI, LangChain |
174
175
A receipt produced by any of them verifies against
176
[`@veritasacta/verify`](https://www.npmjs.com/package/@veritasacta/verify).
177
The auditor does not need to trust the operator's tooling choice: the format
178
is the contract.
179
180
## CI/CD integration
181
182
Verify receipts in CI so a tampered receipt fails the build.
183
[`references/ci-cd.md`](references/ci-cd.md) has a GitHub Actions workflow
184
that runs on pushes to the default branch. It installs the signing key from a
185
branch-limited environment, runs the agent, verifies the receipts, and uploads
186
them. It does not run on pull requests, because that would hand the key to
187
unreviewed code.
188
189
## Composition with SLSA provenance for agent-built software
190
191
When Claude Code builds and releases software (running `npm install`,
192
`npm build`, `npm publish` as tool calls), the receipt chain is the
193
per-step build log. SLSA Provenance v1 has an extension point for this: the
194
`byproducts` field can reference the receipt chain alongside the build
195
attestation.
196
197
The [agent-commit build type](https://refs.arewm.com/agent-commit/v0.2)
198
documents the pattern using the ResourceDescriptor shape:
199
200
```json
201
{
202
"name": "decision-receipts",
203
"digest": { "sha256": "..." },
204
"uri": "oci://registry/org/build-xyz/receipts:sha256-...",
205
"annotations": {
206
"predicateType": "https://veritasacta.com/attestation/decision-receipt/v0.1",
207
"signerRole": "supervisor-hook"
208
}
209
}
210
```
211
212
The SLSA provenance is signed by the builder identity; the receipt
213
attestation is signed by the supervisor-hook identity. Two trust domains,
214
cross-referenced at the byproduct layer. See
215
[slsa-framework/slsa#1594](https://github.com/slsa-framework/slsa/issues/1594)
216
for the composition discussion.
217
218
## Common pitfalls
219
220
**Private key in version control.** The generated `./protect-mcp.key` must
221
not be committed. The examples above add it to `.gitignore`. If a key is
222
accidentally committed, rotate it immediately. Move the key and
223
`./receipts/receipts.jsonl` to an archive, then run the Step 1 command again.
224
Verify the archived receipts with the old public key.
225
226
**Hook payload on stdin.** Claude Code sets no `$TOOL_NAME` or `$TOOL_INPUT`
227
variables. A hook command that passes `--tool "$TOOL_NAME"` sends an empty
228
tool name, so the policy denies every call. Read the payload from stdin as the
229
plugin scripts do.
230
231
**Receipts directory in CI.** If Claude Code runs in CI, upload receipts as
232
an artifact at the end of the job or the receipts are lost at job end.
233
234
**Policy is missing.** When `./protect.cedar` does not exist, `evaluate.sh`
235
prints a warning to stderr and allows the call. No call is gated until you
236
create the policy in Step 2.
237
238
## Related in this marketplace
239
240
- [`protect-mcp`](../../../protect-mcp/) — the runtime hook implementation
241
(use this plugin in production)
242
- [`review-agent-governance`](../../../review-agent-governance/) — require
243
human approval before review-surface actions; composes with protect-mcp
244
245
## References
246
247
- [`draft-farley-acta-signed-receipts`](https://datatracker.ietf.org/doc/draft-farley-acta-signed-receipts/) — IETF draft, receipt wire format
248
- [RFC 8032](https://datatracker.ietf.org/doc/html/rfc8032) — Ed25519
249
- [RFC 8785](https://datatracker.ietf.org/doc/html/rfc8785) — JCS
250
- [Cedar policy language](https://docs.cedarpolicy.com/)
251
- [protect-mcp on npm](https://www.npmjs.com/package/protect-mcp)
252
- [@veritasacta/verify on npm](https://www.npmjs.com/package/@veritasacta/verify)
253
- [in-toto/attestation#549](https://github.com/in-toto/attestation/pull/549) — Decision Receipt predicate proposal
254
- [agent-commit build type](https://refs.arewm.com/agent-commit/v0.2) — SLSA provenance for agent-produced commits
255
- [Microsoft Agent Governance Toolkit](https://github.com/microsoft/agent-governance-toolkit) (`examples/protect-mcp-governed/`)
256
- [AWS Cedar for Agents](https://github.com/cedar-policy/cedar-for-agents)
257

© Tom Farley · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…