@intentius/chant 0.124.85 → 0.124.86
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/dist/bundle-check.d.ts +102 -0
- package/dist/bundle-check.d.ts.map +1 -0
- package/dist/bundle-check.js +310 -0
- package/dist/chant-install.d.ts +100 -0
- package/dist/chant-install.d.ts.map +1 -0
- package/dist/chant-install.js +158 -0
- package/dist/ci-commit.d.ts +19 -6
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +23 -4
- package/dist/ci-evidence-jobs.d.ts +54 -0
- package/dist/ci-evidence-jobs.d.ts.map +1 -0
- package/dist/ci-evidence-jobs.js +55 -0
- package/dist/ci-image.d.ts +274 -0
- package/dist/ci-image.d.ts.map +1 -0
- package/dist/ci-image.js +635 -0
- package/dist/ci-login.d.ts +150 -0
- package/dist/ci-login.d.ts.map +1 -0
- package/dist/ci-login.js +240 -0
- package/dist/ci-product.d.ts +16 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +17 -0
- package/dist/cli/commands/import-index.js +2 -2
- package/dist/cli/handlers/build.d.ts +8 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -4
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +57 -2
- package/dist/cli/handlers/ci-evidence.d.ts +3 -0
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
- package/dist/cli/handlers/ci-evidence.js +171 -0
- package/dist/cli/handlers/components.js +3 -3
- package/dist/cli/handlers/dead-guards.d.ts +3 -0
- package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
- package/dist/cli/handlers/dead-guards.js +35 -0
- package/dist/cli/handlers/graph.js +4 -4
- package/dist/cli/handlers/lifecycle.d.ts +2 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +5 -4
- package/dist/cli/handlers/local-chant.d.ts +16 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -0
- package/dist/cli/handlers/local-chant.js +109 -0
- package/dist/cli/handlers/operator.js +2 -2
- package/dist/cli/handlers/search.js +5 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +28 -0
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +49 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +64 -4
- package/dist/components/check-steps.d.ts +17 -0
- package/dist/components/check-steps.d.ts.map +1 -1
- package/dist/components/check-steps.js +37 -5
- package/dist/components/product-pipeline.d.ts +23 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +6 -2
- package/dist/components/product-plan.d.ts +137 -0
- package/dist/components/product-plan.d.ts.map +1 -0
- package/dist/components/product-plan.js +143 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +2 -2
- package/dist/config.d.ts +39 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -3
- package/dist/dead-guards.d.ts +82 -0
- package/dist/dead-guards.d.ts.map +1 -0
- package/dist/dead-guards.js +436 -0
- package/dist/discovery/files.d.ts +3 -1
- package/dist/discovery/files.d.ts.map +1 -1
- package/dist/discovery/files.js +5 -3
- package/dist/drift-issue.d.ts +152 -0
- package/dist/drift-issue.d.ts.map +1 -0
- package/dist/drift-issue.js +167 -0
- package/dist/floor-table.d.ts +30 -0
- package/dist/floor-table.d.ts.map +1 -0
- package/dist/floor-table.data.d.ts +3 -0
- package/dist/floor-table.data.d.ts.map +1 -0
- package/dist/floor-table.data.js +178 -0
- package/dist/floor-table.js +56 -0
- package/dist/forge-flags.d.ts +90 -0
- package/dist/forge-flags.d.ts.map +1 -0
- package/dist/forge-flags.js +184 -0
- package/dist/lexicon.d.ts +69 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.d.ts +7 -1
- package/dist/lifecycle/gated-op.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.js +7 -4
- package/dist/local-chant.d.ts +98 -0
- package/dist/local-chant.d.ts.map +1 -0
- package/dist/local-chant.js +307 -0
- package/dist/op/activities/predict-behaviour.js +2 -2
- package/dist/op/op-waves-evidence-spec.d.ts +13 -0
- package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-spec.js +21 -0
- package/dist/op/op-waves-evidence.d.ts +38 -0
- package/dist/op/op-waves-evidence.d.ts.map +1 -0
- package/dist/op/op-waves-evidence.js +57 -0
- package/dist/op/op-waves-run.d.ts +4 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +24 -1
- package/dist/op/op-waves.d.ts +17 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +23 -0
- package/dist/op/schedule-overdue.d.ts +41 -9
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +154 -25
- package/dist/plan-summary.d.ts +25 -0
- package/dist/plan-summary.d.ts.map +1 -1
- package/dist/plan-summary.js +31 -0
- package/dist/pr-plan-note.d.ts +35 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +10 -0
- package/dist/pr-post.d.ts +23 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +125 -3
- package/dist/release-floors.d.ts +31 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +31 -1
- package/dist/state-migration.d.ts +24 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +100 -5
- package/dist/wave-runtime.mjs +305 -298
- package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
- package/dist/workspace/lexicon-outputs.js +21 -7
- package/dist/workspace/reason-codes.d.ts +3 -0
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +4 -0
- package/dist/workspace/ref-gate.schema.json +85 -0
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/search-contract.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.d.ts +51 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence-report.js +102 -0
- package/dist/workspace/trust/check-evidence.d.ts +126 -0
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence.js +237 -0
- package/dist/workspace/trust/local-evidence.d.ts +120 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/local-evidence.js +259 -0
- package/dist/workspace/trust/policy.d.ts +84 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +94 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-cli.js +234 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-fixture.js +97 -0
- package/dist/workspace/trust/ref-gate.d.ts +187 -0
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate.js +430 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +18 -1
- package/package.json +1 -1
- package/src/bundle-check.test.ts +140 -0
- package/src/bundle-check.ts +352 -0
- package/src/chant-install.test.ts +112 -0
- package/src/chant-install.ts +179 -0
- package/src/ci-commit.test.ts +45 -0
- package/src/ci-commit.ts +38 -4
- package/src/ci-evidence-jobs.ts +67 -0
- package/src/ci-image.test.ts +506 -0
- package/src/ci-image.ts +822 -0
- package/src/ci-login.test.ts +235 -0
- package/src/ci-login.ts +307 -0
- package/src/ci-product.ts +18 -0
- package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/import-index.ts +2 -2
- package/src/cli/handlers/build-source-dir.test.ts +64 -0
- package/src/cli/handlers/build.ts +21 -4
- package/src/cli/handlers/ci-check.ts +56 -3
- package/src/cli/handlers/ci-evidence.ts +162 -0
- package/src/cli/handlers/components.ts +3 -3
- package/src/cli/handlers/dead-guards.ts +37 -0
- package/src/cli/handlers/graph.ts +4 -4
- package/src/cli/handlers/lifecycle.ts +5 -4
- package/src/cli/handlers/local-chant.ts +106 -0
- package/src/cli/handlers/operator.ts +2 -2
- package/src/cli/handlers/search.ts +5 -5
- package/src/cli/main.test.ts +7 -0
- package/src/cli/main.ts +38 -0
- package/src/cli/parse-args.ts +21 -0
- package/src/cli/registry.ts +16 -0
- package/src/components/check-evidence-stage.test.ts +80 -0
- package/src/components/check-hooks.ts +84 -4
- package/src/components/check-local-evidence-stage.test.ts +141 -0
- package/src/components/check-steps.ts +56 -6
- package/src/components/product-pipeline.ts +28 -3
- package/src/components/product-plan.test.ts +87 -0
- package/src/components/product-plan.ts +226 -0
- package/src/components/release-compile.ts +2 -2
- package/src/config.ts +44 -3
- package/src/dead-guards.test.ts +206 -0
- package/src/dead-guards.ts +446 -0
- package/src/discovery/files.ts +5 -3
- package/src/drift-issue-bundle.test.ts +31 -0
- package/src/drift-issue.test.ts +206 -0
- package/src/drift-issue.ts +274 -0
- package/src/fit-note.test.ts +44 -0
- package/src/floor-table.data.ts +180 -0
- package/src/floor-table.ts +77 -0
- package/src/forge-flags.test.ts +110 -0
- package/src/forge-flags.ts +208 -0
- package/src/gate-decision-bundle.test.ts +1 -0
- package/src/lexicon.ts +68 -0
- package/src/lifecycle/gated-op.ts +10 -5
- package/src/local-chant.e2e.test.ts +94 -0
- package/src/local-chant.test.ts +162 -0
- package/src/local-chant.ts +341 -0
- package/src/op/activities/predict-behaviour.ts +2 -2
- package/src/op/op-waves-evidence-spec.ts +24 -0
- package/src/op/op-waves-evidence.test.ts +130 -0
- package/src/op/op-waves-evidence.ts +57 -0
- package/src/op/op-waves-run.ts +25 -1
- package/src/op/op-waves.ts +31 -1
- package/src/op/schedule-overdue.test.ts +85 -0
- package/src/op/schedule-overdue.ts +162 -26
- package/src/plan-summary.ts +40 -0
- package/src/pr-plan-note.ts +34 -0
- package/src/pr-post-plan-note.test.ts +146 -0
- package/src/pr-post.ts +127 -3
- package/src/release-floors.ts +44 -1
- package/src/stage-hooks-bundle.test.ts +1 -0
- package/src/state-migration.test.ts +52 -1
- package/src/state-migration.ts +107 -5
- package/src/workspace/lexicon-outputs.ts +23 -6
- package/src/workspace/reason-codes.test.ts +3 -0
- package/src/workspace/reason-codes.ts +4 -0
- package/src/workspace/ref-gate.schema.json +85 -0
- package/src/workspace/trust/check-evidence-report.ts +106 -0
- package/src/workspace/trust/check-evidence.test.ts +133 -0
- package/src/workspace/trust/check-evidence.ts +257 -0
- package/src/workspace/trust/local-evidence.test.ts +127 -0
- package/src/workspace/trust/local-evidence.ts +266 -0
- package/src/workspace/trust/policy.ts +134 -1
- package/src/workspace/trust/ref-gate-cli.ts +244 -0
- package/src/workspace/trust/ref-gate-fixture.ts +125 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
- package/src/workspace/trust/ref-gate.test.ts +247 -0
- package/src/workspace/trust/ref-gate.ts +538 -0
- package/src/workspace/trust/trust-files.test.ts +16 -0
- package/src/workspace/trust/trust-files.ts +41 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4868: local evidence, signed on a developer's or an agent's machine by a
|
|
3
|
+
* key `.chant/trust.json` at base lists, stands in for a CI run of a check
|
|
4
|
+
* the policy at base names, and for nothing else.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { generateKeyPairSync } from "node:crypto";
|
|
9
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { describe, expect, test } from "vitest";
|
|
13
|
+
import { loadRunnerKey } from "./dsse";
|
|
14
|
+
import { missingCheckEvidence, readCheckEvidence } from "./check-evidence";
|
|
15
|
+
import { acceptedLocalEvidence, localKeyEvidenceSigner, recordLocalChecks, signLocalChecks } from "./local-evidence";
|
|
16
|
+
import { readTrustPolicy, trustConfigSchema } from "./policy";
|
|
17
|
+
import { gitRevisionSource } from "../record-source";
|
|
18
|
+
import { decideRefUpdate } from "./ref-gate";
|
|
19
|
+
|
|
20
|
+
function git(cwd: string, ...args: string[]): string {
|
|
21
|
+
return execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.invalid", "-c", "init.defaultBranch=main", ...args], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function pemKey(): string {
|
|
25
|
+
return generateKeyPairSync("ed25519").privateKey.export({ format: "pem", type: "pkcs8" }).toString();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const pub = (pem: string) => loadRunnerKey(pem).publicKey;
|
|
29
|
+
|
|
30
|
+
function repo(trust: Record<string, unknown>): { cwd: string; base: string } {
|
|
31
|
+
const cwd = mkdtempSync(join(tmpdir(), "chant-4868-"));
|
|
32
|
+
git(cwd, "init", "--quiet");
|
|
33
|
+
mkdirSync(join(cwd, ".chant"));
|
|
34
|
+
writeFileSync(join(cwd, ".chant/trust.json"), JSON.stringify({ schema: 1, ...trust }));
|
|
35
|
+
git(cwd, "add", ".");
|
|
36
|
+
git(cwd, "commit", "--quiet", "-m", "base");
|
|
37
|
+
return { cwd, base: git(cwd, "rev-parse", "HEAD") };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function sign(cwd: string, base: string, pem: string, checks: string[]): Promise<void> {
|
|
41
|
+
await recordLocalChecks(cwd, signLocalChecks(cwd, "HEAD", checks.map((check) => ({ check })), localKeyEvidenceSigner(cwd, base, pem)), { push: false });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe("local evidence (#4868)", () => {
|
|
45
|
+
test("a check the policy names is accepted for the tree it was signed over, and not after the tree changes", async () => {
|
|
46
|
+
const alice = pemKey();
|
|
47
|
+
const { cwd, base } = repo({ local: { keys: [{ principal: "alice", class: "person", key: pub(alice) }], checks: [{ check: "lint" }] } });
|
|
48
|
+
await sign(cwd, base, alice, ["lint", "unit"]);
|
|
49
|
+
const now = acceptedLocalEvidence(cwd, "HEAD", base, ["lint", "unit"]);
|
|
50
|
+
expect(now.map((v) => v.status)).toEqual(["accepted", "not-accepted"]);
|
|
51
|
+
writeFileSync(join(cwd, "x.ts"), "x\n");
|
|
52
|
+
git(cwd, "add", ".");
|
|
53
|
+
git(cwd, "commit", "--quiet", "-m", "change the tree");
|
|
54
|
+
expect(acceptedLocalEvidence(cwd, "HEAD", base, ["lint"])[0]!.status).toBe("missing");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("no check takes local evidence by default", async () => {
|
|
58
|
+
const alice = pemKey();
|
|
59
|
+
const { cwd, base } = repo({ local: { keys: [{ principal: "alice", class: "person", key: pub(alice) }] } });
|
|
60
|
+
await sign(cwd, base, alice, ["lint"]);
|
|
61
|
+
expect(acceptedLocalEvidence(cwd, "HEAD", base, ["lint"])[0]!.status).toBe("not-accepted");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("a key the change adds itself does not count until it is merged", async () => {
|
|
65
|
+
const { cwd, base } = repo({ local: { checks: [{ check: "lint" }] } });
|
|
66
|
+
const mallory = pemKey();
|
|
67
|
+
writeFileSync(join(cwd, ".chant/trust.json"), JSON.stringify({ schema: 1, local: { keys: [{ principal: "mallory", class: "person", key: pub(mallory) }], checks: [{ check: "lint" }] } }));
|
|
68
|
+
git(cwd, "commit", "--quiet", "-am", "add my key");
|
|
69
|
+
const head = git(cwd, "rev-parse", "HEAD");
|
|
70
|
+
// Signing against the base refuses, and evidence signed against the change's own policy is untrusted at base.
|
|
71
|
+
expect(() => localKeyEvidenceSigner(cwd, base, mallory)).toThrow(/lists no local key/);
|
|
72
|
+
await sign(cwd, head, mallory, ["lint"]);
|
|
73
|
+
const v = acceptedLocalEvidence(cwd, "HEAD", base, ["lint"])[0]!;
|
|
74
|
+
expect(v.status).toBe("untrusted");
|
|
75
|
+
expect(acceptedLocalEvidence(cwd, "HEAD", head, ["lint"])[0]!.status).toBe("accepted");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("an agent's key where the policy takes people only is not accepted", async () => {
|
|
79
|
+
const agent = pemKey();
|
|
80
|
+
const alice = pemKey();
|
|
81
|
+
const { cwd, base } = repo({
|
|
82
|
+
local: {
|
|
83
|
+
keys: [{ principal: "alice", class: "person", key: pub(alice) }, { principal: "agent:session-1", class: "agent", key: pub(agent) }],
|
|
84
|
+
checks: [{ check: "lint" }, { check: "fmt", from: ["person", "agent"] }],
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
await sign(cwd, base, agent, ["lint", "fmt"]);
|
|
88
|
+
const [lint, fmt] = acceptedLocalEvidence(cwd, "HEAD", base, ["lint", "fmt"]);
|
|
89
|
+
expect(lint!.status).toBe("untrusted");
|
|
90
|
+
expect(lint!.status === "untrusted" && lint!.reason).toMatch(/from agent agent:session-1, and the policy .* takes it from person only/);
|
|
91
|
+
expect(fmt).toMatchObject({ status: "accepted", signer: "agent:session-1", class: "agent" });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("a check that gates an apply or a release can't take local evidence", () => {
|
|
95
|
+
for (const check of ["plan", "policy", "apply", "drift", "release", "gate", "plan:wave-1", "policy:wave-1"]) {
|
|
96
|
+
expect(trustConfigSchema.safeParse({ schema: 1, local: { checks: [{ check }] } }).success).toBe(false);
|
|
97
|
+
}
|
|
98
|
+
expect(trustConfigSchema.safeParse({ schema: 1, local: { checks: [{ check: "planner-lint" }] } }).success).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("a policy that names plan accepts nothing, and the plan runs", async () => {
|
|
102
|
+
const alice = pemKey();
|
|
103
|
+
const { cwd, base } = repo({ local: { keys: [{ principal: "alice", class: "person", key: pub(alice) }], checks: [{ check: "plan" }, { check: "lint" }] } });
|
|
104
|
+
expect(readTrustPolicy(gitRevisionSource(cwd, base), base).problems.length).toBeGreaterThan(0);
|
|
105
|
+
expect(acceptedLocalEvidence(cwd, "HEAD", base, ["plan", "lint"]).map((v) => v.status)).toEqual(["refused", "refused"]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("local evidence never counts as runner evidence, for the ref gate or an apply's evidence.requires", async () => {
|
|
109
|
+
const alice = pemKey();
|
|
110
|
+
const { cwd, base } = repo({
|
|
111
|
+
local: { keys: [{ principal: "alice", class: "person", key: pub(alice) }], checks: [{ check: "lint" }] },
|
|
112
|
+
refs: [{ ref: "refs/heads/main", checks: [{ check: "lint", command: "chant ci check" }] }],
|
|
113
|
+
});
|
|
114
|
+
await sign(cwd, base, alice, ["lint"]);
|
|
115
|
+
expect((await readCheckEvidence(cwd, "HEAD", base, ["lint"]))[0]!.status).toBe("missing");
|
|
116
|
+
expect(await missingCheckEvidence(cwd, "HEAD", base, ["lint"])).toMatch(/lacks the evidence/);
|
|
117
|
+
const decided = decideRefUpdate({ repo: cwd, base, update: { ref: "refs/heads/main", old: base, new: base } });
|
|
118
|
+
expect(decided.checks.map((c) => c.status)).toEqual(["missing"]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("a runner's key can't sign local evidence, and a key listed as both is left out", () => {
|
|
122
|
+
const ci = pemKey();
|
|
123
|
+
const { cwd, base } = repo({ runners: [{ principal: "ci", class: "runner", key: pub(ci) }], local: { keys: [{ principal: "ci-too", class: "person", key: pub(ci) }], checks: [{ check: "lint" }] } });
|
|
124
|
+
expect(() => localKeyEvidenceSigner(cwd, base, ci)).toThrow(/runner's key/);
|
|
125
|
+
expect(readTrustPolicy(gitRevisionSource(cwd, base), base).local?.excluded.map((e) => e.principal)).toEqual(["ci-too"]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local evidence (#4868): a check proven on a developer's or an agent's
|
|
3
|
+
* machine, which CI accepts in place of running the check again when the
|
|
4
|
+
* policy at base says so.
|
|
5
|
+
*
|
|
6
|
+
* - The statement is the check statement of ./check-evidence.ts with its own
|
|
7
|
+
* predicate type ({@link LOCAL_EVIDENCE_PREDICATE}) and the signer's class
|
|
8
|
+
* (`person` or `agent`) in place of a runner. It binds the commit and its
|
|
9
|
+
* tree, and counts for any commit with the same tree, so a rebase or an
|
|
10
|
+
* amend that keeps the tree keeps it current.
|
|
11
|
+
* - It is signed by a key `local.keys` of `.chant/trust.json` lists at base,
|
|
12
|
+
* for a person or an agent session, and kept under its own notes ref,
|
|
13
|
+
* {@link LOCAL_EVIDENCE_NOTES_REF}. The ref gate (#4867) and an Op waves
|
|
14
|
+
* spec's `evidence.requires` read only `refs/notes/chant/evidence` and only
|
|
15
|
+
* runner keys, so local evidence never counts as runner evidence.
|
|
16
|
+
* - `local.checks` at base names each check it stands in for, and from whom
|
|
17
|
+
* (`from`, default people only). A check it does not name accepts none.
|
|
18
|
+
* The checks that gate an apply, a release or a gate
|
|
19
|
+
* (`LOCAL_EVIDENCE_NEVER`: plan, policy, apply, drift, ...) can't be named:
|
|
20
|
+
* the policy that names one does not parse, and nothing is accepted.
|
|
21
|
+
*
|
|
22
|
+
* The check runner (`chant ci check`, ../../components/check-steps.ts) reads
|
|
23
|
+
* the evidence per hook with {@link acceptedLocalEvidence} and skips a hook
|
|
24
|
+
* whose evidence is current and accepted, so a job that runs several hooks
|
|
25
|
+
* runs the rest and still passes.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { execFileSync } from "node:child_process";
|
|
29
|
+
import { createHash } from "node:crypto";
|
|
30
|
+
import { z } from "zod";
|
|
31
|
+
import { canonicalJson } from "../../effect-receipt";
|
|
32
|
+
import { gitRevisionSource } from "../record-source";
|
|
33
|
+
import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, signEnvelope, verifyEnvelope } from "./dsse";
|
|
34
|
+
import { STATEMENT_TYPE } from "./evidence";
|
|
35
|
+
import { commitAndTree, recordChecks, type EvidenceSigner, type SignedCheck } from "./check-evidence";
|
|
36
|
+
import { localEvidenceAllowedFor, readTrustPolicy, type LocalSignerClass, type TrustPolicy } from "./policy";
|
|
37
|
+
import { parseEvidenceNote } from "./ref-gate";
|
|
38
|
+
|
|
39
|
+
/** The predicate type of a local check statement: never the runner evidence one. */
|
|
40
|
+
export const LOCAL_EVIDENCE_PREDICATE = "https://intentius.io/chant/local-evidence/v1";
|
|
41
|
+
|
|
42
|
+
/** Where local evidence is kept: a notes ref the ref gate never reads. */
|
|
43
|
+
export const LOCAL_EVIDENCE_NOTES_REF = "refs/notes/chant/local-evidence";
|
|
44
|
+
|
|
45
|
+
export { LOCAL_EVIDENCE_KEY_ENV } from "./check-evidence-report";
|
|
46
|
+
|
|
47
|
+
const sha256Hex = z.string().regex(/^[0-9a-f]{64}$/);
|
|
48
|
+
const fullCommit = z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/);
|
|
49
|
+
|
|
50
|
+
/** The statement a local key signs. Strict, as the runner statement is. */
|
|
51
|
+
export const localStatementSchema = z
|
|
52
|
+
.object({
|
|
53
|
+
_type: z.literal(STATEMENT_TYPE),
|
|
54
|
+
subject: z.array(z.never()).length(0),
|
|
55
|
+
predicateType: z.literal(LOCAL_EVIDENCE_PREDICATE),
|
|
56
|
+
predicate: z
|
|
57
|
+
.object({
|
|
58
|
+
signer: z.string().min(1),
|
|
59
|
+
class: z.enum(["person", "agent"]),
|
|
60
|
+
commit: fullCommit,
|
|
61
|
+
tree: fullCommit,
|
|
62
|
+
check: z.string().min(1),
|
|
63
|
+
claim: z.object({ sha256: sha256Hex }).strict().optional(),
|
|
64
|
+
})
|
|
65
|
+
.strict(),
|
|
66
|
+
})
|
|
67
|
+
.strict();
|
|
68
|
+
export type LocalStatement = z.infer<typeof localStatementSchema>;
|
|
69
|
+
|
|
70
|
+
/** A local signer: the key's principal and class as `.chant/trust.json` at base lists them. */
|
|
71
|
+
export interface LocalEvidenceSigner extends EvidenceSigner {
|
|
72
|
+
class: LocalSignerClass;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The signer a local key makes, from `local.keys` of `.chant/trust.json` at
|
|
77
|
+
* `base`. Throws when the key is not an Ed25519 PEM key or is not listed
|
|
78
|
+
* there (a runner's key never is), so nobody keeps evidence CI would ignore.
|
|
79
|
+
*/
|
|
80
|
+
export function localKeyEvidenceSigner(repo: string, base: string, pem: string): LocalEvidenceSigner {
|
|
81
|
+
let loaded: ReturnType<typeof loadRunnerKey>;
|
|
82
|
+
try {
|
|
83
|
+
loaded = loadRunnerKey(pem);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw new Error(`the local evidence key is not an Ed25519 private key in PEM: ${err instanceof Error ? err.message : String(err)}`);
|
|
86
|
+
}
|
|
87
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
88
|
+
if (policy.problems.length > 0) throw new Error(`the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}`);
|
|
89
|
+
const local = policy.local ?? { keys: [], excluded: [], checks: [] };
|
|
90
|
+
if (policy.runners.some((r) => r.key === loaded.publicKey)) {
|
|
91
|
+
throw new Error(`this is a runner's key in .chant/trust.json at ${base.slice(0, 12)}; local evidence is signed by a person's or an agent's key, and a runner signs with chant ci evidence sign`);
|
|
92
|
+
}
|
|
93
|
+
const listed = local.keys.find((k) => k.key === loaded.publicKey);
|
|
94
|
+
if (!listed) {
|
|
95
|
+
throw new Error(`.chant/trust.json at ${base.slice(0, 12)} lists no local key with this key, so CI would ignore the evidence. Add it under "local": { "keys": [...] } first, with class "person" or "agent":\n ${loaded.publicKey}`);
|
|
96
|
+
}
|
|
97
|
+
return { principal: listed.principal, class: listed.class, sign: (payloadType, payload) => signEnvelope(payloadType, payload, loaded.key, loaded.publicKey) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The local statement for one check over `commit`. */
|
|
101
|
+
export function localStatement(input: { commit: string; tree: string; check: string; signer: string; class: LocalSignerClass; claim?: Buffer | string }): LocalStatement {
|
|
102
|
+
if (!input.check.trim()) throw new Error("a check's evidence needs the check's name");
|
|
103
|
+
return {
|
|
104
|
+
_type: STATEMENT_TYPE,
|
|
105
|
+
subject: [],
|
|
106
|
+
predicateType: LOCAL_EVIDENCE_PREDICATE,
|
|
107
|
+
predicate: {
|
|
108
|
+
signer: input.signer,
|
|
109
|
+
class: input.class,
|
|
110
|
+
commit: input.commit,
|
|
111
|
+
tree: input.tree,
|
|
112
|
+
check: input.check,
|
|
113
|
+
...(input.claim !== undefined ? { claim: { sha256: createHash("sha256").update(input.claim).digest("hex") } } : {}),
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Sign each of `checks` over `at` as local evidence. Writes nothing. */
|
|
119
|
+
export function signLocalChecks(repo: string, at: string, checks: readonly { check: string; claim?: Buffer | string }[], signer: LocalEvidenceSigner): SignedCheck[] {
|
|
120
|
+
const { commit, tree } = commitAndTree(repo, at);
|
|
121
|
+
return checks.map(({ check, claim }) => {
|
|
122
|
+
const statement = localStatement({ commit, tree, check, signer: signer.principal, class: signer.class, ...(claim !== undefined ? { claim } : {}) });
|
|
123
|
+
return { check, commit, tree, runner: signer.principal, envelope: signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")) };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Attach local envelopes under {@link LOCAL_EVIDENCE_NOTES_REF} and push that ref, as `recordChecks` does for runner evidence. */
|
|
128
|
+
export function recordLocalChecks(repo: string, signed: readonly SignedCheck[], opts: { push?: boolean; remote?: string } = {}): Promise<{ pushed: boolean; pushWarning?: string }> {
|
|
129
|
+
return recordChecks(repo, signed, { ...opts, notesRef: LOCAL_EVIDENCE_NOTES_REF });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function tryGit(repo: string, args: string[]): string | undefined {
|
|
133
|
+
try {
|
|
134
|
+
return execFileSync("git", args, { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
135
|
+
} catch {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Fetch {@link LOCAL_EVIDENCE_NOTES_REF} from `remote` into the checkout, so
|
|
142
|
+
* a CI job reads what developers pushed. A checkout without the remote, or a
|
|
143
|
+
* remote without the ref, keeps what it has; returns whether the fetch landed.
|
|
144
|
+
*/
|
|
145
|
+
export function fetchLocalEvidence(repo: string, remote = "origin"): boolean {
|
|
146
|
+
if (tryGit(repo, ["remote", "get-url", remote]) === undefined) return false;
|
|
147
|
+
return tryGit(repo, ["fetch", "--quiet", "--no-tags", remote, `+${LOCAL_EVIDENCE_NOTES_REF}:${LOCAL_EVIDENCE_NOTES_REF}`]) !== undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Every local envelope that may be for `tree`: the notes of `commit`, of other
|
|
152
|
+
* commits with that tree, and of commits this checkout doesn't have (a shallow
|
|
153
|
+
* CI clone), whose statements are then held to the tree they name.
|
|
154
|
+
*/
|
|
155
|
+
function localEnvelopes(repo: string, commit: string, tree: string): unknown[] {
|
|
156
|
+
const list = tryGit(repo, ["notes", `--ref=${LOCAL_EVIDENCE_NOTES_REF}`, "list"]);
|
|
157
|
+
if (!list) return [];
|
|
158
|
+
const own: unknown[] = [];
|
|
159
|
+
const others: unknown[] = [];
|
|
160
|
+
for (const line of list.split("\n")) {
|
|
161
|
+
const [blob, annotated] = line.trim().split(/\s+/);
|
|
162
|
+
if (!blob || !annotated) continue;
|
|
163
|
+
if (annotated !== commit) {
|
|
164
|
+
const theirs = tryGit(repo, ["rev-parse", "--verify", "--quiet", `${annotated}^{tree}`]);
|
|
165
|
+
if (theirs !== undefined && theirs !== tree) continue;
|
|
166
|
+
}
|
|
167
|
+
const text = tryGit(repo, ["cat-file", "blob", blob]);
|
|
168
|
+
if (text !== undefined) (annotated === commit ? own : others).push(...parseEvidenceNote(text));
|
|
169
|
+
}
|
|
170
|
+
return [...own, ...others];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** What the local evidence comes to for one check at a commit's tree. */
|
|
174
|
+
export type LocalEvidenceVerdict =
|
|
175
|
+
| { check: string; status: "accepted"; signer: string; class: LocalSignerClass; commit: string }
|
|
176
|
+
| { check: string; status: "not-accepted" | "missing" | "untrusted" | "refused"; reason: string };
|
|
177
|
+
|
|
178
|
+
/** One envelope verified against the local keys at base, or why it does not count. */
|
|
179
|
+
function verifyLocal(envelope: unknown, policy: TrustPolicy): { ok: true; statement: LocalStatement; class: LocalSignerClass } | { ok: false; reason: string } {
|
|
180
|
+
const keys = policy.local?.keys ?? [];
|
|
181
|
+
const v = verifyEnvelope(envelope, keys);
|
|
182
|
+
if (!v.ok) return { ok: false, reason: v.code === "envelope-untrusted" ? "no signature verifies against a local key the policy at base lists" : v.reason };
|
|
183
|
+
if (v.payloadType !== IN_TOTO_PAYLOAD_TYPE) return { ok: false, reason: `payload type ${v.payloadType} is not ${IN_TOTO_PAYLOAD_TYPE}` };
|
|
184
|
+
let raw: unknown;
|
|
185
|
+
try {
|
|
186
|
+
raw = JSON.parse(v.payload.toString("utf8"));
|
|
187
|
+
} catch {
|
|
188
|
+
return { ok: false, reason: "the payload is not JSON" };
|
|
189
|
+
}
|
|
190
|
+
const parsed = localStatementSchema.safeParse(raw);
|
|
191
|
+
if (!parsed.success) return { ok: false, reason: `the payload is not a ${LOCAL_EVIDENCE_PREDICATE} statement` };
|
|
192
|
+
const key = keys.find((k) => k.principal === v.principal)!;
|
|
193
|
+
// The signer and class inside are the key's own: a key cannot sign as someone else, or as a person when it is an agent's.
|
|
194
|
+
if (parsed.data.predicate.signer !== key.principal || parsed.data.predicate.class !== key.class) {
|
|
195
|
+
return { ok: false, reason: `the statement names ${parsed.data.predicate.class} ${JSON.stringify(parsed.data.predicate.signer)}, but the key of ${key.class} ${key.principal} signed it` };
|
|
196
|
+
}
|
|
197
|
+
return { ok: true, statement: parsed.data, class: key.class };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The check a local envelope says it is for, read without verifying. */
|
|
201
|
+
function claimedCheck(envelope: unknown): string | undefined {
|
|
202
|
+
try {
|
|
203
|
+
const payload = (envelope as { payload?: unknown }).payload;
|
|
204
|
+
if (typeof payload !== "string") return undefined;
|
|
205
|
+
const check = (JSON.parse(Buffer.from(payload, "base64").toString("utf8")) as { predicate?: { check?: unknown } }).predicate?.check;
|
|
206
|
+
return typeof check === "string" ? check : undefined;
|
|
207
|
+
} catch {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Whether CI may skip each of `checks` at `at` on local evidence, judged by
|
|
214
|
+
* the policy at `base` (#4868):
|
|
215
|
+
*
|
|
216
|
+
* - `refused`: the check is one local evidence never stands in for, or the policy at base cannot be read.
|
|
217
|
+
* - `not-accepted`: `local.checks` at base does not name it (the default).
|
|
218
|
+
* - `missing`: nothing current is kept for the tree.
|
|
219
|
+
* - `untrusted`: an envelope is kept for it, and none verifies against a
|
|
220
|
+
* local key at base whose class the check accepts (a key the change adds
|
|
221
|
+
* itself, or an agent's key where the check takes people only).
|
|
222
|
+
* - `accepted`: an envelope for the check over `at`'s tree verifies, from a class the check takes.
|
|
223
|
+
*/
|
|
224
|
+
export function acceptedLocalEvidence(repo: string, at: string, base: string, checks: readonly string[]): LocalEvidenceVerdict[] {
|
|
225
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
226
|
+
if (policy.problems.length > 0) return checks.map((check) => ({ check, status: "refused", reason: `the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}` }));
|
|
227
|
+
const rules = new Map((policy.local?.checks ?? []).map((c) => [c.check, c.from]));
|
|
228
|
+
if (!checks.some((c) => rules.has(c) && localEvidenceAllowedFor(c))) {
|
|
229
|
+
return checks.map((check) => verdictWithoutEnvelopes(check, rules, base));
|
|
230
|
+
}
|
|
231
|
+
const { commit, tree } = commitAndTree(repo, at);
|
|
232
|
+
const envelopes = localEnvelopes(repo, commit, tree);
|
|
233
|
+
return checks.map((check): LocalEvidenceVerdict => {
|
|
234
|
+
const from = rules.get(check);
|
|
235
|
+
if (!from || !localEvidenceAllowedFor(check)) return verdictWithoutEnvelopes(check, rules, base);
|
|
236
|
+
let untrusted: string | undefined;
|
|
237
|
+
for (const envelope of envelopes) {
|
|
238
|
+
const v = verifyLocal(envelope, policy);
|
|
239
|
+
if (!v.ok) {
|
|
240
|
+
if (claimedCheck(envelope) === check) untrusted ??= `the local evidence for ${check} does not verify against the local keys at ${base.slice(0, 12)}: ${v.reason}`;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const p = v.statement.predicate;
|
|
244
|
+
if (p.check !== check || p.tree !== tree) continue;
|
|
245
|
+
if (!from.includes(v.class)) {
|
|
246
|
+
untrusted ??= `the local evidence for ${check} is from ${v.class} ${p.signer}, and the policy at ${base.slice(0, 12)} takes it from ${from.join(" or ")} only`;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
return { check, status: "accepted", signer: p.signer, class: v.class, commit: p.commit };
|
|
250
|
+
}
|
|
251
|
+
if (untrusted) return { check, status: "untrusted", reason: untrusted };
|
|
252
|
+
return { check, status: "missing", reason: `no local evidence for ${check} is kept under ${LOCAL_EVIDENCE_NOTES_REF} for the tree of ${commit.slice(0, 12)}` };
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function verdictWithoutEnvelopes(check: string, rules: ReadonlyMap<string, LocalSignerClass[]>, base: string): LocalEvidenceVerdict {
|
|
257
|
+
if (!localEvidenceAllowedFor(check)) return { check, status: "refused", reason: `${check} gates an apply, a release or a gate, so it runs whatever evidence exists` };
|
|
258
|
+
if (!rules.has(check)) return { check, status: "not-accepted", reason: `local.checks in .chant/trust.json at ${base.slice(0, 12)} does not name ${check}` };
|
|
259
|
+
return { check, status: "missing", reason: `no local evidence for ${check}` };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Whether the policy at `base` takes local evidence for any check, so a job knows whether to fetch the notes at all. */
|
|
263
|
+
export function acceptsLocalEvidence(repo: string, base: string): boolean {
|
|
264
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
265
|
+
return policy.problems.length === 0 && (policy.local?.checks ?? []).some((c) => localEvidenceAllowedFor(c.check));
|
|
266
|
+
}
|
|
@@ -49,6 +49,27 @@ const repoPath = z
|
|
|
49
49
|
message: "a path inside the repository, with / separators and no ..",
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
/** A check name a ref rule requires (#4867): it is also part of an override's subject. */
|
|
53
|
+
export const REF_CHECK_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
54
|
+
/** A ref pattern (#4867): a full ref name, where `*` matches within one `/` segment and `**` matches across them. */
|
|
55
|
+
export const REF_PATTERN = /^refs\/[^\s\\]+$/;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Checks local evidence never stands in for (#4868): the ones that gate an
|
|
59
|
+
* apply, a release or a gate. A name is refused when it is one of these, or
|
|
60
|
+
* one of these followed by `:` (a wave's `plan:<wave>`).
|
|
61
|
+
*/
|
|
62
|
+
export const LOCAL_EVIDENCE_NEVER = ["plan", "policy", "apply", "drift", "release", "gate", "approval", "confirm"] as const;
|
|
63
|
+
|
|
64
|
+
/** Whether local evidence may ever be accepted for `check` (#4868). */
|
|
65
|
+
export function localEvidenceAllowedFor(check: string): boolean {
|
|
66
|
+
return !LOCAL_EVIDENCE_NEVER.some((n) => check === n || check.startsWith(`${n}:`));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Who signs local evidence (#4868): a person on their machine, or an agent session as itself. */
|
|
70
|
+
export const LOCAL_SIGNER_CLASSES = ["person", "agent"] as const;
|
|
71
|
+
export type LocalSignerClass = (typeof LOCAL_SIGNER_CLASSES)[number];
|
|
72
|
+
|
|
52
73
|
export const trustConfigSchema = z
|
|
53
74
|
.object({
|
|
54
75
|
schema: z.literal(1),
|
|
@@ -127,6 +148,73 @@ export const trustConfigSchema = z
|
|
|
127
148
|
.strict(),
|
|
128
149
|
)
|
|
129
150
|
.optional(),
|
|
151
|
+
/**
|
|
152
|
+
* The checks a ref update must carry evidence for (#4867). Each entry
|
|
153
|
+
* names a ref pattern and the checks a commit pushed there needs current
|
|
154
|
+
* runner evidence of, each with what to do without it (`block` refuses
|
|
155
|
+
* the update, `warn` admits it and says what was missing) and the command
|
|
156
|
+
* that produces it. `status` is the commit status a forge requires, by
|
|
157
|
+
* default `chant/ref-gate`. `overrides` says how an override is judged:
|
|
158
|
+
* `sealed` when the signers file at base exists, else `ledger`.
|
|
159
|
+
*/
|
|
160
|
+
refs: z
|
|
161
|
+
.array(
|
|
162
|
+
z
|
|
163
|
+
.object({
|
|
164
|
+
ref: z.string().regex(REF_PATTERN, "a full ref name such as refs/heads/main, where * and ** match"),
|
|
165
|
+
checks: z
|
|
166
|
+
.array(
|
|
167
|
+
z
|
|
168
|
+
.object({
|
|
169
|
+
check: z.string().regex(REF_CHECK_NAME, "a check name: letters, digits, . _ : -"),
|
|
170
|
+
action: z.enum(["block", "warn"]).optional(),
|
|
171
|
+
command: z.string().min(1),
|
|
172
|
+
})
|
|
173
|
+
.strict(),
|
|
174
|
+
)
|
|
175
|
+
.min(1),
|
|
176
|
+
status: z.string().min(1).optional(),
|
|
177
|
+
overrides: z.enum(["ledger", "sealed"]).optional(),
|
|
178
|
+
})
|
|
179
|
+
.strict(),
|
|
180
|
+
)
|
|
181
|
+
.optional(),
|
|
182
|
+
/**
|
|
183
|
+
* Local evidence (#4868): keys that sign on a developer's machine, for a
|
|
184
|
+
* person or an agent session, and the checks whose CI run such evidence
|
|
185
|
+
* stands in for. Off for every check not named in `checks`, and never
|
|
186
|
+
* for the checks {@link LOCAL_EVIDENCE_NEVER} names. A local key is
|
|
187
|
+
* never a runner key: local evidence never counts as runner evidence.
|
|
188
|
+
*/
|
|
189
|
+
local: z
|
|
190
|
+
.object({
|
|
191
|
+
keys: z
|
|
192
|
+
.array(
|
|
193
|
+
z
|
|
194
|
+
.object({
|
|
195
|
+
principal: z.string().min(1),
|
|
196
|
+
class: z.enum(LOCAL_SIGNER_CLASSES),
|
|
197
|
+
key: z.string().regex(/^ssh-ed25519 [A-Za-z0-9+/]+={0,2}$/, "an ssh-ed25519 public key, with no comment"),
|
|
198
|
+
})
|
|
199
|
+
.strict(),
|
|
200
|
+
)
|
|
201
|
+
.optional(),
|
|
202
|
+
checks: z
|
|
203
|
+
.array(
|
|
204
|
+
z
|
|
205
|
+
.object({
|
|
206
|
+
check: z
|
|
207
|
+
.string()
|
|
208
|
+
.regex(REF_CHECK_NAME, "a check name: letters, digits, . _ : -")
|
|
209
|
+
.refine(localEvidenceAllowedFor, { message: `local evidence never stands in for ${LOCAL_EVIDENCE_NEVER.join(", ")} (or <name>:<wave>)` }),
|
|
210
|
+
from: z.array(z.enum(LOCAL_SIGNER_CLASSES)).min(1).optional(),
|
|
211
|
+
})
|
|
212
|
+
.strict(),
|
|
213
|
+
)
|
|
214
|
+
.optional(),
|
|
215
|
+
})
|
|
216
|
+
.strict()
|
|
217
|
+
.optional(),
|
|
130
218
|
})
|
|
131
219
|
.strict();
|
|
132
220
|
|
|
@@ -135,6 +223,31 @@ export type TrustConfig = z.infer<typeof trustConfigSchema>;
|
|
|
135
223
|
/** The role whose holders may change the policy. Without any grant of it, every signer may. */
|
|
136
224
|
export const ADMIN_ROLE = "admin";
|
|
137
225
|
|
|
226
|
+
/** A ref rule of `.chant/trust.json` (#4867), with `action` filled in. */
|
|
227
|
+
export interface RefRule {
|
|
228
|
+
ref: string;
|
|
229
|
+
checks: Array<{ check: string; action: "block" | "warn"; command: string }>;
|
|
230
|
+
status?: string;
|
|
231
|
+
overrides?: "ledger" | "sealed";
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** A key that signs local evidence (#4868): a person's or an agent session's. */
|
|
235
|
+
export interface LocalKey {
|
|
236
|
+
principal: string;
|
|
237
|
+
class: LocalSignerClass;
|
|
238
|
+
/** `ssh-ed25519 <base64>`. */
|
|
239
|
+
key: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** What `local` in `.chant/trust.json` at base says (#4868), with `from` filled in (default: people only). */
|
|
243
|
+
export interface LocalEvidencePolicy {
|
|
244
|
+
keys: LocalKey[];
|
|
245
|
+
/** Keys left out, and why. */
|
|
246
|
+
excluded: Array<{ principal: string; reason: string }>;
|
|
247
|
+
/** The checks local evidence stands in for, and from whom. */
|
|
248
|
+
checks: Array<{ check: string; from: LocalSignerClass[] }>;
|
|
249
|
+
}
|
|
250
|
+
|
|
138
251
|
/** A key that signs runner evidence: a service or CI identity. */
|
|
139
252
|
export interface RunnerKey {
|
|
140
253
|
principal: string;
|
|
@@ -163,6 +276,10 @@ export interface TrustPolicy {
|
|
|
163
276
|
passkeys?: PasskeySigner[];
|
|
164
277
|
/** Signers admitted per return (#2552), keyed by return id. They verify that return's commits and seals only. */
|
|
165
278
|
admitted: Record<string, Signer[]>;
|
|
279
|
+
/** The checks a ref update needs evidence for (#4867). Absent on a policy built by hand: none. */
|
|
280
|
+
refs?: RefRule[];
|
|
281
|
+
/** Local evidence (#4868). Absent on a policy built by hand: no key, no check accepts it. */
|
|
282
|
+
local?: LocalEvidencePolicy;
|
|
166
283
|
/**
|
|
167
284
|
* Set on a copy of the policy used for one returned record (#2552): the
|
|
168
285
|
* return it came back in. A seal by a principal the policy does not list
|
|
@@ -194,7 +311,7 @@ export function policyWriters(policy: TrustPolicy): Set<string> {
|
|
|
194
311
|
|
|
195
312
|
/** A policy with nothing in it: attestation off. */
|
|
196
313
|
export function emptyPolicy(base: string | null, problems: string[] = []): TrustPolicy {
|
|
197
|
-
return { base, signersPath: DEFAULT_SIGNERS_PATH, active: false, signers: [], excluded: [], roles: {}, adopted: [], runners: [], excludedRunners: [], passkeys: [], admitted: {}, problems };
|
|
314
|
+
return { base, signersPath: DEFAULT_SIGNERS_PATH, active: false, signers: [], excluded: [], roles: {}, adopted: [], runners: [], excludedRunners: [], passkeys: [], admitted: {}, refs: [], local: { keys: [], excluded: [], checks: [] }, problems };
|
|
198
315
|
}
|
|
199
316
|
|
|
200
317
|
/**
|
|
@@ -250,10 +367,26 @@ export function readTrustPolicy(source: RecordSource, base: string | null): Trus
|
|
|
250
367
|
excludedRunners,
|
|
251
368
|
passkeys: config.passkeys ?? [],
|
|
252
369
|
admitted: admittedOf(config),
|
|
370
|
+
refs: (config.refs ?? []).map((r) => ({ ...r, checks: r.checks.map((c) => ({ ...c, action: c.action ?? "block" })) })),
|
|
371
|
+
local: localOf(config, runners),
|
|
253
372
|
problems: [],
|
|
254
373
|
};
|
|
255
374
|
}
|
|
256
375
|
|
|
376
|
+
/** The local evidence policy (#4868): a key a runner entry also holds is left out, so one key never speaks as both. */
|
|
377
|
+
function localOf(config: TrustConfig, runners: readonly RunnerKey[]): LocalEvidencePolicy {
|
|
378
|
+
const runnerKeys = new Set([...runners.map((r) => r.key), ...(config.runners ?? []).map((r) => r.key)]);
|
|
379
|
+
const all = config.local?.keys ?? [];
|
|
380
|
+
const keys: LocalKey[] = [];
|
|
381
|
+
const excluded: Array<{ principal: string; reason: string }> = [];
|
|
382
|
+
for (const k of all) {
|
|
383
|
+
if (runnerKeys.has(k.key)) excluded.push({ principal: k.principal, reason: "a runner entry has this key; local evidence is signed by a person's or an agent's key, never a runner's" });
|
|
384
|
+
else if (all.filter((o) => o.key === k.key || o.principal === k.principal).length > 1) excluded.push({ principal: k.principal, reason: "another local key has the same key or principal" });
|
|
385
|
+
else keys.push(k);
|
|
386
|
+
}
|
|
387
|
+
return { keys, excluded, checks: (config.local?.checks ?? []).map((c) => ({ check: c.check, from: c.from ?? ["person"] })) };
|
|
388
|
+
}
|
|
389
|
+
|
|
257
390
|
/** The admitted signers, by return id. Two entries for one return add up. */
|
|
258
391
|
function admittedOf(config: TrustConfig): Record<string, Signer[]> {
|
|
259
392
|
const out: Record<string, Signer[]> = {};
|