@agent-custody/receipts 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +48 -21
  2. package/dist/acs.d.ts +47 -0
  3. package/dist/acs.js +235 -0
  4. package/dist/addresses.d.ts +6 -0
  5. package/dist/addresses.js +90 -0
  6. package/dist/check.d.ts +10 -0
  7. package/dist/check.js +179 -3
  8. package/dist/cli.js +147 -12
  9. package/dist/config.d.ts +198 -1
  10. package/dist/config.js +154 -3
  11. package/dist/console.js +16 -7
  12. package/dist/deny-report.js +1 -1
  13. package/dist/door.d.ts +203 -0
  14. package/dist/door.js +712 -0
  15. package/dist/egress-draft.d.ts +43 -0
  16. package/dist/egress-draft.js +153 -0
  17. package/dist/egress.d.ts +116 -0
  18. package/dist/egress.js +585 -0
  19. package/dist/export.d.ts +39 -0
  20. package/dist/export.js +95 -0
  21. package/dist/gateway.js +53 -21
  22. package/dist/index.d.ts +15 -0
  23. package/dist/index.js +10 -0
  24. package/dist/issue.js +5 -65
  25. package/dist/lock.d.ts +12 -0
  26. package/dist/lock.js +124 -0
  27. package/dist/log.d.ts +11 -5
  28. package/dist/log.js +63 -43
  29. package/dist/opa-server.d.ts +34 -0
  30. package/dist/opa-server.js +93 -0
  31. package/dist/policy-rego.d.ts +30 -0
  32. package/dist/policy-rego.js +116 -0
  33. package/dist/portal.js +147 -41
  34. package/dist/pr-summary.d.ts +25 -0
  35. package/dist/pr-summary.js +87 -0
  36. package/dist/receipt.d.ts +8 -2
  37. package/dist/retention.d.ts +1 -1
  38. package/dist/retention.js +14 -4
  39. package/dist/sdk/index.js +10 -3
  40. package/dist/simulate.d.ts +3 -1
  41. package/dist/simulate.js +15 -7
  42. package/dist/verify.js +35 -4
  43. package/docs/acs.md +107 -0
  44. package/docs/configuration.md +3 -3
  45. package/docs/door-signals.md +66 -0
  46. package/docs/door.md +168 -0
  47. package/docs/egress.md +177 -0
  48. package/docs/github-action.md +164 -0
  49. package/docs/policies.md +112 -1
  50. package/docs/sdk.md +25 -9
  51. package/docs/threat-model.md +1 -1
  52. package/docs/tutorials.md +7 -0
  53. package/docs/usage.md +2 -2
  54. package/docs/verification.md +16 -2
  55. package/package.json +14 -13
  56. package/templates/claude-code.cedar +287 -10
  57. package/vectors/audit.json +27 -27
  58. package/vectors/canonical.json +5 -5
  59. package/vectors/merkle.json +123 -0
  60. package/vectors/receipts.json +1951 -1005
