@agent-custody/receipts 0.14.0 → 0.15.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.
- package/README.md +33 -20
- package/dist/check.d.ts +10 -0
- package/dist/check.js +179 -3
- package/dist/cli.js +82 -11
- package/dist/config.d.ts +128 -1
- package/dist/config.js +92 -3
- package/dist/console.js +16 -7
- package/dist/deny-report.js +1 -1
- package/dist/door.d.ts +203 -0
- package/dist/door.js +712 -0
- package/dist/export.d.ts +39 -0
- package/dist/export.js +95 -0
- package/dist/gateway.js +53 -21
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/issue.js +5 -65
- package/dist/lock.d.ts +12 -0
- package/dist/lock.js +124 -0
- package/dist/log.d.ts +11 -5
- package/dist/log.js +55 -42
- package/dist/opa-server.d.ts +34 -0
- package/dist/opa-server.js +93 -0
- package/dist/policy-rego.d.ts +30 -0
- package/dist/policy-rego.js +114 -0
- package/dist/pr-summary.d.ts +25 -0
- package/dist/pr-summary.js +87 -0
- package/dist/receipt.d.ts +3 -1
- package/dist/retention.d.ts +1 -1
- package/dist/retention.js +14 -4
- package/dist/sdk/index.js +10 -3
- package/dist/simulate.d.ts +3 -1
- package/dist/simulate.js +15 -7
- package/dist/verify.js +6 -3
- package/docs/configuration.md +3 -3
- package/docs/door-signals.md +66 -0
- package/docs/door.md +168 -0
- package/docs/github-action.md +164 -0
- package/docs/policies.md +112 -1
- package/docs/sdk.md +25 -9
- package/docs/tutorials.md +3 -0
- package/docs/usage.md +2 -2
- package/docs/verification.md +9 -2
- package/package.json +14 -13
- package/templates/claude-code.cedar +287 -10
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/merkle.json +123 -0
- package/vectors/receipts.json +1258 -1005
package/dist/sdk/index.js
CHANGED
|
@@ -7,7 +7,8 @@ import { digestOf, loadPrivateKey } from "../crypto.js";
|
|
|
7
7
|
import { createIssuer } from "../issue.js";
|
|
8
8
|
import { openExporter } from "../otel.js";
|
|
9
9
|
import { openLog } from "../log-sink.js";
|
|
10
|
-
import { evaluate, policyReasons } from "../policy.js";
|
|
10
|
+
import { evaluate, policyDigest, policyReasons } from "../policy.js";
|
|
11
|
+
import { compileRego, evaluateRego, isRegoFile } from "../policy-rego.js";
|
|
11
12
|
export const SDK_VERSION = "0.1.0";
|
|
12
13
|
/** True when a decision is a deny that must be enforced: a deny made in observe mode (`enforced: false`) is recorded, not acted on. */
|
|
13
14
|
export function denies(policy) {
|
|
@@ -36,11 +37,17 @@ export function createSdkIssuer(cfg) {
|
|
|
36
37
|
// the capture rules are applied by the issuer to every statement it signs, so every adapter's receipt gets them
|
|
37
38
|
const issuer = createIssuer(key, cfg.receiptsDir, openLog(cfg, key), { exporter: openExporter(cfg), capture: { rules: cfg.capture, key: captureKey } });
|
|
38
39
|
const policyText = cfg.policyFile ? readFileSync(cfg.policyFile, "utf8") : null;
|
|
39
|
-
|
|
40
|
+
// a Rego file is compiled once, here: one that does not compile stops the issuer from being created
|
|
41
|
+
const rego = policyText !== null && isRegoFile(cfg.policyFile) ? compileRego(policyText) : undefined;
|
|
42
|
+
if (rego && !rego.policy)
|
|
43
|
+
throw new Error(`${cfg.policyFile} does not compile: ${rego.errors.join("; ")}`);
|
|
44
|
+
const regoDigest = rego ? policyDigest(policyText) : "";
|
|
45
|
+
const ruleReasons = policyText === null || rego ? [] : policyReasons(policyText);
|
|
40
46
|
const decide = (ev) => {
|
|
41
47
|
if (policyText === null)
|
|
42
48
|
return null;
|
|
43
|
-
const
|
|
49
|
+
const request = { agentId: cfg.agentId, tool: ev.tool, context: { args: ev.args, facts: {} } };
|
|
50
|
+
const d = rego?.policy ? evaluateRego(rego.policy, regoDigest, request) : evaluate(policyText, request);
|
|
44
51
|
return cfg.mode === "observe" ? { ...d, enforced: false } : d;
|
|
45
52
|
};
|
|
46
53
|
function record(ev, outcome, policy = null) {
|
package/dist/simulate.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface SimulationOptions {
|
|
|
42
42
|
disclosures?: ReadonlyMap<string, unknown>;
|
|
43
43
|
/** Calls that have no receipt to replay. Each counts in `total` and is reported as skipped. */
|
|
44
44
|
unreplayable?: SimulationSkip[];
|
|
45
|
+
/** The proposed policy's language. Rego is compiled once with the opa binary on PATH. Default cedar. */
|
|
46
|
+
language?: "cedar" | "rego";
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* Check an authorization bundle that has no receipt, as the verifier does for an embedded one: the issuer signed it, it
|
|
@@ -50,7 +52,7 @@ export interface SimulationOptions {
|
|
|
50
52
|
*/
|
|
51
53
|
export declare function verifyOrphanAuthorization(bundle: AuthorizationBundle, issuerKeys: PublicKeyRef[], logKeys: PublicKeyRef[]): AuthorizationStatement["predicate"];
|
|
52
54
|
/**
|
|
53
|
-
* Compare a proposed Cedar policy with recorded policy decisions, using each receipt's original arguments, fact
|
|
55
|
+
* Compare a proposed Cedar or Rego policy with recorded policy decisions, using each receipt's original arguments, fact
|
|
54
56
|
* values, agent, and (for gateways) grant context. Observe-mode decisions are the baseline even when the call ran.
|
|
55
57
|
* Receipts are not signature-verified here; verify their bundles separately when their authenticity matters. A
|
|
56
58
|
* reconciliation receipt is trusted as a provider read only after `verifyBundle` accepts it: the library checks no more
|
package/dist/simulate.js
CHANGED
|
@@ -6,6 +6,7 @@ import { canonicalize, dsseVerify } from "./crypto.js";
|
|
|
6
6
|
import { decodeDelegation, DELEGATION_TYPE, delegationValidAt } from "./delegation.js";
|
|
7
7
|
import { leafHash, verifyInclusion } from "./log.js";
|
|
8
8
|
import { evaluate, policyDigest } from "./policy.js";
|
|
9
|
+
import { compileRego, evaluateRego } from "./policy-rego.js";
|
|
9
10
|
import { AUTHORIZATION_PREDICATE_TYPE, RECEIPT_TYPE, TREEHEAD_TYPE } from "./receipt.js";
|
|
10
11
|
import { structuralProblem } from "./verify.js";
|
|
11
12
|
const strings = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
@@ -55,7 +56,7 @@ export function verifyOrphanAuthorization(bundle, issuerKeys, logKeys) {
|
|
|
55
56
|
return statement.predicate;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
|
-
* Compare a proposed Cedar policy with recorded policy decisions, using each receipt's original arguments, fact
|
|
59
|
+
* Compare a proposed Cedar or Rego policy with recorded policy decisions, using each receipt's original arguments, fact
|
|
59
60
|
* values, agent, and (for gateways) grant context. Observe-mode decisions are the baseline even when the call ran.
|
|
60
61
|
* Receipts are not signature-verified here; verify their bundles separately when their authenticity matters. A
|
|
61
62
|
* reconciliation receipt is trusted as a provider read only after `verifyBundle` accepts it: the library checks no more
|
|
@@ -66,9 +67,14 @@ export function verifyOrphanAuthorization(bundle, issuerKeys, logKeys) {
|
|
|
66
67
|
* The receipts are read once, one at a time, so a caller can verify and parse a large history lazily.
|
|
67
68
|
*/
|
|
68
69
|
export function simulatePolicy(policyText, receipts, options = {}) {
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
throw new Error(`invalid
|
|
70
|
+
const rego = options.language === "rego" ? compileRego(policyText) : undefined;
|
|
71
|
+
if (rego && !rego.policy)
|
|
72
|
+
throw new Error(`invalid Rego policy: ${rego.errors.join("; ")}`);
|
|
73
|
+
if (!rego) {
|
|
74
|
+
const parsed = cedar.checkParsePolicySet({ staticPolicies: policyText });
|
|
75
|
+
if (parsed.type === "failure")
|
|
76
|
+
throw new Error(`invalid Cedar policy: ${parsed.errors.map((e) => e.message).join("; ")}`);
|
|
77
|
+
}
|
|
72
78
|
const unreplayable = options.unreplayable ?? [];
|
|
73
79
|
const report = {
|
|
74
80
|
runId: randomUUID(),
|
|
@@ -122,7 +128,7 @@ export function simulatePolicy(policyText, receipts, options = {}) {
|
|
|
122
128
|
}
|
|
123
129
|
digests.add(previous.policyDigest);
|
|
124
130
|
if (!receiptId || !tool || typeof original.agent.id !== "string" || !original.agent.id
|
|
125
|
-
|| !Number.isFinite(Date.parse(original.timestamp)) || !["sdk", "gateway"].includes(original.issuer.kind)) {
|
|
131
|
+
|| !Number.isFinite(Date.parse(original.timestamp)) || !["sdk", "gateway", "door"].includes(original.issuer.kind)) {
|
|
126
132
|
skip("malformed receipt: receipt id, tool, agent, timestamp, or issuer is invalid");
|
|
127
133
|
continue;
|
|
128
134
|
}
|
|
@@ -154,7 +160,8 @@ export function simulatePolicy(policyText, receipts, options = {}) {
|
|
|
154
160
|
args: p.request.args,
|
|
155
161
|
facts: Object.fromEntries(Object.entries(p.facts).map(([name, fact]) => [name, fact.value])),
|
|
156
162
|
};
|
|
157
|
-
|
|
163
|
+
// a door receipt carries a grant only when the arrival presented one; the policy then saw context.grant, else not
|
|
164
|
+
if (p.issuer.kind === "gateway" || (p.issuer.kind === "door" && p.delegation)) {
|
|
158
165
|
const envelope = p.delegation?.envelope;
|
|
159
166
|
const grant = envelope?.payloadType === DELEGATION_TYPE ? decodeDelegation(envelope) : null;
|
|
160
167
|
if (!grant || grant.agent !== p.agent.id || grant.principal !== p.principal.id) {
|
|
@@ -173,7 +180,8 @@ export function simulatePolicy(policyText, receipts, options = {}) {
|
|
|
173
180
|
}
|
|
174
181
|
let proposed;
|
|
175
182
|
try {
|
|
176
|
-
|
|
183
|
+
const request = { agentId: p.agent.id, tool, context };
|
|
184
|
+
proposed = rego?.policy ? evaluateRego(rego.policy, report.policyDigest, request) : evaluate(policyText, request);
|
|
177
185
|
}
|
|
178
186
|
catch (e) {
|
|
179
187
|
// An evaluator exception is a deny, just as at the gateway; it must never become an allow in a replay.
|
package/dist/verify.js
CHANGED
|
@@ -53,8 +53,8 @@ function verifyOriginalAuthorization(bundle, opts) {
|
|
|
53
53
|
add("structural parts in clear", !problem, problem ?? undefined);
|
|
54
54
|
if (problem)
|
|
55
55
|
return { ok: false, predicate: null, checks };
|
|
56
|
-
add("authorization issued by the gateway", p.issuer.kind === "gateway" && p.issuer.keyid === sig.keyid);
|
|
57
|
-
add("authorization operation is submitted", p.operation?.status === "submitted");
|
|
56
|
+
add("authorization issued by the gateway", (p.issuer.kind === "gateway" || p.issuer.kind === "door") && p.issuer.keyid === sig.keyid, p.issuer.kind === "door" ? "a door commits a request before relaying it, as a gateway commits a call" : undefined);
|
|
57
|
+
add("authorization operation is submitted", p.issuer.kind === "door" || p.operation?.status === "submitted", p.issuer.kind === "door" ? "a door has no operations" : undefined);
|
|
58
58
|
add("authorization permits the original call", p.policy?.decision === "allow" ? Array.isArray(p.policy.errors) && p.policy.errors.length === 0 : p.policy?.decision === "deny" && p.policy.enforced === false);
|
|
59
59
|
const del = p.delegation && verifyDelegation(p.delegation.envelope, opts.principalKeys);
|
|
60
60
|
add("delegation signature (principal key)", !!del?.ok);
|
|
@@ -184,7 +184,7 @@ export function verifyBundle(bundle, opts) {
|
|
|
184
184
|
if (!add("structural parts in clear", !broken, broken ?? undefined))
|
|
185
185
|
return done(null);
|
|
186
186
|
const p = st.predicate;
|
|
187
|
-
add("issuer kind is known", p.issuer.kind === "gateway" || p.issuer.kind === "sdk", `${p.issuer.kind}${p.issuer.framework ? ` / ${p.issuer.framework}` : ""}`);
|
|
187
|
+
add("issuer kind is known", p.issuer.kind === "gateway" || p.issuer.kind === "sdk" || p.issuer.kind === "door", `${p.issuer.kind}${p.issuer.framework ? ` / ${p.issuer.framework}` : ""}`);
|
|
188
188
|
add("issuer keyid matches signer", p.issuer.keyid === sig.keyid);
|
|
189
189
|
if (opts.requireStrict) {
|
|
190
190
|
add("strict mode in force", p.issuer.kind === "gateway" && p.issuer.strict === true, p.issuer.strict === true ? undefined : "the issuer does not say it ran in strict mode");
|
|
@@ -207,6 +207,9 @@ export function verifyBundle(bundle, opts) {
|
|
|
207
207
|
add("gateway receipt carries a delegation", p.delegation !== undefined);
|
|
208
208
|
add("gateway receipt carries a policy decision", p.policy !== null);
|
|
209
209
|
}
|
|
210
|
+
// A door decides every arrival by policy; an arrival carries a grant only when it chose to present one.
|
|
211
|
+
if (p.issuer.kind === "door")
|
|
212
|
+
add("door receipt carries a policy decision", p.policy !== null);
|
|
210
213
|
if (p.delegation) {
|
|
211
214
|
const del = verifyDelegation(p.delegation.envelope, opts.principalKeys);
|
|
212
215
|
add("delegation signature (principal key)", del.ok, del.ok ? `signed by ${short(del.keyid)}` : del.error);
|
package/docs/configuration.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Configuring the gateway
|
|
2
2
|
|
|
3
|
-
Who may use which tools, and where those tools live, is set in three files and a few environment variables. This page is the map: what each one decides, how they fit together, a worked example with two agents on one shared gateway, how it all works in the Docker image, and how to check a config before you start. The full list of config keys is in [the gateway reference](/reference/gateway); the Cedar
|
|
3
|
+
Who may use which tools, and where those tools live, is set in three files and a few environment variables. This page is the map: what each one decides, how they fit together, a worked example with two agents on one shared gateway, how it all works in the Docker image, and how to check a config before you start. The full list of config keys is in [the gateway reference](/reference/gateway); the Cedar and Rego languages are in [policies.md](policies.md).
|
|
4
4
|
|
|
5
5
|
## What you configure, and where
|
|
6
6
|
|
|
@@ -22,7 +22,7 @@ For each call, in this order, and a refusal at any step is a signed receipt:
|
|
|
22
22
|
1. **The grant** is valid, signed by a trusted principal, inside its window, and not revoked.
|
|
23
23
|
2. **The tool** is one of the grant's scopes.
|
|
24
24
|
3. **Facts** the policy needs are fetched by the gateway from an upstream (`facts` in the config).
|
|
25
|
-
4. **The
|
|
25
|
+
4. **The policy** permits the call: Cedar, a Rego file, or an OPA server ([policies.md](policies.md#rego)). Nothing permitting it means deny.
|
|
26
26
|
5. **For `precommit` tools**, the authorization is committed to the log before anything is forwarded.
|
|
27
27
|
6. **The call** is forwarded to the upstream that owns the tool.
|
|
28
28
|
|
|
@@ -197,7 +197,7 @@ docker run --rm -v "$PWD/config:/config:ro" -v gateway-data:/data --env-file .en
|
|
|
197
197
|
| a key that is not in the schema (a typo such as `precomit` is otherwise silently ignored, and the setting stays at its default) | **error**, with the key it nearly is |
|
|
198
198
|
| the gateway key loads, and is not readable by other users | error, and a warning |
|
|
199
199
|
| every trusted principal key loads | error |
|
|
200
|
-
| the Cedar policy parses, and has at least one `permit` rule (a `permit(` in a comment does not count) | error, and a warning |
|
|
200
|
+
| the Cedar policy parses, and has at least one `permit` rule (a `permit(` in a comment does not count); a `.rego` file compiles; an OPA server answers for the package, and reports a bundle revision | error, and a warning |
|
|
201
201
|
| every credential variable the config names is set: upstream tokens and headers, the log's token, the capture key, the Splunk token, and the OpenTelemetry headers | **error**: the gateway does not start without it |
|
|
202
202
|
| a stdio `command` exists, and a script argument exists | error, and a warning |
|
|
203
203
|
| the receipts, log, revocation, operations database, and approvals paths can be written, and the revocation file is a JSON array | error |
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Door signals: what each one does and does not mean
|
|
2
|
+
|
|
3
|
+
The door records one fact for every arrival, `arrival`, and gives it to the policy as `context.facts.arrival`. Every field in it is a signal: something the door observed, labelled by how far it was checked. None of them is a verdict. This page says, for each signal, what it establishes, what it does not, and how a policy should read it. The door's guide is [the door](door.md); the contract is the [reference](https://agent-custody.dev/reference/door).
|
|
4
|
+
|
|
5
|
+
Three labels run through the table:
|
|
6
|
+
|
|
7
|
+
- **Checked.** The door verified it against a key it trusts or computed it itself. A policy may rely on it.
|
|
8
|
+
- **Observed.** The door saw it on the wire. It is true that it was sent; nothing about the sender follows.
|
|
9
|
+
- **A claim.** The caller asserted it and the door could not check it. A policy that relies on it relies on the caller.
|
|
10
|
+
|
|
11
|
+
## The signals
|
|
12
|
+
|
|
13
|
+
| signal | label | what it means | what it does not mean |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| `class: "verified"` | checked | A grant signed by a principal in `trustedPrincipalKeys`, inside its validity window, names this agent and lists this arrival's route among its scopes. The Cedar `principal` is that agent | That the agent is well-behaved, that the principal is who they say they are beyond holding the key, or that the request body is what the principal intended. The grant has no revocation list: it stands until it expires |
|
|
16
|
+
| `class: "claimed"` | a claim | Something was asserted that the door could not accept: a grant from a key it does not trust, an expired one, one for other routes, a declared agent name, or an HTTP signature header. `grant` and `grantError` say which | That the arrival is an agent, or that it is hostile. A misconfigured client, a grant for the wrong route, and an impostor all look the same here |
|
|
17
|
+
| `class: "unknown"` | observed | Nothing was presented | That the arrival is a person. A browser, a crawler, and a script that sends no headers are all `unknown`. There is no `human` class, and a policy that admits `unknown` on a route admits everything on that route |
|
|
18
|
+
| `grant: "verified"` | checked | As `class: "verified"` | |
|
|
19
|
+
| `grant: "out-of-scope"` | checked | The grant verified and is valid, but this route is not among its scopes. `subject` is the agent it names | That the agent may do anything here. The principal did not grant this route |
|
|
20
|
+
| `grant: "invalid"` | checked | The grant did not verify against a trusted key, did not decode, or is outside its window. `grantError` says which | Who signed it. A grant from an untrusted principal is `invalid` even when it is genuine |
|
|
21
|
+
| `grant: "absent"` | observed | No grant header | |
|
|
22
|
+
| `subject` | checked only when `class` is `verified` | The agent a verified grant names; else the declared name or the agent a rejected grant named; else `unknown` | For a `claimed` arrival, anything. It is recorded so the receipt shows what was asserted; the Cedar `principal` is `Agent::"unknown"` for it |
|
|
23
|
+
| `declared` | a claim | The `x-agent-custody-agent` header, as sent, cut at 200 characters | That the agent is that agent. Anyone can send the header. A permit on a declared name admits whoever types it |
|
|
24
|
+
| `signature: true` | a claim | An RFC 9421 `Signature-Input` header was present, so the arrival asserts a signature | That the signature is valid, or who signed. **The door does not check it yet.** It is recorded so that a later verifier, or a reader of the receipt, knows a signature travelled with the request |
|
|
25
|
+
| `remote` | observed | The socket's address, or with `trustProxy` the last address in `X-Forwarded-For`, the one your proxy appended | Who the person or program is. One address serves a whole office, a mobile carrier, or a cloud region; one program can use many |
|
|
26
|
+
| `challenge.outcome` | checked, against the provider | Only when `challenge` is configured. `passed`: Turnstile or hCaptcha confirmed the token this arrival sent, so the provider judged a person present when the token was made. `failed`: the provider refused the token itself (bad, expired, or already used; `error` carries the codes), the token was issued on a hostname not in `hostnames` or for another action, or it was too long to be a token. `unavailable`: the provider did not answer in time, answered a non-200, a redirect, or something that is not JSON, reported a fault of its own or of the operator's (a wrong or rotated secret, a site key that does not match it), or too many checks were already waiting, which is the provider's or the door's state, not the arrival's. `absent`: no token | That the arrival is a person now, or that the person is who they say: a token is made once and sent by whatever holds it, and the provider's own error rate applies. It does not change `class`. `unavailable` is not `failed`: a policy that treats it as one locks everyone out when the provider is down, and one that treats it as a pass admits everyone; say which, on purpose |
|
|
27
|
+
| `rate.burst`, `rate.minute` | checked | Arrivals from the same source in the last 10 and 60 seconds, this one included, whatever the policy decided about them, counted by this door process on a monotonic clock, so a step of the wall clock does not move the windows. `rate.by` says what the source is: `agent`, the verified agent's name, or `remote`, the address | That the source is a program, or that it is abusive. Twenty arrivals a minute is one page load for a site that fans out to its API, and one agent on a job. The count is one process's memory: it starts at one when the door starts, two doors do not share it, and an address shared by many people counts them together. It keeps at most 10,000 sources and forgets the least recently seen first, so a client that sends from many new addresses can make another source's count start again |
|
|
28
|
+
| `method`, `path`, `route` | observed | What arrived, the path percent-decoded once, and the route it fell under | |
|
|
29
|
+
|
|
30
|
+
## Reading them in a policy
|
|
31
|
+
|
|
32
|
+
The signals are attributes of `context.facts.arrival`. A permit for an agent requires the arrival to be verified, or the permit admits nothing but a header:
|
|
33
|
+
|
|
34
|
+
```cedar
|
|
35
|
+
permit(principal == Agent::"shopping-agent", action == Action::"api", resource)
|
|
36
|
+
when { context.facts.arrival.class == "verified" };
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`agent-custody check` warns about a permit that names an agent without that condition.
|
|
40
|
+
|
|
41
|
+
Rate is a reason to slow a route down or to ask for more, not a reason to decide what the arrival is. A forbid on it refuses the arrivals past the limit and receipts each refusal, so the receipts show how often the limit was hit and by what:
|
|
42
|
+
|
|
43
|
+
```cedar
|
|
44
|
+
forbid(principal, action == Action::"refund", resource)
|
|
45
|
+
when { context.facts.arrival.rate.minute > 30 };
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
A limit by `remote` reaches everyone behind one address. Put it high enough that a shared address is not refused for one user's pace, or scope it to routes where a person's pace is slow in any case, as a refund form is. For a verified agent the count is by agent name across every address it uses, so a limit on a verified agent is a limit on the agent.
|
|
49
|
+
|
|
50
|
+
An `unknown` arrival that comes fast is still unknown. The honest policy for a route that should not take bursts from strangers is to refuse them and say why, and to route the agents you want through a grant, which makes them `verified` and counted by name.
|
|
51
|
+
|
|
52
|
+
A challenge is the way a person gets through a route that refuses `unknown`. The permit names the outcome, not the class, and a second permit lets the agents you trust through without the widget:
|
|
53
|
+
|
|
54
|
+
```cedar
|
|
55
|
+
permit(principal, action == Action::"refund", resource)
|
|
56
|
+
when { context.facts.arrival.challenge.outcome == "passed" };
|
|
57
|
+
|
|
58
|
+
permit(principal == Agent::"shopping-agent", action == Action::"refund", resource)
|
|
59
|
+
when { context.facts.arrival.class == "verified" };
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Decide what `unavailable` means for each route before the provider has its first outage: a forbid on `outcome != "passed"` closes the route then, and the receipts show that the provider, not the arrivals, was the reason.
|
|
63
|
+
|
|
64
|
+
## What is not a signal yet
|
|
65
|
+
|
|
66
|
+
Nothing in the arrival fact says whether the arrival is a program. Behavioural and fingerprint signals, HTTP message signature verification, and Web Bot Auth directory lookups are not built; when they are, each will arrive with a measured error rate beside it, and this page will say what it means. Until then a policy has the grant, the claims, the address, and the pace, and the receipt records which of them it used.
|
package/docs/door.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# The door: a receipted reverse proxy in front of your own site or API
|
|
2
|
+
|
|
3
|
+
The gateway stands between an agent and the tools it uses. The door stands between the world and your own HTTP surface: a website, an API, a form. Every arrival, a browser, an API client, a crawler, or an agent acting for someone, is classified by what it presented, decided by a Cedar policy for the route it hit, relayed to your origin or refused, and receipted either way. The receipt is the same signed, logged, independently verifiable receipt the gateway issues, with `issuer.kind: "door"`.
|
|
4
|
+
|
|
5
|
+
This is the first piece of the agent front door. It answers "what may this arrival do here" and "what did it do, provably". It does not yet answer "is this an agent" for web traffic: that is detection, and the door records only what it can check. Read [what the door knows](#what-the-door-knows-about-an-arrival) before writing a policy.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
agent-custody keygen --dir keys --name door
|
|
9
|
+
agent-custody check --config door.json
|
|
10
|
+
agent-custody door --config door.json --port 8780
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## The config file
|
|
14
|
+
|
|
15
|
+
`door.json`, paths relative to the file. Loaded with `loadDoorConfig(path)`.
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"identity": { "keyFile": "keys/door.key" },
|
|
20
|
+
"origin": { "url": "http://127.0.0.1:3000", "timeoutMs": 30000 },
|
|
21
|
+
"routes": [
|
|
22
|
+
{ "name": "catalogue", "methods": ["GET"], "path": "/catalogue/*" },
|
|
23
|
+
{ "name": "refund", "methods": ["POST"], "path": "/refunds" },
|
|
24
|
+
{ "name": "api", "path": "/api/*" }
|
|
25
|
+
],
|
|
26
|
+
"unmatchedRoute": "other",
|
|
27
|
+
"trustedPrincipalKeys": ["keys/principal.pub"],
|
|
28
|
+
"policyFile": "policy.cedar",
|
|
29
|
+
"receiptsDir": "receipts",
|
|
30
|
+
"logFile": "log.jsonl"
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| field | meaning |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `identity.keyFile` | the door's Ed25519 key; signs every receipt. From `agent-custody keygen` |
|
|
37
|
+
| `origin.url` | where allowed arrivals are relayed: the site or API behind the door. `headers` and `headerEnv` add headers to every relayed request, the latter from the environment, so the origin can require a secret only the door holds. `timeoutMs` bounds one relayed request, default 30 s. A path in the URL (`https://host/api/v1`) is kept: the arrival's path goes under it, and a redirect from the origin to a place under it comes back as a door path |
|
|
38
|
+
| `routes` | what the policy sees as the action. `path` is exact (`/refunds`), a prefix (`/api/*`), or `*`; `methods` narrows it, default every method. The first route that matches wins; an arrival no route matches is the action `unmatchedRoute`, default `other`. The match reads the path as the origin will: percent-decoded once, so `/%61dmin` falls under `/admin/*`, and with empty segments merged, so `//admin/users` and `/admin//users` fall under it too (nginx, Apache, and many frameworks merge them). A trailing slash matches as none: `/refunds/` falls under `/refunds`. The origin is sent that merged, decoded form, trailing slash kept, so the door and the origin read one path. A path with a segment that does not decode, or decodes to a slash or a backslash, falls under `unmatchedRoute` and is never relayed |
|
|
39
|
+
| `trustedPrincipalKeys` | public keys of principals whose signed grants the door accepts as a passport. Without any, no arrival can be `verified` |
|
|
40
|
+
| `policyFile` | the Cedar policy, re-read when the file changes; one that does not parse is refused and the policy in force stays |
|
|
41
|
+
| `mode` | `enforce` (default) refuses what the policy denies. `observe` relays everything and records the decision with `enforced: false` |
|
|
42
|
+
| `trustProxy` | behind one reverse proxy you run: the arrival's address is the last in `X-Forwarded-For`, the one your proxy appended; everything before it is what the client sent. The proxy's `X-Forwarded-For`, `-Proto`, and `-Host` are kept on the relay, with the door's own socket address appended, and the other client-address headers (`Forwarded`, `X-Real-IP`, `True-Client-IP`, `CF-Connecting-IP`, every `X-Forwarded-*`) are relayed as the proxy sent them. Without `trustProxy` the client wrote all of these: the door drops them and sets `X-Forwarded-For`, `-Host`, `-Proto`, and `X-Real-IP` itself |
|
|
43
|
+
| `maxBodyBytes` | the largest request body the door relays; a larger one gets 413 and a `withheld` receipt once the policy has allowed it. Default 1 MiB |
|
|
44
|
+
| `maxResponseBytes` | the largest origin response the door relays; see [what the arrival gets back](#what-the-arrival-gets-back). Default 32 MiB |
|
|
45
|
+
| `maxInFlight` | arrivals handled at once. Each holds its body and the origin's answer in memory until it is answered, so this bounds the door's memory at about `maxInFlight × (maxBodyBytes + maxResponseBytes)`. Past it the next arrival gets 503 with `Retry-After: 1` before its body is read: it is not decided, relayed, or receipted. Default 256 |
|
|
46
|
+
| `precommit` | route names whose arrivals are committed to the log before they are relayed whatever their method, or `["*"]`. Every arrival whose method is not GET, HEAD, or OPTIONS is committed regardless; see [before the origin hears of it](#before-the-origin-hears-of-it). Default `[]` |
|
|
47
|
+
| `challenge` | the human branch: `{ provider: "turnstile" or "hcaptcha", siteKey, secretEnv, hostnames, action?, header?, timeoutMs?, maxInFlight? }`. `hostnames` lists the hosts of the pages that render the widget, `action` (Turnstile only) the widget's action, and `maxInFlight` (default 64) how many checks may wait on the provider at once. A token an arrival sends in `header` (default `x-agent-custody-challenge`) is verified with the provider, and the outcome is the arrival's `challenge` signal; see [challenging a human](#challenging-a-human). The secret comes from the environment variable, read at startup; missing is a startup error |
|
|
48
|
+
| `receiptsDir`, `logFile` or `log`, `otel`, `splunk`, `capture`, `captureKeyEnv` | as for the [gateway](configuration.md): where receipts and the log go, exporters, and private evidence per route. A remote `log` needs `log.keys`, because its answer is checked before a request is relayed. Unlike the gateway, the door withholds by default: see [what a receipt records](#what-a-receipt-records-of-the-query-and-the-body) |
|
|
49
|
+
|
|
50
|
+
`agent-custody check --config door.json` reads a door config the way the door would: unknown keys, the key, the principal keys, the policy (including a permit that names an agent without requiring a verified arrival, see below), the routes, what is precommitted, the challenge provider or its absence, the origin's scheme, every credential variable the door reads at startup (origin headers, the log, Splunk, OTel, the capture key, the challenge secret), and the paths. It exits 1 on an error.
|
|
51
|
+
|
|
52
|
+
## What the door knows about an arrival
|
|
53
|
+
|
|
54
|
+
The door records one fact for every arrival, `arrival`, observed by the door itself, and the policy reads it as `context.facts.arrival`:
|
|
55
|
+
|
|
56
|
+
| field | values | meaning |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, one for other routes, a declared agent name, or an HTTP signature header. `unknown`: nothing was presented |
|
|
59
|
+
| `subject` | string | the agent named in a verified grant; else the declared name or the agent a rejected grant named; else `unknown`. Only a verified subject reaches the Cedar `principal` |
|
|
60
|
+
| `grant` | `verified`, `out-of-scope`, `invalid`, `absent` | what became of the grant header, with `grantError` when it was not accepted |
|
|
61
|
+
| `signature` | boolean | an RFC 9421 `Signature-Input` header was present. **Not checked yet.** It is a claim |
|
|
62
|
+
| `declared` | string | the `x-agent-custody-agent` header, when sent. A claim |
|
|
63
|
+
| `remote` | string | the arrival's address |
|
|
64
|
+
| `challenge` | `{ provider, outcome, error? }` | only when `challenge` is configured. `passed`: the provider confirmed the token the arrival sent. `failed`: the provider refused the token (`invalid-input-response`, `timeout-or-duplicate`, `expired-input-response`, `already-seen-response`, `missing-input-response`, with the codes in `error`), it confirmed a token issued on another hostname or for another action, or the token was longer than 4096 characters, which is refused without calling the provider. `unavailable`: the provider did not answer in time, answered a non-200, a redirect, or something that is not JSON, answered a code that is its own or the operator's fault (`internal-error`, `bad-request`, `missing-input-secret`, `invalid-input-secret`, `sitekey-secret-mismatch`, `invalid-sitekey`, `missing-sitekey`, `invalid-remoteip`: a rotated secret gives every person one of these), or `maxInFlight` checks were already waiting. `absent`: no token. A passed challenge leaves `class` as it was: it says a provider's test was passed in front of this arrival, not who the arrival is |
|
|
65
|
+
| `rate` | `{ by, burst, minute }` | arrivals from the same source in the last 10 and 60 seconds, this one included, whatever was decided about them, counted by this door process alone. `by` is `agent` for a verified arrival (counted by the agent's name across addresses) or `remote` (by address). A pace, not a verdict |
|
|
66
|
+
| `method`, `path`, `route` | strings | what arrived, and the route it fell under |
|
|
67
|
+
|
|
68
|
+
[Door signals](door-signals.md) says, for each field, what it establishes and what it does not, and how a policy should read it.
|
|
69
|
+
|
|
70
|
+
There is no `human` class. The door cannot tell a person from a program that presents nothing, and it does not pretend to. With `challenge` configured, a policy can require a passed challenge on a route instead; without it, a policy that lets `unknown` through on a route is letting everything through on that route, and should say so.
|
|
71
|
+
|
|
72
|
+
**Presenting a passport.** An agent presents its grant exactly as it does to the HTTP gateway: the DSSE envelope as base64url in `Authorization: Bearer <value>` or in `X-Agent-Custody-Grant`. The scopes of the grant are route names. A grant that travelled in `Authorization` is stripped before the request is relayed, so the origin never sees it; one in the custom header is stripped too. The door's own headers are added to the relayed request: `X-Agent-Custody-Receipt` (the receipt id), `X-Agent-Custody-Class`, and `X-Forwarded-For`, `-Host`, `-Proto`, with `X-Real-IP` when `trustProxy` is off.
|
|
73
|
+
|
|
74
|
+
**A verified arrival is bearer-grade.** The door checks the grant's signature, window, and scope. It does not check that the sender holds the agent's key: there is no request signature yet (RFC 9421 is [future work](#what-it-does-not-do-yet)). Anyone who holds the grant's bytes is that agent until the grant expires, and every verified receipt carries the grant in `delegation`, so a person who can read one receipt can replay its grant. Issue door grants with short lifetimes (minutes, not days), scope them to the routes they need, bound what a route allows per call in the policy, and treat receipt files and logs as holding live credentials until those grants expire.
|
|
75
|
+
|
|
76
|
+
**Challenging a human.** The door builds no CAPTCHA. With `challenge` configured, a page in front of a protected route renders the provider's widget (Cloudflare Turnstile or hCaptcha) with `siteKey`, and sends the token the widget produced in the `challenge.header` header of its request. The door posts the token and the secret from `secretEnv` to the provider's `siteverify` endpoint, with a timeout, and records the answer as `challenge.outcome`. It adds the arrival's address as `remoteip` only with `trustProxy`, where that address is the client's; without it the socket's address may be a proxy's, and the provider would refuse a token the client solved. It never follows a redirect, which would resend the secret and the token elsewhere. To hCaptcha it also sends `siteKey` as `sitekey`: an hCaptcha secret belongs to the account, and without it a token solved on the account's easiest widget would pass on the hardest. A Turnstile secret belongs to one widget already. `success` alone does not pass: the token must have been issued on one of `hostnames`, and for `action` when one is set, or a token solved on another site that uses this site key, or for another widget, would count. At most `maxInFlight` checks wait on the provider at once; an arrival past that is `unavailable`. The token is stripped before the request is relayed, and neither the token nor the secret is recorded. A policy admits a person on a form route with
|
|
77
|
+
|
|
78
|
+
```cedar
|
|
79
|
+
permit(principal, action == Action::"refund", resource)
|
|
80
|
+
when { context.facts.arrival.challenge.outcome == "passed" };
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
and a refused arrival that has not passed is told how in the 403 body: `challenge: { provider, siteKey, header }`, so a page can render the widget and try again.
|
|
84
|
+
|
|
85
|
+
**A token serves one request.** Turnstile and hCaptcha refuse a token they have seen (`timeout-or-duplicate`, `already-seen-response`), and the door keeps no pass between requests: it does not set a cookie or remember an address. So the page must take a new token for every request it sends to a challenged route, and for every retry: call `turnstile.reset()` or `hcaptcha.reset()` after each request, and wait for the new token before the next. The door checks the token before it reads the body, so a request refused for its size (413), its path (400), or by the policy has used its token too. A second request that sends the same token is `failed`, and the person sees another 403. The outcome is a signal, not a class: a `verified` agent that also passes a challenge is still the agent its grant names, and an `unknown` arrival that passes is still `unknown`, with `challenge.outcome: "passed"` beside it. What the provider's pass means, and what it does not, is in [door signals](door-signals.md). Passkeys are not a provider here: a passkey proves possession of a credential the site registered, which is a login, not a challenge, and belongs to the origin.
|
|
86
|
+
|
|
87
|
+
## How an arrival becomes a Cedar request
|
|
88
|
+
|
|
89
|
+
| Cedar slot | value |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `principal` | `Agent::"<agent>"` for the agent a verified grant names; `Agent::"unknown"` for every other arrival. A declared name and the agent a rejected grant names stay in the arrival fact: a permit on `principal == Agent::"shopping-agent"` cannot be satisfied by sending a header |
|
|
92
|
+
| `action` | `Action::"<route>"` |
|
|
93
|
+
| `resource` | `Tool::"<route>"` |
|
|
94
|
+
| `context.args` | `{ method, path, query, headers, body?, bodyBytes, bodyDigest }`. `query` holds every parameter by name, as own properties, so `?constructor=x` is a parameter. `headers` carries `user-agent`, `content-type`, `accept`, and `host` only. `body` is present for a JSON body of at most 64 KiB; every body the door read is recorded by `bodyDigest` (sha256 of the raw bytes) and `bodyBytes`. A body above `maxBodyBytes` is dropped as it passes the limit and recorded as `bodyBytes` read so far and `bodyOversized: true`, with no digest and no `body`. The policy reads a copy that Cedar accepts: Cedar has no `null` and no non-integer number, and refuses the whole request on either, so in the copy a `null` member is dropped and a number that is not a safe integer becomes its string (`9.99` becomes `"9.99"`). A rule that compares such a value as a number then errors, and that rule's deny is the answer. The receipt keeps the body as it arrived. **Provenance: claimed** |
|
|
95
|
+
| `context.facts.arrival` | the fact above. **Provenance: observed** |
|
|
96
|
+
| `context.grant` | `{ principal, scopes }`, present only when the arrival is `verified`. **Provenance: attested** |
|
|
97
|
+
|
|
98
|
+
Every rule the gateway's policies obey applies: default deny, `forbid` wins, an evaluation error is a deny, the policy digest is in the receipt. A policy for the shop in the tutorial:
|
|
99
|
+
|
|
100
|
+
```cedar
|
|
101
|
+
// The catalogue is public: humans, agents, anyone.
|
|
102
|
+
permit(principal, action == Action::"catalogue", resource);
|
|
103
|
+
|
|
104
|
+
// Refunds: a verified agent, in its grant's scope, for a positive amount of at most £50.
|
|
105
|
+
permit(principal, action == Action::"refund", resource)
|
|
106
|
+
when {
|
|
107
|
+
context.facts.arrival.class == "verified" &&
|
|
108
|
+
context.args.body.amount > 0 &&
|
|
109
|
+
context.args.body.amount <= 5000
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Everything else on the API is for verified agents.
|
|
113
|
+
permit(principal, action == Action::"api", resource)
|
|
114
|
+
when { context.facts.arrival.class == "verified" };
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
A refund without a JSON body, with no `amount`, or with an `amount` that is not an integer (`45.5` reaches the policy as `"45.5"`), is an evaluation error and a deny. That is the behaviour you want in front of a payments route. The bound has two ends on purpose: `amount <= 5000` alone admits `{"amount": -1}`, and the door relays the body as it came.
|
|
118
|
+
|
|
119
|
+
A permit that names an agent, `permit(principal == Agent::"shopping-agent", action == Action::"refund", resource)`, admits only an arrival whose verified grant names that agent, since nothing else reaches the principal slot. `agent-custody check` still warns on such a permit when it does not also require `context.facts.arrival.class == "verified"`: the same text in a gateway policy reads differently, and the condition says what the permit relies on.
|
|
120
|
+
|
|
121
|
+
## Before the origin hears of it
|
|
122
|
+
|
|
123
|
+
A request that can change something at the origin, any method but GET, HEAD, and OPTIONS, and any arrival at a route named in `precommit`, is committed to the log before it is relayed, exactly as the gateway's precommit does for a consequential tool call: the door signs an authorization statement (the receipt without its outcome), appends it, writes it as `receipts/<receiptId>.authorization.json`, and only then relays. The receipt embeds it as `authorization`, and the verifier checks that it names this receipt and sits in the log before it. A door that dies between the relay and the receipt leaves the authorization behind, so the side effect has a record and a retry can be told from a first attempt. If the log will not take the authorization, the request is not relayed: 503 and a `withheld` receipt. In observe mode it is relayed and the missing authorization is printed.
|
|
124
|
+
|
|
125
|
+
## What the arrival gets back
|
|
126
|
+
|
|
127
|
+
| the door's decision | HTTP | body | receipt `execution.status` |
|
|
128
|
+
| --- | --- | --- | --- |
|
|
129
|
+
| policy allows, origin answered | the origin's status and body, plus the door's headers | the origin's | `executed`, or `failed` when the origin answered 5xx |
|
|
130
|
+
| policy denies, whatever the body's size | 403 | `{ error, reason, receipt }`, plus `challenge: { provider, siteKey, header }` when a challenge is configured and this arrival has not passed it | `denied` |
|
|
131
|
+
| origin unreachable: the connection was refused or the host did not resolve | 502 | `{ error, detail, receipt }`, "the origin could not be reached" | `error`; the request never left the door |
|
|
132
|
+
| the request left, and its answer did not arrive: a timeout, a reset, or a body that stopped after the headers | 504 | `{ error, detail, receipt }`, "the origin may have acted on the request ... Do not retry" | `error`, and `execution.error` says the origin may have acted. Find out from the origin before retrying a refund |
|
|
133
|
+
| policy allows, body above `maxBodyBytes` | 413 | `{ error, reason, receipt }` | `withheld`; nothing was relayed |
|
|
134
|
+
| policy allows, the log refused the authorization | 503 | `{ error, reason, receipt }` | `withheld`; nothing was relayed |
|
|
135
|
+
| policy allows, the path does not decode cleanly | 400 | `{ error, reason, receipt }` | `withheld`; nothing was relayed |
|
|
136
|
+
| policy allows, the origin's response above `maxResponseBytes` | 502 | `{ error, receipt }`, and "do not retry" | `executed` or `failed`: the origin acted; `result` carries the status and `bodyOversized: true`, no digest |
|
|
137
|
+
| the receipt could not be written | 500 | `{ error, outcome, receipt }` | none on disk; `outcome` says whether the origin acted, so that a refund is not retried on the strength of a 500 |
|
|
138
|
+
| more than `maxInFlight` arrivals at once | 503, `Retry-After: 1` | `{ error }` | none: the arrival was not read, decided, or relayed |
|
|
139
|
+
|
|
140
|
+
A redirect from the origin to its own host, on any scheme or port, is rewritten to a path, so the client's next request comes back through the door and is classified again. A path under the origin's path loses that prefix; any other path, including one that `..` takes out of it, is kept as it is. A redirect to another host is relayed as sent. Every `Set-Cookie` the origin sent reaches the client. An `Expect: 100-continue` is the client's conversation with the door, which answers it; the origin does not see the header.
|
|
141
|
+
|
|
142
|
+
Every answer carries `X-Agent-Custody-Receipt` and `X-Agent-Custody-Class`. When the log did not take the receipt, it waits in `receipts/outbox/` and the answer also carries `X-Agent-Custody-Log-Pending: true`; a serving door appends the outbox every 30 seconds, as the gateway does.
|
|
143
|
+
|
|
144
|
+
`GET /.well-known/agent-custody-door` answers the door's key id, the policy digest in force, the version, and the count of pending receipts.
|
|
145
|
+
|
|
146
|
+
## What a receipt records of the query and the body
|
|
147
|
+
|
|
148
|
+
A query can carry an API key (`?api_key=sk_live_...`) and a JSON body a password. When the config gives a route no `capture` rule, and has no `"*"` rule, the door applies its own private rule to it: `method`, `path`, `headers` (the four above), `bodyBytes`, and `bodyOversized` stay in clear, and the query, the body, and `bodyDigest` leave one salted commitment, `request.args.$rest`, in their place. The policy still decides on the real values, because the rule is applied after the decision, and the receipt still verifies. As under any private rule, the denial reason and the policy's error messages are withheld too; the client's 403 still carries the reason. The facts (the arrival) and the result (the origin's status and digest) stay in clear.
|
|
149
|
+
|
|
150
|
+
To record more in clear, give the route a rule of its own, as for the gateway ([private evidence](configuration.md)): `{ "capture": { "refund": { "args": { "mode": "digest", "clear": ["method", "path", "body"] } } } }` keeps a refund's body in clear, and `{ "capture": { "*": { "args": { "mode": "clear" } } } }` keeps every route's arguments in clear, as before.
|
|
151
|
+
|
|
152
|
+
## The receipt
|
|
153
|
+
|
|
154
|
+
A door receipt is a v0.2 receipt with `issuer.kind: "door"` and `issuer.framework: "http"`. The route is the tool, observed. `request.args` is the arrival as the table above describes it, claimed. `facts.arrival` is the door's observation. When the arrival was verified, `principal` and `agent` are attested and `delegation` carries the grant; otherwise `principal` is `{ id: null, provenance: "claimed" }` and `agent` is the subject, claimed. `execution.result` for a relayed call is `{ status, contentType?, bodyBytes, bodyDigest }`: the origin's body is never copied into the receipt, only committed to.
|
|
155
|
+
|
|
156
|
+
The verifier runs `door receipt carries a policy decision` in place of the gateway's two checks, and otherwise the same checks: a verified arrival's receipt passes `delegation binds principal and agent` and `executed tool within delegated scope`; an unknown arrival's passes `principal is claimed, not attested`; a receipt that carries an `authorization` passes the authorization checks, including `authorization logged before execution`. Both verifiers, the Python verifier, and `policy simulate` accept door receipts; the conformance vectors `door-unknown-executed`, `door-unknown-denied`, and `door-verified-executed` pin them.
|
|
157
|
+
|
|
158
|
+
## What it does not do yet
|
|
159
|
+
|
|
160
|
+
- Detect agents in web or API traffic. The only signals are the ones in the arrival fact: `signature` and `declared` are claims, and `rate` is a pace ([door signals](door-signals.md)).
|
|
161
|
+
- Check RFC 9421 HTTP message signatures, Web Bot Auth directories, or AP2 mandates. The grant is the only passport today.
|
|
162
|
+
- Challenge an arrival with a passkey. Turnstile and hCaptcha are the providers; see [challenging a human](#challenging-a-human).
|
|
163
|
+
- Revoke a grant by a revocation list; a grant stands until it expires.
|
|
164
|
+
- Bind a grant to its sender. A verified arrival is bearer-grade: see [presenting a passport](#what-the-door-knows-about-an-arrival).
|
|
165
|
+
- Stream a request body: the body is read whole, up to `maxBodyBytes`, so that the policy can read it and the receipt can commit to it.
|
|
166
|
+
- Relay a response larger than `maxResponseBytes`, or stream one: the body is relayed whole so that its digest can be recorded. A larger one is not held: reading stops at the limit, the client gets 502, and the receipt records that the origin answered.
|
|
167
|
+
|
|
168
|
+
Tutorial: [40-door.ts](../examples/40-door.ts).
|
|
@@ -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.
|
|
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.15.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.15.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.
|