@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,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evidence for each named check a generated pipeline runs (#4870).
|
|
3
|
+
*
|
|
4
|
+
* A check job (`chant ci check`, the plan job's note job, a wave job) signs,
|
|
5
|
+
* for each check that passed, the runner evidence statement of #2553
|
|
6
|
+
* (./evidence.ts): the commit, its tree, the check's name, and the digest of
|
|
7
|
+
* what the check said (`claim`) when there is one. No record is a subject:
|
|
8
|
+
* a check reads the tree, and the statement binds the tree.
|
|
9
|
+
*
|
|
10
|
+
* The envelope is attached where #4867's ref gate reads evidence: a line
|
|
11
|
+
* of the commit's git note under `refs/notes/chant/evidence`
|
|
12
|
+
* (`EVIDENCE_NOTES_REF`, ./ref-gate.ts), which the job then pushes. The
|
|
13
|
+
* statement names no record, so it counts for the tree it was signed over:
|
|
14
|
+
* {@link readCheckEvidence} also reads the notes of other commits with the
|
|
15
|
+
* same tree, so the squash of a pull request whose tree is the head's finds
|
|
16
|
+
* the evidence the head was given, as #4868's rebase that keeps the tree
|
|
17
|
+
* will.
|
|
18
|
+
*
|
|
19
|
+
* Who signs is an {@link EvidenceSigner}: today a runner key the policy at
|
|
20
|
+
* base lists ({@link runnerKeyEvidenceSigner}, the key `CHANT_RUNNER_KEY`
|
|
21
|
+
* holds, as for the tick's tags and the run records). #4869 adds a signer
|
|
22
|
+
* that trades the job's OIDC token for a short-lived certificate and returns
|
|
23
|
+
* the same envelope with the certificate in it; nothing that calls a signer
|
|
24
|
+
* changes.
|
|
25
|
+
*
|
|
26
|
+
* Reading ({@link readCheckEvidence}) verifies each envelope against the
|
|
27
|
+
* runner keys of `.chant/trust.json` at base, so evidence a change signs
|
|
28
|
+
* with a key it adds itself does not count until that key is merged.
|
|
29
|
+
*/
|
|
30
|
+
import { execFileSync } from "node:child_process";
|
|
31
|
+
import { createHash } from "node:crypto";
|
|
32
|
+
import { canonicalJson } from "../../effect-receipt.js";
|
|
33
|
+
import { gitRevisionSource } from "../record-source.js";
|
|
34
|
+
import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, signEnvelope } from "./dsse.js";
|
|
35
|
+
import { RUNNER_EVIDENCE_PREDICATE, STATEMENT_TYPE, verifyEvidence } from "./evidence.js";
|
|
36
|
+
import { readTrustPolicy } from "./policy.js";
|
|
37
|
+
import { attachEvidence, EVIDENCE_NOTES_REF, parseEvidenceNote } from "./ref-gate.js";
|
|
38
|
+
export { CHECK_EVIDENCE_KEY_ENV } from "./check-evidence-report.js";
|
|
39
|
+
export { EVIDENCE_NOTES_REF };
|
|
40
|
+
/** The named checks the plan job stands for (#4870): its plan, and the policy evaluated inside it. */
|
|
41
|
+
export const PLAN_EVIDENCE_CHECKS = ["plan", "policy"];
|
|
42
|
+
/**
|
|
43
|
+
* The signer a runner key makes: the principal `.chant/trust.json` at
|
|
44
|
+
* `base` lists the key under `runners`. Throws when the key is not an
|
|
45
|
+
* Ed25519 PEM key, is a signer's (a person's) key, or is not listed, so a
|
|
46
|
+
* job never keeps evidence its readers would ignore.
|
|
47
|
+
*/
|
|
48
|
+
export function runnerKeyEvidenceSigner(repo, base, pem) {
|
|
49
|
+
let loaded;
|
|
50
|
+
try {
|
|
51
|
+
loaded = loadRunnerKey(pem);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
throw new Error(`the runner key is not an Ed25519 private key in PEM: ${err instanceof Error ? err.message : String(err)}`);
|
|
55
|
+
}
|
|
56
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
57
|
+
if (policy.problems.length > 0)
|
|
58
|
+
throw new Error(`the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}`);
|
|
59
|
+
if (policy.signers.some((s) => s.key === loaded.publicKey)) {
|
|
60
|
+
throw new Error(`the runner key is a signer's key in ${policy.signersPath}; check evidence is signed by a CI identity's key, never by a person's`);
|
|
61
|
+
}
|
|
62
|
+
const listed = policy.runners.find((r) => r.key === loaded.publicKey);
|
|
63
|
+
if (!listed)
|
|
64
|
+
throw new Error(`.chant/trust.json at ${base.slice(0, 12)} lists no runner with this key, so the evidence would be ignored. Add it under "runners" first:\n ${loaded.publicKey}`);
|
|
65
|
+
return { principal: listed.principal, sign: (payloadType, payload) => signEnvelope(payloadType, payload, loaded.key, loaded.publicKey) };
|
|
66
|
+
}
|
|
67
|
+
function git(repo, args) {
|
|
68
|
+
return execFileSync("git", args, { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
69
|
+
}
|
|
70
|
+
/** The full commit id and tree of `rev`. Throws when `rev` names no commit. */
|
|
71
|
+
export function commitAndTree(repo, rev) {
|
|
72
|
+
const commit = git(repo, ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]);
|
|
73
|
+
return { commit, tree: git(repo, ["rev-parse", `${commit}^{tree}`]) };
|
|
74
|
+
}
|
|
75
|
+
/** The check's statement over `commit`, with the digest of what it said when given. */
|
|
76
|
+
export function checkStatement(input) {
|
|
77
|
+
if (!input.check.trim())
|
|
78
|
+
throw new Error("a check's evidence needs the check's name");
|
|
79
|
+
return {
|
|
80
|
+
_type: STATEMENT_TYPE,
|
|
81
|
+
subject: [],
|
|
82
|
+
predicateType: RUNNER_EVIDENCE_PREDICATE,
|
|
83
|
+
predicate: {
|
|
84
|
+
runner: input.runner,
|
|
85
|
+
commit: input.commit,
|
|
86
|
+
tree: input.tree,
|
|
87
|
+
check: input.check,
|
|
88
|
+
...(input.claim !== undefined ? { claim: { sha256: createHash("sha256").update(input.claim).digest("hex") } } : {}),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Sign each of `checks` over `at` with `signer`. Writes nothing. */
|
|
93
|
+
export function signChecks(repo, at, checks, signer) {
|
|
94
|
+
const { commit, tree } = commitAndTree(repo, at);
|
|
95
|
+
return checks.map(({ check, claim }) => {
|
|
96
|
+
const statement = checkStatement({ commit, tree, check, runner: signer.principal, ...(claim !== undefined ? { claim } : {}) });
|
|
97
|
+
return {
|
|
98
|
+
check,
|
|
99
|
+
commit,
|
|
100
|
+
tree,
|
|
101
|
+
runner: signer.principal,
|
|
102
|
+
envelope: signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")),
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** How many times {@link recordChecks} fetches, attaches and pushes when another job pushed the notes first. */
|
|
107
|
+
const NOTES_PUSH_TRIES = 3;
|
|
108
|
+
function tryGit(repo, args) {
|
|
109
|
+
try {
|
|
110
|
+
return git(repo, args);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Attach each envelope to its commit's evidence note and push
|
|
118
|
+
* `refs/notes/chant/evidence` to `origin`. The remote's notes are fetched
|
|
119
|
+
* first, so the push adds to them; a push another job beat is tried again
|
|
120
|
+
* on the newer notes. Returns why the push did not land, when it did not;
|
|
121
|
+
* the local notes hold the envelopes either way.
|
|
122
|
+
*/
|
|
123
|
+
export async function recordChecks(repo, signed, opts = {}) {
|
|
124
|
+
if (signed.length === 0)
|
|
125
|
+
return { pushed: false };
|
|
126
|
+
const push = opts.push !== false;
|
|
127
|
+
const remote = opts.remote ?? "origin";
|
|
128
|
+
// #4868: local evidence goes under a notes ref of its own.
|
|
129
|
+
const notesRef = opts.notesRef ?? EVIDENCE_NOTES_REF;
|
|
130
|
+
const hasRemote = push && tryGit(repo, ["remote", "get-url", remote]) !== undefined;
|
|
131
|
+
if (!hasRemote) {
|
|
132
|
+
for (const s of signed)
|
|
133
|
+
attachEvidence(repo, s.commit, s.envelope, notesRef);
|
|
134
|
+
return push ? { pushed: false, pushWarning: `no remote ${remote}, so the evidence is attached here only` } : { pushed: false };
|
|
135
|
+
}
|
|
136
|
+
let said = "";
|
|
137
|
+
for (let attempt = 1; attempt <= NOTES_PUSH_TRIES; attempt++) {
|
|
138
|
+
// The remote's notes are the ones to add to; a CI checkout has none of its own to keep.
|
|
139
|
+
if (tryGit(repo, ["fetch", "--quiet", "--no-tags", remote, `+${notesRef}:${notesRef}`]) === undefined && attempt > 1)
|
|
140
|
+
break;
|
|
141
|
+
for (const s of signed)
|
|
142
|
+
attachEvidence(repo, s.commit, s.envelope, notesRef);
|
|
143
|
+
try {
|
|
144
|
+
execFileSync("git", ["push", "--quiet", remote, `${notesRef}:${notesRef}`], { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
|
|
145
|
+
return { pushed: true };
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
said = String(err.stderr ?? (err instanceof Error ? err.message : err)).trim().split("\n")[0] ?? "";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { pushed: false, pushWarning: `git push ${remote} ${notesRef} did not land${said ? ` (git said: ${said})` : ""}` };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Every envelope attached to a commit whose tree is `tree`: `commit`'s own first. Read from `notesRef`
|
|
155
|
+
* (default {@link EVIDENCE_NOTES_REF}; #4868 reads local evidence from its own).
|
|
156
|
+
*/
|
|
157
|
+
export function envelopesForTree(repo, commit, tree, notesRef = EVIDENCE_NOTES_REF) {
|
|
158
|
+
const list = tryGit(repo, ["notes", `--ref=${notesRef}`, "list"]);
|
|
159
|
+
if (!list)
|
|
160
|
+
return [];
|
|
161
|
+
const own = [];
|
|
162
|
+
const others = [];
|
|
163
|
+
for (const line of list.split("\n")) {
|
|
164
|
+
const [blob, annotated] = line.trim().split(/\s+/);
|
|
165
|
+
if (!blob || !annotated)
|
|
166
|
+
continue;
|
|
167
|
+
const same = annotated === commit || tryGit(repo, ["rev-parse", "--verify", "--quiet", `${annotated}^{tree}`]) === tree;
|
|
168
|
+
if (!same)
|
|
169
|
+
continue;
|
|
170
|
+
const text = tryGit(repo, ["cat-file", "blob", blob]);
|
|
171
|
+
if (text !== undefined)
|
|
172
|
+
(annotated === commit ? own : others).push(...parseEvidenceNote(text));
|
|
173
|
+
}
|
|
174
|
+
return [...own, ...others];
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Read and verify the evidence for each of `checks` at `at`'s tree, against
|
|
178
|
+
* the runner keys `.chant/trust.json` lists at `base`. `missing`: nothing is
|
|
179
|
+
* kept for the tree. `untrusted`: an envelope is kept, and no runner key at
|
|
180
|
+
* base signed it, or it is not a check statement for that tree.
|
|
181
|
+
*/
|
|
182
|
+
export async function readCheckEvidence(repo, at, base, checks) {
|
|
183
|
+
const { tree, commit } = commitAndTree(repo, at);
|
|
184
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
185
|
+
const envelopes = envelopesForTree(repo, commit, tree);
|
|
186
|
+
return checks.map((check) => {
|
|
187
|
+
let untrusted;
|
|
188
|
+
for (const envelope of envelopes) {
|
|
189
|
+
const v = verifyEvidence(envelope, policy.runners, repo, commit);
|
|
190
|
+
if (!v.ok) {
|
|
191
|
+
if (claimedCheck(envelope) === check)
|
|
192
|
+
untrusted ?? (untrusted = `the evidence attached for check ${check} does not verify against the runner keys at ${base.slice(0, 12)}: ${v.reason}`);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (v.statement.predicate.check !== check || v.statement.predicate.tree !== tree)
|
|
196
|
+
continue;
|
|
197
|
+
if (v.status === "current")
|
|
198
|
+
return { check, status: "current", runner: v.runner, commit: v.statement.predicate.commit };
|
|
199
|
+
}
|
|
200
|
+
if (untrusted)
|
|
201
|
+
return { check, status: "untrusted", reason: untrusted };
|
|
202
|
+
return { check, status: "missing", reason: `no evidence for check ${check} is attached under ${EVIDENCE_NOTES_REF} to a commit with the tree of ${commit.slice(0, 12)}` };
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/** The check an envelope says it is for, read without verifying, so a refusal can name it. */
|
|
206
|
+
function claimedCheck(envelope) {
|
|
207
|
+
try {
|
|
208
|
+
const payload = envelope.payload;
|
|
209
|
+
if (typeof payload !== "string")
|
|
210
|
+
return undefined;
|
|
211
|
+
const check = JSON.parse(Buffer.from(payload, "base64").toString("utf8")).predicate?.check;
|
|
212
|
+
return typeof check === "string" ? check : undefined;
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** The command that produces a check's evidence, for a refusal to name. */
|
|
219
|
+
export function checkEvidenceCommand(check) {
|
|
220
|
+
return `chant ci evidence sign --check-id ${check}`;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Why `at` is refused for want of evidence, or null when every one of
|
|
224
|
+
* `required` has current evidence. Names each missing check and the
|
|
225
|
+
* command that produces it.
|
|
226
|
+
*/
|
|
227
|
+
export async function missingCheckEvidence(repo, at, base, required) {
|
|
228
|
+
if (required.length === 0)
|
|
229
|
+
return null;
|
|
230
|
+
const verdicts = await readCheckEvidence(repo, at, base, required);
|
|
231
|
+
const missing = verdicts.filter((v) => v.status !== "current");
|
|
232
|
+
if (missing.length === 0)
|
|
233
|
+
return null;
|
|
234
|
+
return `${at.slice(0, 12)} lacks the evidence the policy at ${base.slice(0, 12)} requires: ${missing
|
|
235
|
+
.map((v) => `${v.check} (${v.reason}; run it in CI, where ${checkEvidenceCommand(v.check)} signs it)`)
|
|
236
|
+
.join("; ")}`;
|
|
237
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
import { z } from "zod";
|
|
28
|
+
import { type EvidenceSigner, type SignedCheck } from "./check-evidence.js";
|
|
29
|
+
import { type LocalSignerClass } from "./policy.js";
|
|
30
|
+
/** The predicate type of a local check statement: never the runner evidence one. */
|
|
31
|
+
export declare const LOCAL_EVIDENCE_PREDICATE = "https://intentius.io/chant/local-evidence/v1";
|
|
32
|
+
/** Where local evidence is kept: a notes ref the ref gate never reads. */
|
|
33
|
+
export declare const LOCAL_EVIDENCE_NOTES_REF = "refs/notes/chant/local-evidence";
|
|
34
|
+
export { LOCAL_EVIDENCE_KEY_ENV } from "./check-evidence-report.js";
|
|
35
|
+
/** The statement a local key signs. Strict, as the runner statement is. */
|
|
36
|
+
export declare const localStatementSchema: z.ZodObject<{
|
|
37
|
+
_type: z.ZodLiteral<"https://in-toto.io/Statement/v1">;
|
|
38
|
+
subject: z.ZodArray<z.ZodNever>;
|
|
39
|
+
predicateType: z.ZodLiteral<"https://intentius.io/chant/local-evidence/v1">;
|
|
40
|
+
predicate: z.ZodObject<{
|
|
41
|
+
signer: z.ZodString;
|
|
42
|
+
class: z.ZodEnum<{
|
|
43
|
+
agent: "agent";
|
|
44
|
+
person: "person";
|
|
45
|
+
}>;
|
|
46
|
+
commit: z.ZodString;
|
|
47
|
+
tree: z.ZodString;
|
|
48
|
+
check: z.ZodString;
|
|
49
|
+
claim: z.ZodOptional<z.ZodObject<{
|
|
50
|
+
sha256: z.ZodString;
|
|
51
|
+
}, z.core.$strict>>;
|
|
52
|
+
}, z.core.$strict>;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
export type LocalStatement = z.infer<typeof localStatementSchema>;
|
|
55
|
+
/** A local signer: the key's principal and class as `.chant/trust.json` at base lists them. */
|
|
56
|
+
export interface LocalEvidenceSigner extends EvidenceSigner {
|
|
57
|
+
class: LocalSignerClass;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The signer a local key makes, from `local.keys` of `.chant/trust.json` at
|
|
61
|
+
* `base`. Throws when the key is not an Ed25519 PEM key or is not listed
|
|
62
|
+
* there (a runner's key never is), so nobody keeps evidence CI would ignore.
|
|
63
|
+
*/
|
|
64
|
+
export declare function localKeyEvidenceSigner(repo: string, base: string, pem: string): LocalEvidenceSigner;
|
|
65
|
+
/** The local statement for one check over `commit`. */
|
|
66
|
+
export declare function localStatement(input: {
|
|
67
|
+
commit: string;
|
|
68
|
+
tree: string;
|
|
69
|
+
check: string;
|
|
70
|
+
signer: string;
|
|
71
|
+
class: LocalSignerClass;
|
|
72
|
+
claim?: Buffer | string;
|
|
73
|
+
}): LocalStatement;
|
|
74
|
+
/** Sign each of `checks` over `at` as local evidence. Writes nothing. */
|
|
75
|
+
export declare function signLocalChecks(repo: string, at: string, checks: readonly {
|
|
76
|
+
check: string;
|
|
77
|
+
claim?: Buffer | string;
|
|
78
|
+
}[], signer: LocalEvidenceSigner): SignedCheck[];
|
|
79
|
+
/** Attach local envelopes under {@link LOCAL_EVIDENCE_NOTES_REF} and push that ref, as `recordChecks` does for runner evidence. */
|
|
80
|
+
export declare function recordLocalChecks(repo: string, signed: readonly SignedCheck[], opts?: {
|
|
81
|
+
push?: boolean;
|
|
82
|
+
remote?: string;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
pushed: boolean;
|
|
85
|
+
pushWarning?: string;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Fetch {@link LOCAL_EVIDENCE_NOTES_REF} from `remote` into the checkout, so
|
|
89
|
+
* a CI job reads what developers pushed. A checkout without the remote, or a
|
|
90
|
+
* remote without the ref, keeps what it has; returns whether the fetch landed.
|
|
91
|
+
*/
|
|
92
|
+
export declare function fetchLocalEvidence(repo: string, remote?: string): boolean;
|
|
93
|
+
/** What the local evidence comes to for one check at a commit's tree. */
|
|
94
|
+
export type LocalEvidenceVerdict = {
|
|
95
|
+
check: string;
|
|
96
|
+
status: "accepted";
|
|
97
|
+
signer: string;
|
|
98
|
+
class: LocalSignerClass;
|
|
99
|
+
commit: string;
|
|
100
|
+
} | {
|
|
101
|
+
check: string;
|
|
102
|
+
status: "not-accepted" | "missing" | "untrusted" | "refused";
|
|
103
|
+
reason: string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Whether CI may skip each of `checks` at `at` on local evidence, judged by
|
|
107
|
+
* the policy at `base` (#4868):
|
|
108
|
+
*
|
|
109
|
+
* - `refused`: the check is one local evidence never stands in for, or the policy at base cannot be read.
|
|
110
|
+
* - `not-accepted`: `local.checks` at base does not name it (the default).
|
|
111
|
+
* - `missing`: nothing current is kept for the tree.
|
|
112
|
+
* - `untrusted`: an envelope is kept for it, and none verifies against a
|
|
113
|
+
* local key at base whose class the check accepts (a key the change adds
|
|
114
|
+
* itself, or an agent's key where the check takes people only).
|
|
115
|
+
* - `accepted`: an envelope for the check over `at`'s tree verifies, from a class the check takes.
|
|
116
|
+
*/
|
|
117
|
+
export declare function acceptedLocalEvidence(repo: string, at: string, base: string, checks: readonly string[]): LocalEvidenceVerdict[];
|
|
118
|
+
/** Whether the policy at `base` takes local evidence for any check, so a job knows whether to fetch the notes at all. */
|
|
119
|
+
export declare function acceptsLocalEvidence(repo: string, base: string): boolean;
|
|
120
|
+
//# sourceMappingURL=local-evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-evidence.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/local-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAA+B,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACtG,OAAO,EAA4C,KAAK,gBAAgB,EAAoB,MAAM,UAAU,CAAC;AAG7G,oFAAoF;AACpF,eAAO,MAAM,wBAAwB,iDAAiD,CAAC;AAEvF,0EAA0E;AAC1E,eAAO,MAAM,wBAAwB,oCAAoC,CAAC;AAE1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAKjE,2EAA2E;AAC3E,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;kBAgBtB,CAAC;AACZ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,+FAA+F;AAC/F,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAkBnG;AAED,uDAAuD;AACvD,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,cAAc,CAevK;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAAE,EAAE,MAAM,EAAE,mBAAmB,GAAG,WAAW,EAAE,CAMnK;AAED,mIAAmI;AACnI,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,WAAW,EAAE,EAAE,IAAI,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAElL;AAUD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAW,GAAG,OAAO,CAG3E;AAyBD,yEAAyE;AACzE,MAAM,MAAM,oBAAoB,GAC5B;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC9F;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAoCpG;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,oBAAoB,EAAE,CA8B/H;AAQD,yHAAyH;AACzH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAGxE"}
|
|
@@ -0,0 +1,259 @@
|
|
|
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
|
+
import { execFileSync } from "node:child_process";
|
|
28
|
+
import { createHash } from "node:crypto";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
import { canonicalJson } from "../../effect-receipt.js";
|
|
31
|
+
import { gitRevisionSource } from "../record-source.js";
|
|
32
|
+
import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, signEnvelope, verifyEnvelope } from "./dsse.js";
|
|
33
|
+
import { STATEMENT_TYPE } from "./evidence.js";
|
|
34
|
+
import { commitAndTree, recordChecks } from "./check-evidence.js";
|
|
35
|
+
import { localEvidenceAllowedFor, readTrustPolicy } from "./policy.js";
|
|
36
|
+
import { parseEvidenceNote } from "./ref-gate.js";
|
|
37
|
+
/** The predicate type of a local check statement: never the runner evidence one. */
|
|
38
|
+
export const LOCAL_EVIDENCE_PREDICATE = "https://intentius.io/chant/local-evidence/v1";
|
|
39
|
+
/** Where local evidence is kept: a notes ref the ref gate never reads. */
|
|
40
|
+
export const LOCAL_EVIDENCE_NOTES_REF = "refs/notes/chant/local-evidence";
|
|
41
|
+
export { LOCAL_EVIDENCE_KEY_ENV } from "./check-evidence-report.js";
|
|
42
|
+
const sha256Hex = z.string().regex(/^[0-9a-f]{64}$/);
|
|
43
|
+
const fullCommit = z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/);
|
|
44
|
+
/** The statement a local key signs. Strict, as the runner statement is. */
|
|
45
|
+
export const localStatementSchema = z
|
|
46
|
+
.object({
|
|
47
|
+
_type: z.literal(STATEMENT_TYPE),
|
|
48
|
+
subject: z.array(z.never()).length(0),
|
|
49
|
+
predicateType: z.literal(LOCAL_EVIDENCE_PREDICATE),
|
|
50
|
+
predicate: z
|
|
51
|
+
.object({
|
|
52
|
+
signer: z.string().min(1),
|
|
53
|
+
class: z.enum(["person", "agent"]),
|
|
54
|
+
commit: fullCommit,
|
|
55
|
+
tree: fullCommit,
|
|
56
|
+
check: z.string().min(1),
|
|
57
|
+
claim: z.object({ sha256: sha256Hex }).strict().optional(),
|
|
58
|
+
})
|
|
59
|
+
.strict(),
|
|
60
|
+
})
|
|
61
|
+
.strict();
|
|
62
|
+
/**
|
|
63
|
+
* The signer a local key makes, from `local.keys` of `.chant/trust.json` at
|
|
64
|
+
* `base`. Throws when the key is not an Ed25519 PEM key or is not listed
|
|
65
|
+
* there (a runner's key never is), so nobody keeps evidence CI would ignore.
|
|
66
|
+
*/
|
|
67
|
+
export function localKeyEvidenceSigner(repo, base, pem) {
|
|
68
|
+
let loaded;
|
|
69
|
+
try {
|
|
70
|
+
loaded = loadRunnerKey(pem);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
throw new Error(`the local evidence key is not an Ed25519 private key in PEM: ${err instanceof Error ? err.message : String(err)}`);
|
|
74
|
+
}
|
|
75
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
76
|
+
if (policy.problems.length > 0)
|
|
77
|
+
throw new Error(`the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}`);
|
|
78
|
+
const local = policy.local ?? { keys: [], excluded: [], checks: [] };
|
|
79
|
+
if (policy.runners.some((r) => r.key === loaded.publicKey)) {
|
|
80
|
+
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`);
|
|
81
|
+
}
|
|
82
|
+
const listed = local.keys.find((k) => k.key === loaded.publicKey);
|
|
83
|
+
if (!listed) {
|
|
84
|
+
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}`);
|
|
85
|
+
}
|
|
86
|
+
return { principal: listed.principal, class: listed.class, sign: (payloadType, payload) => signEnvelope(payloadType, payload, loaded.key, loaded.publicKey) };
|
|
87
|
+
}
|
|
88
|
+
/** The local statement for one check over `commit`. */
|
|
89
|
+
export function localStatement(input) {
|
|
90
|
+
if (!input.check.trim())
|
|
91
|
+
throw new Error("a check's evidence needs the check's name");
|
|
92
|
+
return {
|
|
93
|
+
_type: STATEMENT_TYPE,
|
|
94
|
+
subject: [],
|
|
95
|
+
predicateType: LOCAL_EVIDENCE_PREDICATE,
|
|
96
|
+
predicate: {
|
|
97
|
+
signer: input.signer,
|
|
98
|
+
class: input.class,
|
|
99
|
+
commit: input.commit,
|
|
100
|
+
tree: input.tree,
|
|
101
|
+
check: input.check,
|
|
102
|
+
...(input.claim !== undefined ? { claim: { sha256: createHash("sha256").update(input.claim).digest("hex") } } : {}),
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Sign each of `checks` over `at` as local evidence. Writes nothing. */
|
|
107
|
+
export function signLocalChecks(repo, at, checks, signer) {
|
|
108
|
+
const { commit, tree } = commitAndTree(repo, at);
|
|
109
|
+
return checks.map(({ check, claim }) => {
|
|
110
|
+
const statement = localStatement({ commit, tree, check, signer: signer.principal, class: signer.class, ...(claim !== undefined ? { claim } : {}) });
|
|
111
|
+
return { check, commit, tree, runner: signer.principal, envelope: signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")) };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** Attach local envelopes under {@link LOCAL_EVIDENCE_NOTES_REF} and push that ref, as `recordChecks` does for runner evidence. */
|
|
115
|
+
export function recordLocalChecks(repo, signed, opts = {}) {
|
|
116
|
+
return recordChecks(repo, signed, { ...opts, notesRef: LOCAL_EVIDENCE_NOTES_REF });
|
|
117
|
+
}
|
|
118
|
+
function tryGit(repo, args) {
|
|
119
|
+
try {
|
|
120
|
+
return execFileSync("git", args, { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Fetch {@link LOCAL_EVIDENCE_NOTES_REF} from `remote` into the checkout, so
|
|
128
|
+
* a CI job reads what developers pushed. A checkout without the remote, or a
|
|
129
|
+
* remote without the ref, keeps what it has; returns whether the fetch landed.
|
|
130
|
+
*/
|
|
131
|
+
export function fetchLocalEvidence(repo, remote = "origin") {
|
|
132
|
+
if (tryGit(repo, ["remote", "get-url", remote]) === undefined)
|
|
133
|
+
return false;
|
|
134
|
+
return tryGit(repo, ["fetch", "--quiet", "--no-tags", remote, `+${LOCAL_EVIDENCE_NOTES_REF}:${LOCAL_EVIDENCE_NOTES_REF}`]) !== undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Every local envelope that may be for `tree`: the notes of `commit`, of other
|
|
138
|
+
* commits with that tree, and of commits this checkout doesn't have (a shallow
|
|
139
|
+
* CI clone), whose statements are then held to the tree they name.
|
|
140
|
+
*/
|
|
141
|
+
function localEnvelopes(repo, commit, tree) {
|
|
142
|
+
const list = tryGit(repo, ["notes", `--ref=${LOCAL_EVIDENCE_NOTES_REF}`, "list"]);
|
|
143
|
+
if (!list)
|
|
144
|
+
return [];
|
|
145
|
+
const own = [];
|
|
146
|
+
const others = [];
|
|
147
|
+
for (const line of list.split("\n")) {
|
|
148
|
+
const [blob, annotated] = line.trim().split(/\s+/);
|
|
149
|
+
if (!blob || !annotated)
|
|
150
|
+
continue;
|
|
151
|
+
if (annotated !== commit) {
|
|
152
|
+
const theirs = tryGit(repo, ["rev-parse", "--verify", "--quiet", `${annotated}^{tree}`]);
|
|
153
|
+
if (theirs !== undefined && theirs !== tree)
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const text = tryGit(repo, ["cat-file", "blob", blob]);
|
|
157
|
+
if (text !== undefined)
|
|
158
|
+
(annotated === commit ? own : others).push(...parseEvidenceNote(text));
|
|
159
|
+
}
|
|
160
|
+
return [...own, ...others];
|
|
161
|
+
}
|
|
162
|
+
/** One envelope verified against the local keys at base, or why it does not count. */
|
|
163
|
+
function verifyLocal(envelope, policy) {
|
|
164
|
+
const keys = policy.local?.keys ?? [];
|
|
165
|
+
const v = verifyEnvelope(envelope, keys);
|
|
166
|
+
if (!v.ok)
|
|
167
|
+
return { ok: false, reason: v.code === "envelope-untrusted" ? "no signature verifies against a local key the policy at base lists" : v.reason };
|
|
168
|
+
if (v.payloadType !== IN_TOTO_PAYLOAD_TYPE)
|
|
169
|
+
return { ok: false, reason: `payload type ${v.payloadType} is not ${IN_TOTO_PAYLOAD_TYPE}` };
|
|
170
|
+
let raw;
|
|
171
|
+
try {
|
|
172
|
+
raw = JSON.parse(v.payload.toString("utf8"));
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return { ok: false, reason: "the payload is not JSON" };
|
|
176
|
+
}
|
|
177
|
+
const parsed = localStatementSchema.safeParse(raw);
|
|
178
|
+
if (!parsed.success)
|
|
179
|
+
return { ok: false, reason: `the payload is not a ${LOCAL_EVIDENCE_PREDICATE} statement` };
|
|
180
|
+
const key = keys.find((k) => k.principal === v.principal);
|
|
181
|
+
// 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.
|
|
182
|
+
if (parsed.data.predicate.signer !== key.principal || parsed.data.predicate.class !== key.class) {
|
|
183
|
+
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` };
|
|
184
|
+
}
|
|
185
|
+
return { ok: true, statement: parsed.data, class: key.class };
|
|
186
|
+
}
|
|
187
|
+
/** The check a local envelope says it is for, read without verifying. */
|
|
188
|
+
function claimedCheck(envelope) {
|
|
189
|
+
try {
|
|
190
|
+
const payload = envelope.payload;
|
|
191
|
+
if (typeof payload !== "string")
|
|
192
|
+
return undefined;
|
|
193
|
+
const check = JSON.parse(Buffer.from(payload, "base64").toString("utf8")).predicate?.check;
|
|
194
|
+
return typeof check === "string" ? check : undefined;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Whether CI may skip each of `checks` at `at` on local evidence, judged by
|
|
202
|
+
* the policy at `base` (#4868):
|
|
203
|
+
*
|
|
204
|
+
* - `refused`: the check is one local evidence never stands in for, or the policy at base cannot be read.
|
|
205
|
+
* - `not-accepted`: `local.checks` at base does not name it (the default).
|
|
206
|
+
* - `missing`: nothing current is kept for the tree.
|
|
207
|
+
* - `untrusted`: an envelope is kept for it, and none verifies against a
|
|
208
|
+
* local key at base whose class the check accepts (a key the change adds
|
|
209
|
+
* itself, or an agent's key where the check takes people only).
|
|
210
|
+
* - `accepted`: an envelope for the check over `at`'s tree verifies, from a class the check takes.
|
|
211
|
+
*/
|
|
212
|
+
export function acceptedLocalEvidence(repo, at, base, checks) {
|
|
213
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
214
|
+
if (policy.problems.length > 0)
|
|
215
|
+
return checks.map((check) => ({ check, status: "refused", reason: `the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}` }));
|
|
216
|
+
const rules = new Map((policy.local?.checks ?? []).map((c) => [c.check, c.from]));
|
|
217
|
+
if (!checks.some((c) => rules.has(c) && localEvidenceAllowedFor(c))) {
|
|
218
|
+
return checks.map((check) => verdictWithoutEnvelopes(check, rules, base));
|
|
219
|
+
}
|
|
220
|
+
const { commit, tree } = commitAndTree(repo, at);
|
|
221
|
+
const envelopes = localEnvelopes(repo, commit, tree);
|
|
222
|
+
return checks.map((check) => {
|
|
223
|
+
const from = rules.get(check);
|
|
224
|
+
if (!from || !localEvidenceAllowedFor(check))
|
|
225
|
+
return verdictWithoutEnvelopes(check, rules, base);
|
|
226
|
+
let untrusted;
|
|
227
|
+
for (const envelope of envelopes) {
|
|
228
|
+
const v = verifyLocal(envelope, policy);
|
|
229
|
+
if (!v.ok) {
|
|
230
|
+
if (claimedCheck(envelope) === check)
|
|
231
|
+
untrusted ?? (untrusted = `the local evidence for ${check} does not verify against the local keys at ${base.slice(0, 12)}: ${v.reason}`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const p = v.statement.predicate;
|
|
235
|
+
if (p.check !== check || p.tree !== tree)
|
|
236
|
+
continue;
|
|
237
|
+
if (!from.includes(v.class)) {
|
|
238
|
+
untrusted ?? (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`);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
return { check, status: "accepted", signer: p.signer, class: v.class, commit: p.commit };
|
|
242
|
+
}
|
|
243
|
+
if (untrusted)
|
|
244
|
+
return { check, status: "untrusted", reason: untrusted };
|
|
245
|
+
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)}` };
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function verdictWithoutEnvelopes(check, rules, base) {
|
|
249
|
+
if (!localEvidenceAllowedFor(check))
|
|
250
|
+
return { check, status: "refused", reason: `${check} gates an apply, a release or a gate, so it runs whatever evidence exists` };
|
|
251
|
+
if (!rules.has(check))
|
|
252
|
+
return { check, status: "not-accepted", reason: `local.checks in .chant/trust.json at ${base.slice(0, 12)} does not name ${check}` };
|
|
253
|
+
return { check, status: "missing", reason: `no local evidence for ${check}` };
|
|
254
|
+
}
|
|
255
|
+
/** Whether the policy at `base` takes local evidence for any check, so a job knows whether to fetch the notes at all. */
|
|
256
|
+
export function acceptsLocalEvidence(repo, base) {
|
|
257
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
258
|
+
return policy.problems.length === 0 && (policy.local?.checks ?? []).some((c) => localEvidenceAllowedFor(c.check));
|
|
259
|
+
}
|