package/docs/egress.md ADDED
@@ -0,0 +1,177 @@
1
+ # The egress witness: receipts for calls that go around the gateway
2
+
3
+ The gateway holds an agent's tool credentials and receipts every call made through it. An agent that has a credential of its own, or that calls a public API with none, can go around it. The egress witness is for those connections. It is an HTTP forward proxy in the agent's network path, the [door](door.md) turned around to face outbound traffic. For each connection that does not go to the gateway, it:
4
+
5
+ - identifies the agent by a proxy credential it checks;
6
+ - lets a Cedar or Rego policy decide per destination (host and port);
7
+ - relays the connection or refuses it;
8
+ - signs a receipt either way, with `issuer.kind: "egress"`. The receipt goes to the log like any other.
9
+
10
+ **It needs lockdown.** A proxy alone is advice: an agent can ignore `HTTPS_PROXY` and connect directly. The witness means something only when the agent's network reaches nothing but the gateway and the witness. The witness runs anywhere Node 22 runs, but the lockdown belongs to the platform the agent runs on. `deploy/gateway/lockdown` ships it for Kubernetes (a NetworkPolicy), docker compose (an internal network), and a Linux VM or bare metal (`lockdown/vm`: an nftables rule on the agent's Unix user, a systemd drop-in for the agent's unit, a unit for the witness, and a script that runs the lockdown checks). On a cloud task or a laptop, you build the default-deny egress with that platform's own firewall. [Credential custody and lockdown](../../../site/guide/credential-custody.md) explains each.
11
+
12
+ **What it cannot see.** Every page about the witness repeats this list:
13
+
14
+ - **Payloads.** CONNECT is relayed as an opaque tunnel, with no TLS interception. The witness records where traffic went, when, and how many bytes went each way. It never records what was sent or received. For plain HTTP it records the method, host, and port, not the path, the headers, or the body.
15
+ - **Traffic that skips it.** With lockdown off, an agent that ignores `HTTPS_PROXY` leaves no receipt at all. With lockdown on Kubernetes, DNS to the cluster resolver stays open, and a resolver that forwards to the internet can still carry data in its queries. The VM recipe closes DNS to the agent.
16
+ - **Protocols other than HTTP.** The witness relays HTTP requests and CONNECT tunnels. Under lockdown, other protocols cannot leave. Without lockdown they are invisible to it.
17
+
18
+ Each receipt is an **observed bypass**: evidence that the agent connected to a destination around the gateway. It is not a record of what the agent did there.
19
+
20
+ ## The config file
21
+
22
+ `egress.json`, paths relative to the file:
23
+
24
+ ```json
25
+ {
26
+ "identity": { "keyFile": "keys/egress.key" },
27
+ "agents": [{ "id": "research-agent", "secretEnv": "EGRESS_SECRET_RESEARCH_AGENT" }],
28
+ "policyFile": "egress-policy.cedar",
29
+ "mode": "enforce",
30
+ "connectTimeoutMs": 10000,
31
+ "idleTimeoutMs": 300000,
32
+ "maxInFlight": 256,
33
+ "receiptsDir": "receipts",
34
+ "logFile": "log.jsonl"
35
+ }
36
+ ```
37
+
38
+ - `policyFile`: a Cedar file, or a Rego file when the name ends in `.rego` (see [the same policy in Rego](#the-same-policy-in-rego)). The witness re-reads it when it changes. A file that does not parse or compile is not loaded, and the policy in force stays.
39
+ - `agents`: each agent the witness knows, and the environment variable that holds its proxy secret. The secret is never in the file. An agent id has no colon or whitespace, because Basic credentials split at the first colon. The witness refuses to start if a variable is unset.
40
+ - `mode`: `enforce` (the default) refuses what the policy denies. `observe` relays every connection from a known agent and records the decision with `enforced: false`, so you can see what your agents call before you block anything. A connection without a valid credential is refused in both modes.
41
+ - `connectTimeoutMs`: how long the witness waits for the destination to accept the connection. `idleTimeoutMs`: a relayed connection with no bytes in either direction for this long is closed.
42
+ - `maxInFlight`: connections handled at once. Past this, the next one gets 503 and is not decided, relayed, or receipted. The door has the same rule.
43
+ - `log`, `otel`, `splunk`: as for the gateway.
44
+
45
+ Run it with `agent-custody egress --config egress.json [--port 8791] [--host 127.0.0.1]`.
46
+
47
+ ## How an agent uses it
48
+
49
+ The agent sets `HTTPS_PROXY` and `HTTP_PROXY` to `http://<agent id>:<secret>@<witness>:8791`, and `NO_PROXY` to the gateway's host, because the gateway receipts its own calls. Most HTTP clients send the credential from the URL as `Proxy-Authorization: Basic`. Node's `fetch` reads these variables when `NODE_USE_ENV_PROXY=1` is set, on versions that support it. Other clients need their own proxy setting.
50
+
51
+ ## How the witness knows the agent
52
+
53
+ Only from the proxy credential. The witness compares a sha256 of the presented secret with the one it holds for that id, in constant time. An id that is not known is compared against a stand-in, so the answer time does not reveal which ids exist.
54
+
55
+ - **Verified:** the agent is that id, with provenance `observed`. This means the witness checked a secret it holds. Anyone who has the secret can act as that agent, so give each agent its own secret and keep it in that agent's environment only.
56
+ - **Invalid or absent:** the agent is `unknown`, with provenance `claimed`. An id that came with a wrong secret stays in the destination fact as `declared`, a claim. The connection is refused with `407 Proxy Authentication Required`, whatever the policy says.
57
+
58
+ Nothing the agent writes in a header names it. The connection's source address is the socket's own. A forward proxy has nothing in front of it, so the witness never reads `X-Forwarded-For` (the door's `trustProxy` rule, with nothing to trust).
59
+
60
+ ## How a connection becomes a Cedar request
61
+
62
+ - **Principal:** `Agent::"<id>"` when the credential verified, otherwise `Agent::"unknown"`.
63
+ - **Action:** the destination as `host:port`, for example `Action::"api.stripe.com:443"`. An IPv6 address is in brackets. Host names are lowercase, without a final dot. A CONNECT host goes through the same URL parser as a plain request's. So an IPv4 address written another way is decided on as the address it names: `2130706433` and `0x7f.1` become `127.0.0.1`, and `010.0.0.1` becomes `8.0.0.1`, the address `getaddrinfo` would dial. A rule on an address cannot be dodged by spelling it differently.
64
+ - **Resource:** the same as the action.
65
+ - **Context:** `context.args` holds `{ method, host, port }` as the agent asked for them. `context.facts.destination` holds the witness's own observation: `host`, `port`, `scheme` (`connect` or `http`), `credential` (`verified`, `invalid`, or `absent`), `remote` (the socket's address), and, after a failed credential, `declared`.
66
+
67
+ ```cedar
68
+ // The research agent may read the package registry over TLS.
69
+ permit(principal == Agent::"research-agent", action == Action::"registry.npmjs.org:443", resource);
70
+
71
+ // Any known agent may reach hosts under example.com on 443.
72
+ permit(principal, action, resource)
73
+ when { context.facts.destination.credential == "verified" && context.facts.destination.port == 443 && context.facts.destination.host like "*.example.com" };
74
+ ```
75
+
76
+ ### The same policy in Rego
77
+
78
+ Give `policyFile` a name ending in `.rego`, and the witness compiles it with `opa build`, exactly as the gateway does ([Rego](policies.md#rego)). The policy declares `package agentcustody`, with an `allow` boolean and a `deny` set of strings. The input is the Cedar request above with plain strings: `input.principal` is the agent id, or `"unknown"` when the credential did not verify, `input.action` and `input.resource` are `host:port`, and `input.context` holds `args` and `facts.destination`. The `opa` binary must be on `PATH` when the policy loads or changes. The witness notices a change on the first connection after it and compiles the file then, synchronously: the whole witness waits for `opa build`, typically a few hundred milliseconds, so every other connection waits too. The compile has no deadline, so an `opa` that hangs stalls the witness until it exits or the process is killed. A file that does not compile is compiled once, not again on each connection, until it changes. The gateway image includes `opa`.
79
+
80
+ This is `deploy/gateway/lockdown/config/egress-policy.cedar` in Rego:
81
+
82
+ ```rego
83
+ package agentcustody
84
+
85
+ # The research agent may read the package registry and the public docs over TLS.
86
+ allow if {
87
+ input.principal == "research-agent"
88
+ input.action in {"registry.npmjs.org:443", "docs.python.org:443"}
89
+ }
90
+
91
+ # Any known agent may reach hosts under example.com on 443; context.facts.destination is the witness's own observation.
92
+ allow if {
93
+ d := input.context.facts.destination
94
+ d.credential == "verified"
95
+ d.port == 443
96
+ endswith(d.host, ".example.com")
97
+ }
98
+ ```
99
+
100
+ `endswith(d.host, ".example.com")` is Cedar's `like "*.example.com"`. A `deny` entry wins over `allow`, as a `forbid` wins over a `permit`, and its strings are the reason in the 403 and in the receipt. The receipt's `policyDigest` is the sha256 of the file's text, as for Cedar.
101
+
102
+ An OPA server (`opa: { url }`) is not supported here yet. The gateway can ask one, but the witness decides each connection synchronously, before it relays a byte. An HTTP query per connection would need that decision to wait, and fail closed, on a server outside the witness. Use a `.rego` file.
103
+
104
+ [Writing egress policies](../../../site/guide/egress-policies.md) is the guide to these rules: allow lists, wildcard hosts, ports, IP literals, `forbid`, and rolling out from observe mode. Every example in it is tested.
105
+
106
+ Do not permit a provider whose calls belong in the gateway. The point of the gateway is that it holds the provider's key and decides each call on its arguments. The witness sees only a host name.
107
+
108
+ **Internal addresses.** The policy decides on a host name, and the witness then resolves it. A name the agent chose, or a DNS answer someone else chose, could point a permit for a public host at the metadata service or the private network. So the witness drops every internal address from the answer before it connects: loopback, private and shared ranges, link-local (the cloud metadata address `169.254.169.254`), `192.0.0.0/24` (Oracle's metadata at `192.0.0.192`), multicast, reserved space, and their IPv6 forms. That includes IPv4-mapped and NAT64 (`64:ff9b::/96`) addresses, which are judged by the IPv4 address they carry, since a DNS64 answer can wrap an internal one. A name with nothing left fails with an `error` receipt, and no connection is made. The check is in the resolver the socket connects with, so there is no second lookup to rebind. An IP literal is not looked up: it is the Cedar action itself, so it is dialled only when a rule names that address. On Kubernetes, `deploy/gateway/lockdown/k8s/egress-networkpolicy.yaml` refuses the same ranges a second time, at the network.
109
+
110
+ `agent-custody policy simulate` replays egress receipts like any other.
111
+
112
+ ## Drafting a policy from observe mode
113
+
114
+ ```bash
115
+ agent-custody egress draft-policy --receipts receipts --issuer-key keys/egress.pub [--log-key <pub>]... [--log log.jsonl] > egress-policy.draft.cedar
116
+ ```
117
+
118
+ It reads every regular file `*.json` in the directory, never through a symlink, and verifies each one. A symlink, a special file such as a fifo, and a receipt that does not verify are skipped; a receipt that does not verify is named on stderr. It keeps the egress receipts whose agent is `observed` (a verified proxy credential) and whose connection was relayed (`executed`). It prints one `permit` per agent and scheme over the `host:port` destinations that agent used, sorted, with no duplicates. A plain request and a tunnel to the same `host:port` are the same Cedar action, so each permit also names the scheme it saw (`context.facts.destination.scheme`): an observed plain GET never becomes a permitted CONNECT tunnel. Each permit and each destination carries a comment with its count and its first and last time. A destination that is an IP literal in an internal range is marked `INTERNAL ADDRESS`, because the witness dials a literal that a rule names. The output starts with a warning: the draft permits whatever the agents did in the window, bad destinations included, and a person must review it before it is enforced. It exits 1 when there is nothing to permit.
119
+
120
+ An observe-mode witness writes the receipt of a 407 with the policy's unenforced decision beside a `denied` status, and that receipt does not verify (`policy decision consistent with execution`). `draft-policy` skips it like any receipt that does not verify. `policy simulate` stops on it.
121
+
122
+ Tutorial: [42-egress-draft.ts](../examples/42-egress-draft.ts).
123
+
124
+ ## What the agent gets back
125
+
126
+ | case | answer | receipt |
127
+ | --- | --- | --- |
128
+ | allowed, CONNECT | `200 Connection Established`, then the tunnel | `executed` when the tunnel closes |
129
+ | allowed, plain HTTP | the destination's answer, without hop-by-hop headers | `executed` when the answer ends |
130
+ | policy refuses | `403`, JSON with the reason | `denied` |
131
+ | no valid credential | `407`, with `Proxy-Authenticate: Basic realm="agent-custody egress"` | `denied` |
132
+ | destination unreachable, or a host name that resolves only to internal addresses | `502` (plain HTTP: `504` if the request may have arrived) | `error` |
133
+ | the log will not commit the connection first | `503` | `withheld` |
134
+ | the witness stops before the connection opens | `503` | `error` |
135
+ | past `maxInFlight` | `503`, `Retry-After: 1` | none |
136
+ | malformed target, or `https://` in a plain request | `400` | none |
137
+
138
+ Every answer that has a receipt carries `x-agent-custody-receipt`. A plain HTTP request is relayed without `Proxy-Authorization`, so the agent's secret never reaches the destination. The `Host` header is set to the destination the policy decided on, whatever the agent wrote. A request in origin form (`GET /…`) is for the witness itself: `GET /.well-known/agent-custody-egress` answers the key id, the policy digest, and the number of receipts waiting for the log.
139
+
140
+ ## The receipt
141
+
142
+ The same in-toto statement and v0.2 predicate as every other receipt, signed by the witness's key:
143
+
144
+ - `issuer`: `{ kind: "egress", framework: "connect" | "http" }`.
145
+ - `principal`: `null`, claimed. The witness checks no grant.
146
+ - `agent`: as above.
147
+ - `tool`: `{ name: "host:port", provenance: "observed" }`.
148
+ - `request.args`: `{ method, host, port }`, claimed, as the agent asked.
149
+ - `facts.destination`: the observation the policy decided on, observed.
150
+ - `execution`:
151
+ - for a relayed connection, `executed` with `result`: `peer`, `openedAt`, `closedAt`, `bytesUp`, `bytesDown`, `end`, and for plain HTTP `status`. `peer` is the address the witness connected to. `end` is `closed`, `reset`, `idle-timeout`, or `witness-stopped`.
152
+ - otherwise `denied` with the reason, or `error`.
153
+
154
+ For a tunnel, the bytes are the tunnel's payload, which is ciphertext for HTTPS. For plain HTTP, they are the request body and the response body.
155
+
156
+ **Committed before relaying.** Before any byte of the agent's moves, the witness commits the connection to the log as an authorization: the agent, the destination, and the decision. This is what the door does for a request that can change something. If the log will not take it, nothing is relayed and the agent gets 503. Observe mode is the exception, as at the door: it relays and prints the gap, and that receipt then fails `egress open committed before relaying`, because nothing was committed first. The receipt, written when the connection ends, embeds that authorization and adds the times, the byte counts, and how it ended. So the bypass is on record before it happens, even if the closing receipt is never written. A witness that is stopped normally closes its open connections, including those still connecting, and receipts each one. A witness that is killed leaves the committed authorization in the log, but not the closing receipt with the byte counts.
157
+
158
+ ## What a verifier checks
159
+
160
+ [Verifying a receipt](verification.md) lists the common checks. On an egress receipt, all three verifiers (TypeScript, the browser page, Python) also run these:
161
+
162
+ - `egress receipt carries a policy decision`: the witness decides every connection.
163
+ - `egress destination observed`: the tool name is observed, and it equals the host and port in the observed destination fact.
164
+ - `egress relayed only for a checked agent`: a connection that was relayed (`executed`, `failed`, or `error`) has an agent with provenance `observed`.
165
+ - `egress open committed before relaying`: a relayed connection carries the authorization the witness committed before any byte moved. The usual authorization checks then confirm that it names this call and that it sits in the log before the receipt.
166
+ - `egress peer matches the destination`: for an IP literal, the recorded `peer` is that very address, since the policy named it. For a host name, the `peer` is a public address.
167
+
168
+ Vectors `egress-*` and `resigned-egress-*` in `vectors/receipts.json` cover them.
169
+
170
+ ## What it does not do yet
171
+
172
+ - Record the byte counts of a connection open when the witness is killed: the committed authorization is in the log, the closing receipt is not.
173
+ - Identify an agent by its source address or by a signed grant. Today only per-agent proxy credentials identify an agent.
174
+ - `agent-custody check` does not read an egress config yet.
175
+ - Ask an OPA server for the decision. A `.rego` file works; `opa: { url }` does not, because the decision is made synchronously before the relay.
176
+
177
+ Tutorials: [41-egress.ts](../examples/41-egress.ts), and [44-egress-rego.ts](../examples/44-egress-rego.ts) for a Rego policy.
@@ -0,0 +1,164 @@
1
+ # Verifying receipts on a pull request
2
+
3
+ A pull request is where a team reviews the work of an agent. The GitHub Action in this repository verifies the receipts of that work and puts the result on the pull request. A reviewer sees the result and installs nothing. The action is listed on the GitHub Marketplace as [agent-custody receipts](https://github.com/marketplace/actions/agent-custody-receipts).
4
+
5
+ The action runs `agent-custody verify --markdown` on a directory of receipt bundles. It writes one table to the job summary. On a pull request it also posts the same table as one comment, and it edits that comment on each later push. The `agent-custody export` command puts the receipts into the branch, and it refuses a receipt that publishes the call.
6
+
7
+ ## The workflow file
8
+
9
+ Copy this file to `.github/workflows/receipts.yml`.
10
+
11
+ ```yaml
12
+ name: receipts
13
+ on:
14
+ pull_request:
15
+ permissions:
16
+ contents: read
17
+ pull-requests: write
18
+ jobs:
19
+ verify:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
23
+ - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.0
24
+ with:
25
+ path: .custody/receipts
26
+ issuer-key: .custody/keys/agent.pub
27
+ ```
28
+
29
+ Pin the action to the commit of a release, as you pin every other action. A moving tag lets a third party change what runs with your token.
30
+
31
+ ## The inputs
32
+
33
+ | input | meaning | default |
34
+ | --- | --- | --- |
35
+ | `path` | a directory of receipt bundles; the action reads the `.json` files in it, not `<id>.authorization.json` files, not symbolic links, and not subdirectories | `.custody/receipts` |
36
+ | `issuer-key` | the public key files of the issuers you trust, one path on each line (required) | |
37
+ | `principal-key` | the public key files of the principals whose grants a gateway receipt carries, one path on each line; SDK and Claude Code hook receipts need none | |
38
+ | `log-url` | the URL of the log; the action fetches the log key from it (`verify --log-url`) | |
39
+ | `log-id` | the id that every tree head must name (`verify --log-id`) | |
40
+ | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.0` |
41
+ | `github-token` | a token that can write pull request comments | `github.token` |
42
+ | `comment-author` | the login of the account that `github-token` posts as; the action edits only a comment from this account | `github-actions[bot]` |
43
+
44
+ ## What the action does
45
+
46
+ 1. It sets up Node 22 and runs `npx @agent-custody/receipts@<version> verify --markdown <path> --issuer-key ...`.
47
+ 2. It writes the table to `$GITHUB_STEP_SUMMARY`.
48
+ 3. On a `pull_request` event, it looks for an earlier comment that starts with `<!-- agent-custody -->` and that the account in `comment-author` posted, and it edits that comment. When there is none, it posts a new comment.
49
+ 4. It fails the step when one receipt does not verify, and when the directory holds no receipt.
50
+
51
+ Any user can post a comment that starts with the marker line. The action ignores such a comment, because the author does not match. If you give `github-token` the token of a user or of an app, set `comment-author` to the login of that account. With the wrong login, the action does not find its own comment, and it posts a new comment on each push.
52
+
53
+ When the token cannot write a comment, the action prints a warning and keeps the job summary. This is the case for a pull request from a fork, where GitHub gives the `pull_request` event a read-only token. The step does not fail for that reason. Do not switch to `pull_request_target` to get the comment. That event gives a write token to a workflow that handles code from the fork.
54
+
55
+ The table has one row for each receipt. The failed rows come first.
56
+
57
+ | Receipt | Tool | Status | Result |
58
+ | --- | --- | --- | --- |
59
+ | `981d2afd-63f2-49ed-854a-83fc1bf1c035` | - | - | `receipt signature (issuer key)` |
60
+ | `6e2de8f3-4e51-43e5-af8b-a2b283dd7709` | `stripe.refund` | executed | verified |
61
+
62
+ - `Status` is the execution status in the signed receipt: `executed`, `denied`, `failed`, `error`, or `withheld`. When the signature does not verify, the table shows `-`, because nothing in that receipt is trusted.
63
+ - `Result` is `verified`, or the names of the checks that failed. [Verifying a receipt](verification.md#what-each-check-means) explains each check.
64
+ - A file that is not valid JSON shows `not a JSON file`, and a file with the wrong shape shows `not a receipt bundle`. The table never shows text from the file, because anyone who can change the branch can choose the file. The action does not read a symbolic link in `path`, so a link cannot bring a file from the runner into the comment.
65
+ - `verify --markdown` follows a symbolic link when the link is the file argument or the directory argument itself, but not a link inside the directory. The table shows only fixed error text or verified fields, so a followed link shows no text from its target.
66
+ - A file whose name is not `<receipt id>.json` fails with `file name matches receipt id`. A valid receipt under the name of another receipt could hide that receipt.
67
+ - The table shows 200 rows at most. Every failed row is in it.
68
+
69
+ ## What the table proves, and what it does not
70
+
71
+ A `verified` row proves that the issuer key you gave signed the receipt, that the receipt has not changed since, and that its checks hold. It does not prove that the receipts are all the calls the agent made. The author of the pull request chooses which receipts to commit. [Completeness](completeness.md) answers that question from the provider's side.
72
+
73
+ Keep the key files out of reach of the pull request. With the `pull_request` event, the workflow checks out the merge of the pull request. An author who changes `.custody/keys/agent.pub` in the same pull request can sign a receipt with a key of their own. Protect the key path with a code owner rule, or keep the key in a repository that the author cannot change.
74
+
75
+ ## How receipts get into the pull request
76
+
77
+ Receipts stay on the machine of the developer, in the `receiptsDir` of the gateway or the SDK. The action reads a directory in the checkout, so the receipts you want reviewed must be in the branch. The `export` command puts them there.
78
+
79
+ ```bash
80
+ agent-custody export --receipts ~/.config/agent-custody/receipts --out .custody/receipts \
81
+ --issuer-key .custody/keys/agent.pub --since 2026-11-02T09:00:00Z
82
+ git add .custody/receipts
83
+ ```
84
+
85
+ The command prints one line for each receipt, then a count.
86
+
87
+ ```
88
+ copied 6e2de8f3-4e51-43e5-af8b-a2b283dd7709.json
89
+ refused 981d2afd-63f2-49ed-854a-83fc1bf1c035.json: args and result in clear: a capture rule must withhold it (or give --allow-clear)
90
+ skipped 0b7c5f6e-93f7-4f06-a1f1-2f8d2d5f63a0.json: issued 2026-11-01T17:02:11.480Z, before --since
91
+ 1 copied, 1 refused, 1 skipped
92
+ ```
93
+
94
+ | flag | meaning |
95
+ | --- | --- |
96
+ | `--receipts <dir>` | the receipts directory of the machine |
97
+ | `--out <dir>` | where the copies go; the command creates it when it copies a receipt |
98
+ | `--issuer-key <pub>` | the public key of the issuer; repeat it for more than one issuer (required) |
99
+ | `--principal-key <pub>` | the public key of a principal whose grant a gateway receipt carries; SDK and Claude Code hook receipts need none |
100
+ | `--approval-key <pub>` | the public key of an approver, for a gateway receipt that carries approval evidence |
101
+ | `--since <ISO time>` | keep the receipts issued at or after this time, for example the start of the branch |
102
+ | `--allow-clear` | copy a receipt that carries plain values; see the warning below |
103
+
104
+ What the command does, in this order, for each file:
105
+
106
+ 1. It reads only the `<id>.json` files at the top level of `--receipts`. It never reads or copies `salts/`, `outbox/`, `*.authorization.json`, a subdirectory, a symbolic link, or any other file.
107
+ 2. It verifies the receipt with the issuer key. It refuses a receipt that does not verify, and a receipt whose file name is not its signed receipt id (`file name matches receipt id`, as the action does). `--issuer-key` is required, because the next step trusts what the signed receipt says about its own capture. An unverified file can claim anything.
108
+ 3. It skips a receipt issued before `--since`. A skipped receipt is not a failure.
109
+ 4. It runs the privacy check below. It refuses a receipt that fails the check.
110
+ 5. It copies the file byte for byte. It never rewrites a receipt, because the signature covers it. It writes nothing to `--out` for a refused or a skipped receipt.
111
+
112
+ The command exits 1 when it refuses any receipt, and when it copies none. The other receipts are still copied. A file in the directory with a `.json` name that is not a receipt bundle is refused as well.
113
+
114
+ ### The privacy check
115
+
116
+ The signed receipt has a capture note. The note lists the paths that hold a commitment in place of the value. The check reads the note, and it refuses a receipt when a side that holds data has no withheld path under it. The sides are the arguments (`request.args`), the result (`execution.result`, with the error message and the denial reason), and the value of each fact (`facts.<name>.value`). The command prints the sides in the reason, for example `args and result in clear`.
117
+
118
+ A field that a rule lists in its `clear` list stays in clear on purpose, so the check allows it when the rule withholds the other fields of that side. An empty side is not data.
119
+
120
+ `--allow-clear` turns the check off. The command then copies the receipt, marks it `(plain values: args, result)`, and prints this warning on standard error: each receipt marked with plain values publishes its arguments or its result to everyone who can read the output directory.
121
+
122
+ The check has limits. Read them before you rely on it.
123
+
124
+ - A receipt cannot be redacted after it is issued. The arguments and the result are signed as they are, and a change breaks the signature. Only a capture rule at issue time keeps a value out of the receipt. A receipt that an agent made before you set the rule stays in clear. Use `--since` to leave it out.
125
+ - A side whose every field is on the `clear` list has nothing left to withhold, so it has no commitment. The check cannot tell it from a side in mode `clear`, and it refuses it. A `Bash` call with the argument `command` alone is such a side under the second rule below. Read the receipt, and give `--allow-clear` if you accept it.
126
+ - The check does not look inside a value that the rule keeps in clear. The command text of a `Bash` call can hold a secret as well, for example a token in a `curl` header or in an `export` line. Keep a field in clear only when you accept that a reader sees all of it.
127
+ - The tool name, the ids, the timestamps, the status, and the policy decision always stay in clear.
128
+
129
+ ### A committed receipt publishes the call
130
+
131
+ By default a receipt carries the call in plain text. It holds the arguments the agent sent and the result the tool returned. For a `Bash` call that is the command and its output. For a file tool it is the content of the file. Anyone who can read the repository can read these values. If the repository is public, everyone can.
132
+
133
+ Before you commit a receipt, check these points.
134
+
135
+ 1. Set a capture rule before the session starts. A `capture` rule in the gateway config or in the SDK config (`sdk.json`) withholds a side of the call. With mode `digest`, the receipt holds one commitment over the fields you do not list in `clear`. With mode `encrypted`, it holds the same commitment and the value encrypted under a key that only you hold (`captureKeyEnv`). The rule applies to the receipt, to the log, and to every exporter. [Private evidence](usage.md#private-evidence) has the full rules. Two rules follow.
136
+
137
+ The strict rule. Every tool, every side, in mode `digest`. A reviewer sees the tool name, the status, and the decision of each call, and no value.
138
+
139
+ ```json
140
+ "capture": {
141
+ "*": { "args": { "mode": "digest" }, "result": { "mode": "digest" }, "facts": { "mode": "digest" } }
142
+ }
143
+ ```
144
+
145
+ The rule that shows the commands. The `command` argument of `Bash` stays in clear, and the result is in mode `digest`. A reviewer sees what the agent ran, and not what it printed. Every other tool takes the strict rule from `"*"`.
146
+
147
+ ```json
148
+ "capture": {
149
+ "*": { "args": { "mode": "digest" }, "result": { "mode": "digest" }, "facts": { "mode": "digest" } },
150
+ "Bash": { "args": { "mode": "digest", "clear": ["command"] }, "result": { "mode": "digest" } }
151
+ }
152
+ ```
153
+
154
+ The second rule has a cost. The command text can hold a secret: a token on a command line, a password in a connection string, a path that names a customer. The rule publishes that text. In the second rule the other arguments of `Bash` (`description`, `timeout`) are withheld together in one commitment. Use the strict rule when you cannot read every command.
155
+
156
+ 2. Run `agent-custody export` instead of a copy by hand. It leaves `salts/`, `outbox/`, `*.authorization.json`, and a local `log.jsonl` behind. The salts let a reader confirm a guess of a withheld value, and the authorization files and the log hold the call data as well. Never copy these files into a branch.
157
+ 3. Keep the capture key out of the repository and out of the workflow. The action needs no key. A receipt with withheld values verifies as committed, and the table still shows the tool and the status, because those parts stay in clear.
158
+ 4. Read one exported receipt before the first push. Run `agent-custody verify <file> --issuer-key <pub>` and read the `args` and `execution` rows.
159
+
160
+ A reviewer who needs a withheld value asks the owner of the key for a disclosure (`agent-custody reveal`), and verifies it with `verify --disclose`.
161
+
162
+ If you set up the Claude Code hook with `agent-custody init claude-code`, the `sdk.json` that it writes has no `capture` rule. Add the rule to that file before the session, and run `export` on the `receipts` directory next to it.
163
+
164
+ An agent that runs inside the CI job needs no transport. Write its receipts in the job and run the action in the same job.
package/docs/policies.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Writing policies
2
2
 
3
- Policies are written in [Cedar](https://www.cedarpolicy.com/), the language AWS uses for AgentCore and Verified Permissions. There is no home-grown policy language here. Every example on this page is executed against the real evaluator in the test suite.
3
+ Policies are written in [Cedar](https://www.cedarpolicy.com/), the language AWS uses for AgentCore and Verified Permissions, or in [Rego](https://www.openpolicyagent.org/docs/policy-language), the language of Open Policy Agent. There is no home-grown policy language here. Cedar is the default and most of this page uses it; [Rego](#rego) has its own section, including the choice between a Rego file the gateway compiles and an OPA server you already run. Every example on this page is executed against the real evaluator in the test suite.
4
4
 
5
5
  ## How a tool call becomes a Cedar request
6
6
 
@@ -168,6 +168,100 @@ permit(principal, action == Action::"memory.retract", resource)
168
168
  when { context.facts has target && context.facts.target.provenance == "claimed" };
169
169
  ```
170
170
 
171
+ ## Rego
172
+
173
+ A gateway decides by Rego in one of two ways. Give `policyFile` a path ending in `.rego`, and the gateway compiles the file itself. Or give `opa` instead of `policyFile`, and the gateway asks an OPA server you run. Both read the same request and the same rules, so a policy moves between them unchanged.
174
+
175
+ ### The request and the rules
176
+
177
+ The input is the Cedar request with plain strings for the three identifiers:
178
+
179
+ | Rego | value |
180
+ | --- | --- |
181
+ | `input.principal` | the agent id from the grant |
182
+ | `input.action` | the tool name |
183
+ | `input.resource` | the tool name |
184
+ | `input.context.args` | the call's arguments. **Provenance: claimed.** |
185
+ | `input.context.facts` | the gateway's own upstream lookups. **Provenance: observed.** |
186
+ | `input.context.grant` | `{ principal, scopes }` from the signed delegation. **Provenance: attested.** |
187
+
188
+ The policy declares `package agentcustody` and defines two rules:
189
+
190
+ - **`allow`**, a boolean. **Default deny:** the call is permitted only when `allow` is exactly `true`.
191
+ - **`deny`**, a set of strings. Any entry wins over `allow`, as a Cedar `forbid` wins over a `permit`. Its strings are the reasons in the receipt and in the message the agent gets.
192
+ - **Errors deny.** A policy that fails while it evaluates, or whose `allow` is not a boolean or whose `deny` is not a set of strings, denies the call. The receipt records the error.
193
+ - **The scope check and the fact lookups run first**, exactly as for Cedar, and no policy can override them.
194
+
195
+ The fixture policy from the top of this page, in Rego:
196
+
197
+ ```rego
198
+ package agentcustody
199
+
200
+ # Reads of customer records are permitted to any agent holding the scope.
201
+ allow if input.action == "customer.lookup"
202
+
203
+ # Refunds: a whole number of pence from 1 to 100000 (£1,000), and only for customers the gateway itself verified.
204
+ allow if {
205
+ input.action == "stripe.refund"
206
+ amount := input.context.args.amount
207
+ is_number(amount)
208
+ amount == floor(amount)
209
+ amount > 0
210
+ amount <= 100000
211
+ input.context.facts.customer.verified == true
212
+ }
213
+
214
+ deny contains "this customer is flagged for review" if {
215
+ input.action == "stripe.refund"
216
+ input.context.facts.customer.flagged == true
217
+ }
218
+ ```
219
+
220
+ A missing attribute is *undefined* in Rego, not an error: the rule does not hold when there is no `amount`, so the call is denied. That is the same outcome as Cedar's error, reached a different way. Rego has floats, which Cedar does not, so `amount <= 100000` alone would hold for `0.5`, and for `0` and `-1` as well. Amounts are integer minor units: `amount == floor(amount)` holds only for a whole number, and `amount > 0` sets the floor.
221
+
222
+ ### A Rego file, or an OPA server
223
+
224
+ | | `policyFile: "policy.rego"` | `opa: { "url": ... }` |
225
+ | --- | --- | --- |
226
+ | where the policy lives | a file beside `gateway.json`, as with Cedar | in the bundles of an OPA server your platform team runs |
227
+ | how it is evaluated | compiled to WebAssembly by `opa build` when the file loads or changes, then evaluated inside the gateway | an HTTP query to the server's Data API for every call |
228
+ | what it needs | the `opa` binary on `PATH` when the policy loads or changes. The gateway notices a change on the first call after it and compiles the file then, synchronously: the whole process waits for `opa build`, typically a few hundred milliseconds, so `/health` and every other call wait too. The compile has no deadline, so an `opa` that hangs stalls the gateway until it exits or the process is killed. A file that does not compile is compiled once, not again on each call, until it changes. The gateway image includes `opa` | a reachable server at an `https` URL, or `http` on a loopback address. A call it cannot answer within `timeoutMs` (default 2000) is denied |
229
+ | what `policyDigest` in a receipt is | the sha256 of the file's text, as for Cedar. The portal can name it, and anyone with the file can check it | the sha256 of the decision URL and the revision of every bundle the server reports. Map it back with `receipts/policy-reloads.jsonl`. A call the server did not answer is denied under the URL's own "unanswered" digest, never under a revision that did not decide it |
230
+ | changing the policy | write the file by rename. It applies from the next call, and a file that does not compile is refused while the policy in force stays | publish a new bundle revision. The first call under it records the new digest |
231
+ | builtins | those the WebAssembly runtime supports. `http.send`, `time.now_ns`, and other builtins it cannot run are refused when the file loads | everything the server allows, including `http.send` |
232
+ | best for | a gateway that should decide on its own, with the policy text pinned in every receipt | an organisation that already governs policy centrally in OPA and wants agents under the same bundles |
233
+
234
+ **What a receipt can prove differs.** With a file, the receipt pins the exact text that decided, so a verifier holding the file can show it was this policy. With a server, the receipt pins only what the server *said* it was running: the bundle revisions in its `provenance` answer. The gateway asks for provenance on every query, records each new combination in `policy-reloads.jsonl` with the bundle names and revisions, and prints it. Serve the policy from a bundle built with `opa build --revision <id>`, so the revision names a version you can find again. A server that reports no revision still works, but the gateway warns at start and on each new answer that its receipts cannot name the policy. `agent-custody check` warns about it as well.
235
+
236
+ **A server outside the policy also decides.** A Rego file is evaluated where the gateway runs, under the operator's control. An OPA server's answer is trusted as it comes back over HTTP. Run it where only your platform team can change it, and give the gateway a token with `tokenEnv` when the server requires one. Each query carries the call's arguments and that token, so the gateway refuses a plain `http` URL unless the host is a loopback address, and it never follows a redirect: a 3xx answer denies the call. The gateway refuses to start when it cannot reach the server, or when the server does not define the package.
237
+
238
+ A gateway config with an OPA server:
239
+
240
+ ```json
241
+ "opa": {
242
+ "url": "http://localhost:8181",
243
+ "decision": "agentcustody",
244
+ "tokenEnv": "OPA_TOKEN",
245
+ "timeoutMs": 2000
246
+ }
247
+ ```
248
+
249
+ `decision` is the package path under `/v1/data`, such as `authz/agents` for `package authz.agents`, and defaults to `agentcustody`. The document at that path must have the `allow` and `deny` rules above. The gateway posts `{ "input": ... }` to `<url>/v1/data/<decision>?provenance=true`.
250
+
251
+ ### Testing and simulating a Rego policy
252
+
253
+ `opa test` runs Rego unit tests as usual. `evaluateRego` and `compileRego` from `@agent-custody/receipts` evaluate a policy exactly as the gateway does, with the same decision and digest:
254
+
255
+ ```ts
256
+ import { compileRego, evaluateRego, policyDigest } from "@agent-custody/receipts";
257
+
258
+ const text = readFileSync("policy.rego", "utf8");
259
+ const { policy, errors } = compileRego(text); // errors: why it cannot load
260
+ const d = evaluateRego(policy!, policyDigest(text), { agentId: "support-agent", tool: "stripe.refund", context: { args: { amount: 50000 }, facts: { customer: { verified: true } } } });
261
+ ```
262
+
263
+ `agent-custody policy simulate --policy proposed.rego ...` replays recorded receipts against a Rego policy, including receipts a Cedar policy decided, so a move from Cedar to Rego can be checked against history before it is enforced. `agent-custody check` compiles a `.rego` file, or queries the OPA server once. An SDK issuer reads a `.rego` `policyFile` the same way. The console's policy editor, the deny report, and `init claude-code` work with Cedar only for now.
264
+
171
265
  ## Saying why a rule denies
172
266
 
173
267
  Put a `@reason("...")` annotation before a `forbid` rule. The Claude Code hook shows the text to the agent and to the person who reads the session, and `agent-custody report` prints it before the rule.
@@ -236,3 +330,20 @@ The report lists every call whose `allow` or `deny` decision changes, grouped by
236
330
  Every run records a `runId`, `timestamp`, the proposed text's sha256 as `policyDigest`, and the original digests as `previousPolicyDigests`. `--out` saves the full JSON report, and `--json` prints it to stdout. Changes alone exit 0. A report that cannot replay every call says `INCOMPLETE` and exits 1: `skipped` names each receipt and why. This includes record-only receipts with no policy baseline, withheld arguments or fact values, calls whose receipt is missing, and calls stopped before Cedar could evaluate. Grant failures cannot become permits through a policy change, and neither can an approval refusal: the gateway checks the approval before Cedar runs, so the call is skipped as a non-policy gate. The approval record says so even under a private rule. Withheld results alone do not prevent replay. A reconciliation receipt is a provider read, so no policy decision exists to replay. The report counts it in `reconciliations`, not in `evaluated` or `skipped`, and it does not make the report incomplete. A reconciliation whose original receipt is missing is the exception: the call that it settles cannot be replayed, so the report skips that call and says `INCOMPLETE`. The library trusts a reconciliation receipt only after `verifyBundle` accepts it; the CLI and the console verify first.
237
331
 
238
332
  The report is an analysis of the supplied receipt directory; it does not prove that the directory contains the whole history. Keep the report beside the proposed policy and review the changed receipt ids before switching from observe mode to enforcement. [Tutorial 28](../examples/28-policy-simulation.ts) records three refunds, stops the gateway, and replays them against a lower limit.
333
+
334
+ ## How an arrival at the door becomes a Cedar request
335
+
336
+ The [door](door.md) uses the same evaluator for arrivals at your own HTTP surface. `principal` is `Agent::"<agent>"` for the agent a verified grant names, and `Agent::"unknown"` for every other arrival: a declared name is a claim and stays in the arrival fact. `action` and `resource` are the route the arrival fell under. `context.args` is the request (`method`, `path`, `query`, `headers`, a JSON `body` when small, `bodyBytes`, `bodyDigest`; `bodyOversized: true` and no digest when the body passed `maxBodyBytes`), claimed. The policy reads it with `null` members dropped and numbers that are not safe integers as strings, since Cedar refuses both. `context.facts.arrival` is the door's own observation of the arrival: its `class` (`verified`, `claimed`, `unknown`), `subject`, what became of its `grant`, and its `remote` address. `context.grant` is present only for a verified arrival. A policy that lets `unknown` through on a route lets everything through on that route.
337
+
338
+ ```cedar
339
+ permit(principal, action == Action::"catalogue", resource);
340
+
341
+ permit(principal, action == Action::"refund", resource)
342
+ when {
343
+ context.facts.arrival.class == "verified" &&
344
+ context.args.body.amount > 0 &&
345
+ context.args.body.amount <= 5000
346
+ };
347
+ ```
348
+
349
+ A bound on an amount needs both ends: `amount <= 5000` alone lets a negative refund through, and the door relays the body as it came. A permit that names an agent, `principal == Agent::"shopping-agent"`, is satisfied only by a verified grant for that agent: a declared name never reaches the principal slot. `agent-custody check` still warns on a permit that names an agent without requiring `context.facts.arrival.class == "verified"`, because a policy copied from the gateway reads as if it did.
package/docs/sdk.md CHANGED
@@ -48,13 +48,15 @@ The command sets up custody for your own Claude Code sessions. It prints each st
48
48
 
49
49
  1. It makes an agent key in `~/.config/agent-custody/keys/`.
50
50
  2. It writes `sdk.json` in `~/.config/agent-custody/` with `"mode": "observe"` and a `receiptsDir`. No log is configured, so the receipts stay on your machine.
51
- 3. It writes a starter deny set to `policy.cedar`: force push, `rm -rf` on `/`, `~`, and `$HOME`, `terraform destroy`, `terraform apply -destroy`, and `drop database` in both cases. Each rule has a `@reason`, so the denial text says what the rule forbids. The policy permits every other call, and it permits `git push --force-with-lease` (see [The starter deny set](#the-starter-deny-set)).
51
+ 3. It writes a starter deny set to `policy.cedar`: force push (`--force`, `-f`, and `+refspec`), `rm -rf` on `/`, `~`, and `$HOME`, `terraform destroy`, `terraform apply -destroy`, and `drop database` in both cases. Each rule has a `@reason`, so the denial text says what the rule forbids. The policy permits every other call, and it permits `git push --force-with-lease` (see [The starter deny set](#the-starter-deny-set)).
52
52
  4. It registers the `PreToolUse`, `PostToolUse`, and `PostToolUseFailure` hooks in `.claude/settings.local.json` of the current directory. Claude Code adds that file to your global git ignore only when Claude Code itself creates it, so `init` does not rely on that. When the project is a git repository and git does not ignore the file, `init` prints a warning with the line to add to `.gitignore`: `.claude/settings.local.json`. The file holds absolute paths of your home directory. `init` never edits `.gitignore`. With `--user`, the hooks go to `~/.claude/settings.json` and apply to every project.
53
53
  5. It prints the next step: start a Claude Code session, then run the report.
54
54
 
55
55
  The hook command in the settings file uses absolute paths: the Node binary, the CLI script that runs now, and the absolute path of `sdk.json`. The command merges into an existing settings file. It keeps every other key and every other hook, and it does not add a hook that is already there. If the settings file is not valid JSON, the command stops with an error and changes nothing.
56
56
 
57
- Each hook is its own process, and Claude Code runs hooks at the same time for parallel tool calls, subagents, and several sessions. The local log `log.jsonl` takes the lock file `log.jsonl.lock` for each append, reads the leaves that other processes appended, and then writes its own leaf. A lock file that is older than ten seconds belongs to a process that died, and the next append removes it.
57
+ Each hook is its own process, and Claude Code runs hooks at the same time for parallel tool calls, subagents, and several sessions. The local log `log.jsonl` takes the lock file `log.jsonl.lock` for each append, reads the leaves that other processes appended, and then writes its own leaf. The lock file holds an owner token, the process id, and the start time of the process. A holder removes the lock file only when it still holds its own token. A lock is stale when its process on this host is gone. The lock of a live process on this host is never broken. The lock of a process on another host, or a lock file with no readable owner, is stale when nobody touched it for 60 seconds. To break a stale lock, a writer first takes `log.jsonl.lock.break` with an exclusive create, so only one writer breaks at a time. It then reads the lock again, and moves it away only when its inode and token are still the ones it judged stale. A lock file that is gone between the create and the judgment is not broken: the writer tries the create again. The outbox of the gateway uses the same lock code. `agent-custody prune` takes the same lock, so a hook that appends during a prune waits and its leaf is kept.
58
+
59
+ A writer that waits for the lock gives up after 20 seconds. A `PreToolUse` hook that gives up cannot record a denial: in enforce mode the call is still blocked, and the denial text ends with `no receipt: <reason>`. A `PostToolUse` or `PostToolUseFailure` hook that gives up exits with code 1 and prints the error on stderr. That receipt is lost, because the tool call has already run and the hook does not retry. The other receipts are not affected. If a process was killed in the middle of a write, the last line of `log.jsonl` has no newline. The next append moves those bytes to `log.jsonl.torn`, and the log continues after the last whole line. No leaf was returned for those bytes.
58
60
 
59
61
  The hook command pins the path of the Node binary that runs `init`. With nvm, a removed Node version breaks the hook, and every tool call then prints an error. After you remove a Node version, run `init` again. The second run updates the path.
60
62
 
@@ -76,15 +78,29 @@ Each rule matches the text of a Bash command with the Cedar `like` operator, and
76
78
 
77
79
  | command | the policy |
78
80
  | --- | --- |
79
- | `git push --force`, `git push -f`, `git push origin main -f` | denied |
80
- | `git push --force-with-lease` | allowed. It is a force push that fails when the remote has new commits, so it is the safer form. The `@reason` of the rule says so |
81
- | `git push origin main && rm -f stale.lock`, `git push origin fix-f` | allowed |
82
- | `rm -rf /`, `rm -fr /`, `rm -rf /*`, `rm -rf ~`, `rm -rf $HOME`, `rm -rf ${HOME}` | denied |
83
- | `rm -rf /tmp/build`, `rm -rf ~/projects/app/dist` | allowed |
81
+ | `git push --force`, `git push -f`, `git push origin main -f`, `git push origin -f main`, `git push origin +main`, `git -C repo push --force` | denied |
82
+ | `git push origin main --force && gh pr create`, `git push origin +main && echo done` | denied |
83
+ | `git push --force-with-lease`, `git -C repo push --force-with-lease` | allowed. It is a force push that fails when the remote has new commits, so it is the safer form. The `@reason` of the rule says so |
84
+ | `git push origin main && rm -f stale.lock`, `git push origin fix-f`, `git push origin main && npm install --force`, `git push && git status -f` | allowed |
85
+ | `rm -rf /`, `rm -fr /`, `rm -Rf /`, `rm -r -f /`, `rm -rf /*`, `rm -rf ~`, `rm -rf $HOME`, `rm -rf "$HOME"`, `rm -rf ${HOME}` | denied |
86
+ | `rm -rf /tmp/build`, `rm -rf ~/projects/app/dist`, `rm -rf "$HOME"/projects/app/dist` | allowed |
84
87
  | `terraform destroy`, `terraform apply -destroy` | denied |
85
88
  | `terraform plan`, `terraform plan -destroy` | allowed |
86
89
 
87
- A `--force` flag matches anywhere after `git push`. A `-f` flag matches right after `git push` or at the end of the command. A `-f` in the middle of a command does not match. The reason is that `like` cannot find where one shell command ends and the next starts, and a match there would block `git push origin main && rm -f stale.lock`. `test/claude-init.test.ts` runs every command of this table.
90
+ A force push has `--force`, `-f`, or a refspec that starts with `+`. The push can be `git push` or `git -C <dir> push` (any `git` option before `push`). A flag counts in three cases: it is the first argument after `push`, or no `&`, `|`, `;`, or newline follows `push`, or one of them follows the flag. A flag that comes after an operator belongs to another command, so `git push origin main && npm install --force` passes.
91
+
92
+ The `rm` rules know the flags `-rf`, `-fr`, `-Rf`, `-fR`, and the separate forms `-r -f`, `-f -r`, `-R -f`, `-f -R`. The home directory can be `~`, `$HOME`, or `${HOME}`, and `$HOME` can be in double quotes.
93
+
94
+ The rule ids are the place of each rule in `policy.cedar`: the permit rule is `policy0`, the force push rule is `policy1`, and `terraform destroy` is `policy5`. Change a rule in place, and add a new rule at the end of the file, so that an id keeps naming the same rule. Receipts, reports, and pages name rules by id.
95
+
96
+ What Cedar `like` cannot express, and the starter policy therefore does not catch:
97
+
98
+ - `like` has `*` and nothing else. It cannot find where one shell command ends. A chain with two operators after `git push` can be denied by mistake: `git push && npm install --force && echo done` is denied.
99
+ - It cannot read shell words. These forms pass: `rm --recursive --force /`, `rm --no-preserve-root -rf /`, `terraform -chdir=infra destroy`, a command in a variable or in a script file, and a path that reaches the same directory (`rm -rf /usr/..`).
100
+ - It cannot tell a flag from the text of an argument. `git push origin "message -f"` is denied.
101
+ - A force push that the git configuration or an alias sets (a `+` in `remote.<name>.push`) is not in the text of the command.
102
+
103
+ Use a sandbox, or a protected branch on the remote, for these. `test/claude-init.test.ts` runs every command of this table and of this list.
88
104
 
89
105
  ### The denial text
90
106
 
@@ -110,7 +126,7 @@ The receipt does not change. It keeps the policy ids and the policy digest, and
110
126
  agent-custody report --config ~/.config/agent-custody/sdk.json
111
127
  ```
112
128
 
113
- `init` prints this command with absolute paths. The report reads the receipts directory of the config and verifies each receipt with the agent's key. Then it prints `would have denied N calls`, and for each call the tool, the command or the file path, the `@reason` of the rule when it has one, the Cedar rule, and the receipt id. A receipt that does not verify is counted apart, listed with the reason, and never counted as a denial. The command then exits with code 1. The report ends with the next step: remove the `"mode": "observe"` line from `sdk.json` to enforce the policy. A denial that the policy enforced (a config without the observe line) is listed apart as `denied`.
129
+ `init` prints this command with absolute paths. The report reads the receipts directory of the config and verifies each receipt with the agent's key. Then it prints `would have denied N calls`, and for each call the tool, the command or the file path, the `@reason` of the rule when it has one, the Cedar rule (cut to 160 characters), and the receipt id. A receipt that does not verify is counted apart, listed with the reason, and never counted as a denial. The command then exits with code 1. The report ends with the next step: remove the `"mode": "observe"` line from `sdk.json` to enforce the policy. A denial that the policy enforced (a config without the observe line) is listed apart as `denied`.
114
130
 
115
131
  `policy simulate` answers another question: what a proposed policy would change in recorded history. Use `report` to read what the policy in the config decided in observe mode.
116
132
 
@@ -41,7 +41,7 @@ Each row names the attacker, the move, the defence, and whether the defence is a
41
41
  | Feed the policy lies in the arguments | `context.args` is `claimed`; policies that matter read `context.facts`, which the gateway fetched itself and marks `observed`. A policy that decides on args alone is the operator's choice and the receipt shows it. Arguments are passed to Cedar as data only: a value shaped as a Cedar entity or extension (`__entity`, `__extn`) is a deny before evaluation, so an argument cannot satisfy a comparison by its shape. | evidence: provenance is in the receipt |
42
42
  | Make the gateway run a fact lookup on the way to a denial | A fact lookup runs before the policy decides, because the policy decides on it, and only after the tool is in the grant's scope. It is therefore a read the gateway makes on the agent's request: a fact tool named in `precommit` is refused at startup, so no consequential call can be reached through a lookup, and every lookup is on the receipt with its arguments. | deployment: fact tools must be reads |
43
43
  | Read the gateway's secrets from a tool process | A stdio upstream is started with a minimal environment (the path, home, and temp directories, plus what its own config names), never the gateway's, so the tokens other upstreams and the log are given do not reach it. | deployment |
44
- | Bypass the gateway with a credential in its own environment | Nothing in the packages prevents this. The gateway covers the tools behind it and no others. | not covered; the deployment must keep credentials out of the agent |
44
+ | Bypass the gateway with a credential in its own environment | The gateway covers only the tools behind it. Two deployment steps narrow this route: credential custody, where tool credentials live only in the gateway, and egress lockdown, where the agent's network reaches only the gateway and the [egress witness](egress.md) (`deploy/gateway/lockdown`). Under lockdown, a direct call has to pass through the witness. The witness identifies the agent by the proxy credential it checked, lets the Cedar or Rego policy refuse or allow the destination, and receipts the connection either way. That receipt is an observed bypass: it records the destination, the times, and the byte counts, never the payload, because there is no TLS interception. The witness sees nothing when lockdown is off, since an agent can ignore `HTTPS_PROXY`, and it relays no protocol other than HTTP. `completeness` still catches a bypass after the fact, for Stripe. | deployment: custody and lockdown; detected and receipted by the egress witness, never its payload |
45
45
  | Skip an in-process hook or SDK wrapper | Same: an SDK receipt is the agent's own report, and every field in it is `claimed`. | not covered; use the gateway for anything consequential |
46
46
  | Write memory the fleet will trust | Writes not made through the gateway are `claimed` and quarantined until a gateway confirms them; reads leave them out unless asked for. | deployment |
47
47
  | Exhaust the log so its own calls are withheld rather than recorded | A withheld call shows `allow` next to `withheld` and nothing happened upstream; there is no state in which an action occurs without a receipt when `precommit` names the tool. | evidence |
package/docs/tutorials.md CHANGED
@@ -46,7 +46,14 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
46
46
  | 34 | strict mode | [34-strict-mode.ts](../examples/34-strict-mode.ts) | `check` lists what strict mode would refuse; a local log and a log that is not hash-only are refused at startup; behind a hash-only log with a pinned key, a read is precommitted and its receipt says `issuer.strict`; `requireStrict` accepts it and refuses an ordinary receipt; with the log down the call is not forwarded and the outbox stays empty | `src/config.ts`, `src/gateway.ts`, `src/check.ts`, `src/verify.ts` |
47
47
  | 35 | completeness from the provider's side | [35-completeness.ts](../examples/35-completeness.ts) | two refunds through the gateway and a third issued straight through the provider; the auditor lists the provider's refunds with a read-only key, matches two to verified receipts, and reports the third as an action with no receipt |
48
48
  | 36 | one command for Claude Code | [36-claude-code-init.ts](../examples/36-claude-code-init.ts) | `init claude-code` in a temporary home: the key, the observe-mode config, the starter policy, and the three hooks; a second run adds nothing; a session of four calls; the report that lists the two calls the policy would have denied | `src/claude-init.ts`, `src/deny-report.ts` |
49
+ | 37 | receipts on a pull request | [37-pr-summary.ts](../examples/37-pr-summary.ts) | two receipts from a gateway verify into one Markdown table (what `verify --markdown` and the GitHub Action post); one changed byte makes the table name the failed check; a directory with no receipt fails | `src/pr-summary.ts`, `action.yml` |
49
50
  | 38 | an incident replay | [38-incident-replay.ts](../examples/38-incident-replay.ts) | the same setup as `init claude-code --enforce`, in a temporary home; a scripted Claude Code session that runs the real hook command for each event: `terraform plan` runs and gets an executed receipt, `terraform destroy -auto-approve` and `rm -rf ~` are denied before they run, with the denial text and the receipt id; a reviewer with only the public key verifies all three receipts, and a stranger's key fails | `src/sdk/claude.ts`, `src/claude-init.ts`, `templates/claude-code.cedar` |
51
+ | 39 | exporting receipts to a pull request | [39-export.ts](../examples/39-export.ts) | an agent works under a capture rule; `export` copies the two receipts that withhold their values, byte for byte, and refuses the one that records plain values; one changed byte makes it refuse a third | `src/export.ts`, `src/cli.ts` |
52
+ | 40 | the door: a receipted reverse proxy in front of your own API | [40-door.ts](../examples/40-door.ts) | a stand-in shop behind the door; an unknown arrival reads the catalogue and is refused a refund; an agent with a grant signed by the shop's principal is verified and refunds within the policy, refused above it; a forged grant is claimed; the origin saw only what was allowed; both receipts verified | `src/door.ts`, `src/config.ts` |
53
+ | 41 | the egress witness: a receipted forward proxy for calls around the gateway | [41-egress.ts](../examples/41-egress.ts) | a locked-down agent tries a direct call to a payment provider (CONNECT api.stripe.com:443) and the witness refuses it; an allowed tunnel to a stand-in docs mirror is relayed and recorded by destination and byte counts, never its contents; a connection with no proxy credential gets 407; the refusal's receipt verifies with the witness's key | `src/egress.ts`, `src/config.ts` |
54
+ | 42 | a first egress policy from what the agents did in observe mode | [42-egress-draft.ts](../examples/42-egress-draft.ts) | the witness observes an agent reach a docs mirror three times and a paste site once; `egress draft-policy` verifies the receipts and drafts one permit with a count and first and last time per destination, under a warning that it permits everything the agent did; the review deletes the paste site, and the enforced policy relays the mirror and refuses the paste site | `src/egress-draft.ts` |
55
+ | 43 | an OWASP ACS Guardian whose decisions land in a transparency log | [43-acs-guardian.ts](../examples/43-acs-guardian.ts) | a log runs under a key of its own; the ACS README's sample `steps/toolCallRequest` piped through `agent-custody acs` is allowed, its receipt carries the session's `chain_hash`, and it verifies offline with only the Guardian's and the log's public keys; in one session a read outside `/reports` is denied, a result for an allowed request passes, and a result for an unknown request is denied; a consistency proof shows the log after the deny extends the log that held the first decision (ACS issue #18, directions 1 and 3) | `src/acs.ts`, `src/config.ts` |
56
+ | 44 | the egress witness deciding by Rego | [44-egress-rego.ts](../examples/44-egress-rego.ts) | `policyFile: "policy.rego"`: the witness compiles it with `opa build`; a Rego `deny` refuses CONNECT api.stripe.com:443 with its string as the reason, an `allow` relays the docs mirror for the agent the credential proved, a guessed secret naming that agent is the principal `"unknown"` and gets 407, and an edit that does not compile leaves the policy in force; the refusal verifies | `src/egress.ts`, `src/policy-rego.ts` |
50
57
 
51
58
  ## How policies are defined, in one paragraph
52
59