@intentius/chant 0.124.85 → 0.124.87
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 +78 -0
- package/dist/ci-evidence-jobs.d.ts.map +1 -0
- package/dist/ci-evidence-jobs.js +85 -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 +61 -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 +174 -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 +143 -0
- package/dist/components/product-plan.d.ts.map +1 -0
- package/dist/components/product-plan.js +145 -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 +179 -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 +40 -0
- package/dist/op/op-waves-evidence.d.ts.map +1 -0
- package/dist/op/op-waves-evidence.js +58 -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 +33 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +33 -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 +309 -302
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +4 -3
- 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 +58 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence-report.js +109 -0
- package/dist/workspace/trust/check-evidence.d.ts +160 -0
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence.js +309 -0
- package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
- package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.d.ts +40 -2
- package/dist/workspace/trust/dsse.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.js +34 -2
- package/dist/workspace/trust/evidence.d.ts +2 -2
- package/dist/workspace/trust/evidence.d.ts.map +1 -1
- package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
- package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/keyless-fixture.js +161 -0
- package/dist/workspace/trust/keyless.d.ts +202 -0
- package/dist/workspace/trust/keyless.d.ts.map +1 -0
- package/dist/workspace/trust/keyless.js +488 -0
- package/dist/workspace/trust/local-evidence.d.ts +123 -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/op-run-statement.d.ts +2 -2
- package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/policy.d.ts +140 -1
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +197 -3
- 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 +432 -0
- package/dist/workspace/trust/run-statement.d.ts +3 -3
- package/dist/workspace/trust/run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/runner-identity.d.ts +56 -0
- package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
- package/dist/workspace/trust/runner-identity.js +65 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +25 -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 +105 -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 +60 -3
- package/src/cli/handlers/ci-evidence.ts +167 -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 +230 -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 +181 -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 +58 -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 +47 -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/ci-green.ts +4 -3
- 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 +115 -0
- package/src/workspace/trust/check-evidence.test.ts +133 -0
- package/src/workspace/trust/check-evidence.ts +327 -0
- package/src/workspace/trust/ci-tag-statement.ts +2 -2
- package/src/workspace/trust/dsse.ts +48 -4
- package/src/workspace/trust/evidence.ts +2 -2
- package/src/workspace/trust/keyless-fixture.ts +214 -0
- package/src/workspace/trust/keyless.test.ts +220 -0
- package/src/workspace/trust/keyless.ts +557 -0
- package/src/workspace/trust/local-evidence.test.ts +127 -0
- package/src/workspace/trust/local-evidence.ts +268 -0
- package/src/workspace/trust/op-run-statement.ts +2 -2
- package/src/workspace/trust/policy.ts +263 -3
- 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 +539 -0
- package/src/workspace/trust/run-statement.ts +3 -3
- package/src/workspace/trust/runner-identity.ts +92 -0
- package/src/workspace/trust/trust-files.test.ts +22 -0
- package/src/workspace/trust/trust-files.ts +54 -1
|
@@ -0,0 +1,160 @@
|
|
|
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), or the job's OIDC
|
|
22
|
+
* identity ({@link keylessEvidenceSigner}, #4869), which trades the job's
|
|
23
|
+
* token for a short-lived certificate and returns the same envelope with
|
|
24
|
+
* the certificate and a timestamp in it. {@link runnerEvidenceSigner} picks
|
|
25
|
+
* one from the job's environment, the one place every signing step reads.
|
|
26
|
+
*
|
|
27
|
+
* Reading ({@link readCheckEvidence}) verifies each envelope against the
|
|
28
|
+
* runner keys and keyless identities of `.chant/trust.json` at base, so
|
|
29
|
+
* evidence a change signs with a key or identity it adds itself does not
|
|
30
|
+
* count until that is merged.
|
|
31
|
+
*/
|
|
32
|
+
import { type DsseEnvelope } from "./dsse.js";
|
|
33
|
+
import { type EvidenceStatement } from "./evidence.js";
|
|
34
|
+
import { EVIDENCE_NOTES_REF } from "./ref-gate.js";
|
|
35
|
+
import { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV } from "./check-evidence-report.js";
|
|
36
|
+
export { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV };
|
|
37
|
+
export { EVIDENCE_NOTES_REF };
|
|
38
|
+
/** The named checks the plan job stands for (#4870): its plan, and the policy evaluated inside it. */
|
|
39
|
+
export declare const PLAN_EVIDENCE_CHECKS: readonly ["plan", "policy"];
|
|
40
|
+
/**
|
|
41
|
+
* Who signs a check's statement (#4870). `sign` returns the DSSE envelope
|
|
42
|
+
* of the in-toto payload it is given; a keyless signer (#4869) answers
|
|
43
|
+
* once its signature is timestamped.
|
|
44
|
+
*/
|
|
45
|
+
export interface EvidenceSigner {
|
|
46
|
+
/** The runner principal the statement names, as `.chant/trust.json` at base lists it. */
|
|
47
|
+
principal: string;
|
|
48
|
+
sign(payloadType: string, payload: Buffer): DsseEnvelope | Promise<DsseEnvelope>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The signer of a job that signs keyless from its OIDC identity (#4869):
|
|
52
|
+
* it requests the job's token for the policy's audience, trades it at the
|
|
53
|
+
* policy's certificate authority for a certificate over a key made for this
|
|
54
|
+
* run, and signs each envelope with that key, each signature timestamped.
|
|
55
|
+
* The principal is the identity of `keyless.identities` at `base` the
|
|
56
|
+
* certificate matches. Throws when the policy at base lists no keyless
|
|
57
|
+
* identity, the job has no token, or the certificate names an identity the
|
|
58
|
+
* policy does not list, so a job never keeps evidence its readers would
|
|
59
|
+
* ignore. Each envelope is verified against the policy before it is
|
|
60
|
+
* returned.
|
|
61
|
+
*/
|
|
62
|
+
export declare function keylessEvidenceSigner(repo: string, base: string, opts?: {
|
|
63
|
+
env?: NodeJS.ProcessEnv;
|
|
64
|
+
fetch?: typeof fetch;
|
|
65
|
+
}): Promise<EvidenceSigner>;
|
|
66
|
+
/**
|
|
67
|
+
* The job's signer, read from its environment in one place (#4869): the
|
|
68
|
+
* runner key in `key` or `CHANT_RUNNER_KEY` ({@link runnerKeyEvidenceSigner}),
|
|
69
|
+
* else, with `CHANT_RUNNER_IDENTITY=oidc`, the job's OIDC identity
|
|
70
|
+
* ({@link keylessEvidenceSigner}). Undefined when the job has neither, so
|
|
71
|
+
* a project with no runner identity gets the job it had. Throws as those do.
|
|
72
|
+
*/
|
|
73
|
+
export declare function runnerEvidenceSigner(repo: string, base: string, opts?: {
|
|
74
|
+
env?: NodeJS.ProcessEnv;
|
|
75
|
+
key?: string;
|
|
76
|
+
fetch?: typeof fetch;
|
|
77
|
+
}): Promise<EvidenceSigner | undefined>;
|
|
78
|
+
/** What {@link runnerEvidenceSigner} would sign with, for a line saying why nothing was signed. */
|
|
79
|
+
export declare function noRunnerIdentity(): string;
|
|
80
|
+
/**
|
|
81
|
+
* The signer a runner key makes: the principal `.chant/trust.json` at
|
|
82
|
+
* `base` lists the key under `runners`. Throws when the key is not an
|
|
83
|
+
* Ed25519 PEM key, is a signer's (a person's) key, or is not listed, so a
|
|
84
|
+
* job never keeps evidence its readers would ignore.
|
|
85
|
+
*/
|
|
86
|
+
export declare function runnerKeyEvidenceSigner(repo: string, base: string, pem: string): EvidenceSigner;
|
|
87
|
+
/** The full commit id and tree of `rev`. Throws when `rev` names no commit. */
|
|
88
|
+
export declare function commitAndTree(repo: string, rev: string): {
|
|
89
|
+
commit: string;
|
|
90
|
+
tree: string;
|
|
91
|
+
};
|
|
92
|
+
/** The check's statement over `commit`, with the digest of what it said when given. */
|
|
93
|
+
export declare function checkStatement(input: {
|
|
94
|
+
commit: string;
|
|
95
|
+
tree: string;
|
|
96
|
+
check: string;
|
|
97
|
+
runner: string;
|
|
98
|
+
claim?: Buffer | string;
|
|
99
|
+
}): EvidenceStatement;
|
|
100
|
+
/** One check signed. */
|
|
101
|
+
export interface SignedCheck {
|
|
102
|
+
check: string;
|
|
103
|
+
commit: string;
|
|
104
|
+
tree: string;
|
|
105
|
+
runner: string;
|
|
106
|
+
envelope: DsseEnvelope;
|
|
107
|
+
}
|
|
108
|
+
/** Sign each of `checks` over `at` with `signer`. Writes nothing. */
|
|
109
|
+
export declare function signChecks(repo: string, at: string, checks: readonly {
|
|
110
|
+
check: string;
|
|
111
|
+
claim?: Buffer | string;
|
|
112
|
+
}[], signer: EvidenceSigner): Promise<SignedCheck[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Attach each envelope to its commit's evidence note and push
|
|
115
|
+
* `refs/notes/chant/evidence` to `origin`. The remote's notes are fetched
|
|
116
|
+
* first, so the push adds to them; a push another job beat is tried again
|
|
117
|
+
* on the newer notes. Returns why the push did not land, when it did not;
|
|
118
|
+
* the local notes hold the envelopes either way.
|
|
119
|
+
*/
|
|
120
|
+
export declare function recordChecks(repo: string, signed: readonly SignedCheck[], opts?: {
|
|
121
|
+
push?: boolean;
|
|
122
|
+
remote?: string;
|
|
123
|
+
notesRef?: string;
|
|
124
|
+
}): Promise<{
|
|
125
|
+
pushed: boolean;
|
|
126
|
+
pushWarning?: string;
|
|
127
|
+
}>;
|
|
128
|
+
/**
|
|
129
|
+
* Every envelope attached to a commit whose tree is `tree`: `commit`'s own first. Read from `notesRef`
|
|
130
|
+
* (default {@link EVIDENCE_NOTES_REF}; #4868 reads local evidence from its own).
|
|
131
|
+
*/
|
|
132
|
+
export declare function envelopesForTree(repo: string, commit: string, tree: string, notesRef?: string): unknown[];
|
|
133
|
+
/** What the evidence notes hold for one check at a commit's tree. */
|
|
134
|
+
export type CheckEvidenceVerdict = {
|
|
135
|
+
check: string;
|
|
136
|
+
status: "current";
|
|
137
|
+
runner: string;
|
|
138
|
+
commit: string;
|
|
139
|
+
} | {
|
|
140
|
+
check: string;
|
|
141
|
+
status: "missing" | "untrusted";
|
|
142
|
+
reason: string;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Read and verify the evidence for each of `checks` at `at`'s tree, against
|
|
146
|
+
* the runner keys and keyless identities `.chant/trust.json` lists at
|
|
147
|
+
* `base` (#4869). `missing`: nothing is
|
|
148
|
+
* kept for the tree. `untrusted`: an envelope is kept, and no runner key at
|
|
149
|
+
* base signed it, or it is not a check statement for that tree.
|
|
150
|
+
*/
|
|
151
|
+
export declare function readCheckEvidence(repo: string, at: string, base: string, checks: readonly string[]): Promise<CheckEvidenceVerdict[]>;
|
|
152
|
+
/** The command that produces a check's evidence, for a refusal to name. */
|
|
153
|
+
export declare function checkEvidenceCommand(check: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Why `at` is refused for want of evidence, or null when every one of
|
|
156
|
+
* `required` has current evidence. Names each missing check and the
|
|
157
|
+
* command that produces it.
|
|
158
|
+
*/
|
|
159
|
+
export declare function missingCheckEvidence(repo: string, at: string, base: string, required: readonly string[]): Promise<string | null>;
|
|
160
|
+
//# sourceMappingURL=check-evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-evidence.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/check-evidence.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,309 @@
|
|
|
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), or the job's OIDC
|
|
22
|
+
* identity ({@link keylessEvidenceSigner}, #4869), which trades the job's
|
|
23
|
+
* token for a short-lived certificate and returns the same envelope with
|
|
24
|
+
* the certificate and a timestamp in it. {@link runnerEvidenceSigner} picks
|
|
25
|
+
* one from the job's environment, the one place every signing step reads.
|
|
26
|
+
*
|
|
27
|
+
* Reading ({@link readCheckEvidence}) verifies each envelope against the
|
|
28
|
+
* runner keys and keyless identities of `.chant/trust.json` at base, so
|
|
29
|
+
* evidence a change signs with a key or identity it adds itself does not
|
|
30
|
+
* count until that is merged.
|
|
31
|
+
*/
|
|
32
|
+
import { execFileSync } from "node:child_process";
|
|
33
|
+
import { createHash } from "node:crypto";
|
|
34
|
+
import { canonicalJson } from "../../effect-receipt.js";
|
|
35
|
+
import { gitRevisionSource } from "../record-source.js";
|
|
36
|
+
import { X509Certificate } from "node:crypto";
|
|
37
|
+
import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, pae, signEnvelope } from "./dsse.js";
|
|
38
|
+
import { RUNNER_EVIDENCE_PREDICATE, STATEMENT_TYPE, verifyEvidence } from "./evidence.js";
|
|
39
|
+
import { certificateIssuer, certificateSubjects, keylessSignature, requestCertificate, signingToken, subjectPattern, verifyKeylessSignature } from "./keyless.js";
|
|
40
|
+
import { readTrustPolicy, runnersAt } from "./policy.js";
|
|
41
|
+
import { attachEvidence, EVIDENCE_NOTES_REF, parseEvidenceNote } from "./ref-gate.js";
|
|
42
|
+
import { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV } from "./check-evidence-report.js";
|
|
43
|
+
export { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV };
|
|
44
|
+
export { EVIDENCE_NOTES_REF };
|
|
45
|
+
/** The named checks the plan job stands for (#4870): its plan, and the policy evaluated inside it. */
|
|
46
|
+
export const PLAN_EVIDENCE_CHECKS = ["plan", "policy"];
|
|
47
|
+
/**
|
|
48
|
+
* The signer of a job that signs keyless from its OIDC identity (#4869):
|
|
49
|
+
* it requests the job's token for the policy's audience, trades it at the
|
|
50
|
+
* policy's certificate authority for a certificate over a key made for this
|
|
51
|
+
* run, and signs each envelope with that key, each signature timestamped.
|
|
52
|
+
* The principal is the identity of `keyless.identities` at `base` the
|
|
53
|
+
* certificate matches. Throws when the policy at base lists no keyless
|
|
54
|
+
* identity, the job has no token, or the certificate names an identity the
|
|
55
|
+
* policy does not list, so a job never keeps evidence its readers would
|
|
56
|
+
* ignore. Each envelope is verified against the policy before it is
|
|
57
|
+
* returned.
|
|
58
|
+
*/
|
|
59
|
+
export async function keylessEvidenceSigner(repo, base, opts = {}) {
|
|
60
|
+
const env = opts.env ?? process.env;
|
|
61
|
+
const fetchFn = opts.fetch ?? fetch;
|
|
62
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
63
|
+
if (policy.problems.length > 0)
|
|
64
|
+
throw new Error(`the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}`);
|
|
65
|
+
const identities = policy.runnerIdentities ?? [];
|
|
66
|
+
if (!policy.keyless || identities.length === 0) {
|
|
67
|
+
const why = policy.excludedRunners.map((r) => `${r.principal}: ${r.reason}`).join("; ");
|
|
68
|
+
throw new Error(`.chant/trust.json at ${base.slice(0, 12)} lists no keyless identity, so keyless evidence would be ignored. Add one under "keyless"${why ? ` (${why})` : ""}`);
|
|
69
|
+
}
|
|
70
|
+
const { fulcio, timestamp, audience } = policy.keyless;
|
|
71
|
+
const token = await signingToken(env, audience, fetchFn);
|
|
72
|
+
const cert = await requestCertificate(token, fulcio, fetchFn);
|
|
73
|
+
const leaf = new X509Certificate(Buffer.from(cert.certificates[0], "base64"));
|
|
74
|
+
const issuer = certificateIssuer(leaf);
|
|
75
|
+
const subjects = certificateSubjects(leaf);
|
|
76
|
+
const listed = identities.find((i) => i.issuer === issuer && subjects.some((s) => subjectPattern(i.subject).test(s)));
|
|
77
|
+
if (!listed) {
|
|
78
|
+
throw new Error(`.chant/trust.json at ${base.slice(0, 12)} lists no keyless identity for this job (issuer ${issuer ?? "none"}, subject ${subjects.join(", ") || "none"}), so the evidence would be ignored`);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
principal: listed.principal,
|
|
82
|
+
sign: async (payloadType, payload) => {
|
|
83
|
+
const message = pae(payloadType, payload);
|
|
84
|
+
const signature = await keylessSignature(message, cert, timestamp, fetchFn);
|
|
85
|
+
const v = verifyKeylessSignature(message, signature, [listed]);
|
|
86
|
+
if (!v.ok)
|
|
87
|
+
throw new Error(`the keyless signature does not verify against the policy at ${base.slice(0, 12)}: ${v.reason}`);
|
|
88
|
+
return { payloadType, payload: payload.toString("base64"), signatures: [signature] };
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The job's signer, read from its environment in one place (#4869): the
|
|
94
|
+
* runner key in `key` or `CHANT_RUNNER_KEY` ({@link runnerKeyEvidenceSigner}),
|
|
95
|
+
* else, with `CHANT_RUNNER_IDENTITY=oidc`, the job's OIDC identity
|
|
96
|
+
* ({@link keylessEvidenceSigner}). Undefined when the job has neither, so
|
|
97
|
+
* a project with no runner identity gets the job it had. Throws as those do.
|
|
98
|
+
*/
|
|
99
|
+
export async function runnerEvidenceSigner(repo, base, opts = {}) {
|
|
100
|
+
const env = opts.env ?? process.env;
|
|
101
|
+
const pem = opts.key ?? env[CHECK_EVIDENCE_KEY_ENV];
|
|
102
|
+
if (pem)
|
|
103
|
+
return runnerKeyEvidenceSigner(repo, base, pem);
|
|
104
|
+
const identity = env[RUNNER_IDENTITY_ENV];
|
|
105
|
+
if (!identity)
|
|
106
|
+
return undefined;
|
|
107
|
+
if (identity !== "oidc")
|
|
108
|
+
throw new Error(`${RUNNER_IDENTITY_ENV} is ${JSON.stringify(identity)}; the one runner identity chant signs with is oidc`);
|
|
109
|
+
return keylessEvidenceSigner(repo, base, { env, ...(opts.fetch ? { fetch: opts.fetch } : {}) });
|
|
110
|
+
}
|
|
111
|
+
/** What {@link runnerEvidenceSigner} would sign with, for a line saying why nothing was signed. */
|
|
112
|
+
export function noRunnerIdentity() {
|
|
113
|
+
return `no runner identity: neither ${CHECK_EVIDENCE_KEY_ENV} nor ${RUNNER_IDENTITY_ENV}=oidc is set`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The signer a runner key makes: the principal `.chant/trust.json` at
|
|
117
|
+
* `base` lists the key under `runners`. Throws when the key is not an
|
|
118
|
+
* Ed25519 PEM key, is a signer's (a person's) key, or is not listed, so a
|
|
119
|
+
* job never keeps evidence its readers would ignore.
|
|
120
|
+
*/
|
|
121
|
+
export function runnerKeyEvidenceSigner(repo, base, pem) {
|
|
122
|
+
let loaded;
|
|
123
|
+
try {
|
|
124
|
+
loaded = loadRunnerKey(pem);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
throw new Error(`the runner key is not an Ed25519 private key in PEM: ${err instanceof Error ? err.message : String(err)}`);
|
|
128
|
+
}
|
|
129
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
130
|
+
if (policy.problems.length > 0)
|
|
131
|
+
throw new Error(`the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}`);
|
|
132
|
+
if (policy.signers.some((s) => s.key === loaded.publicKey)) {
|
|
133
|
+
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`);
|
|
134
|
+
}
|
|
135
|
+
const listed = policy.runners.find((r) => r.key === loaded.publicKey);
|
|
136
|
+
if (!listed)
|
|
137
|
+
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}`);
|
|
138
|
+
return { principal: listed.principal, sign: (payloadType, payload) => signEnvelope(payloadType, payload, loaded.key, loaded.publicKey) };
|
|
139
|
+
}
|
|
140
|
+
function git(repo, args) {
|
|
141
|
+
return execFileSync("git", args, { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
142
|
+
}
|
|
143
|
+
/** The full commit id and tree of `rev`. Throws when `rev` names no commit. */
|
|
144
|
+
export function commitAndTree(repo, rev) {
|
|
145
|
+
const commit = git(repo, ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]);
|
|
146
|
+
return { commit, tree: git(repo, ["rev-parse", `${commit}^{tree}`]) };
|
|
147
|
+
}
|
|
148
|
+
/** The check's statement over `commit`, with the digest of what it said when given. */
|
|
149
|
+
export function checkStatement(input) {
|
|
150
|
+
if (!input.check.trim())
|
|
151
|
+
throw new Error("a check's evidence needs the check's name");
|
|
152
|
+
return {
|
|
153
|
+
_type: STATEMENT_TYPE,
|
|
154
|
+
subject: [],
|
|
155
|
+
predicateType: RUNNER_EVIDENCE_PREDICATE,
|
|
156
|
+
predicate: {
|
|
157
|
+
runner: input.runner,
|
|
158
|
+
commit: input.commit,
|
|
159
|
+
tree: input.tree,
|
|
160
|
+
check: input.check,
|
|
161
|
+
...(input.claim !== undefined ? { claim: { sha256: createHash("sha256").update(input.claim).digest("hex") } } : {}),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Sign each of `checks` over `at` with `signer`. Writes nothing. */
|
|
166
|
+
export async function signChecks(repo, at, checks, signer) {
|
|
167
|
+
const { commit, tree } = commitAndTree(repo, at);
|
|
168
|
+
const out = [];
|
|
169
|
+
for (const { check, claim } of checks) {
|
|
170
|
+
const statement = checkStatement({ commit, tree, check, runner: signer.principal, ...(claim !== undefined ? { claim } : {}) });
|
|
171
|
+
out.push({ check, commit, tree, runner: signer.principal, envelope: await signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")) });
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
/** How many times {@link recordChecks} fetches, attaches and pushes when another job pushed the notes first. */
|
|
176
|
+
const NOTES_PUSH_TRIES = 3;
|
|
177
|
+
function tryGit(repo, args) {
|
|
178
|
+
try {
|
|
179
|
+
return git(repo, args);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Attach each envelope to its commit's evidence note and push
|
|
187
|
+
* `refs/notes/chant/evidence` to `origin`. The remote's notes are fetched
|
|
188
|
+
* first, so the push adds to them; a push another job beat is tried again
|
|
189
|
+
* on the newer notes. Returns why the push did not land, when it did not;
|
|
190
|
+
* the local notes hold the envelopes either way.
|
|
191
|
+
*/
|
|
192
|
+
export async function recordChecks(repo, signed, opts = {}) {
|
|
193
|
+
if (signed.length === 0)
|
|
194
|
+
return { pushed: false };
|
|
195
|
+
const push = opts.push !== false;
|
|
196
|
+
const remote = opts.remote ?? "origin";
|
|
197
|
+
// #4868: local evidence goes under a notes ref of its own.
|
|
198
|
+
const notesRef = opts.notesRef ?? EVIDENCE_NOTES_REF;
|
|
199
|
+
const hasRemote = push && tryGit(repo, ["remote", "get-url", remote]) !== undefined;
|
|
200
|
+
if (!hasRemote) {
|
|
201
|
+
for (const s of signed)
|
|
202
|
+
attachEvidence(repo, s.commit, s.envelope, notesRef);
|
|
203
|
+
return push ? { pushed: false, pushWarning: `no remote ${remote}, so the evidence is attached here only` } : { pushed: false };
|
|
204
|
+
}
|
|
205
|
+
let said = "";
|
|
206
|
+
for (let attempt = 1; attempt <= NOTES_PUSH_TRIES; attempt++) {
|
|
207
|
+
// The remote's notes are the ones to add to; a CI checkout has none of its own to keep.
|
|
208
|
+
if (tryGit(repo, ["fetch", "--quiet", "--no-tags", remote, `+${notesRef}:${notesRef}`]) === undefined && attempt > 1)
|
|
209
|
+
break;
|
|
210
|
+
for (const s of signed)
|
|
211
|
+
attachEvidence(repo, s.commit, s.envelope, notesRef);
|
|
212
|
+
try {
|
|
213
|
+
execFileSync("git", ["push", "--quiet", remote, `${notesRef}:${notesRef}`], { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
|
|
214
|
+
return { pushed: true };
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
said = String(err.stderr ?? (err instanceof Error ? err.message : err)).trim().split("\n")[0] ?? "";
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { pushed: false, pushWarning: `git push ${remote} ${notesRef} did not land${said ? ` (git said: ${said})` : ""}` };
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Every envelope attached to a commit whose tree is `tree`: `commit`'s own first. Read from `notesRef`
|
|
224
|
+
* (default {@link EVIDENCE_NOTES_REF}; #4868 reads local evidence from its own).
|
|
225
|
+
*/
|
|
226
|
+
export function envelopesForTree(repo, commit, tree, notesRef = EVIDENCE_NOTES_REF) {
|
|
227
|
+
const list = tryGit(repo, ["notes", `--ref=${notesRef}`, "list"]);
|
|
228
|
+
if (!list)
|
|
229
|
+
return [];
|
|
230
|
+
const own = [];
|
|
231
|
+
const others = [];
|
|
232
|
+
for (const line of list.split("\n")) {
|
|
233
|
+
const [blob, annotated] = line.trim().split(/\s+/);
|
|
234
|
+
if (!blob || !annotated)
|
|
235
|
+
continue;
|
|
236
|
+
const same = annotated === commit || tryGit(repo, ["rev-parse", "--verify", "--quiet", `${annotated}^{tree}`]) === tree;
|
|
237
|
+
if (!same)
|
|
238
|
+
continue;
|
|
239
|
+
const text = tryGit(repo, ["cat-file", "blob", blob]);
|
|
240
|
+
if (text !== undefined)
|
|
241
|
+
(annotated === commit ? own : others).push(...parseEvidenceNote(text));
|
|
242
|
+
}
|
|
243
|
+
return [...own, ...others];
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Read and verify the evidence for each of `checks` at `at`'s tree, against
|
|
247
|
+
* the runner keys and keyless identities `.chant/trust.json` lists at
|
|
248
|
+
* `base` (#4869). `missing`: nothing is
|
|
249
|
+
* kept for the tree. `untrusted`: an envelope is kept, and no runner key at
|
|
250
|
+
* base signed it, or it is not a check statement for that tree.
|
|
251
|
+
*/
|
|
252
|
+
export async function readCheckEvidence(repo, at, base, checks) {
|
|
253
|
+
const { tree, commit } = commitAndTree(repo, at);
|
|
254
|
+
const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
|
|
255
|
+
// #4869: the keys and the keyless identities; under keyless.since, the keys only for a commit before it.
|
|
256
|
+
const runners = runnersAt(policy, { repo, commit });
|
|
257
|
+
const envelopes = envelopesForTree(repo, commit, tree);
|
|
258
|
+
return checks.map((check) => {
|
|
259
|
+
let untrusted;
|
|
260
|
+
for (const envelope of envelopes) {
|
|
261
|
+
const v = verifyEvidence(envelope, runners, repo, commit);
|
|
262
|
+
if (!v.ok) {
|
|
263
|
+
if (claimedCheck(envelope) === check)
|
|
264
|
+
untrusted ?? (untrusted = `the evidence attached for check ${check} does not verify against the runners at ${base.slice(0, 12)}: ${v.reason}`);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (v.statement.predicate.check !== check || v.statement.predicate.tree !== tree)
|
|
268
|
+
continue;
|
|
269
|
+
if (v.status === "current")
|
|
270
|
+
return { check, status: "current", runner: v.runner, commit: v.statement.predicate.commit };
|
|
271
|
+
}
|
|
272
|
+
if (untrusted)
|
|
273
|
+
return { check, status: "untrusted", reason: untrusted };
|
|
274
|
+
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)}` };
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/** The check an envelope says it is for, read without verifying, so a refusal can name it. */
|
|
278
|
+
function claimedCheck(envelope) {
|
|
279
|
+
try {
|
|
280
|
+
const payload = envelope.payload;
|
|
281
|
+
if (typeof payload !== "string")
|
|
282
|
+
return undefined;
|
|
283
|
+
const check = JSON.parse(Buffer.from(payload, "base64").toString("utf8")).predicate?.check;
|
|
284
|
+
return typeof check === "string" ? check : undefined;
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/** The command that produces a check's evidence, for a refusal to name. */
|
|
291
|
+
export function checkEvidenceCommand(check) {
|
|
292
|
+
return `chant ci evidence sign --check-id ${check}`;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Why `at` is refused for want of evidence, or null when every one of
|
|
296
|
+
* `required` has current evidence. Names each missing check and the
|
|
297
|
+
* command that produces it.
|
|
298
|
+
*/
|
|
299
|
+
export async function missingCheckEvidence(repo, at, base, required) {
|
|
300
|
+
if (required.length === 0)
|
|
301
|
+
return null;
|
|
302
|
+
const verdicts = await readCheckEvidence(repo, at, base, required);
|
|
303
|
+
const missing = verdicts.filter((v) => v.status !== "current");
|
|
304
|
+
if (missing.length === 0)
|
|
305
|
+
return null;
|
|
306
|
+
return `${at.slice(0, 12)} lacks the evidence the policy at ${base.slice(0, 12)} requires: ${missing
|
|
307
|
+
.map((v) => `${v.check} (${v.reason}; run it in CI, where ${checkEvidenceCommand(v.check)} signs it)`)
|
|
308
|
+
.join("; ")}`;
|
|
309
|
+
}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
import { z } from "zod";
|
|
30
30
|
import { type DsseEnvelope } from "./dsse.js";
|
|
31
31
|
import type { KeyObject } from "node:crypto";
|
|
32
|
-
import type {
|
|
32
|
+
import type { Runner } from "./policy.js";
|
|
33
33
|
export declare const CI_TAG_PREDICATE = "https://intentius.io/chant/ci-tag/v1";
|
|
34
34
|
/** The role a tag's signer must hold in `.chant/trust.json` (#4031): the core class `runner`. */
|
|
35
35
|
export declare const CI_TAG_SIGNER_ROLE = "runner";
|
|
@@ -99,5 +99,5 @@ export declare function verifyCiTagStatement(record: Record<string, unknown> | n
|
|
|
99
99
|
kind: "green" | "revoked";
|
|
100
100
|
branch: string;
|
|
101
101
|
lane?: string;
|
|
102
|
-
}, runners: readonly
|
|
102
|
+
}, runners: readonly Runner[], roles: Readonly<Record<string, readonly string[]>>): CiTagVerdict;
|
|
103
103
|
//# sourceMappingURL=ci-tag-statement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ci-tag-statement.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ci-tag-statement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAsD,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ci-tag-statement.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ci-tag-statement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAsD,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,UAAU,CAAC;AAElD,eAAO,MAAM,gBAAgB,yCAAyC,CAAC;AAEvE,iGAAiG;AACjG,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAK3C,+GAA+G;AAC/G,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;kBAqBtB,CAAC;AACZ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,kDAAkD;AAClD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjH,4GAA4G;AAC5G,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,SAAS,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAOvF;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,YAAY,CAGtF;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;AAE7E,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnE;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAI7C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EACtC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EACjF,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,GACjD,YAAY,CAmCd"}
|
|
@@ -10,12 +10,22 @@
|
|
|
10
10
|
* Public keys are written the way ssh writes them (`ssh-ed25519 AAAA...`), so
|
|
11
11
|
* the runner keys in `.chant/trust.json` read like the signers file beside
|
|
12
12
|
* them, and a key id is the key's ssh fingerprint (`SHA256:...`).
|
|
13
|
+
*
|
|
14
|
+
* A signature can instead be keyless (#4869, ./keyless.ts): it carries the
|
|
15
|
+
* short-lived certificate of a CI job's OIDC identity and a timestamp, and
|
|
16
|
+
* verifies against an identity the policy lists rather than a key. The
|
|
17
|
+
* identity brings its own verifier, so this file, which bundles such as the
|
|
18
|
+
* runner-start verifier carry, holds no certificate code.
|
|
13
19
|
*/
|
|
14
20
|
import { type KeyObject } from "node:crypto";
|
|
15
21
|
export declare const IN_TOTO_PAYLOAD_TYPE = "application/vnd.in-toto+json";
|
|
16
22
|
export interface DsseSignature {
|
|
17
23
|
keyid: string;
|
|
18
24
|
sig: string;
|
|
25
|
+
/** Keyless (#4869): the certificate chain, base64 DER, the signing certificate first. */
|
|
26
|
+
certificates?: string[];
|
|
27
|
+
/** Keyless (#4869): the RFC 3161 timestamp token over the signature, base64 DER. */
|
|
28
|
+
timestamp?: string;
|
|
19
29
|
}
|
|
20
30
|
export interface DsseEnvelope {
|
|
21
31
|
payloadType: string;
|
|
@@ -42,17 +52,45 @@ export interface TrustedKey {
|
|
|
42
52
|
/** `ssh-ed25519 <base64>`. */
|
|
43
53
|
key: string;
|
|
44
54
|
}
|
|
55
|
+
/** What a keyless identity says of one signature (#4869). `named`: the certificate is this identity's, and something else failed. */
|
|
56
|
+
export type KeylessCheck = {
|
|
57
|
+
ok: true;
|
|
58
|
+
keyid: string;
|
|
59
|
+
issuer: string;
|
|
60
|
+
subject: string;
|
|
61
|
+
signedAt: string;
|
|
62
|
+
} | {
|
|
63
|
+
ok: false;
|
|
64
|
+
named: boolean;
|
|
65
|
+
reason: string;
|
|
66
|
+
};
|
|
67
|
+
/** A CI identity that signs keyless (#4869), as the policy at base reads it, with the verifier for its trusted root. */
|
|
68
|
+
export interface TrustedIdentity {
|
|
69
|
+
principal: string;
|
|
70
|
+
issuer: string;
|
|
71
|
+
verifyKeyless(message: Buffer, signature: DsseSignature): KeylessCheck;
|
|
72
|
+
}
|
|
73
|
+
/** Who may sign: a runner key, or a CI identity that signs keyless (#4869). */
|
|
74
|
+
export type TrustedSigner = TrustedKey | TrustedIdentity;
|
|
45
75
|
export type EnvelopeVerdict = {
|
|
46
76
|
ok: true;
|
|
47
77
|
principal: string;
|
|
48
78
|
keyid: string;
|
|
49
79
|
payloadType: string;
|
|
50
80
|
payload: Buffer;
|
|
81
|
+
keyless?: {
|
|
82
|
+
issuer: string;
|
|
83
|
+
subject: string;
|
|
84
|
+
signedAt: string;
|
|
85
|
+
};
|
|
51
86
|
} | {
|
|
52
87
|
ok: false;
|
|
53
88
|
code: "envelope-invalid" | "envelope-untrusted";
|
|
54
89
|
reason: string;
|
|
55
90
|
};
|
|
56
|
-
/**
|
|
57
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Verify an envelope against `trusted`. One valid signature by a trusted
|
|
93
|
+
* key, or one keyless signature by a trusted identity (#4869), is enough.
|
|
94
|
+
*/
|
|
95
|
+
export declare function verifyEnvelope(envelope: unknown, trusted: readonly TrustedSigner[]): EnvelopeVerdict;
|
|
58
96
|
//# sourceMappingURL=dsse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dsse.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/dsse.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dsse.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/dsse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAA+D,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE1G,eAAO,MAAM,oBAAoB,iCAAiC,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,yFAAyF;IACzF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED,sFAAsF;AACtF,wBAAgB,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGhE;AAWD,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASnD;AAED,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGnD;AAMD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAKhF;AAID,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,YAAY,CAGlH;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qIAAqI;AACrI,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1J,wHAAwH;AACxH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,GAAG,YAAY,CAAC;CACxE;AAED,+EAA+E;AAC/E,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,eAAe,CAAC;AAIzD,MAAM,MAAM,eAAe,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACrJ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,kBAAkB,GAAG,oBAAoB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,eAAe,CAmCpG"}
|
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
* Public keys are written the way ssh writes them (`ssh-ed25519 AAAA...`), so
|
|
11
11
|
* the runner keys in `.chant/trust.json` read like the signers file beside
|
|
12
12
|
* them, and a key id is the key's ssh fingerprint (`SHA256:...`).
|
|
13
|
+
*
|
|
14
|
+
* A signature can instead be keyless (#4869, ./keyless.ts): it carries the
|
|
15
|
+
* short-lived certificate of a CI job's OIDC identity and a timestamp, and
|
|
16
|
+
* verifies against an identity the policy lists rather than a key. The
|
|
17
|
+
* identity brings its own verifier, so this file, which bundles such as the
|
|
18
|
+
* runner-start verifier carry, holds no certificate code.
|
|
13
19
|
*/
|
|
14
20
|
import { createHash, createPrivateKey, createPublicKey, sign, verify } from "node:crypto";
|
|
15
21
|
export const IN_TOTO_PAYLOAD_TYPE = "application/vnd.in-toto+json";
|
|
@@ -71,7 +77,11 @@ export function signEnvelope(payloadType, payload, key, publicKey) {
|
|
|
71
77
|
const sig = sign(null, pae(payloadType, payload), key);
|
|
72
78
|
return { payloadType, payload: payload.toString("base64"), signatures: [{ keyid: sshFingerprint(publicKey), sig: sig.toString("base64") }] };
|
|
73
79
|
}
|
|
74
|
-
|
|
80
|
+
const isKeyless = (s) => Array.isArray(s.certificates) && typeof s.timestamp === "string";
|
|
81
|
+
/**
|
|
82
|
+
* Verify an envelope against `trusted`. One valid signature by a trusted
|
|
83
|
+
* key, or one keyless signature by a trusted identity (#4869), is enough.
|
|
84
|
+
*/
|
|
75
85
|
export function verifyEnvelope(envelope, trusted) {
|
|
76
86
|
if (!isEnvelope(envelope))
|
|
77
87
|
return { ok: false, code: "envelope-invalid", reason: "not a DSSE envelope: it needs payloadType, payload and signatures" };
|
|
@@ -79,8 +89,28 @@ export function verifyEnvelope(envelope, trusted) {
|
|
|
79
89
|
if (payload.toString("base64") !== envelope.payload)
|
|
80
90
|
return { ok: false, code: "envelope-invalid", reason: "the payload is not canonical base64" };
|
|
81
91
|
const message = pae(envelope.payloadType, payload);
|
|
82
|
-
const
|
|
92
|
+
const keys = trusted.filter((t) => typeof t.key === "string");
|
|
93
|
+
const identities = trusted.filter((t) => typeof t.verifyKeyless === "function");
|
|
94
|
+
const byId = new Map(keys.map((t) => [sshFingerprint(t.key), t]));
|
|
95
|
+
let keyless;
|
|
83
96
|
for (const s of envelope.signatures) {
|
|
97
|
+
if (isKeyless(s)) {
|
|
98
|
+
if (identities.length === 0)
|
|
99
|
+
keyless ?? (keyless = "the signature is keyless, and the policy at base lists no keyless identity");
|
|
100
|
+
let named;
|
|
101
|
+
for (const id of identities) {
|
|
102
|
+
const k = id.verifyKeyless(message, s);
|
|
103
|
+
if (k.ok)
|
|
104
|
+
return { ok: true, principal: id.principal, keyid: k.keyid, payloadType: envelope.payloadType, payload, keyless: { issuer: k.issuer, subject: k.subject, signedAt: k.signedAt } };
|
|
105
|
+
if (k.named)
|
|
106
|
+
named ?? (named = k.reason);
|
|
107
|
+
else
|
|
108
|
+
keyless ?? (keyless = k.reason);
|
|
109
|
+
}
|
|
110
|
+
if (named)
|
|
111
|
+
keyless = named;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
84
114
|
const t = byId.get(s.keyid);
|
|
85
115
|
if (!t)
|
|
86
116
|
continue;
|
|
@@ -95,6 +125,8 @@ export function verifyEnvelope(envelope, trusted) {
|
|
|
95
125
|
return { ok: true, principal: t.principal, keyid: s.keyid, payloadType: envelope.payloadType, payload };
|
|
96
126
|
}
|
|
97
127
|
const ids = envelope.signatures.map((s) => s.keyid).join(", ") || "none";
|
|
128
|
+
if (keyless)
|
|
129
|
+
return { ok: false, code: "envelope-untrusted", reason: keyless };
|
|
98
130
|
return { ok: false, code: "envelope-untrusted", reason: `no signature verifies against a runner key the policy at base lists (key ids: ${ids})` };
|
|
99
131
|
}
|
|
100
132
|
function isEnvelope(v) {
|