@agent-custody/receipts 0.6.19 → 0.7.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 +9 -6
- package/dist/a2a.js +19 -7
- package/dist/capture.d.ts +153 -0
- package/dist/capture.js +559 -0
- package/dist/cli.js +98 -4
- package/dist/config.d.ts +59 -0
- package/dist/config.js +21 -2
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +7 -4
- package/dist/delegation.d.ts +7 -0
- package/dist/delegation.js +15 -1
- package/dist/gateway-http.js +13 -1
- package/dist/gateway.d.ts +10 -0
- package/dist/gateway.js +132 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/issue.d.ts +14 -4
- package/dist/issue.js +66 -7
- package/dist/log-sink.d.ts +11 -1
- package/dist/log-sink.js +24 -5
- package/dist/otel.js +5 -4
- package/dist/portal.d.ts +23 -2
- package/dist/portal.js +181 -36
- package/dist/receipt.d.ts +19 -8
- package/dist/retention.d.ts +8 -1
- package/dist/retention.js +21 -2
- package/dist/sdk/index.js +10 -1
- package/dist/splunk.js +6 -4
- package/dist/upstream.d.ts +9 -7
- package/dist/upstream.js +16 -8
- package/dist/verify.d.ts +16 -0
- package/dist/verify.js +171 -13
- package/docs/compliance.md +1 -1
- package/docs/tutorials.md +2 -0
- package/docs/usage.md +44 -4
- package/docs/verification.md +11 -4
- package/package.json +1 -1
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +1394 -270
package/dist/upstream.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// upstream's key checks it. Provider-native formats, such as Stripe's webhook signatures, are adapters on top of this.
|
|
5
5
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
6
6
|
import { digestOf, dsseSign, dsseVerify } from "./crypto.js";
|
|
7
|
+
import { isCommitment } from "./capture.js";
|
|
7
8
|
export const UPSTREAM_SIG_META_KEY = "agent-custody/upstream-signature";
|
|
8
9
|
export const UPSTREAM_TYPE = "application/vnd.agent-custody.upstream+json";
|
|
9
10
|
export function contentDigest(result) {
|
|
@@ -37,7 +38,8 @@ export function checkUpstream(envelope, keys, expected) {
|
|
|
37
38
|
}
|
|
38
39
|
export function isProviderAttestation(v) {
|
|
39
40
|
const p = v;
|
|
40
|
-
|
|
41
|
+
const stringOrCommitment = (v) => typeof v === "string" || isCommitment(v);
|
|
42
|
+
return !!p && (p.provider === "stripe-webhook" || p.provider === "github-delivery") && stringOrCommitment(p.rawBody) && stringOrCommitment(p.signature) && stringOrCommitment(p.bind);
|
|
41
43
|
}
|
|
42
44
|
/** For upstreams wrapping a provider: attaches the provider's own delivery for this call. */
|
|
43
45
|
export function attachProviderAttestation(result, attestation) {
|
|
@@ -54,13 +56,17 @@ export function upstreamEvidenceOf(result) {
|
|
|
54
56
|
const pathValue = (body, path) => path.split(".").reduce((v, k) => (v && typeof v === "object" ? v[k] : undefined), body);
|
|
55
57
|
/** Stripe: header `t=<unix>,v1=<hex>`, HMAC-SHA256 over `<t>.<rawBody>`; GitHub: header `sha256=<hex>` over rawBody. */
|
|
56
58
|
export function checkProvider(att, secrets, ctx) {
|
|
59
|
+
if (typeof att.rawBody !== "string" || typeof att.signature !== "string" || typeof att.bind !== "string")
|
|
60
|
+
return { ok: false, error: "the delivery body, signature, or bind is withheld; disclose them or give the capture key" };
|
|
61
|
+
const signature = att.signature;
|
|
62
|
+
const bind = att.bind;
|
|
57
63
|
const secret = att.provider === "stripe-webhook" ? secrets.stripe : secrets.github;
|
|
58
64
|
if (!secret)
|
|
59
65
|
return { ok: false, error: `no ${att.provider === "stripe-webhook" ? "Stripe" : "GitHub"} secret given` };
|
|
60
66
|
const hmac = (data) => createHmac("sha256", secret).update(data).digest("hex");
|
|
61
67
|
const equal = (a, b) => a.length === b.length && timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
62
68
|
if (att.provider === "stripe-webhook") {
|
|
63
|
-
const parts = Object.fromEntries(
|
|
69
|
+
const parts = Object.fromEntries(signature.split(",").map((kv) => kv.split("=")));
|
|
64
70
|
const t = parts.t;
|
|
65
71
|
const v1 = parts.v1;
|
|
66
72
|
if (!t || !v1)
|
|
@@ -72,7 +78,7 @@ export function checkProvider(att, secrets, ctx) {
|
|
|
72
78
|
return { ok: false, error: `Stripe timestamp is ${Math.round(skew)}s from the receipt, beyond tolerance` };
|
|
73
79
|
}
|
|
74
80
|
else {
|
|
75
|
-
const hex =
|
|
81
|
+
const hex = signature.startsWith("sha256=") ? signature.slice(7) : "";
|
|
76
82
|
if (!hex || !equal(hmac(att.rawBody), hex))
|
|
77
83
|
return { ok: false, error: "GitHub signature does not verify with this secret" };
|
|
78
84
|
}
|
|
@@ -83,12 +89,14 @@ export function checkProvider(att, secrets, ctx) {
|
|
|
83
89
|
catch {
|
|
84
90
|
return { ok: false, error: "delivery body is not JSON" };
|
|
85
91
|
}
|
|
86
|
-
const bound = pathValue(body,
|
|
92
|
+
const bound = pathValue(body, bind);
|
|
87
93
|
if (bound === undefined || bound === null || bound === "")
|
|
88
|
-
return { ok: false, error: `delivery has no value at ${
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
return { ok: false, error: `delivery has no value at ${bind}` };
|
|
95
|
+
// what the agent received: the content and the flag, never _meta, which carries the delivery itself and so always contains the bound value
|
|
96
|
+
const received = ctx.result;
|
|
97
|
+
if (!JSON.stringify({ content: received.content, isError: received.isError, structuredContent: received.structuredContent }).includes(JSON.stringify(bound).replace(/^"|"$/g, "")))
|
|
98
|
+
return { ok: false, error: `delivery's ${bind} (${String(bound)}) does not appear in the receipt's result` };
|
|
99
|
+
return { ok: true, keyid: `shared secret (${att.provider}, bound on ${bind})` };
|
|
92
100
|
}
|
|
93
101
|
/** For fake providers and tests: a Stripe-Signature header for a body at a time. */
|
|
94
102
|
export function stripeSignature(rawBody, secret, unixSeconds) {
|
package/dist/verify.d.ts
CHANGED
|
@@ -20,12 +20,28 @@ export interface VerifyOptions {
|
|
|
20
20
|
logFile?: string;
|
|
21
21
|
/** If given, every tree head in the bundle must name this log, so a head from another tenant's log cannot be presented as this one's. */
|
|
22
22
|
logId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The withheld values, as `agent-custody reveal` writes them or the party that holds them hands them over: a partial
|
|
25
|
+
* predicate with `{ $custody: "disclosed", salt, value }` at each withheld path (`{ receiptId, request: { args: { reason: {...} } }, execution: { result: { content: {...} }, error, upstream: { rawBody } }, policy: { errors }, facts: { <name>: { value, args } } }`).
|
|
26
|
+
* The digests are then recomputed and every disclosed value checked against its commitment under its salt.
|
|
27
|
+
*/
|
|
28
|
+
disclosed?: Record<string, unknown> & {
|
|
29
|
+
receiptId?: string;
|
|
30
|
+
};
|
|
31
|
+
/** the customer's capture key: encrypted fields are revealed and the digests recomputed */
|
|
32
|
+
captureKey?: Buffer;
|
|
23
33
|
}
|
|
24
34
|
export interface VerifyResult {
|
|
25
35
|
ok: boolean;
|
|
26
36
|
checks: Check[];
|
|
27
37
|
statement: ReceiptStatement | null;
|
|
28
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Why a statement cannot be verified at all, or null: the capture note is malformed, names a structural part, or a
|
|
41
|
+
* structural part is not what every check assumes it to be. Checked once, before anything reads the statement, so that
|
|
42
|
+
* a crafted note cannot hide the status, the tool, the decision, or the digests behind a commitment and still verify.
|
|
43
|
+
*/
|
|
44
|
+
export declare function structuralProblem(p: unknown): string | null;
|
|
29
45
|
export declare function verifyBundle(bundle: ReceiptBundle, opts: VerifyOptions): VerifyResult;
|
|
30
46
|
export interface AuditResult {
|
|
31
47
|
ok: boolean;
|
package/dist/verify.js
CHANGED
|
@@ -1,10 +1,63 @@
|
|
|
1
1
|
// Independent verification of a receipt bundle. Needs only public keys, and optionally a copy of the log.
|
|
2
2
|
import { canonicalize, digestOf, dsseVerifiers, dsseVerify } from "./crypto.js";
|
|
3
|
+
import { digestSaltFor, getAt, isCommitment, pathKey, pathText, restorePaths, under } from "./capture.js";
|
|
3
4
|
import { delegationHasParent, delegationValidAt, describeChain, verifyDelegation } from "./delegation.js";
|
|
4
5
|
import { leafHash, MerkleLog, verifyConsistency, verifyInclusion } from "./log.js";
|
|
5
6
|
import { checkProvider, checkUpstream, contentDigest, isProviderAttestation } from "./upstream.js";
|
|
6
7
|
import { AUTHORIZATION_PREDICATE_TYPE, RECEIPT_PREDICATE_TYPE, RECEIPT_TYPE, TREEHEAD_TYPE } from "./receipt.js";
|
|
7
8
|
const short = (s) => s.slice(0, 12);
|
|
9
|
+
const isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
10
|
+
/** The parts of a statement a capture note may never name: what a verifier reads to run its checks. A note naming one, or a commitment sitting there, is not a private receipt but a broken one. */
|
|
11
|
+
const STRUCTURAL_TOP = new Set(["receiptId", "timestamp", "issuer", "principal", "agent", "delegation", "tool", "authorization", "capture"]);
|
|
12
|
+
const STRUCTURAL_IN = { request: new Set(["argsDigest", "provenance"]), execution: new Set(["status", "provenance"]), policy: new Set(["decision", "reasons", "policyDigest", "enforced", "provenance"]), consumed: new Set(["provenance"]), session: new Set(["provenance"]), model: new Set(["provenance"]) };
|
|
13
|
+
/**
|
|
14
|
+
* Why a statement cannot be verified at all, or null: the capture note is malformed, names a structural part, or a
|
|
15
|
+
* structural part is not what every check assumes it to be. Checked once, before anything reads the statement, so that
|
|
16
|
+
* a crafted note cannot hide the status, the tool, the decision, or the digests behind a commitment and still verify.
|
|
17
|
+
*/
|
|
18
|
+
export function structuralProblem(p) {
|
|
19
|
+
if (!isObject(p))
|
|
20
|
+
return "the predicate is not an object";
|
|
21
|
+
const note = p.capture;
|
|
22
|
+
if (note !== undefined) {
|
|
23
|
+
if (!isObject(note) || (note.mode !== "digest" && note.mode !== "encrypted") || !Array.isArray(note.withheld))
|
|
24
|
+
return "the capture note is malformed";
|
|
25
|
+
if (new Set(note.withheld.map((w) => JSON.stringify(w))).size !== note.withheld.length)
|
|
26
|
+
return "the capture note names a path twice";
|
|
27
|
+
for (const w of note.withheld) {
|
|
28
|
+
if (!Array.isArray(w) || w.length === 0 || !w.every((s) => typeof s === "string"))
|
|
29
|
+
return "the capture note names a malformed path";
|
|
30
|
+
const path = w;
|
|
31
|
+
const head = path[0];
|
|
32
|
+
const named = STRUCTURAL_TOP.has(head) || (path.length === 1 && Object.hasOwn(STRUCTURAL_IN, head)) || (path.length === 2 && Object.hasOwn(STRUCTURAL_IN, head) && STRUCTURAL_IN[head].has(path[1])) || head === "facts" && (path.length <= 2 || path[2] === "tool" || path[2] === "provenance") || (head === "execution" && path.length === 2 && path[1] === "upstream") || (head === "execution" && path.length === 3 && path[1] === "upstream" && path[2] === "provider") || (head === "execution" && path.length === 3 && path[1] === "result" && path[2] === "isError");
|
|
33
|
+
if (named)
|
|
34
|
+
return `the capture note names a structural part: ${pathText(path)}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (typeof p.receiptId !== "string" || typeof p.timestamp !== "string")
|
|
38
|
+
return "receiptId or timestamp is not a string";
|
|
39
|
+
if (!isObject(p.issuer) || !isObject(p.principal) || !isObject(p.agent) || !isObject(p.session) || !isObject(p.model))
|
|
40
|
+
return "issuer, principal, agent, session, or model is not an object";
|
|
41
|
+
if (!isObject(p.tool) || typeof p.tool.name !== "string")
|
|
42
|
+
return "tool.name is not a string";
|
|
43
|
+
if (!isObject(p.request) || typeof p.request.argsDigest !== "string" || !isObject(p.request.args))
|
|
44
|
+
return "request.args or request.argsDigest is not what it should be";
|
|
45
|
+
if (!isObject(p.execution) || !["executed", "failed", "denied", "error", "withheld"].includes(String(p.execution.status)))
|
|
46
|
+
return "execution.status is not a status";
|
|
47
|
+
if (p.policy !== null && (!isObject(p.policy) || (p.policy.decision !== "allow" && p.policy.decision !== "deny") || !Array.isArray(p.policy.reasons)))
|
|
48
|
+
return "policy is neither null nor a decision";
|
|
49
|
+
if (!isObject(p.facts) || Object.values(p.facts).some((f) => !isObject(f) || typeof f.tool !== "string"))
|
|
50
|
+
return "facts is not a map of facts";
|
|
51
|
+
if (p.consumed !== undefined && !isObject(p.consumed))
|
|
52
|
+
return "consumed is not an object";
|
|
53
|
+
if (p.delegation !== undefined && (!isObject(p.delegation) || !isObject(p.delegation.envelope)))
|
|
54
|
+
return "delegation is not a signed envelope";
|
|
55
|
+
if (p.authorization !== undefined && (!isObject(p.authorization) || !isObject(p.authorization.envelope)))
|
|
56
|
+
return "authorization is not a bundle";
|
|
57
|
+
if (isObject(p.execution.upstream) && typeof p.execution.upstream.provider !== "undefined" && typeof p.execution.upstream.provider !== "string")
|
|
58
|
+
return "execution.upstream.provider is not a string";
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
8
61
|
export function verifyBundle(bundle, opts) {
|
|
9
62
|
const checks = [];
|
|
10
63
|
const add = (name, ok, detail) => {
|
|
@@ -21,6 +74,9 @@ export function verifyBundle(bundle, opts) {
|
|
|
21
74
|
const st = sig.payload;
|
|
22
75
|
if (!add("receipt payload type", bundle.envelope.payloadType === RECEIPT_TYPE && st.predicateType === RECEIPT_PREDICATE_TYPE))
|
|
23
76
|
return done(null);
|
|
77
|
+
const broken = structuralProblem(st.predicate);
|
|
78
|
+
if (!add("structural parts in clear", !broken, broken ?? undefined))
|
|
79
|
+
return done(null);
|
|
24
80
|
const p = st.predicate;
|
|
25
81
|
add("issuer kind is known", p.issuer.kind === "gateway" || p.issuer.kind === "sdk", `${p.issuer.kind}${p.issuer.framework ? ` / ${p.issuer.framework}` : ""}`);
|
|
26
82
|
add("issuer keyid matches signer", p.issuer.keyid === sig.keyid);
|
|
@@ -40,34 +96,135 @@ export function verifyBundle(bundle, opts) {
|
|
|
40
96
|
const d = del.delegation;
|
|
41
97
|
const principalKeyid = p.principal.provenance === "attested" ? p.principal.keyid : null;
|
|
42
98
|
add("delegation binds principal and agent", d.principal === p.principal.id && d.agent === p.agent.id && del.keyid === principalKeyid);
|
|
43
|
-
add("delegation valid at receipt time", delegationValidAt(d, p.timestamp), `${d.issuedAt} .. ${d.expiresAt}`);
|
|
44
99
|
const inScope = d.scopes.includes(p.tool.name);
|
|
45
100
|
const executed = p.execution.status === "executed" || p.execution.status === "failed";
|
|
101
|
+
// a call the gateway refused after the grant ran out is still a true record; only an executed call has to sit inside the window
|
|
102
|
+
const valid = delegationValidAt(d, p.timestamp);
|
|
103
|
+
add("delegation valid at receipt time", valid || !executed, valid ? `${d.issuedAt} .. ${d.expiresAt}` : `${d.issuedAt} .. ${d.expiresAt}; the call was ${p.execution.status}, so the grant need not have been in force`);
|
|
46
104
|
add("executed tool within delegated scope", !executed || inScope, inScope ? p.tool.name : `${p.tool.name} not in [${d.scopes.join(", ")}]`);
|
|
47
105
|
}
|
|
48
106
|
}
|
|
49
107
|
else {
|
|
50
108
|
add("principal is claimed, not attested", p.principal.provenance === "claimed", "no signed delegation in this receipt");
|
|
51
109
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
110
|
+
// Private evidence: the signed capture note names every path whose value is withheld behind a commitment. Each path
|
|
111
|
+
// is put back when the receipt carries the value, when it is disclosed, or when the capture key reveals it; a digest
|
|
112
|
+
// over values that are all back is recomputed (with the salt the statement carries), and otherwise the check passes
|
|
113
|
+
// as a commitment and says so. The note decides, never the shape of the data: a path it names must hold a
|
|
114
|
+
// commitment, and commitment-shaped data it does not name is ordinary data, inside the digest.
|
|
115
|
+
const subjectOk = st.subject[0]?.digest.sha256 === p.request.argsDigest;
|
|
116
|
+
const note = p.capture;
|
|
117
|
+
if (opts.disclosed && typeof opts.disclosed === "object" && "receiptId" in opts.disclosed && opts.disclosed.receiptId !== undefined) {
|
|
118
|
+
add("disclosure names this receipt", opts.disclosed.receiptId === p.receiptId, opts.disclosed.receiptId === p.receiptId ? undefined : `the disclosure is for receipt ${String(opts.disclosed.receiptId)}`);
|
|
119
|
+
}
|
|
120
|
+
const back = restorePaths(p, note, opts.disclosed, opts.captureKey);
|
|
121
|
+
const full = back.predicate;
|
|
122
|
+
const committedNote = (paths) => {
|
|
123
|
+
const encrypted = paths.filter((w) => getAt(p, w)?.$custody === "encrypted").length;
|
|
124
|
+
return `committed, not recomputed: ${paths.length} value(s) withheld${encrypted ? ` (${encrypted} encrypted)` : ""}; ${encrypted ? "give the capture key or " : ""}disclose them to recompute`;
|
|
125
|
+
};
|
|
126
|
+
const claimed = new Set();
|
|
127
|
+
/** the state of the withheld paths under a prefix, and the paths it claims for its check line */
|
|
128
|
+
const region = (prefix) => {
|
|
129
|
+
const paths = (note?.withheld ?? []).filter((w) => under(w, prefix));
|
|
130
|
+
for (const w of paths)
|
|
131
|
+
claimed.add(pathKey(w));
|
|
132
|
+
const problem = back.problems.find((x) => under(x.path, prefix))?.error ?? null;
|
|
133
|
+
const missing = back.missing.filter((w) => under(w, prefix));
|
|
134
|
+
const hows = [...new Set(paths.map((w) => back.restored.get(pathKey(w))).filter((h) => !!h))];
|
|
135
|
+
const how = hows.length === 2 ? "disclosed and decrypted" : hows[0];
|
|
136
|
+
return { paths, problem, missing, how };
|
|
137
|
+
};
|
|
138
|
+
const args = region(["request", "args"]);
|
|
139
|
+
if (args.problem)
|
|
140
|
+
add("request args digest", false, args.problem);
|
|
141
|
+
else if (args.missing.length)
|
|
142
|
+
add("request args digest", subjectOk, committedNote(args.missing));
|
|
143
|
+
else
|
|
144
|
+
add("request args digest", digestOf(full.request.args, digestSaltFor(back, note, ["request", "args"])) === p.request.argsDigest && subjectOk, args.how ? `recomputed from ${args.how} values` : undefined);
|
|
145
|
+
// a captured fact: its commitments are checked against a disclosure or the key; the policy decided on the real value
|
|
146
|
+
for (const name of Object.keys(p.facts)) {
|
|
147
|
+
for (const part of ["value", "args"]) {
|
|
148
|
+
const r = region(["facts", name, part]);
|
|
149
|
+
if (!r.paths.length)
|
|
150
|
+
continue;
|
|
151
|
+
if (r.problem)
|
|
152
|
+
add(`fact ${name} ${part}`, false, r.problem);
|
|
153
|
+
else
|
|
154
|
+
add(`fact ${name} ${part}`, true, r.missing.length ? committedNote(r.missing) : `commitments hold against the ${r.how} value`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const executedOrFailed = p.execution.status === "executed" || p.execution.status === "failed";
|
|
158
|
+
let result = null;
|
|
159
|
+
if (executedOrFailed) {
|
|
160
|
+
const r = region(["execution", "result"]);
|
|
161
|
+
const ex = full.execution;
|
|
162
|
+
if (r.problem)
|
|
163
|
+
add("execution result digest", false, r.problem);
|
|
164
|
+
else if (r.missing.length) {
|
|
165
|
+
add("execution result digest", true, committedNote(r.missing));
|
|
166
|
+
// the upstream checks read the content, isError, and structuredContent, never _meta, which carries what the
|
|
167
|
+
// upstream wrote and is withheld beside a result the rule leaves in clear: with only _meta withheld they still run
|
|
168
|
+
if (r.missing.every((w) => pathKey(w) === pathKey(["execution", "result", "_meta"])))
|
|
169
|
+
result = ex.result;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
add("execution result digest", digestOf(ex.result, digestSaltFor(back, note, ["execution", "result"])) === ex.resultDigest, r.how ? `recomputed from ${r.how} values` : undefined);
|
|
173
|
+
result = ex.result;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// every other withheld path gets its own line: a message, a denial reason, a provider's delivery body, a part added later
|
|
177
|
+
for (const w of note?.withheld ?? []) {
|
|
178
|
+
if (claimed.has(pathKey(w)))
|
|
179
|
+
continue;
|
|
180
|
+
const problem = back.problems.find((x) => pathKey(x.path) === pathKey(w))?.error;
|
|
181
|
+
const how = back.restored.get(pathKey(w));
|
|
182
|
+
add(`withheld ${pathText(w)}`, !problem, problem ?? (how ? `holds against the ${how} value` : committedNote([w])));
|
|
183
|
+
}
|
|
184
|
+
const evidence = executedOrFailed && "upstream" in p.execution ? p.execution.upstream : undefined;
|
|
185
|
+
if (executedOrFailed && evidence) {
|
|
186
|
+
// The evidence as restored: the delivery body or the signed envelope may have been withheld with the result. A
|
|
187
|
+
// check is skipped only for a part the signed note declares withheld and the verifier could not restore; a body
|
|
188
|
+
// or an envelope that is simply not there, or commitment-shaped without the note saying so, fails the check.
|
|
189
|
+
const restoredEvidence = full.execution.upstream;
|
|
190
|
+
const withheldStill = (path) => (note?.withheld ?? []).some((w) => pathKey(w) === pathKey(path)) && back.missing.some((w) => pathKey(w) === pathKey(path));
|
|
191
|
+
if (isProviderAttestation(evidence)) {
|
|
56
192
|
if (opts.providerSecrets) {
|
|
57
|
-
const
|
|
58
|
-
|
|
193
|
+
const re = restoredEvidence;
|
|
194
|
+
const parts = ["rawBody", "signature", "bind"];
|
|
195
|
+
if (!result || parts.some((f) => withheldStill(["execution", "upstream", f])))
|
|
196
|
+
add("upstream signature not checked", true, "the result, the delivery body, its signature, or its bind is withheld; disclose them or give the capture key to check the provider's delivery");
|
|
197
|
+
else if (parts.some((f) => typeof re?.[f] !== "string"))
|
|
198
|
+
add("upstream signature (provider secret)", false, "the receipt carries no delivery body, signature, or bind to check, and the capture note does not say they are withheld");
|
|
199
|
+
else {
|
|
200
|
+
const u = checkProvider({ ...evidence, rawBody: re.rawBody, signature: re.signature, bind: re.bind }, opts.providerSecrets, { timestamp: p.timestamp, result });
|
|
201
|
+
add("upstream signature (provider secret)", u.ok, u.ok ? u.keyid : u.error);
|
|
202
|
+
}
|
|
59
203
|
}
|
|
60
204
|
}
|
|
61
205
|
else if ((opts.upstreamKeys?.length ?? 0) > 0) {
|
|
62
|
-
const
|
|
63
|
-
|
|
206
|
+
const env = restoredEvidence?.envelope;
|
|
207
|
+
const wellFormed = !!env && typeof env === "object" && typeof env.payload === "string" && Array.isArray(env.signatures);
|
|
208
|
+
if (!result)
|
|
209
|
+
add("upstream signature not checked", true, "the result is withheld; disclose it or give the capture key to check the upstream's signature against it");
|
|
210
|
+
// the issuer withholds the envelope beside a result it leaves in clear only when the envelope is anything but the plain attestation for this call (a field, a claim, or an encoding the upstream added); a verifier given the upstream's key is then told, not waved past
|
|
211
|
+
else if (withheldStill(["execution", "upstream", "envelope"]))
|
|
212
|
+
add("upstream signature (upstream key)", false, "the result is in clear but the upstream's signature is withheld; disclose it or give the capture key to check it");
|
|
213
|
+
else if (!wellFormed)
|
|
214
|
+
add("upstream signature (upstream key)", false, "the receipt carries no upstream envelope to check, and the capture note does not say it is withheld");
|
|
215
|
+
else {
|
|
216
|
+
const u = checkUpstream(env, opts.upstreamKeys, { receiptId: p.receiptId, tool: p.tool.name, contentDigest: contentDigest(result) });
|
|
217
|
+
add("upstream signature (upstream key)", u.ok, u.ok ? `keyid ${short(u.keyid)}` : u.error);
|
|
218
|
+
}
|
|
64
219
|
}
|
|
65
220
|
}
|
|
66
221
|
if (p.policy) {
|
|
67
222
|
// a deny that was not enforced (observe mode, enforced: false on the receipt) may sit beside an executed call; an enforced one never does
|
|
68
223
|
const consistent = p.policy.decision === "allow" ? p.execution.status !== "denied" : p.policy.enforced === false ? p.execution.status !== "denied" : p.execution.status === "denied";
|
|
69
224
|
add("policy decision consistent with execution", consistent, `${p.policy.decision}${p.policy.enforced === false ? " (observe mode, not enforced)" : ""} -> ${p.execution.status}`);
|
|
70
|
-
|
|
225
|
+
// a withheld error list is a non-empty one: the issuer leaves an empty list in clear
|
|
226
|
+
const errors = isCommitment(p.policy.errors) || (Array.isArray(p.policy.errors) && p.policy.errors.length > 0);
|
|
227
|
+
add("no policy errors on an allow", !(p.policy.decision === "allow" && errors));
|
|
71
228
|
}
|
|
72
229
|
const logKeys = opts.logKeys ?? [];
|
|
73
230
|
if (p.authorization) {
|
|
@@ -167,9 +324,10 @@ export function formatReport(r) {
|
|
|
167
324
|
const row = (f, prov, v) => lines.push(`${f.padEnd(15)} ${prov.padEnd(11)} ${typeof v === "string" ? v : JSON.stringify(v)}`);
|
|
168
325
|
row("principal", p.principal.provenance, p.principal.id ?? "(none)");
|
|
169
326
|
row("agent", p.agent.provenance, p.agent.id);
|
|
327
|
+
const idText = (v) => (typeof v === "string" ? v : v === null || v === undefined ? "-" : "(withheld under the capture rule)");
|
|
170
328
|
if (p.session.id || p.session.toolUseId)
|
|
171
|
-
row("session", p.session.provenance, `${p.session.id
|
|
172
|
-
row("model", p.model.provenance, p.model.id
|
|
329
|
+
row("session", p.session.provenance, `${idText(p.session.id)} / ${idText(p.session.toolUseId)}`);
|
|
330
|
+
row("model", p.model.provenance, p.model.id === null ? "(none supplied)" : idText(p.model.id));
|
|
173
331
|
row("tool", p.tool.provenance, p.tool.name);
|
|
174
332
|
row("args", p.request.provenance, p.request.args);
|
|
175
333
|
for (const [k, f] of Object.entries(p.facts))
|
|
@@ -179,7 +337,7 @@ export function formatReport(r) {
|
|
|
179
337
|
else
|
|
180
338
|
row("policy", "-", "(none evaluated)");
|
|
181
339
|
if (p.consumed)
|
|
182
|
-
row("consumed", p.consumed.provenance, p.consumed.factIds.length === 0 ? "(no facts shown before this call)" : p.consumed.factIds);
|
|
340
|
+
row("consumed", p.consumed.provenance, !Array.isArray(p.consumed.factIds) ? "(withheld under the capture rule)" : p.consumed.factIds.length === 0 ? "(no facts shown before this call)" : p.consumed.factIds);
|
|
183
341
|
if (p.authorization) {
|
|
184
342
|
const committed = r.checks.filter((c) => c.name.startsWith("authorization ")).every((c) => c.ok);
|
|
185
343
|
row("authorization", "observed", committed ? `committed to the log as leaf ${p.authorization.inclusion.leafIndex}, before the call was forwarded` : "carried, but its checks FAILED");
|
package/docs/compliance.md
CHANGED
|
@@ -24,7 +24,7 @@ Two rules keep the answers honest. First, say which producer made the receipt: a
|
|
|
24
24
|
| criterion | what it asks | what answers it |
|
|
25
25
|
| --- | --- | --- |
|
|
26
26
|
| CC6.1, logical access | access to systems is restricted to authorized users | the delegation grant: a human-signed statement of which agent may call which tools, for how long, embedded in every gateway receipt and re-checked by the verifier |
|
|
27
|
-
| CC6.3, authorization changes | access is granted, modified, and removed by authorized parties | grants have validity windows and are signed by a principal key the gateway is configured to trust; a new grant is a new signed file, a
|
|
27
|
+
| CC6.3, authorization changes | access is granted, modified, and removed by authorized parties | grants have validity windows and are signed by a principal key the gateway is configured to trust; a new grant is a new signed file; `agent-custody revoke` revokes a grant, and every session under it or under a grant delegated from it refuses its next call |
|
|
28
28
|
| CC7.2, monitoring for anomalies | the entity monitors system components for anomalies | every call has a receipt, allowed or denied, and `explain` answers who, why, and what depended on it; the OpenTelemetry and Splunk exports carry each receipt into the existing SIEM |
|
|
29
29
|
| CC7.3, evaluation of security events | events are evaluated to determine whether they are incidents | the action pack: one receipt with every downstream receipt, verifiable by the evaluator without access to the system |
|
|
30
30
|
| CC7.4, incident response | incidents are contained and remediated | blast radius names every action and belief that depended on a wrong fact; retract and forget are receipted calls, so the remediation has its own evidence |
|
package/docs/tutorials.md
CHANGED
|
@@ -35,6 +35,8 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
|
|
|
35
35
|
| 23 | a LangChain agent under custody, end to end | [23-langchain-kb-agent.ts](../examples/23-langchain-kb-agent.ts) | a docs agent on LangChain's `createAgent` reading a runbook, refused when it edits one, writing a note that cites its source; three receipts verified with the public key and the log copy; the auditor's report for the refused write. Scripted model, no API key. [23-langchain-kb-agent.tape](../examples/23-langchain-kb-agent.tape) renders it as a film with vhs | `src/sdk/index.ts`, `src/verify.ts` |
|
|
36
36
|
| 24 | an agentic CI/CD merge gate with evidence | [24-agentic-cicd-merge-gate.ts](../examples/24-agentic-cicd-merge-gate.ts) | a release agent merging pull requests through the gateway against a stand-in git host: the risk tier is a policy on facts the gateway fetched itself (diff size, sensitive paths, gate results, human approvals); low merges alone, medium needs a CODEOWNER, high is refused for any agent, production promotion refused; merges pre-committed to the log; an evidence index from the receipts alone, every line verified | `src/gateway.ts`, `src/rest.ts`, `src/verify.ts` |
|
|
37
37
|
| 25 | an agent delegating to an agent over A2A | [25-a2a-delegation.ts](../examples/25-a2a-delegation.ts) | a stand-in document agent speaking A2A 1.0, the gateway serving A2A in front of it with the document agent's card at its own address, an engagement agent delegating twice as an A2A client: one task allowed and answered with the receipt id in its metadata, one refused as a rejected task because it names a privileged matter, the policy deciding on the card the gateway fetched itself; both receipts verified, the allowed one carrying the card as a fact and the authorization logged before the task went out | `src/a2a.ts`, `src/gateway.ts` |
|
|
38
|
+
| 26 | private evidence | [26-private-evidence.ts](../examples/26-private-evidence.ts) | a capture rule for a refund: the arguments encrypted except the amount and the customer id, the provider's answer and the customer record withheld as digests; the receipt file carrying commitments and none of the phone number, the card, the note, or the record; verified as committed without the key; `reveal` with the key writing the disclosure and `verify --capture-key-env` recomputing every digest; a disclosure that lies failing the commitment | `src/capture.ts`, `src/verify.ts` |
|
|
39
|
+
| 27 | revoking an agent's authority mid-session | [27-revocation.ts](../examples/27-revocation.ts) | a support agent and the sub-agent it delegated to, both mid-session on one gateway, cut off on their next call when the operator runs `agent-custody revoke` from another process: no key rotated, no restart, each refusal a signed receipt that verifies, and a new session, a repacked grant, or a fresh delegation from it all refused | `src/gateway.ts` (`revokedGrants`, re-read on every call), `src/delegation.ts` (`grantDigest`, the chain), `src/cli.ts` (`revoke`) |
|
|
38
40
|
|
|
39
41
|
## How policies are defined, in one paragraph
|
|
40
42
|
|
package/docs/usage.md
CHANGED
|
@@ -121,7 +121,7 @@ At startup the gateway fetches the agent's card from `<url>/.well-known/agent-ca
|
|
|
121
121
|
"log": { "url": "https://log.example.com/", "tokenEnv": "AGENT_CUSTODY_LOG_TOKEN" }
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log refuses a leaf, the receipt is not issued and the call returns an error to the agent. For an ordinary call the upstream action has already happened by then, and the error says so; a receipt that was never logged must not be handed out. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]`, `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls, so a tenant out of quota never acts without evidence. The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
|
|
124
|
+
Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. The gateway does not take the log's answer on trust either: the tree head in every append's answer must verify against the log's keys, name the expected log, match the proof's size, and the inclusion proof must place that very leaf under the signed root, all before a pre-committed call is forwarded and before any receipt is handed out; an answer that fails any of it is a refusal. `"keys": ["keys/log.pub"]` pins the log's public keys, `"logId"` the id its heads must carry; without `keys` the log's key document at `/.well-known/agent-custody-log.json` is fetched from the log itself once, on the first append, and pinned. That catches a log that turns dishonest later, not one that is dishonest from the start, so a gateway config with `precommit` and a remote log must list `keys`. When the log rotates its key, add the new public key to `keys`; a gateway that fetched the keys needs a restart. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log refuses a leaf, the receipt is not issued and the call returns an error to the agent. For an ordinary call the upstream action has already happened by then, and the error says so; a receipt that was never logged must not be handed out. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]`, `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls, so a tenant out of quota never acts without evidence. The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
|
|
125
125
|
|
|
126
126
|
`otel`, optional in both the gateway and SDK configs, sends every receipt to the collector you already run as one span over OTLP/HTTP, after the receipt is issued: `"otel": { "url": "http://localhost:4318", "headersEnv": { "x-api-key": "OTEL_KEY" }, "serviceName": "support-agents" }`. The span's trace id is the receipt id, its attributes carry the tool, agent, principal, execution status, policy decision, and log position, and its status is an error only when the upstream failed or errored, since a denial is the policy working. Export is best effort: a collector that is down or refuses costs a line on stderr, never a receipt. Tutorial 18 shows it against a stand-in collector.
|
|
127
127
|
|
|
@@ -129,9 +129,9 @@ Exactly one of the two. The bearer token comes from the named environment variab
|
|
|
129
129
|
|
|
130
130
|
`facts` tells the gateway which upstream tool to call before evaluating policy for a given tool. `$args.<key>` copies a value from the intercepted call. The result appears in Cedar as `context.facts.<name>` and in the receipt with its own digest, labelled `observed`. If a fact lookup fails, the call is denied and the receipt says why. A lookup with `"optional": true` is skipped when a `$args.<key>` it needs is absent from the call, and the fact is then simply not present, which a policy tests with `context.facts has <name>`; this is how a policy sees the fact a `memory.write` is about to supersede without denying every write that supersedes nothing.
|
|
131
131
|
|
|
132
|
-
`mode` is `"enforce"` by default. Set it to `"observe"` to run a new policy against real traffic before turning it on: every call the grant allows is forwarded, the decision the policy would have made is recorded on the receipt with `enforced: false`, and nothing is withheld. The verifier accepts such a receipt and names the mode; strip the flag and the same receipt fails. Switch to `"enforce"` when the receipts stop saying "would have been denied" for calls you meant to allow.
|
|
132
|
+
`mode` is `"enforce"` by default. Set it to `"observe"` to run a new policy against real traffic before turning it on: every call the grant allows is forwarded, the decision the policy would have made is recorded on the receipt with `enforced: false`, and nothing is withheld. Observe mode suspends the policy and nothing else: a tool outside the grant's scopes, or a call after the grant expired or was revoked, is denied and never forwarded in either mode. The verifier accepts such a receipt and names the mode; strip the flag and the same receipt fails. Switch to `"enforce"` when the receipts stop saying "would have been denied" for calls you meant to allow.
|
|
133
133
|
|
|
134
|
-
`precommit` names the consequential tools, or `["*"]` for all of them. For every other tool the gateway forwards the call and then records it, so if the log is unreachable at that moment the side effect exists before its evidence does. For a tool in `precommit` the gateway first signs an authorization statement, everything the receipt will say except the outcome, and appends it to the log. Only if the log took it does the call go upstream. The receipt then embeds that authorization with its own inclusion proof, and a verifier checks that it names this call and sits in the log before the receipt does. If the log will not take it, the call is not forwarded, the agent is told `Not executed`, and the receipt records `execution.status: "withheld"` with the policy's `allow` beside it. The authorization is also written on its own as `receipts/<receiptId>.authorization.json`, which is the evidence that survives if the gateway dies between forwarding and the receipt. Use it for money, for anything irreversible, and for anything a counterparty could later dispute; the cost is one extra log append per call.
|
|
134
|
+
The grant is checked on every call, not only when the session opens: a call after `expiresAt` is denied with a receipt that says so, the check is repeated just before the forward (a grant that ran out while the facts were gathered leaves the call `withheld`), and over HTTP a session whose grant has expired or been revoked is closed on its next request with `403`. `"revokedGrants": "revoked.json"` names a file of grant digests the gateway re-reads whenever it changes. The digest is sha256 over the grant's signed payload, so extra signatures or fields on the envelope do not change it, and revoking a grant also revokes every grant delegated from it. A file that cannot be read denies every call until it can be read; `agent-custody revoke --config gateway.json --grant grant.json` appends a grant's digest to it, after which every session under that grant refuses its next call and no new session opens for it, with no key rotation. `precommit` names the consequential tools, or `["*"]` for all of them. For every other tool the gateway forwards the call and then records it, so if the log is unreachable at that moment the side effect exists before its evidence does. For a tool in `precommit` the gateway first signs an authorization statement, everything the receipt will say except the outcome, and appends it to the log. Only if the log took it does the call go upstream. The receipt then embeds that authorization with its own inclusion proof, and a verifier checks that it names this call and sits in the log before the receipt does. If the log will not take it, or answers with a head or proof that does not verify, the call is not forwarded, the agent is told `Not executed`, and the receipt records `execution.status: "withheld"` with the policy's `allow` beside it. The authorization is also written on its own as `receipts/<receiptId>.authorization.json`, which is the evidence that survives if the gateway dies between forwarding and the receipt. Use it for money, for anything irreversible, and for anything a counterparty could later dispute; the cost is one extra log append per call.
|
|
135
135
|
|
|
136
136
|
**5. Run the gateway.** It speaks MCP on stdin/stdout and logs to stderr only.
|
|
137
137
|
|
|
@@ -141,6 +141,46 @@ node src/cli.ts gateway --config ./gateway.json
|
|
|
141
141
|
|
|
142
142
|
You will not normally run this by hand. The agent host spawns it, as below.
|
|
143
143
|
|
|
144
|
+
## Private evidence
|
|
145
|
+
|
|
146
|
+
A receipt carries the call as it happened: the arguments, the result, and the facts the policy decided on. Some of that a reviewer has no business seeing: the note on a refund with the caller's phone number, the customer record the policy read, the provider's full answer. `capture` in the config says, per tool, what the receipt file carries of each part:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
"capture": {
|
|
150
|
+
"stripe.refund": {
|
|
151
|
+
"args": { "mode": "encrypted", "clear": ["customer_id", "amount"] },
|
|
152
|
+
"result": { "mode": "digest" },
|
|
153
|
+
"facts": { "mode": "encrypted" }
|
|
154
|
+
},
|
|
155
|
+
"*": { "facts": { "mode": "digest" } }
|
|
156
|
+
},
|
|
157
|
+
"captureKeyEnv": "AGENT_CUSTODY_CAPTURE_KEY"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
A rule names a tool, or `"*"` for every tool without a rule of its own, and gives a side for the arguments, the result, and the facts, each with a `mode`:
|
|
161
|
+
|
|
162
|
+
- `clear`: the side in the receipt as it was.
|
|
163
|
+
- `digest`: the fields listed in `clear` stay, and every other top-level field is withheld together, as one commitment at `$rest`, `{ "$custody": "withheld", "sha256": "<sha256 over a random salt and the canonical object of those fields>" }`, so that not even their names appear (a field name is chosen by the agent or the upstream, like a value). The salt is not in the receipt: the issuer keeps it in `receipts/salts/<id>.json`, a private file beside the receipts that never goes to a reviewer, and nowhere else. Whoever holds the value and the salt can later show them, and the commitment proves it is the value the receipt was made over; without the salt, nobody can confirm a guess of the value against it.
|
|
164
|
+
- `encrypted`: the same commitment, carrying the value and its salt as well under a 32-byte key you hold, `{ "$custody": "encrypted", "alg": "A256GCM", "keyid", "iv", "ciphertext", "tag", "sha256" }`. The key is read at startup from the environment variable `captureKeyEnv` names, 64 hex characters or base64, never from the file; a rule in mode `encrypted` without it fails at startup. `keyid` is the sha256 of the key, so a reviewer knows which key reveals a value.
|
|
165
|
+
|
|
166
|
+
The rule is applied in one place, by the issuer, to the whole statement just before it is signed, so nothing it guards reaches the receipt file, the log, or an exporter in clear. Once any side is private, the receipt for that tool is: a side the rule does not set is withheld whole, field by field, and so is every other value that is not structural: the policy's error messages, a denial reason, the message of a tool that threw, the result's `_meta` (which carries whatever an upstream put there, even when the result itself is left in clear), a provider delivery's body, an upstream's signed envelope (whose payload may carry any claim the upstream chose; beside a result the rule leaves in clear, an envelope that is exactly the plain attestation for this call stays, so the signature over that public result can be checked: the three envelope fields, one signature entry of a key id and a signature, and a canonical payload naming this receipt, this tool, and this result's digest; any other field, claim, or encoding withholds it, and a verifier given the upstream's key then fails the check until the envelope is disclosed or opened with the key), the fact ids an upstream declared it served (`consumed.factIds`), a provider's signature and bind (the signature is a MAC over the withheld body: whoever holds the secret could confirm a guess of the body against it), and the session and model ids the agent's call or process supplied. Only the provider's name stays. What stays in clear is a fixed list: the receipt id, the key ids and timestamps, the tool name (a name no upstream offers is recorded as `(unknown tool)` under a private rule, since it is text the agent chose, and takes its name's rule and the wildcard together, side by side: the more private mode and only the fields both keep in clear, so a rule left for a retired name never widens what the wildcard keeps private), the grant, the digests, the decision and the ids of the policies behind it, the status, the provenance fields, a provider's name, and the note itself. The test: the issuer, the grant, or the config produced it; nothing the agent, an upstream, or a provider wrote stays in clear. A side set to `clear` stays in clear. A field added to the receipt later starts withheld, never in clear. The values outside the three sides take the rule's mode: `encrypted` as soon as any side is, so the key brings everything back, `digest` otherwise.
|
|
167
|
+
|
|
168
|
+
`clear` lists the top-level fields kept in clear, each kept whole whatever it holds (list a field only when everything it may carry is fit for a reviewer); a value that is not a plain object is withheld whole; a field literally named `$rest` is never kept in clear. On a result, `isError` stays in clear when it is the boolean status flag (anything else under that name is a value and is withheld), and `_meta` is withheld whatever the list says. The receipt's `request.args` is then `{ "amount": 2500, "customer_id": "cust_123", "$rest": { "$custody": "withheld", "sha256": "…" } }`, and the same shape holds for `execution.result` and each fact's `value`; a fact's lookup arguments are captured field by field, since their names are the fact config's. Facts are captured field by field under the `facts` side. A fact lookup's arguments follow the call's `args` side, because they are copied from the call: a fact argument stays in clear only when its template is a constant or copies a call argument the rule keeps in clear, so a field withheld from the request does not reappear as the argument of the lookup that used it. What the lookup answers follows the `facts` side, which is private unless you set it to `clear`. The same two fields work in the SDK config, where the same issuer applies the rule, so every adapter's receipts get it, a wrapped tool's thrown message included. The SDK trusts the tool name it is given, since the application chose it; the sidecar records whatever name its caller sends.
|
|
169
|
+
|
|
170
|
+
What changes is the receipt file and nothing else. The policy decides on the real values; the agent gets the real result, the real error, and the real reason; the digests and the signature are over the whole call. Under a private rule `request.argsDigest` and `execution.resultDigest` are sha256 over the full value and a salt derived from the salts of the withheld values under them, so whoever can restore those values can recompute the digest and nobody else can confirm a guess against it; a digest over values that are all in clear is unsalted, as before. A fact's `resultDigest` becomes a commitment to the lookup's full result, since the receipt shows only the selected value and the rest of that result (its metadata, its other content) is never public under a private rule, whatever the selected fields are; it is disclosed, decrypted, and checked like any withheld value. The signed statement carries one note, `capture: { "mode", "withheld": [["request", "args", "$rest"], ["execution", "result", "$rest"], ["execution", "upstream", "rawBody"], …] }`, naming every path that holds a commitment in place of its value. The note is what a verifier trusts, not the shape of the data: a path the note names must hold a commitment, or the check fails, and commitment-shaped data at a path the note does not name is ordinary data inside the digest. The receipt format stays v0.2; the fields are optional.
|
|
171
|
+
|
|
172
|
+
A reviewer verifies such a receipt three ways:
|
|
173
|
+
|
|
174
|
+
- With the receipt alone, every signature and proof checks as before. `request args digest` and `execution result digest` pass as committed, with the detail "committed, not recomputed: N value(s) withheld; give the capture key or disclose them to recompute", because the signed statement carries the digest; a captured fact gets a `fact <name> value` line, and `fact <name> args` when its arguments were withheld, saying the same; every other withheld path gets a `withheld <path>` line. With an upstream key or a provider secret and a withheld result, body, or envelope, `upstream signature not checked` passes with a note in place of the signature check.
|
|
175
|
+
- With the key: `agent-custody verify ... --capture-key-env AGENT_CUSTODY_CAPTURE_KEY` decrypts every encrypted value, checks each against its commitment, and recomputes the digests and the upstream's signature from the real values. A key that is not the one the values were encrypted under fails the checks, naming the key id, rather than passing them as committed.
|
|
176
|
+
- With a disclosure: `agent-custody verify ... --disclose disclosure.json` does the same from a file holding, at each withheld path, the real value and the salt its commitment was made with: `{ "receiptId", "request": { "args": { "$rest": { "$custody": "disclosed", "salt": "<hex>", "value": { "reason": "…" } } } }, "execution": { "result": { "$rest": { … } }, "error", "upstream": { "rawBody", "signature", "bind" } }, "policy": { "errors" }, "facts": { "<name>": { "value": { "$rest": { … } }, "args": { … }, "resultDigest" } } }`, any part of it. A disclosed `$rest` is folded back into its object before the digest is recomputed. A value without its salt cannot be checked and is refused as such. A disclosure that contradicts a commitment fails the check with the path named, a fact's value included: a reviewer cannot be handed a false policy fact. A disclosure for another receipt is refused.
|
|
177
|
+
|
|
178
|
+
`agent-custody reveal receipts/<id>.json --capture-key-env AGENT_CUSTODY_CAPTURE_KEY --issuer-key keys/gateway.pub --out disclosure.json` writes that disclosure from the key, every encrypted value decrypted and checked against its commitment, with its salt. The bundle must verify against the issuer key given, and each ciphertext is bound to its receipt and path, so a bundle someone assembled around another receipt's ciphertexts reveals nothing. The file is written owner-only and never through a symlink. A value withheld as a digest only carries nothing to reveal, and the command says which paths it could not reveal. With `--include-salts` it also writes, at each such path, the salt from the issuer's salts file beside the receipt, for whoever holds the value to add `value` beside; a file with a salt and no value does not verify, so it cannot be handed over unfinished by mistake. Hand the finished file to the reviewer with the receipt, never the salts file.
|
|
179
|
+
|
|
180
|
+
The salts file, `receipts/salts/<id>.json`, is written for the owner alone (mode 0600 in a 0700 directory) and is as sensitive as the values: with it a guess can be confirmed. In mode `digest` it is also the only copy of each salt: lose it, and nobody can disclose those values again, not even the party that holds them, since a value alone cannot be checked against its commitment; the receipt then verifies only as committed. Back the directory up with the receipts, under the same access control as the values themselves. Mode `encrypted` carries each salt inside the ciphertext and nowhere else (the salts file holds only the digest-only ones), so the key alone recovers everything; choose it when a key is easier to keep safe than a directory of files. The key must be 32 random bytes: a reviewer sees its sha256 as `keyid` in every encrypted commitment, which is harmless for a random key and an offline oracle for a key derived from a passphrase. `agent-custody prune` removes the salts and the pre-committed authorization with the receipt.
|
|
181
|
+
|
|
182
|
+
The limits. A commitment covers a top-level field, so a field is withheld whole, not in part; put what a reviewer may see in fields of its own. An upstream's own signature covers `contentDigest`, an unsalted sha256 over `{ content, isError }` that the upstream computes, so a reviewer holding the upstream's key and a guess of the whole result can confirm the guess; the gateway cannot salt what the upstream signs. A `digest`-only value can be recomputed only by whoever holds it. A result's top-level `_meta` is withheld whatever the rule says, but a `content` item listed in `clear` is kept whole, its own item-level `_meta` or annotations included; list `content` in `clear` only when every item is fit for a reviewer. The verifier cannot tell a redacted receipt from a complete one beyond the capture note; what it establishes is that whatever is shown, disclosed, or decrypted is the value the signed digest was made over. Nothing here changes what the log receives: a remote log run with `hashOnly` gets leaf hashes, as before, and the exporters are handed the same view as the file and carry digests only. The browser verifier at agent-custody.dev/verify reports the committed case and takes no key or disclosure; use the command-line verifier for those. Tutorial 26 runs the refund above end to end.
|
|
183
|
+
|
|
144
184
|
## One gateway for many agents, over HTTP
|
|
145
185
|
|
|
146
186
|
`agent-custody gateway --config gateway.json --http --port 8790` serves the same gateway as an MCP server over Streamable HTTP at `/mcp`, and every connection presents its own grant: the delegation envelope, base64url-encoded, as `Authorization: Bearer <value>` or `X-Agent-Custody-Grant` on the initialize request. The gateway verifies it against `trustedPrincipalKeys` and its validity window, and opens a session for exactly that grant; a grant signed by a stranger, an expired one, or none at all gets 403 with the reason and no session (403 rather than 401, because MCP clients treat 401 as an OAuth challenge and hide the body). Sessions share the key, the policy, the upstreams, the log, and the fact lookups; each has its own tools (the scopes its grant names), its own receipts (its own principal and agent, attested), and its own consumed facts. `grantFile` in the config is then optional and ignored. A session ends when the client terminates it or after `--idle-minutes` (default 30) without a request; `GET /health` reports the live count and the gateway's key id. The transport is plain HTTP: bind to loopback, a private network, or put TLS in front. From JavaScript, `grantHeader(envelope)` builds the header value; from any language it is `base64url(JSON.stringify(envelope))`. Tutorial 20 runs two agents against one gateway.
|
|
@@ -154,7 +194,7 @@ from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
|
|
|
154
194
|
docs = RemoteA2aAgent(name="document_agent", agent_card="http://127.0.0.1:8790/.well-known/agent-card.json")
|
|
155
195
|
```
|
|
156
196
|
|
|
157
|
-
The gateway serves the remote agent's card at `/.well-known/agent-card.json` (and `/.well-known/agent.json`) with its own address as the endpoint; the card's `signatures` are dropped, since they signed a card that named another address. `POST /` takes JSON-RPC. `SendMessage` and `SendStreamingMessage` (0.3: `message/send` and `message/stream`; the 1.0 HTTP+JSON binding at `POST /message:send` and `POST /message:stream` as well) become a `<prefix>.send` call under the grant in `grantFile`, or under the grant the request presents in `Authorization: Bearer` or `X-Agent-Custody-Grant`, base64url, exactly as for `--http`; every other method, `GetTask`, `CancelTask`, the push notification configs, is forwarded to the remote agent untouched
|
|
197
|
+
The gateway serves the remote agent's card at `/.well-known/agent-card.json` (and `/.well-known/agent.json`) with its own address as the endpoint; the card's `signatures` are dropped, since they signed a card that named another address. `POST /` takes JSON-RPC. `SendMessage` and `SendStreamingMessage` (0.3: `message/send` and `message/stream`; the 1.0 HTTP+JSON binding at `POST /message:send` and `POST /message:stream` as well) become a `<prefix>.send` call under the grant in `grantFile`, or under the grant the request presents in `Authorization: Bearer` or `X-Agent-Custody-Grant`, base64url, exactly as for `--http`; every other method, `GetTask`, `CancelTask`, the push notification configs, is forwarded to the remote agent untouched, with no receipt, but only under a grant in force: a missing, expired, or revoked grant gets `403`. An allowed delegation answers with the remote agent's task or message with `metadata["agent-custody/receipt"]` set to the receipt id, on every event of a stream too. A refused one answers a task in state `TASK_STATE_REJECTED` (0.3: `rejected`) whose status message reads `agent-custody: <reason> (receipt <id>)`, and nothing reached the remote agent; a delegation the log would not pre-commit is rejected the same way. A remote agent the gateway could not reach is a task in `TASK_STATE_FAILED`; a JSON-RPC error the remote agent answered is relayed as a JSON-RPC error with the receipt id under `error.data.receipt`, and the receipt records the call as failed. `GET /health` reports the fronted agent's name and the gateway's key id. ADK 2.x with a2a-sdk 1.x speaks A2A 1.0 and streams by default; both are handled. Tutorial 25 is the whole thing: a stand-in document agent, the gateway in front of it, an engagement agent delegating twice, one allowed and one refused because the task names a privileged matter, both receipts verified.
|
|
158
198
|
|
|
159
199
|
## Wiring it into an agent host
|
|
160
200
|
|
package/docs/verification.md
CHANGED
|
@@ -23,6 +23,8 @@ node src/cli.ts verify receipts/<id>.json \
|
|
|
23
23
|
|
|
24
24
|
Exit code 0 when every check passes, 1 otherwise. Add `--json` for machine-readable output. `--issuer-key` and `--principal-key` can be repeated to accept rotated keys; signatures are matched by keyid. `--gateway-key` is an alias for `--issuer-key`. `--principal-key` may be omitted for SDK receipts, which carry no delegation.
|
|
25
25
|
|
|
26
|
+
When a receipt was issued under a capture rule ([private evidence](usage.md#private-evidence)), some of its arguments, result, or facts are commitments rather than values. `--capture-key-env NAME` names the environment variable holding the customer's capture key: the verifier decrypts every encrypted field, checks it against its commitment, and recomputes the digests from the real values. `--disclose disclosure.json` does the same from a file holding the withheld values, `{ "receiptId", "args"?, "result"? }`, as `agent-custody reveal` writes it or as the party that holds them hands it over. Without either, the withheld parts pass as committed and the report says so.
|
|
27
|
+
|
|
26
28
|
A real report, produced by `node scripts/demo.ts`:
|
|
27
29
|
|
|
28
30
|
```
|
|
@@ -37,6 +39,7 @@ PASS delegation binds principal and agent
|
|
|
37
39
|
PASS delegation valid at receipt time (2026-09-04T13:06:20.074Z .. 2026-09-04T14:06:21.074Z)
|
|
38
40
|
PASS executed tool within delegated scope (stripe.refund)
|
|
39
41
|
PASS request args digest
|
|
42
|
+
PASS execution result digest
|
|
40
43
|
PASS policy decision consistent with execution (allow -> executed)
|
|
41
44
|
PASS no policy errors on an allow
|
|
42
45
|
PASS tree head signature
|
|
@@ -72,10 +75,13 @@ execution observed executed
|
|
|
72
75
|
| delegation signature (principal key) | the embedded grant was signed by a key you trust as a principal | a grant the principal never issued |
|
|
73
76
|
| delegation chain to the principal | only when the grant embeds a parent: every link is signed by the key its parent names, holds no scope its parent lacks, sits inside its parent's window, and names the same principal, up to three delegations deep | a sub-agent given more than its delegator had, a link signed by the wrong key, a chain that never reaches a trusted principal |
|
|
74
77
|
| delegation binds principal and agent | the grant names the same principal and agent the receipt names, and the principal keyid matches | a valid grant for someone else, spliced in |
|
|
75
|
-
| delegation valid at receipt time | the receipt's timestamp is inside the grant's window | expired or not-yet-valid authority |
|
|
78
|
+
| delegation valid at receipt time | the receipt's timestamp is inside the grant's window; a call the gateway refused after the grant ran out passes with a note, since only an executed call must sit inside the window | expired or not-yet-valid authority behind an executed call |
|
|
76
79
|
| executed tool within delegated scope | if the tool ran, the grant covered it. Denied calls pass this check by construction | a gateway that forwarded out of scope |
|
|
77
80
|
| principal is claimed, not attested | SDK receipts only: there is no delegation, so the principal is a config string and is labelled as such | an SDK receipt pretending to an attested principal |
|
|
78
|
-
| request args digest | the args in the predicate hash to the digest in the subject | edited arguments |
|
|
81
|
+
| request args digest | the args in the predicate hash to the digest in the subject. Recomputed when the arguments are in clear, disclosed with `--disclose`, or decrypted with `--capture-key-env`; when fields are withheld and neither is given, it passes as committed, the detail saying "committed, not recomputed" and how many fields are withheld | edited arguments, or a disclosure that contradicts a commitment |
|
|
82
|
+
| execution result digest | executed and failed calls: the result in the predicate hashes to `execution.resultDigest`, under the same rules as the arguments; a provider delivery withheld with the result is restored first, since the digest covered it | an edited result, or a disclosure or key that does not match the commitment, or a capture note naming a field that is not a commitment |
|
|
83
|
+
| fact `<name>` value, fact `<name>` args | only for a captured fact: its commitments hold against the disclosed or decrypted value, or pass as committed when neither is given | a disclosure that lies about a fact the policy decided on |
|
|
84
|
+
| upstream signature not checked | only when the result is withheld and an upstream key or provider secret was given: the signature cannot be checked against a result the verifier cannot see, so the line passes with a note in place of the signature check; disclose the result or give the key to run it | nothing; it is a note |
|
|
79
85
|
| policy decision consistent with execution | allow went with executed or failed; an enforced deny went with denied; a deny carrying `enforced: false` (observe mode) went with anything but denied, and the detail says "observe mode, not enforced". Skipped when no policy was evaluated | an issuer that executed after a deny |
|
|
80
86
|
| no policy errors on an allow | an allow was not produced while Cedar reported errors | broken fail-closed behaviour |
|
|
81
87
|
| authorization signature (issuer key) | pre-commit receipts only: the embedded authorization statement was signed by the same issuer key as the receipt | an authorization from another gateway, or none the issuer signed |
|
|
@@ -89,7 +95,7 @@ execution observed executed
|
|
|
89
95
|
| log inclusion proof | this exact envelope is a leaf of the tree with that root | receipt never logged, or logged then changed |
|
|
90
96
|
| log file root matches tree head | recomputing the root from your copy of the log at that size gives the same value | your log copy and the issuer's history diverge: deletion, reordering, or edit |
|
|
91
97
|
|
|
92
|
-
Gateway receipts run seventeen checks, eighteen with a log file, and five more when the tool was committed before it ran (`precommit` in the gateway config). SDK receipts run fewer, because there is no delegation to check, and the report says so on the `principal is claimed` line. A receipt issued to a sub-agent under a delegation chain runs one more, `delegation chain to the principal`.
|
|
98
|
+
Gateway receipts run seventeen checks, eighteen with a log file, one more (`execution result digest`) when the call was executed or failed, and five more when the tool was committed before it ran (`precommit` in the gateway config). SDK receipts run fewer, because there is no delegation to check, and the report says so on the `principal is claimed` line. A receipt issued to a sub-agent under a delegation chain runs one more, `delegation chain to the principal`.
|
|
93
99
|
|
|
94
100
|
## What a verified receipt lets you conclude
|
|
95
101
|
|
|
@@ -104,6 +110,7 @@ A gateway receipt does **not** support:
|
|
|
104
110
|
- that Stripe really executed the refund. The upstream result is `observed`, not signed by Stripe. That is the first roadmap item.
|
|
105
111
|
- that the side effect exists because the receipt does, unless the receipt carries an authorization. Without one, the call was forwarded first and logged second. With one, the five `authorization` checks establish that the gateway had committed the call to the log before it went out, and a `withheld` execution establishes that it never went out.
|
|
106
112
|
- that the arguments were correct. They are `claimed`: they are what the agent asked for, which is what a receipt should record.
|
|
113
|
+
- that a receipt issued under a capture rule shows everything the call carried. The `capture` note says which fields are withheld; the verifier establishes that every value shown, disclosed, or decrypted is the one the signed digest was made over, and nothing about the ones it was not shown.
|
|
107
114
|
- that the model named in `model` produced the call. No hosted provider signs model identity.
|
|
108
115
|
- that the gateway operator is honest. The operator holds the gateway key. Against a dishonest operator you need a log copy taken out of their control, or a signer they do not control. See the threat model table in the README.
|
|
109
116
|
|
|
@@ -133,7 +140,7 @@ result.statement?.predicate // the decoded receipt, only when the signatu
|
|
|
133
140
|
console.log(formatReport(result));
|
|
134
141
|
```
|
|
135
142
|
|
|
136
|
-
`verifyBundle` is pure and synchronous. It reads the log file only when `logFile` is given.
|
|
143
|
+
`verifyBundle` is pure and synchronous. It reads the log file only when `logFile` is given. `disclosed: { args?, result? }` hands it the withheld values of a receipt issued under a capture rule and `captureKey: Buffer` the customer's key (`captureKeyFrom(text)` parses the hex or base64 form); the digests are then recomputed instead of passing as committed.
|
|
137
144
|
|
|
138
145
|
## Verifying without this codebase
|
|
139
146
|
|