@agent-custody/receipts 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -21
- package/dist/acs.d.ts +47 -0
- package/dist/acs.js +235 -0
- package/dist/addresses.d.ts +6 -0
- package/dist/addresses.js +90 -0
- package/dist/check.d.ts +10 -0
- package/dist/check.js +179 -3
- package/dist/cli.js +147 -12
- package/dist/config.d.ts +198 -1
- package/dist/config.js +154 -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/egress-draft.d.ts +43 -0
- package/dist/egress-draft.js +153 -0
- package/dist/egress.d.ts +116 -0
- package/dist/egress.js +585 -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 +15 -0
- package/dist/index.js +10 -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 +63 -43
- 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 +116 -0
- package/dist/portal.js +147 -41
- package/dist/pr-summary.d.ts +25 -0
- package/dist/pr-summary.js +87 -0
- package/dist/receipt.d.ts +8 -2
- 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 +35 -4
- package/docs/acs.md +107 -0
- package/docs/configuration.md +3 -3
- package/docs/door-signals.md +66 -0
- package/docs/door.md +168 -0
- package/docs/egress.md +177 -0
- package/docs/github-action.md +164 -0
- package/docs/policies.md +112 -1
- package/docs/sdk.md +25 -9
- package/docs/threat-model.md +1 -1
- package/docs/tutorials.md +7 -0
- package/docs/usage.md +2 -2
- package/docs/verification.md +16 -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 +1951 -1005
package/dist/check.js
CHANGED
|
@@ -6,10 +6,12 @@ import * as cedar from "@cedar-policy/cedar-wasm/nodejs";
|
|
|
6
6
|
import { accessSync, constants, existsSync, mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
8
|
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
9
|
-
import { GatewayConfigSchema, loadConfig, strictRefusals } from "./config.js";
|
|
9
|
+
import { DoorConfigSchema, GatewayConfigSchema, loadConfig, loadDoorConfig, strictRefusals } from "./config.js";
|
|
10
10
|
import { generateKeyPair, loadPrivateKey, loadPublicKey, writeKeyPair } from "./crypto.js";
|
|
11
11
|
import { delegationValidAt, verifyDelegation } from "./delegation.js";
|
|
12
12
|
import { hasPermitRule } from "./policy.js";
|
|
13
|
+
import { compileRego, isRegoFile } from "./policy-rego.js";
|
|
14
|
+
import { createOpaServerPolicy } from "./opa-server.js";
|
|
13
15
|
import { createGatewayHost } from "./gateway.js";
|
|
14
16
|
const distance = (a, b) => {
|
|
15
17
|
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
@@ -46,6 +48,158 @@ function onPath(command) {
|
|
|
46
48
|
return existsSync(command);
|
|
47
49
|
return (process.env.PATH ?? "").split(delimiter).some((d) => d && existsSync(join(d, command)));
|
|
48
50
|
}
|
|
51
|
+
/** True when the file is a door config rather than a gateway config: it names an origin, which no gateway config has. */
|
|
52
|
+
export function isDoorConfig(configPath) {
|
|
53
|
+
try {
|
|
54
|
+
const raw = JSON.parse(readFileSync(configPath, "utf8"));
|
|
55
|
+
return !!raw && typeof raw === "object" && !Array.isArray(raw) && "origin" in raw && !("upstream" in raw) && !("upstreams" in raw);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The agents named by permits that do not also require a verified arrival. At the door the principal is the agent of a
|
|
63
|
+
* verified grant, or `unknown`, so such a permit admits only a verified agent; the warning is for the reader who
|
|
64
|
+
* expects it to admit a declared name, as the same text would at the gateway.
|
|
65
|
+
*/
|
|
66
|
+
export function permitsNamingAgentWithoutVerifiedArrival(policyText) {
|
|
67
|
+
const parts = cedar.policySetTextToParts(policyText);
|
|
68
|
+
if (parts.type !== "success")
|
|
69
|
+
return [];
|
|
70
|
+
const out = [];
|
|
71
|
+
for (const policy of parts.policies) {
|
|
72
|
+
const j = cedar.policyToJson(policy);
|
|
73
|
+
if (j.type !== "success" || j.json.effect !== "permit")
|
|
74
|
+
continue;
|
|
75
|
+
const principal = j.json.principal;
|
|
76
|
+
if (principal.op === "All" || !principal.entity)
|
|
77
|
+
continue;
|
|
78
|
+
const conditions = JSON.stringify(j.json.conditions ?? []);
|
|
79
|
+
if (conditions.includes('"class"') && conditions.includes('"verified"'))
|
|
80
|
+
continue;
|
|
81
|
+
out.push(`${principal.entity.type}::"${principal.entity.id}"`);
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/** `agent-custody check` on a door config: what the door would fail on at startup, and what it would silently do less than the config seems to promise. */
|
|
86
|
+
export function checkDoorConfig(configPath) {
|
|
87
|
+
const out = [];
|
|
88
|
+
const add = (level, check, message) => out.push({ level, check, message });
|
|
89
|
+
let raw;
|
|
90
|
+
try {
|
|
91
|
+
raw = JSON.parse(readFileSync(configPath, "utf8"));
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
add("error", "config", `${configPath} is not readable JSON: ${e instanceof Error ? e.message : String(e)}`);
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
const known = Object.keys(DoorConfigSchema.shape);
|
|
98
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
99
|
+
for (const key of Object.keys(raw)) {
|
|
100
|
+
if (known.includes(key))
|
|
101
|
+
continue;
|
|
102
|
+
const near = known.find((k) => distance(k.toLowerCase(), key.toLowerCase()) <= 2);
|
|
103
|
+
add("error", "config", `unknown key "${key}" is ignored by the door${near ? `; did you mean "${near}"?` : ""} A mistyped key leaves the setting it was meant for at its default`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const parsed = DoorConfigSchema.safeParse(raw);
|
|
107
|
+
if (!parsed.success) {
|
|
108
|
+
for (const issue of parsed.error.issues)
|
|
109
|
+
add("error", "config", `${issue.path.join(".") || "(root)"}: ${issue.message}`);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
add("ok", "config", "the config parses");
|
|
113
|
+
const cfg = loadDoorConfig(configPath);
|
|
114
|
+
if (!existsSync(cfg.identity.keyFile))
|
|
115
|
+
add("warn", "key", `${cfg.identity.keyFile} does not exist yet; \`agent-custody keygen\` creates it`);
|
|
116
|
+
else {
|
|
117
|
+
try {
|
|
118
|
+
loadPrivateKey(cfg.identity.keyFile);
|
|
119
|
+
add("ok", "key", `the door key at ${cfg.identity.keyFile} loads`);
|
|
120
|
+
if (process.platform !== "win32" && (statSync(cfg.identity.keyFile).mode & 0o077) !== 0)
|
|
121
|
+
add("warn", "key", `${cfg.identity.keyFile} is readable by other users; make it mode 0600`);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
add("error", "key", `${cfg.identity.keyFile}: ${e instanceof Error ? e.message : String(e)}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
let principals = 0;
|
|
128
|
+
for (const f of cfg.trustedPrincipalKeys) {
|
|
129
|
+
try {
|
|
130
|
+
loadPublicKey(f);
|
|
131
|
+
principals++;
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
add("error", "principal keys", `${f}: ${e instanceof Error ? e.message : String(e)}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (cfg.trustedPrincipalKeys.length === 0)
|
|
138
|
+
add("warn", "principal keys", "no trusted principal keys: no arrival can be verified, every one is claimed or unknown");
|
|
139
|
+
else if (principals === cfg.trustedPrincipalKeys.length)
|
|
140
|
+
add("ok", "principal keys", `${principals} trusted principal key${principals === 1 ? "" : "s"} load`);
|
|
141
|
+
if (!existsSync(cfg.policyFile))
|
|
142
|
+
add("error", "policy", `${cfg.policyFile} does not exist`);
|
|
143
|
+
else {
|
|
144
|
+
const text = readFileSync(cfg.policyFile, "utf8");
|
|
145
|
+
const r = cedar.checkParsePolicySet({ staticPolicies: text });
|
|
146
|
+
if (r.type !== "success")
|
|
147
|
+
for (const e of r.errors)
|
|
148
|
+
add("error", "policy", `${cfg.policyFile}: ${e.message}`);
|
|
149
|
+
else if (!hasPermitRule(text))
|
|
150
|
+
add("warn", "policy", `${cfg.policyFile} has no permit rule, so every arrival is refused`);
|
|
151
|
+
else {
|
|
152
|
+
add("ok", "policy", "the policy parses");
|
|
153
|
+
for (const name of permitsNamingAgentWithoutVerifiedArrival(text))
|
|
154
|
+
add("warn", "policy", `a permit names ${name} without requiring context.facts.arrival.class == "verified": the principal is that agent only for a verified grant, so this permit admits nothing else; if it was copied from a gateway policy, add the arrival condition`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (cfg.mode === "observe")
|
|
158
|
+
add("warn", "mode", "observe mode relays every arrival and records what the policy would have decided; nothing is refused by policy");
|
|
159
|
+
add("ok", "precommit", cfg.precommit.includes("*") ? "every arrival is committed to the log before it is relayed" : `every POST, PUT, PATCH, and DELETE${cfg.precommit.length ? `, and every arrival at ${cfg.precommit.join(", ")},` : ""} is committed to the log before it is relayed`);
|
|
160
|
+
if (cfg.routes.length === 0)
|
|
161
|
+
add("warn", "routes", `no routes: every arrival is the action "${cfg.unmatchedRoute}"`);
|
|
162
|
+
else
|
|
163
|
+
add("ok", "routes", `${cfg.routes.length} route(s); unmatched arrivals are "${cfg.unmatchedRoute}"`);
|
|
164
|
+
const origin = new URL(cfg.origin.url);
|
|
165
|
+
if (origin.protocol !== "https:" && !["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname))
|
|
166
|
+
add("warn", "origin", `${cfg.origin.url} is plain HTTP to a remote host; the relayed traffic is not encrypted on that leg`);
|
|
167
|
+
else
|
|
168
|
+
add("ok", "origin", `relays to ${cfg.origin.url}`);
|
|
169
|
+
for (const [, variable] of Object.entries(cfg.origin.headerEnv ?? {}))
|
|
170
|
+
if (!process.env[variable])
|
|
171
|
+
add("error", "credentials", `origin header variable ${variable} is not set in this environment`);
|
|
172
|
+
if (cfg.log?.tokenEnv && !process.env[cfg.log.tokenEnv])
|
|
173
|
+
add("error", "credentials", `log token variable ${cfg.log.tokenEnv} is not set in this environment`);
|
|
174
|
+
if (cfg.splunk?.tokenEnv && !process.env[cfg.splunk.tokenEnv])
|
|
175
|
+
add("error", "credentials", `splunk token variable ${cfg.splunk.tokenEnv} is not set in this environment`);
|
|
176
|
+
for (const v of Object.values(cfg.otel?.headersEnv ?? {}))
|
|
177
|
+
if (!process.env[v])
|
|
178
|
+
add("error", "credentials", `otel header variable ${v} is not set in this environment`);
|
|
179
|
+
for (const f of cfg.log?.keys ?? [])
|
|
180
|
+
if (!existsSync(f))
|
|
181
|
+
add("error", "log keys", `${f} does not exist`);
|
|
182
|
+
if (cfg.captureKeyEnv && !process.env[cfg.captureKeyEnv])
|
|
183
|
+
add("error", "credentials", `capture key variable ${cfg.captureKeyEnv} is not set in this environment`);
|
|
184
|
+
if (cfg.challenge) {
|
|
185
|
+
if (!process.env[cfg.challenge.secretEnv])
|
|
186
|
+
add("error", "credentials", `challenge secret variable ${cfg.challenge.secretEnv} is not set in this environment`);
|
|
187
|
+
add("ok", "challenge", `${cfg.challenge.provider} tokens in the ${cfg.challenge.header} header are verified with the provider; the outcome is context.facts.arrival.challenge.outcome, and class is unchanged by it`);
|
|
188
|
+
}
|
|
189
|
+
else
|
|
190
|
+
add("ok", "challenge", "no challenge: an unknown arrival has no way to become anything else on this door");
|
|
191
|
+
const dir = writableAncestor(cfg.receiptsDir);
|
|
192
|
+
if (!dir)
|
|
193
|
+
add("error", "paths", `${cfg.receiptsDir} cannot be created: no writable directory above it`);
|
|
194
|
+
else
|
|
195
|
+
add("ok", "paths", `receipts go to ${cfg.receiptsDir}`);
|
|
196
|
+
if (cfg.logFile) {
|
|
197
|
+
const ldir = writableAncestor(cfg.logFile);
|
|
198
|
+
if (!ldir)
|
|
199
|
+
add("error", "paths", `${cfg.logFile} cannot be written`);
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
49
203
|
export async function checkConfig(configPath, options = {}) {
|
|
50
204
|
const out = [];
|
|
51
205
|
const add = (level, check, message) => out.push({ level, check, message });
|
|
@@ -101,10 +255,30 @@ export async function checkConfig(configPath, options = {}) {
|
|
|
101
255
|
}
|
|
102
256
|
if (principals.length === cfg.trustedPrincipalKeys.length)
|
|
103
257
|
add("ok", "principal keys", `${principals.length} trusted principal key${principals.length === 1 ? "" : "s"} load`);
|
|
104
|
-
// the policy
|
|
105
|
-
if (
|
|
258
|
+
// the policy: an OPA server answers for its package, a Rego file compiles, a Cedar file parses
|
|
259
|
+
if (cfg.opa) {
|
|
260
|
+
let bundles = {};
|
|
261
|
+
try {
|
|
262
|
+
await createOpaServerPolicy(cfg.opa, (p) => { if (p.bundles)
|
|
263
|
+
bundles = p.bundles; }).probe();
|
|
264
|
+
add("ok", "policy", `the OPA server at ${cfg.opa.url} answers for data.${(cfg.opa.decision ?? "agentcustody").replaceAll("/", ".")}`);
|
|
265
|
+
if (!Object.keys(bundles).length)
|
|
266
|
+
add("warn", "policy", "the OPA server reports no bundle revision, so receipts cannot name the policy that decided; serve the policy from a bundle with a revision");
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
add("error", "policy", e instanceof Error ? e.message : String(e));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else if (!cfg.policyFile || !existsSync(cfg.policyFile)) {
|
|
106
273
|
add("error", "policy", `${cfg.policyFile} does not exist`);
|
|
107
274
|
}
|
|
275
|
+
else if (isRegoFile(cfg.policyFile)) {
|
|
276
|
+
const errors = compileRego(readFileSync(cfg.policyFile, "utf8")).errors;
|
|
277
|
+
for (const e of errors)
|
|
278
|
+
add("error", "policy", `${cfg.policyFile}: ${e}`);
|
|
279
|
+
if (!errors.length)
|
|
280
|
+
add("ok", "policy", "the Rego policy compiles");
|
|
281
|
+
}
|
|
108
282
|
else {
|
|
109
283
|
const text = readFileSync(cfg.policyFile, "utf8");
|
|
110
284
|
const r = cedar.checkParsePolicySet({ staticPolicies: text });
|
|
@@ -139,6 +313,8 @@ export async function checkConfig(configPath, options = {}) {
|
|
|
139
313
|
envNames.push(["otel", v]);
|
|
140
314
|
if (cfg.captureKeyEnv)
|
|
141
315
|
envNames.push(["capture", cfg.captureKeyEnv]);
|
|
316
|
+
if (cfg.opa?.tokenEnv)
|
|
317
|
+
envNames.push(["opa", cfg.opa.tokenEnv]);
|
|
142
318
|
const skipEnvironment = options.environment === "skip";
|
|
143
319
|
const missing = skipEnvironment ? [] : envNames.filter(([, v]) => !process.env[v]);
|
|
144
320
|
for (const [who, v] of missing)
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { saltsFileFor } from "./retention.js";
|
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import { closeSync, constants as fsConstants, existsSync, fchmodSync, openSync, readFileSync, readdirSync, writeFileSync, writeSync } from "node:fs";
|
|
7
7
|
import { dirname, join, resolve } from "node:path";
|
|
8
|
-
import { loadConfig, loadSdkConfig } from "./config.js";
|
|
8
|
+
import { loadAcsGuardianConfig, loadConfig, loadDoorConfig, loadEgressConfig, loadSdkConfig } from "./config.js";
|
|
9
9
|
import { dsseVerify, generateKeyPair, loadPrivateKey, loadPublicKey, writeKeyPair } from "./crypto.js";
|
|
10
10
|
import { createDelegation, decodeDelegation, delegateFrom, grantDigest } from "./delegation.js";
|
|
11
11
|
import { createGateway, createGatewayHost, serveStdio, writeRevokedGrants } from "./gateway.js";
|
|
@@ -19,6 +19,10 @@ import { Anchor, ANCHOR_CHAINS, resolveAnchorChain } from "./anchor.js";
|
|
|
19
19
|
import { checkCompleteness, formatCompleteness, stripeSource } from "./completeness.js";
|
|
20
20
|
import { evmChain } from "./anchor-evm.js";
|
|
21
21
|
import { serveHttp } from "./gateway-http.js";
|
|
22
|
+
import { createDoorHost, serveDoor } from "./door.js";
|
|
23
|
+
import { createEgressHost, serveEgress } from "./egress.js";
|
|
24
|
+
import { draftEgressPolicy } from "./egress-draft.js";
|
|
25
|
+
import { createAcsGuardian } from "./acs.js";
|
|
22
26
|
import { serveA2a } from "./a2a.js";
|
|
23
27
|
import { PortalStore, sendFollowUps, servePortal } from "./portal.js";
|
|
24
28
|
import { exportLog, formatExport } from "./log-export.js";
|
|
@@ -26,7 +30,7 @@ import { CheckpointPublisher, fileResolver } from "./log-sink.js";
|
|
|
26
30
|
import { createRequire } from "node:module";
|
|
27
31
|
import { pruneLog } from "./retention.js";
|
|
28
32
|
import { serveSidecar } from "./sidecar.js";
|
|
29
|
-
import { checkConfig, formatFindings } from "./check.js";
|
|
33
|
+
import { checkConfig, checkDoorConfig, formatFindings, isDoorConfig } from "./check.js";
|
|
30
34
|
import { serveConsole } from "./console.js";
|
|
31
35
|
import { TREEHEAD_TYPE } from "./receipt.js";
|
|
32
36
|
import { MerkleLog } from "./log.js";
|
|
@@ -36,7 +40,10 @@ import { denyReport, formatDenyReport } from "./deny-report.js";
|
|
|
36
40
|
import { fileURLToPath } from "node:url";
|
|
37
41
|
import { handleHookEvent } from "./sdk/claude.js";
|
|
38
42
|
import { auditExtends, formatReport, verifyBundle } from "./verify.js";
|
|
43
|
+
import { CLEAR_WARNING, exportReceipts, formatReceiptExport as formatExportLines } from "./export.js";
|
|
44
|
+
import { formatSummaryMarkdown, receiptFiles, summarizeReceipts } from "./pr-summary.js";
|
|
39
45
|
import { formatSimulation, simulatePolicy, verifyOrphanAuthorization } from "./simulate.js";
|
|
46
|
+
import { isRegoFile } from "./policy-rego.js";
|
|
40
47
|
/**
|
|
41
48
|
* Resolves on SIGINT or SIGTERM: a container runtime and systemd stop a service with SIGTERM, which PID 1 ignores unless
|
|
42
49
|
* it is handled. The handlers are installed once, before a service starts, so a signal that arrives while it starts up
|
|
@@ -50,9 +57,9 @@ function untilStopped() {
|
|
|
50
57
|
});
|
|
51
58
|
return stopped;
|
|
52
59
|
}
|
|
53
|
-
const SERVICES = new Set(["serve", "witness", "signer", "portal", "log", "console"]);
|
|
60
|
+
const SERVICES = new Set(["serve", "witness", "signer", "portal", "log", "console", "door", "egress"]);
|
|
54
61
|
/** a command that waits for untilStopped(); a stdio gateway runs until its input closes and keeps the default signal behaviour */
|
|
55
|
-
const runsUntilStopped = (cmd, args) => !!cmd && (SERVICES.has(cmd) || (cmd === "gateway" && (args.includes("--http") || args.includes("--a2a"))));
|
|
62
|
+
const runsUntilStopped = (cmd, args) => !!cmd && ((SERVICES.has(cmd) && !(cmd === "egress" && args[0] === "draft-policy")) || (cmd === "gateway" && (args.includes("--http") || args.includes("--a2a"))));
|
|
56
63
|
/** A secret kept in a file that only this process can read, such as a container secret mounted at /run/secrets. The file's path is not a secret; its contents are. */
|
|
57
64
|
function tokenFromFile(path) {
|
|
58
65
|
const v = readFileSync(path, "utf8").trim();
|
|
@@ -90,6 +97,21 @@ const USAGE = `agent-custody <command>
|
|
|
90
97
|
gateway --config <gateway.json> [--http [--port 8790] [--host 127.0.0.1] [--idle-minutes 30]]
|
|
91
98
|
stdio: one gateway for the grant the config names. --http: one shared gateway, MCP over
|
|
92
99
|
Streamable HTTP at /mcp, each connection presenting its own grant as Authorization: Bearer
|
|
100
|
+
door --config <door.json> [--port 8780] [--host 127.0.0.1]
|
|
101
|
+
a reverse proxy in front of your own site or API: every arrival classified (verified by a
|
|
102
|
+
trusted grant, claimed, or unknown), decided by the Cedar policy for its route, relayed to the
|
|
103
|
+
origin or refused with 403, and receipted either way; GET /.well-known/agent-custody-door
|
|
104
|
+
egress --config <egress.json> [--port 8791] [--host 127.0.0.1]
|
|
105
|
+
the egress witness: a forward proxy (CONNECT and plain HTTP, no TLS interception) for a
|
|
106
|
+
locked-down agent's calls that do not go to the gateway. Each agent proves itself with its own
|
|
107
|
+
Proxy-Authorization; the Cedar policy decides per host:port; every connection is receipted
|
|
108
|
+
egress draft-policy --receipts <dir> --issuer-key <witness.pub>... [--log-key <pub>]... [--log <log.jsonl>]
|
|
109
|
+
a first egress policy from observe-mode receipts: one permit per verified agent and scheme over the
|
|
110
|
+
host:port destinations the witness relayed for it, each with its count and first and last time. It permits
|
|
111
|
+
whatever the agents did, bad destinations included: review it. Receipts that do not verify are skipped
|
|
112
|
+
acs --config <acs.json> an OWASP Agent Control Standard Guardian, one document at a time: reads a JSON-RPC
|
|
113
|
+
steps/toolCallRequest or steps/toolCallResult (or a batch) on stdin, answers allow or
|
|
114
|
+
deny by the Cedar policy on stdout, and writes a signed receipt for each decision
|
|
93
115
|
init claude-code [--dir <dir>] [--user] [--enforce] [--log-url <url> [--log-id <id>] [--log-token-env NAME] [--log-key <pub>]]
|
|
94
116
|
one command for your own Claude Code sessions: an agent key, sdk.json in observe mode, a starter deny
|
|
95
117
|
policy, and the three hooks in .claude/settings.local.json (--user: ~/.claude/settings.json). Safe to run twice
|
|
@@ -101,7 +123,11 @@ const USAGE = `agent-custody <command>
|
|
|
101
123
|
retention on the receipt log: replaces older leaves with their hashes, so proofs still verify and the content is gone
|
|
102
124
|
log --file <log.jsonl> --key <log.key> [--port 8787] [--host 127.0.0.1] [--token-env <NAME>] reference log server
|
|
103
125
|
verify <bundle.json> --issuer-key <pub> [--principal-key <pub>] [--approval-key <pub>] [--log-key <pub> | --log-url <url>] [--log-id <id>] [--require-strict] [--upstream-key <pub>] [--stripe-secret-env NAME] [--github-secret-env NAME] [--log <log.jsonl>] [--disclose <file>] [--capture-key-env NAME] [--json]
|
|
104
|
-
|
|
126
|
+
verify --markdown <dir|bundle.json>... --issuer-key <pub> one Markdown table for a directory of bundles; exit 1 when one does not verify or none exists
|
|
127
|
+
export --receipts <dir> --out <dir> --issuer-key <pub>... [--principal-key <pub>]... [--approval-key <pub>]... [--since <ISO time>] [--allow-clear]
|
|
128
|
+
copies the verified receipt bundles that keep their values private into a directory for a pull request, byte for byte.
|
|
129
|
+
Reads only <id>.json at the top level; never salts/, outbox/, or *.authorization.json. Exits 1 when it refuses a receipt, and when it copies none
|
|
130
|
+
policy simulate --policy <proposed.cedar|.rego> --receipts <dir> --issuer-key <pub>... [--principal-key <pub>]... [--approval-key <pub>]... [--log-key <pub>]... [--json] [--out <file>]
|
|
105
131
|
completeness --receipts <dir> --issuer-key <pub>... [--principal-key <pub>]... [--log-key <pub>]... [--log <log.jsonl>] [--log-id <id>]
|
|
106
132
|
--provider stripe --object refunds|payouts|transfers --key-env NAME --tool <name>... --since <ISO> --until <ISO>
|
|
107
133
|
[--id-path id] [--amount-field amount] [--currency-field currency] [--beneficiary <arg>=<field>]... [--json]
|
|
@@ -281,7 +307,7 @@ async function main(argv) {
|
|
|
281
307
|
const { values } = parseArgs({ args: rest, options: { config: { type: "string" }, connect: { type: "boolean", default: false }, json: { type: "boolean", default: false } } });
|
|
282
308
|
if (!values.config)
|
|
283
309
|
throw new Error("check needs --config");
|
|
284
|
-
const findings = await checkConfig(values.config, { connect: values.connect });
|
|
310
|
+
const findings = isDoorConfig(values.config) ? checkDoorConfig(values.config) : await checkConfig(values.config, { connect: values.connect });
|
|
285
311
|
console.log(values.json ? JSON.stringify(findings, null, 2) : formatFindings(findings));
|
|
286
312
|
return findings.some((f) => f.level === "error") ? 1 : 0;
|
|
287
313
|
}
|
|
@@ -339,6 +365,69 @@ async function main(argv) {
|
|
|
339
365
|
await gw.close();
|
|
340
366
|
return 0;
|
|
341
367
|
}
|
|
368
|
+
case "door": {
|
|
369
|
+
const { values } = parseArgs({ args: rest, options: { config: { type: "string" }, port: { type: "string", default: "8780" }, host: { type: "string", default: "127.0.0.1" } } });
|
|
370
|
+
if (!values.config)
|
|
371
|
+
throw new Error("door needs --config");
|
|
372
|
+
const cfg = loadDoorConfig(values.config);
|
|
373
|
+
const host = await createDoorHost(cfg, { autoFlush: true });
|
|
374
|
+
const running = await serveDoor(host, { port: Number(values.port), host: values.host });
|
|
375
|
+
console.error(`agent-custody door: ${running.url} keyid=${host.keyid} in front of ${cfg.origin.url}; ${cfg.routes.length} route(s), unmatched arrivals are "${cfg.unmatchedRoute}"`);
|
|
376
|
+
await untilStopped();
|
|
377
|
+
await running.close();
|
|
378
|
+
await host.close();
|
|
379
|
+
return 0;
|
|
380
|
+
}
|
|
381
|
+
case "egress": {
|
|
382
|
+
if (rest[0] === "draft-policy") {
|
|
383
|
+
const { values } = parseArgs({ args: rest.slice(1), options: { receipts: { type: "string" }, "issuer-key": { type: "string", multiple: true }, "log-key": { type: "string", multiple: true }, log: { type: "string" } } });
|
|
384
|
+
if (!values.receipts || !values["issuer-key"]?.length)
|
|
385
|
+
throw new Error("egress draft-policy needs --receipts <dir> --issuer-key <witness.pub>");
|
|
386
|
+
const draft = draftEgressPolicy(values.receipts, { issuerKeys: values["issuer-key"].map(loadPublicKey), logKeys: (values["log-key"] ?? []).map(loadPublicKey), ...(values.log ? { logFile: values.log } : {}) });
|
|
387
|
+
for (const s of draft.skipped)
|
|
388
|
+
if (s.kind === "unverified")
|
|
389
|
+
console.error(`skipped ${s.file}: does not verify: ${s.reason}`);
|
|
390
|
+
process.stdout.write(draft.policy);
|
|
391
|
+
if (!draft.agents.length) {
|
|
392
|
+
console.error(`egress draft-policy: no relayed connection from a verified agent among ${draft.read} receipt(s) in ${values.receipts}`);
|
|
393
|
+
return 1;
|
|
394
|
+
}
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
const { values } = parseArgs({ args: rest, options: { config: { type: "string" }, port: { type: "string", default: "8791" }, host: { type: "string", default: "127.0.0.1" } } });
|
|
398
|
+
if (!values.config)
|
|
399
|
+
throw new Error("egress needs --config");
|
|
400
|
+
const cfg = loadEgressConfig(values.config);
|
|
401
|
+
const host = await createEgressHost(cfg, { autoFlush: true });
|
|
402
|
+
const running = await serveEgress(host, { port: Number(values.port), host: values.host });
|
|
403
|
+
console.error(`agent-custody egress: ${running.url} keyid=${host.keyid}; ${cfg.agents.length} agent(s), mode ${cfg.mode ?? "enforce"}; GET /.well-known/agent-custody-egress`);
|
|
404
|
+
await untilStopped();
|
|
405
|
+
// the relayed connections first, so that each is receipted as witness-stopped before the listener goes
|
|
406
|
+
await host.close();
|
|
407
|
+
await running.close();
|
|
408
|
+
return 0;
|
|
409
|
+
}
|
|
410
|
+
case "acs": {
|
|
411
|
+
const { values } = parseArgs({ args: rest, options: { config: { type: "string" } } });
|
|
412
|
+
if (!values.config)
|
|
413
|
+
throw new Error("acs needs --config");
|
|
414
|
+
const guardian = createAcsGuardian(loadAcsGuardianConfig(values.config));
|
|
415
|
+
const chunks = [];
|
|
416
|
+
for await (const c of process.stdin)
|
|
417
|
+
chunks.push(c);
|
|
418
|
+
let message;
|
|
419
|
+
try {
|
|
420
|
+
message = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
421
|
+
}
|
|
422
|
+
catch (e) {
|
|
423
|
+
console.log(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code: -32700, message: `parse error: ${e instanceof Error ? e.message : String(e)}` } }, null, 2));
|
|
424
|
+
return 1;
|
|
425
|
+
}
|
|
426
|
+
const answer = await guardian.handle(message);
|
|
427
|
+
console.log(JSON.stringify(answer, null, 2));
|
|
428
|
+
// a deny is a decision, so 0; an error (no decision, including a receipt that could not be written) is 1
|
|
429
|
+
return (Array.isArray(answer) ? answer : [answer]).some((a) => "error" in a) ? 1 : 0;
|
|
430
|
+
}
|
|
342
431
|
case "init": {
|
|
343
432
|
const [target, ...args] = rest;
|
|
344
433
|
if (target !== "claude-code")
|
|
@@ -770,18 +859,20 @@ async function main(argv) {
|
|
|
770
859
|
disclose: { type: "string" },
|
|
771
860
|
"capture-key-env": { type: "string" },
|
|
772
861
|
json: { type: "boolean", default: false },
|
|
862
|
+
markdown: { type: "boolean", default: false },
|
|
773
863
|
},
|
|
774
864
|
});
|
|
775
865
|
const file = positionals[0];
|
|
776
866
|
const issuerKeyFiles = [...(values["issuer-key"] ?? []), ...(values["gateway-key"] ?? [])];
|
|
777
867
|
if (!file || issuerKeyFiles.length === 0)
|
|
778
868
|
throw new Error("verify needs <bundle> --issuer-key (alias --gateway-key)");
|
|
779
|
-
|
|
869
|
+
if (values.markdown && (values.json || values.disclose))
|
|
870
|
+
throw new Error("verify --markdown does not combine with --json or --disclose");
|
|
780
871
|
const captureKey = values["capture-key-env"] ? captureKeyFrom(secretFrom(values["capture-key-env"])) : undefined;
|
|
781
872
|
const disclosed = values.disclose ? JSON.parse(readFileSync(values.disclose, "utf8")) : undefined;
|
|
782
873
|
const fetchedLogKeys = values["log-url"] ? (await fetchLogKeys(values["log-url"])).keys : [];
|
|
783
874
|
const logKeys = [...(values["log-key"] ?? []).map(loadPublicKey), ...fetchedLogKeys];
|
|
784
|
-
const
|
|
875
|
+
const verifyOptions = {
|
|
785
876
|
issuerKeys: issuerKeyFiles.map(loadPublicKey),
|
|
786
877
|
principalKeys: (values["principal-key"] ?? []).map(loadPublicKey),
|
|
787
878
|
...(values["approval-key"] ? { approvalKeys: values["approval-key"].map(loadPublicKey) } : {}),
|
|
@@ -793,10 +884,54 @@ async function main(argv) {
|
|
|
793
884
|
...(values.log ? { logFile: values.log } : {}),
|
|
794
885
|
...(captureKey ? { captureKey } : {}),
|
|
795
886
|
...(disclosed ? { disclosed } : {}),
|
|
796
|
-
}
|
|
887
|
+
};
|
|
888
|
+
if (values.markdown) {
|
|
889
|
+
const summary = summarizeReceipts(positionals.flatMap(receiptFiles), verifyOptions);
|
|
890
|
+
console.log(formatSummaryMarkdown(summary));
|
|
891
|
+
return summary.ok ? 0 : 1;
|
|
892
|
+
}
|
|
893
|
+
const result = verifyBundle(JSON.parse(readFileSync(file, "utf8")), verifyOptions);
|
|
797
894
|
console.log(values.json ? JSON.stringify(result, null, 2) : formatReport(result));
|
|
798
895
|
return result.ok ? 0 : 1;
|
|
799
896
|
}
|
|
897
|
+
case "export": {
|
|
898
|
+
const { values } = parseArgs({
|
|
899
|
+
args: rest,
|
|
900
|
+
options: {
|
|
901
|
+
receipts: { type: "string" },
|
|
902
|
+
out: { type: "string" },
|
|
903
|
+
"issuer-key": { type: "string", multiple: true },
|
|
904
|
+
"principal-key": { type: "string", multiple: true },
|
|
905
|
+
"approval-key": { type: "string", multiple: true },
|
|
906
|
+
since: { type: "string" },
|
|
907
|
+
"allow-clear": { type: "boolean", default: false },
|
|
908
|
+
},
|
|
909
|
+
});
|
|
910
|
+
if (!values.receipts || !values.out || !values["issuer-key"]?.length)
|
|
911
|
+
throw new Error("export needs --receipts <dir>, --out <dir> and --issuer-key <pub>");
|
|
912
|
+
// Date.parse reads "1" as the year 2001, so the text must start with a date
|
|
913
|
+
const since = values.since === undefined ? undefined : /^\d{4}-\d{2}-\d{2}/.test(values.since) ? Date.parse(values.since) : NaN;
|
|
914
|
+
if (since !== undefined && !Number.isFinite(since))
|
|
915
|
+
throw new Error(`--since must be an ISO time; got "${values.since}"`);
|
|
916
|
+
const result = exportReceipts({
|
|
917
|
+
receiptsDir: values.receipts,
|
|
918
|
+
outDir: values.out,
|
|
919
|
+
verify: {
|
|
920
|
+
issuerKeys: values["issuer-key"].map(loadPublicKey),
|
|
921
|
+
principalKeys: (values["principal-key"] ?? []).map(loadPublicKey),
|
|
922
|
+
...(values["approval-key"] ? { approvalKeys: values["approval-key"].map(loadPublicKey) } : {}),
|
|
923
|
+
},
|
|
924
|
+
...(since !== undefined ? { since } : {}),
|
|
925
|
+
allowClear: values["allow-clear"],
|
|
926
|
+
});
|
|
927
|
+
for (const line of formatExportLines(result))
|
|
928
|
+
console.log(line);
|
|
929
|
+
if (result.lines.some((l) => l.outcome === "copied" && l.clear.length))
|
|
930
|
+
console.error(CLEAR_WARNING);
|
|
931
|
+
if (result.problem)
|
|
932
|
+
console.error(`agent-custody export: ${result.problem}`);
|
|
933
|
+
return result.refused > 0 || result.copied === 0 ? 1 : 0;
|
|
934
|
+
}
|
|
800
935
|
case "completeness": {
|
|
801
936
|
const { values } = parseArgs({
|
|
802
937
|
args: rest,
|
|
@@ -864,7 +999,7 @@ async function main(argv) {
|
|
|
864
999
|
case "policy": {
|
|
865
1000
|
const [subcommand, ...args] = rest;
|
|
866
1001
|
if (subcommand !== "simulate")
|
|
867
|
-
throw new Error("policy needs the simulate subcommand: policy simulate --policy <proposed.cedar> --receipts <dir> --issuer-key <pub>");
|
|
1002
|
+
throw new Error("policy needs the simulate subcommand: policy simulate --policy <proposed.cedar|.rego> --receipts <dir> --issuer-key <pub>");
|
|
868
1003
|
const { values } = parseArgs({
|
|
869
1004
|
args,
|
|
870
1005
|
options: {
|
|
@@ -881,7 +1016,7 @@ async function main(argv) {
|
|
|
881
1016
|
},
|
|
882
1017
|
});
|
|
883
1018
|
if (!values.policy || !values.receipts || !values["issuer-key"]?.length)
|
|
884
|
-
throw new Error("policy simulate needs --policy <proposed.cedar> --receipts <dir> --issuer-key <pub>");
|
|
1019
|
+
throw new Error("policy simulate needs --policy <proposed.cedar|.rego> --receipts <dir> --issuer-key <pub>");
|
|
885
1020
|
const policy = readFileSync(values.policy, "utf8");
|
|
886
1021
|
const keys = {
|
|
887
1022
|
issuerKeys: values["issuer-key"].map(loadPublicKey),
|
|
@@ -945,7 +1080,7 @@ async function main(argv) {
|
|
|
945
1080
|
}
|
|
946
1081
|
}
|
|
947
1082
|
}
|
|
948
|
-
const report = simulatePolicy(policy, verified(), { unreplayable, ...(captureKey ? { captureKey } : {}), disclosures });
|
|
1083
|
+
const report = simulatePolicy(policy, verified(), { unreplayable, ...(captureKey ? { captureKey } : {}), disclosures, language: isRegoFile(values.policy) ? "rego" : "cedar" });
|
|
949
1084
|
const json = JSON.stringify(report, null, 2);
|
|
950
1085
|
if (values.out) {
|
|
951
1086
|
// Reports name calls and decisions: keep them owner-only, including when replacing an existing file.
|