@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/config.d.ts
CHANGED
|
@@ -248,7 +248,13 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
248
248
|
}, z.core.$strip>>>>;
|
|
249
249
|
grantFile: z.ZodOptional<z.ZodString>;
|
|
250
250
|
trustedPrincipalKeys: z.ZodArray<z.ZodString>;
|
|
251
|
-
policyFile: z.ZodString
|
|
251
|
+
policyFile: z.ZodOptional<z.ZodString>;
|
|
252
|
+
opa: z.ZodOptional<z.ZodObject<{
|
|
253
|
+
url: z.ZodString;
|
|
254
|
+
decision: z.ZodOptional<z.ZodString>;
|
|
255
|
+
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
256
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
257
|
+
}, z.core.$strip>>;
|
|
252
258
|
facts: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
253
259
|
name: z.ZodString;
|
|
254
260
|
tool: z.ZodString;
|
|
@@ -357,6 +363,197 @@ export type GatewayConfig = z.infer<typeof GatewayConfigSchema>;
|
|
|
357
363
|
export type FactConfig = z.infer<typeof FactSchema>;
|
|
358
364
|
/** Loads a config file and resolves every path relative to the file's directory. */
|
|
359
365
|
export declare function loadConfig(path: string): GatewayConfig;
|
|
366
|
+
/** One route of the door: a name the policy sees as the action, and what arrives there. `path` is exact, a prefix when it ends in `/*`, or `*` for anything. The first route that matches wins. */
|
|
367
|
+
declare const DoorRouteSchema: z.ZodObject<{
|
|
368
|
+
name: z.ZodString;
|
|
369
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
370
|
+
DELETE: "DELETE";
|
|
371
|
+
GET: "GET";
|
|
372
|
+
HEAD: "HEAD";
|
|
373
|
+
OPTIONS: "OPTIONS";
|
|
374
|
+
PATCH: "PATCH";
|
|
375
|
+
POST: "POST";
|
|
376
|
+
PUT: "PUT";
|
|
377
|
+
}>>>;
|
|
378
|
+
path: z.ZodString;
|
|
379
|
+
}, z.core.$strip>;
|
|
380
|
+
export type DoorRouteConfig = z.infer<typeof DoorRouteSchema>;
|
|
381
|
+
/**
|
|
382
|
+
* The door: a reverse proxy in front of a business's own website, API, or forms. Every arrival is classified (verified,
|
|
383
|
+
* claimed, or unknown), decided by the Cedar policy per route, forwarded to the origin or refused, and receipted either
|
|
384
|
+
* way. The origin's credentials, if any, come from the environment through headerEnv, never from the file or the caller.
|
|
385
|
+
*/
|
|
386
|
+
export declare const DoorConfigSchema: z.ZodObject<{
|
|
387
|
+
identity: z.ZodObject<{
|
|
388
|
+
keyFile: z.ZodString;
|
|
389
|
+
}, z.core.$strip>;
|
|
390
|
+
origin: z.ZodObject<{
|
|
391
|
+
url: z.ZodString;
|
|
392
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
393
|
+
headerEnv: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
394
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
395
|
+
}, z.core.$strip>;
|
|
396
|
+
routes: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
397
|
+
name: z.ZodString;
|
|
398
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
399
|
+
DELETE: "DELETE";
|
|
400
|
+
GET: "GET";
|
|
401
|
+
HEAD: "HEAD";
|
|
402
|
+
OPTIONS: "OPTIONS";
|
|
403
|
+
PATCH: "PATCH";
|
|
404
|
+
POST: "POST";
|
|
405
|
+
PUT: "PUT";
|
|
406
|
+
}>>>;
|
|
407
|
+
path: z.ZodString;
|
|
408
|
+
}, z.core.$strip>>>;
|
|
409
|
+
unmatchedRoute: z.ZodDefault<z.ZodString>;
|
|
410
|
+
trustedPrincipalKeys: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
411
|
+
policyFile: z.ZodString;
|
|
412
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
413
|
+
enforce: "enforce";
|
|
414
|
+
observe: "observe";
|
|
415
|
+
}>>;
|
|
416
|
+
trustProxy: z.ZodOptional<z.ZodBoolean>;
|
|
417
|
+
maxBodyBytes: z.ZodDefault<z.ZodNumber>;
|
|
418
|
+
maxResponseBytes: z.ZodDefault<z.ZodNumber>;
|
|
419
|
+
maxInFlight: z.ZodDefault<z.ZodNumber>;
|
|
420
|
+
precommit: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
421
|
+
challenge: z.ZodOptional<z.ZodObject<{
|
|
422
|
+
provider: z.ZodEnum<{
|
|
423
|
+
hcaptcha: "hcaptcha";
|
|
424
|
+
turnstile: "turnstile";
|
|
425
|
+
}>;
|
|
426
|
+
siteKey: z.ZodString;
|
|
427
|
+
secretEnv: z.ZodString;
|
|
428
|
+
header: z.ZodDefault<z.ZodString>;
|
|
429
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
430
|
+
hostnames: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
431
|
+
action: z.ZodOptional<z.ZodString>;
|
|
432
|
+
maxInFlight: z.ZodDefault<z.ZodNumber>;
|
|
433
|
+
}, z.core.$strip>>;
|
|
434
|
+
receiptsDir: z.ZodString;
|
|
435
|
+
logFile: z.ZodOptional<z.ZodString>;
|
|
436
|
+
log: z.ZodOptional<z.ZodObject<{
|
|
437
|
+
url: z.ZodString;
|
|
438
|
+
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
439
|
+
hashOnly: z.ZodOptional<z.ZodBoolean>;
|
|
440
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
441
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
442
|
+
logId: z.ZodOptional<z.ZodString>;
|
|
443
|
+
}, z.core.$strip>>;
|
|
444
|
+
otel: z.ZodOptional<z.ZodObject<{
|
|
445
|
+
url: z.ZodString;
|
|
446
|
+
headersEnv: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
447
|
+
serviceName: z.ZodOptional<z.ZodString>;
|
|
448
|
+
}, z.core.$strip>>;
|
|
449
|
+
splunk: z.ZodOptional<z.ZodObject<{
|
|
450
|
+
url: z.ZodString;
|
|
451
|
+
tokenEnv: z.ZodString;
|
|
452
|
+
index: z.ZodOptional<z.ZodString>;
|
|
453
|
+
source: z.ZodOptional<z.ZodString>;
|
|
454
|
+
sourcetype: z.ZodOptional<z.ZodString>;
|
|
455
|
+
host: z.ZodOptional<z.ZodString>;
|
|
456
|
+
}, z.core.$strip>>;
|
|
457
|
+
capture: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
458
|
+
args: z.ZodOptional<z.ZodObject<{
|
|
459
|
+
mode: z.ZodEnum<{
|
|
460
|
+
clear: "clear";
|
|
461
|
+
digest: "digest";
|
|
462
|
+
encrypted: "encrypted";
|
|
463
|
+
}>;
|
|
464
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
465
|
+
}, z.core.$strip>>;
|
|
466
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
467
|
+
mode: z.ZodEnum<{
|
|
468
|
+
clear: "clear";
|
|
469
|
+
digest: "digest";
|
|
470
|
+
encrypted: "encrypted";
|
|
471
|
+
}>;
|
|
472
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
473
|
+
}, z.core.$strip>>;
|
|
474
|
+
facts: z.ZodOptional<z.ZodObject<{
|
|
475
|
+
mode: z.ZodEnum<{
|
|
476
|
+
clear: "clear";
|
|
477
|
+
digest: "digest";
|
|
478
|
+
encrypted: "encrypted";
|
|
479
|
+
}>;
|
|
480
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
481
|
+
}, z.core.$strip>>;
|
|
482
|
+
}, z.core.$strip>>>;
|
|
483
|
+
captureKeyEnv: z.ZodOptional<z.ZodString>;
|
|
484
|
+
}, z.core.$strip>;
|
|
485
|
+
export type DoorConfig = z.infer<typeof DoorConfigSchema>;
|
|
486
|
+
/**
|
|
487
|
+
* The egress witness: a forward proxy in the agent's network path for every connection that does not go to the gateway.
|
|
488
|
+
* Each agent proves who it is with its own proxy credential (`Proxy-Authorization: Basic`, id and secret); the secret
|
|
489
|
+
* comes from the environment, never from the file. The Cedar policy decides per destination, and every connection,
|
|
490
|
+
* relayed or refused, is receipted. It records where traffic went, never what was sent: there is no TLS interception.
|
|
491
|
+
*/
|
|
492
|
+
export declare const EgressConfigSchema: z.ZodObject<{
|
|
493
|
+
identity: z.ZodObject<{
|
|
494
|
+
keyFile: z.ZodString;
|
|
495
|
+
}, z.core.$strip>;
|
|
496
|
+
agents: z.ZodArray<z.ZodObject<{
|
|
497
|
+
id: z.ZodString;
|
|
498
|
+
secretEnv: z.ZodString;
|
|
499
|
+
}, z.core.$strip>>;
|
|
500
|
+
policyFile: z.ZodString;
|
|
501
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
502
|
+
enforce: "enforce";
|
|
503
|
+
observe: "observe";
|
|
504
|
+
}>>;
|
|
505
|
+
connectTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
506
|
+
idleTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
507
|
+
maxInFlight: z.ZodDefault<z.ZodNumber>;
|
|
508
|
+
receiptsDir: z.ZodString;
|
|
509
|
+
logFile: z.ZodOptional<z.ZodString>;
|
|
510
|
+
log: z.ZodOptional<z.ZodObject<{
|
|
511
|
+
url: z.ZodString;
|
|
512
|
+
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
513
|
+
hashOnly: z.ZodOptional<z.ZodBoolean>;
|
|
514
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
515
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
516
|
+
logId: z.ZodOptional<z.ZodString>;
|
|
517
|
+
}, z.core.$strip>>;
|
|
518
|
+
otel: z.ZodOptional<z.ZodObject<{
|
|
519
|
+
url: z.ZodString;
|
|
520
|
+
headersEnv: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
521
|
+
serviceName: z.ZodOptional<z.ZodString>;
|
|
522
|
+
}, z.core.$strip>>;
|
|
523
|
+
splunk: z.ZodOptional<z.ZodObject<{
|
|
524
|
+
url: z.ZodString;
|
|
525
|
+
tokenEnv: z.ZodString;
|
|
526
|
+
index: z.ZodOptional<z.ZodString>;
|
|
527
|
+
source: z.ZodOptional<z.ZodString>;
|
|
528
|
+
sourcetype: z.ZodOptional<z.ZodString>;
|
|
529
|
+
host: z.ZodOptional<z.ZodString>;
|
|
530
|
+
}, z.core.$strip>>;
|
|
531
|
+
}, z.core.$strip>;
|
|
532
|
+
export type EgressConfig = z.infer<typeof EgressConfigSchema>;
|
|
533
|
+
export declare function loadEgressConfig(path: string): EgressConfig;
|
|
534
|
+
export declare function loadDoorConfig(path: string): DoorConfig;
|
|
535
|
+
/**
|
|
536
|
+
* An ACS Guardian: answers OWASP Agent Control Standard `steps/toolCallRequest` and `steps/toolCallResult` with the
|
|
537
|
+
* Cedar policy's decision, and receipts each decision. The agent ids on the wire are claimed: nothing checks them.
|
|
538
|
+
*/
|
|
539
|
+
export declare const AcsGuardianConfigSchema: z.ZodObject<{
|
|
540
|
+
identity: z.ZodObject<{
|
|
541
|
+
keyFile: z.ZodString;
|
|
542
|
+
}, z.core.$strip>;
|
|
543
|
+
policyFile: z.ZodString;
|
|
544
|
+
receiptsDir: z.ZodString;
|
|
545
|
+
logFile: z.ZodOptional<z.ZodString>;
|
|
546
|
+
log: z.ZodOptional<z.ZodObject<{
|
|
547
|
+
url: z.ZodString;
|
|
548
|
+
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
549
|
+
hashOnly: z.ZodOptional<z.ZodBoolean>;
|
|
550
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
551
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
552
|
+
logId: z.ZodOptional<z.ZodString>;
|
|
553
|
+
}, z.core.$strip>>;
|
|
554
|
+
}, z.core.$strip>;
|
|
555
|
+
export type AcsGuardianConfig = z.infer<typeof AcsGuardianConfigSchema>;
|
|
556
|
+
export declare function loadAcsGuardianConfig(path: string): AcsGuardianConfig;
|
|
360
557
|
export declare const SdkConfigSchema: z.ZodObject<{
|
|
361
558
|
agentId: z.ZodString;
|
|
362
559
|
principalId: z.ZodOptional<z.ZodString>;
|
package/dist/config.js
CHANGED
|
@@ -149,7 +149,17 @@ export const GatewayConfigSchema = z.object({
|
|
|
149
149
|
/** the one grant a stdio gateway serves; over HTTP each connection presents its own, and this is not needed */
|
|
150
150
|
grantFile: z.string().optional(),
|
|
151
151
|
trustedPrincipalKeys: z.array(z.string()).min(1),
|
|
152
|
-
|
|
152
|
+
/** the policy file: Cedar, or Rego when it ends in .rego (compiled with the opa binary on PATH when it loads) */
|
|
153
|
+
policyFile: z.string().optional(),
|
|
154
|
+
/** an OPA server that decides each call instead of a local file; its package defines allow and deny, as a .rego file does */
|
|
155
|
+
opa: z.object({
|
|
156
|
+
url: z.string().url(),
|
|
157
|
+
/** the package path under /v1/data whose allow and deny rules decide; default agentcustody */
|
|
158
|
+
decision: z.string().min(1).regex(/^[A-Za-z_][A-Za-z0-9_]*([./][A-Za-z_][A-Za-z0-9_]*)*$/, "a package path such as agentcustody or authz/agents").optional(),
|
|
159
|
+
tokenEnv: z.string().min(1).optional(),
|
|
160
|
+
/** milliseconds one decision may take before the call is denied; default 2000 */
|
|
161
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
162
|
+
}).optional(),
|
|
153
163
|
facts: z.array(FactSchema).default([]),
|
|
154
164
|
/**
|
|
155
165
|
* Consequential tools, by name or "*" for all: before forwarding one of these, the gateway commits a signed
|
|
@@ -187,6 +197,7 @@ export const GatewayConfigSchema = z.object({
|
|
|
187
197
|
otel: OtelSchema.optional(),
|
|
188
198
|
splunk: SplunkSchema.optional(),
|
|
189
199
|
}).refine(hasOneLog, oneLog).refine((c) => (c.upstream ? 1 : 0) + (c.upstreams ? 1 : 0) === 1, { message: "exactly one of upstream or upstreams is required" })
|
|
200
|
+
.refine((c) => (c.policyFile ? 1 : 0) + (c.opa ? 1 : 0) === 1, { message: "exactly one of policyFile or opa is required" })
|
|
190
201
|
// a key fetched from the log itself proves nothing about a log that is dishonest from the start, so a remote log that
|
|
191
202
|
// gates consequential calls must have its keys pinned in the config (issue #99)
|
|
192
203
|
.refine((c) => !c.log || (!c.precommit.length && !c.operations) || !!c.log.keys?.length, { message: "precommit with a remote log needs log.keys: the log's public key files, pinned, to check its answer before a consequential call is forwarded" })
|
|
@@ -205,7 +216,7 @@ export function loadConfig(path) {
|
|
|
205
216
|
identity: { keyFile: r(cfg.identity.keyFile) },
|
|
206
217
|
...(cfg.grantFile ? { grantFile: r(cfg.grantFile) } : {}),
|
|
207
218
|
trustedPrincipalKeys: cfg.trustedPrincipalKeys.map(r),
|
|
208
|
-
policyFile: r(cfg.policyFile),
|
|
219
|
+
...(cfg.policyFile ? { policyFile: r(cfg.policyFile) } : {}),
|
|
209
220
|
receiptsDir: r(cfg.receiptsDir),
|
|
210
221
|
...(cfg.logFile ? { logFile: r(cfg.logFile) } : {}),
|
|
211
222
|
...(cfg.log?.keys ? { log: { ...cfg.log, keys: cfg.log.keys.map(r) } } : {}),
|
|
@@ -214,12 +225,152 @@ export function loadConfig(path) {
|
|
|
214
225
|
...(cfg.operations ? { operations: { ...cfg.operations, database: r(cfg.operations.database) } } : {}),
|
|
215
226
|
};
|
|
216
227
|
}
|
|
228
|
+
/** One route of the door: a name the policy sees as the action, and what arrives there. `path` is exact, a prefix when it ends in `/*`, or `*` for anything. The first route that matches wins. */
|
|
229
|
+
const DoorRouteSchema = z.object({
|
|
230
|
+
name: z.string().min(1),
|
|
231
|
+
/** methods this route covers; default every method */
|
|
232
|
+
methods: z.array(z.enum(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"])).min(1).optional(),
|
|
233
|
+
path: z.string().min(1).regex(/^(\*|\/[^*]*(\/\*)?)$/, "a path is exact (/refunds), a prefix (/api/*), or *"),
|
|
234
|
+
});
|
|
235
|
+
/**
|
|
236
|
+
* The door: a reverse proxy in front of a business's own website, API, or forms. Every arrival is classified (verified,
|
|
237
|
+
* claimed, or unknown), decided by the Cedar policy per route, forwarded to the origin or refused, and receipted either
|
|
238
|
+
* way. The origin's credentials, if any, come from the environment through headerEnv, never from the file or the caller.
|
|
239
|
+
*/
|
|
240
|
+
export const DoorConfigSchema = z.object({
|
|
241
|
+
identity: z.object({ keyFile: z.string() }),
|
|
242
|
+
/** where allowed requests go: the site or API the door stands in front of */
|
|
243
|
+
origin: z.object({
|
|
244
|
+
url: z.string().url(),
|
|
245
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
246
|
+
headerEnv: z.record(z.string(), z.string().min(1)).optional(),
|
|
247
|
+
timeoutMs: z.number().int().positive().default(30_000),
|
|
248
|
+
}),
|
|
249
|
+
routes: z.array(DoorRouteSchema).default([]),
|
|
250
|
+
/** the action name for an arrival no route matches; default "other" */
|
|
251
|
+
unmatchedRoute: z.string().min(1).default("other"),
|
|
252
|
+
/** principal keys whose grants the door accepts as a passport: an arrival carrying one of their grants, in scope for its route, is `verified` */
|
|
253
|
+
trustedPrincipalKeys: z.array(z.string()).default([]),
|
|
254
|
+
policyFile: z.string(),
|
|
255
|
+
/** "enforce" (default) refuses what the policy denies; "observe" forwards everything and records the decision with `enforced: false` */
|
|
256
|
+
mode: z.enum(["enforce", "observe"]).optional(),
|
|
257
|
+
/** behind a reverse proxy you run: the arrival's address is the last in X-Forwarded-For, the one that proxy appended, and the client-address headers are relayed as it sent them */
|
|
258
|
+
trustProxy: z.boolean().optional(),
|
|
259
|
+
/** the largest request body the door relays; a larger one is refused with 413 and receipted. Default 1 MiB */
|
|
260
|
+
maxBodyBytes: z.number().int().positive().default(1024 * 1024),
|
|
261
|
+
/** the largest origin response the door relays; a larger one is recorded by size and the client gets 502. Default 32 MiB */
|
|
262
|
+
maxResponseBytes: z.number().int().positive().default(32 * 1024 * 1024),
|
|
263
|
+
/** arrivals handled at once; past this the next is answered 503 before its body is read, and not receipted. Default 256 */
|
|
264
|
+
maxInFlight: z.number().int().positive().default(256),
|
|
265
|
+
/** routes whose arrivals are committed to the log before they are relayed whatever the method, or ["*"]; every arrival whose method is not GET, HEAD, or OPTIONS is committed regardless */
|
|
266
|
+
precommit: z.array(z.string().min(1)).default([]),
|
|
267
|
+
/** the human branch: a Turnstile or hCaptcha token an arrival sends in `header` is verified with the provider, and the outcome is the arrival's `challenge` signal */
|
|
268
|
+
challenge: z.object({
|
|
269
|
+
provider: z.enum(["turnstile", "hcaptcha"]),
|
|
270
|
+
/** the public site key, given back to a refused arrival so a page can render the widget */
|
|
271
|
+
siteKey: z.string().min(1),
|
|
272
|
+
/** the environment variable holding the provider's secret key */
|
|
273
|
+
secretEnv: z.string().min(1),
|
|
274
|
+
header: z.string().min(1).default("x-agent-custody-challenge"),
|
|
275
|
+
timeoutMs: z.number().int().positive().default(5_000),
|
|
276
|
+
/** the hostnames of the pages that render the widget; a token the provider issued on any other host fails */
|
|
277
|
+
hostnames: z.array(z.string().min(1).transform((h) => h.toLowerCase())).min(1),
|
|
278
|
+
/** the widget's action (Turnstile only); when set, a token issued for another action fails */
|
|
279
|
+
action: z.string().min(1).optional(),
|
|
280
|
+
/** checks with the provider at once; an arrival past this is `unavailable`, never relayed on a pass it did not get. Default 64 */
|
|
281
|
+
maxInFlight: z.number().int().positive().default(64),
|
|
282
|
+
}).refine((c) => !c.action || c.provider === "turnstile", { message: "challenge.action is a Turnstile field; hCaptcha does not report an action" }).optional(),
|
|
283
|
+
receiptsDir: z.string(),
|
|
284
|
+
logFile: z.string().optional(),
|
|
285
|
+
log: LogSchema.optional(),
|
|
286
|
+
otel: OtelSchema.optional(),
|
|
287
|
+
splunk: SplunkSchema.optional(),
|
|
288
|
+
capture: CaptureSchema.optional(),
|
|
289
|
+
captureKeyEnv: z.string().min(1).optional(),
|
|
290
|
+
}).refine(hasOneLog, oneLog).refine((c) => new Set(c.routes.map((r) => r.name)).size === c.routes.length, { message: "route names must be unique" })
|
|
291
|
+
.refine((c) => !c.log || !!c.log.keys?.length, { message: "a remote log needs log.keys: the log's public key files, pinned, to check its answer before a request is relayed" });
|
|
292
|
+
/**
|
|
293
|
+
* The egress witness: a forward proxy in the agent's network path for every connection that does not go to the gateway.
|
|
294
|
+
* Each agent proves who it is with its own proxy credential (`Proxy-Authorization: Basic`, id and secret); the secret
|
|
295
|
+
* comes from the environment, never from the file. The Cedar policy decides per destination, and every connection,
|
|
296
|
+
* relayed or refused, is receipted. It records where traffic went, never what was sent: there is no TLS interception.
|
|
297
|
+
*/
|
|
298
|
+
export const EgressConfigSchema = z.object({
|
|
299
|
+
identity: z.object({ keyFile: z.string() }),
|
|
300
|
+
/** the agents the witness knows, each with the environment variable that holds its proxy secret */
|
|
301
|
+
agents: z.array(z.object({ id: z.string().min(1).max(200).regex(/^[^:\s]+$/, "an agent id has no colon or whitespace: Basic credentials split at the first colon"), secretEnv: z.string().min(1) })).min(1),
|
|
302
|
+
policyFile: z.string(),
|
|
303
|
+
/** "enforce" (default) refuses what the policy denies; "observe" relays every connection from a known agent and records the decision with `enforced: false` */
|
|
304
|
+
mode: z.enum(["enforce", "observe"]).optional(),
|
|
305
|
+
/** how long the witness waits for the destination to accept the connection. Default 10 s */
|
|
306
|
+
connectTimeoutMs: z.number().int().positive().default(10_000),
|
|
307
|
+
/** a relayed connection with no bytes either way for this long is closed. Default 5 minutes */
|
|
308
|
+
idleTimeoutMs: z.number().int().positive().default(300_000),
|
|
309
|
+
/** connections handled at once; past this the next is answered 503 and is not relayed or receipted. Default 256 */
|
|
310
|
+
maxInFlight: z.number().int().positive().default(256),
|
|
311
|
+
receiptsDir: z.string(),
|
|
312
|
+
logFile: z.string().optional(),
|
|
313
|
+
log: LogSchema.optional(),
|
|
314
|
+
otel: OtelSchema.optional(),
|
|
315
|
+
splunk: SplunkSchema.optional(),
|
|
316
|
+
}).refine(hasOneLog, oneLog).refine((c) => new Set(c.agents.map((a) => a.id)).size === c.agents.length, { message: "agent ids must be unique" });
|
|
317
|
+
export function loadEgressConfig(path) {
|
|
318
|
+
const cfg = EgressConfigSchema.parse(JSON.parse(readFileSync(path, "utf8")));
|
|
319
|
+
const base = dirname(resolve(path));
|
|
320
|
+
const r = (p) => resolve(base, p);
|
|
321
|
+
return {
|
|
322
|
+
...cfg,
|
|
323
|
+
identity: { keyFile: r(cfg.identity.keyFile) },
|
|
324
|
+
policyFile: r(cfg.policyFile),
|
|
325
|
+
receiptsDir: r(cfg.receiptsDir),
|
|
326
|
+
...(cfg.logFile ? { logFile: r(cfg.logFile) } : {}),
|
|
327
|
+
...(cfg.log?.keys ? { log: { ...cfg.log, keys: cfg.log.keys.map(r) } } : {}),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
export function loadDoorConfig(path) {
|
|
331
|
+
const cfg = DoorConfigSchema.parse(JSON.parse(readFileSync(path, "utf8")));
|
|
332
|
+
const base = dirname(resolve(path));
|
|
333
|
+
const r = (p) => resolve(base, p);
|
|
334
|
+
return {
|
|
335
|
+
...cfg,
|
|
336
|
+
identity: { keyFile: r(cfg.identity.keyFile) },
|
|
337
|
+
trustedPrincipalKeys: cfg.trustedPrincipalKeys.map(r),
|
|
338
|
+
policyFile: r(cfg.policyFile),
|
|
339
|
+
receiptsDir: r(cfg.receiptsDir),
|
|
340
|
+
...(cfg.logFile ? { logFile: r(cfg.logFile) } : {}),
|
|
341
|
+
...(cfg.log?.keys ? { log: { ...cfg.log, keys: cfg.log.keys.map(r) } } : {}),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* An ACS Guardian: answers OWASP Agent Control Standard `steps/toolCallRequest` and `steps/toolCallResult` with the
|
|
346
|
+
* Cedar policy's decision, and receipts each decision. The agent ids on the wire are claimed: nothing checks them.
|
|
347
|
+
*/
|
|
348
|
+
export const AcsGuardianConfigSchema = z.object({
|
|
349
|
+
identity: z.object({ keyFile: z.string() }),
|
|
350
|
+
policyFile: z.string(),
|
|
351
|
+
receiptsDir: z.string(),
|
|
352
|
+
logFile: z.string().optional(),
|
|
353
|
+
log: LogSchema.optional(),
|
|
354
|
+
}).refine(hasOneLog, oneLog);
|
|
355
|
+
export function loadAcsGuardianConfig(path) {
|
|
356
|
+
const cfg = AcsGuardianConfigSchema.parse(JSON.parse(readFileSync(path, "utf8")));
|
|
357
|
+
const base = dirname(resolve(path));
|
|
358
|
+
const r = (p) => resolve(base, p);
|
|
359
|
+
return {
|
|
360
|
+
...cfg,
|
|
361
|
+
identity: { keyFile: r(cfg.identity.keyFile) },
|
|
362
|
+
policyFile: r(cfg.policyFile),
|
|
363
|
+
receiptsDir: r(cfg.receiptsDir),
|
|
364
|
+
...(cfg.logFile ? { logFile: r(cfg.logFile) } : {}),
|
|
365
|
+
...(cfg.log?.keys ? { log: { ...cfg.log, keys: cfg.log.keys.map(r) } } : {}),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
217
368
|
export const SdkConfigSchema = z.object({
|
|
218
369
|
/** identity the receipts will name; nothing checks it, so it is recorded as claimed */
|
|
219
370
|
agentId: z.string().min(1),
|
|
220
371
|
principalId: z.string().min(1).optional(),
|
|
221
372
|
identity: z.object({ keyFile: z.string() }),
|
|
222
|
-
/** optional Cedar
|
|
373
|
+
/** optional policy, Cedar or Rego (.rego); when present, wrapped tools and PreToolUse hooks can deny */
|
|
223
374
|
policyFile: z.string().optional(),
|
|
224
375
|
/** "observe" records the policy's decision with `enforced: false` and never blocks; "enforce" (default) blocks a deny */
|
|
225
376
|
mode: z.enum(["enforce", "observe"]).optional(),
|
package/dist/console.js
CHANGED
|
@@ -15,6 +15,7 @@ import { decodeDelegation, delegationValidAt, grantDigest, verifyDelegation } fr
|
|
|
15
15
|
import { writeRevokedGrants } from "./gateway.js";
|
|
16
16
|
import { CONSOLE_CSP, CONSOLE_HTML } from "./console-page.js";
|
|
17
17
|
import { hasPermitRule, policyDigest } from "./policy.js";
|
|
18
|
+
import { isRegoFile } from "./policy-rego.js";
|
|
18
19
|
import { simulatePolicy } from "./simulate.js";
|
|
19
20
|
import { verifyBundle } from "./verify.js";
|
|
20
21
|
const MAX_BODY = 1_000_000;
|
|
@@ -26,6 +27,14 @@ class HttpError extends Error {
|
|
|
26
27
|
this.status = status;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
30
|
+
/** The console edits Cedar files. A Rego file is edited where it lives, and an OPA server's policy in its bundles. */
|
|
31
|
+
function cedarPolicyFile(cfg) {
|
|
32
|
+
if (!cfg.policyFile)
|
|
33
|
+
throw new HttpError(409, `this gateway asks the OPA server at ${cfg.opa?.url} for its decisions; edit the policy in the server's bundles`);
|
|
34
|
+
if (isRegoFile(cfg.policyFile))
|
|
35
|
+
throw new HttpError(409, `${basename(cfg.policyFile)} is a Rego policy; the console edits Cedar policies only, so edit it in place and the gateway compiles it on its next call`);
|
|
36
|
+
return cfg.policyFile;
|
|
37
|
+
}
|
|
29
38
|
const sha = (s) => createHash("sha256").update(s).digest();
|
|
30
39
|
function atomicWrite(path, text) {
|
|
31
40
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
@@ -280,9 +289,9 @@ export async function serveConsole(options) {
|
|
|
280
289
|
}
|
|
281
290
|
},
|
|
282
291
|
"GET /api/policy": async () => {
|
|
283
|
-
const
|
|
284
|
-
const text = readFileSync(
|
|
285
|
-
return { path:
|
|
292
|
+
const policyFile = cedarPolicyFile(loadConfig(options.configFile));
|
|
293
|
+
const text = readFileSync(policyFile, "utf8");
|
|
294
|
+
return { path: policyFile, text, digest: policyDigest(text), history: readdirSync(join(state, "policy-history")).sort().reverse().slice(0, 20) };
|
|
286
295
|
},
|
|
287
296
|
"POST /api/policy/validate": async (req) => {
|
|
288
297
|
const text = String(object(await readBody(req)).text ?? "");
|
|
@@ -346,18 +355,18 @@ export async function serveConsole(options) {
|
|
|
346
355
|
// from reading the digest to the rename, nothing else may save: two tabs that loaded the same digest would otherwise both pass the
|
|
347
356
|
// check, the later rename would win, and the history of the lost edit would not even be the version it replaced
|
|
348
357
|
return withPolicyLock(() => {
|
|
349
|
-
const
|
|
350
|
-
const current = readFileSync(
|
|
358
|
+
const policyFile = cedarPolicyFile(loadConfig(options.configFile));
|
|
359
|
+
const current = readFileSync(policyFile, "utf8");
|
|
351
360
|
if (body.expectDigest !== policyDigest(current))
|
|
352
361
|
throw new HttpError(409, "the policy file changed since you loaded it; reload and try again");
|
|
353
362
|
writeFileSync(join(state, "policy-history", `${new Date().toISOString().replace(/[:.]/g, "-")}-${policyDigest(current).slice(0, 12)}.cedar`), current);
|
|
354
363
|
try {
|
|
355
|
-
atomicWrite(
|
|
364
|
+
atomicWrite(policyFile, text);
|
|
356
365
|
}
|
|
357
366
|
catch (e) {
|
|
358
367
|
throw new HttpError(500, `the policy file cannot be written (${e instanceof Error ? e.message : String(e)}); mount the config directory read-write for the console`);
|
|
359
368
|
}
|
|
360
|
-
audit("policy.save", { file:
|
|
369
|
+
audit("policy.save", { file: policyFile, from: policyDigest(current), to: policyDigest(text), bytes: text.length, confirmed: issues }, by);
|
|
361
370
|
return { digest: policyDigest(text), note: "saved; a running gateway applies it from its next call" };
|
|
362
371
|
});
|
|
363
372
|
},
|
package/dist/deny-report.js
CHANGED
|
@@ -78,7 +78,7 @@ export function formatDenyReport(r) {
|
|
|
78
78
|
lines.push("", ` ${c.tool}: ${clip(c.target)}`);
|
|
79
79
|
if (c.reasons.length)
|
|
80
80
|
lines.push(` reason: ${c.reasons.join("; ")}`);
|
|
81
|
-
lines.push(` rule: ${c.rules.length ? c.rules.join(" | ") : c.policyIds.join(", ") || "(none)"}${c.rules.length ? ` [${c.policyIds.join(", ")}]` : ""}`);
|
|
81
|
+
lines.push(` rule: ${c.rules.length ? clip(c.rules.join(" | ")) : c.policyIds.join(", ") || "(none)"}${c.rules.length ? ` [${c.policyIds.join(", ")}]` : ""}`);
|
|
82
82
|
lines.push(` receipt: ${c.receiptId} (${c.timestamp})`);
|
|
83
83
|
}
|
|
84
84
|
};
|