@intentius/chant 0.124.86 → 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.
Files changed (91) hide show
  1. package/dist/ci-commit.d.ts +1 -1
  2. package/dist/ci-evidence-jobs.d.ts +31 -7
  3. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  4. package/dist/ci-evidence-jobs.js +35 -5
  5. package/dist/ci-product.d.ts +1 -1
  6. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  7. package/dist/cli/handlers/ci-check.js +17 -13
  8. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  9. package/dist/cli/handlers/ci-evidence.js +11 -8
  10. package/dist/components/check-hooks.js +3 -3
  11. package/dist/components/check-steps.js +1 -1
  12. package/dist/components/product-plan.d.ts +7 -1
  13. package/dist/components/product-plan.d.ts.map +1 -1
  14. package/dist/components/product-plan.js +3 -1
  15. package/dist/floor-table.data.d.ts.map +1 -1
  16. package/dist/floor-table.data.js +1 -0
  17. package/dist/op/op-waves-evidence.d.ts +5 -3
  18. package/dist/op/op-waves-evidence.d.ts.map +1 -1
  19. package/dist/op/op-waves-evidence.js +9 -8
  20. package/dist/release-floors.d.ts +18 -16
  21. package/dist/release-floors.d.ts.map +1 -1
  22. package/dist/release-floors.js +3 -1
  23. package/dist/state-migration.d.ts +1 -1
  24. package/dist/wave-runtime.mjs +299 -299
  25. package/dist/workspace/ci-green.d.ts.map +1 -1
  26. package/dist/workspace/ci-green.js +4 -3
  27. package/dist/workspace/trust/check-evidence-report.d.ts +7 -0
  28. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  29. package/dist/workspace/trust/check-evidence-report.js +7 -0
  30. package/dist/workspace/trust/check-evidence.d.ts +46 -12
  31. package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
  32. package/dist/workspace/trust/check-evidence.js +94 -22
  33. package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
  34. package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
  35. package/dist/workspace/trust/dsse.d.ts +40 -2
  36. package/dist/workspace/trust/dsse.d.ts.map +1 -1
  37. package/dist/workspace/trust/dsse.js +34 -2
  38. package/dist/workspace/trust/evidence.d.ts +2 -2
  39. package/dist/workspace/trust/evidence.d.ts.map +1 -1
  40. package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
  41. package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
  42. package/dist/workspace/trust/keyless-fixture.js +161 -0
  43. package/dist/workspace/trust/keyless.d.ts +202 -0
  44. package/dist/workspace/trust/keyless.d.ts.map +1 -0
  45. package/dist/workspace/trust/keyless.js +488 -0
  46. package/dist/workspace/trust/local-evidence.d.ts +3 -0
  47. package/dist/workspace/trust/local-evidence.d.ts.map +1 -1
  48. package/dist/workspace/trust/op-run-statement.d.ts +2 -2
  49. package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
  50. package/dist/workspace/trust/policy.d.ts +56 -1
  51. package/dist/workspace/trust/policy.d.ts.map +1 -1
  52. package/dist/workspace/trust/policy.js +103 -2
  53. package/dist/workspace/trust/ref-gate.d.ts +1 -1
  54. package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
  55. package/dist/workspace/trust/ref-gate.js +3 -1
  56. package/dist/workspace/trust/run-statement.d.ts +3 -3
  57. package/dist/workspace/trust/run-statement.d.ts.map +1 -1
  58. package/dist/workspace/trust/runner-identity.d.ts +56 -0
  59. package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
  60. package/dist/workspace/trust/runner-identity.js +65 -0
  61. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  62. package/dist/workspace/trust/trust-files.js +8 -1
  63. package/package.json +1 -1
  64. package/src/ci-evidence-jobs.ts +45 -7
  65. package/src/cli/handlers/ci-check.ts +16 -12
  66. package/src/cli/handlers/ci-evidence.ts +13 -8
  67. package/src/components/check-hooks.ts +3 -3
  68. package/src/components/check-steps.ts +1 -1
  69. package/src/components/product-plan.ts +7 -3
  70. package/src/floor-table.data.ts +1 -0
  71. package/src/op/op-waves-evidence.test.ts +1 -1
  72. package/src/op/op-waves-evidence.ts +10 -9
  73. package/src/release-floors.ts +4 -1
  74. package/src/workspace/ci-green.ts +4 -3
  75. package/src/workspace/trust/check-evidence-report.ts +9 -0
  76. package/src/workspace/trust/check-evidence.test.ts +3 -3
  77. package/src/workspace/trust/check-evidence.ts +95 -25
  78. package/src/workspace/trust/ci-tag-statement.ts +2 -2
  79. package/src/workspace/trust/dsse.ts +48 -4
  80. package/src/workspace/trust/evidence.ts +2 -2
  81. package/src/workspace/trust/keyless-fixture.ts +214 -0
  82. package/src/workspace/trust/keyless.test.ts +220 -0
  83. package/src/workspace/trust/keyless.ts +557 -0
  84. package/src/workspace/trust/local-evidence.ts +3 -1
  85. package/src/workspace/trust/op-run-statement.ts +2 -2
  86. package/src/workspace/trust/policy.ts +129 -2
  87. package/src/workspace/trust/ref-gate.ts +3 -2
  88. package/src/workspace/trust/run-statement.ts +3 -3
  89. package/src/workspace/trust/runner-identity.ts +92 -0
  90. package/src/workspace/trust/trust-files.test.ts +6 -0
  91. package/src/workspace/trust/trust-files.ts +14 -1
@@ -31,7 +31,7 @@ import { parseJsonText } from "../workspace/jsonc";
31
31
  import { memberAtCwd } from "../workspace/security";
32
32
  import { locateWorkspace } from "../workspace/which-chant";
33
33
  import type { CheckStepOutcome } from "./check-steps";
34
- import { CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV } from "../workspace/trust/check-evidence-report";
34
+ import { CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV, SIGNING_ID_TOKEN_VAR } from "../workspace/trust/check-evidence-report";
35
35
  import { acceptedLocalEvidence, acceptsLocalEvidence, fetchLocalEvidence } from "../workspace/trust/local-evidence";
36
36
 
37
37
  export { CI_CHECK_HOOK_FLOOR } from "../op/op-waves";
@@ -101,8 +101,8 @@ const CLOUD_CREDENTIAL_VARS = [
101
101
  * else.
102
102
  */
103
103
  export function checkHookEnv(env: NodeJS.ProcessEnv = process.env): Record<string, string> {
104
- // #4870, #4868: the runner key and the local evidence key the check runner signs each hook's evidence with never reach a hook.
105
- const drop = new Set<string>([...FORGE_TOKEN_VARS, ...OIDC_REQUEST_VARS, ...Object.values(TRADED_VARS).flat(), ...CLOUD_CREDENTIAL_VARS, CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV]);
104
+ // #4870, #4868: the runner key and the local evidence key the check runner signs each hook's evidence with never reach a hook, nor (#4869) GitLab's signing token.
105
+ const drop = new Set<string>([...FORGE_TOKEN_VARS, ...OIDC_REQUEST_VARS, ...Object.values(TRADED_VARS).flat(), ...CLOUD_CREDENTIAL_VARS, CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV, SIGNING_ID_TOKEN_VAR]);
106
106
  const out: Record<string, string> = {};
107
107
  for (const [name, value] of Object.entries(env)) {
108
108
  if (value === undefined || drop.has(name) || name.startsWith("TF_TOKEN_")) continue;
@@ -192,7 +192,7 @@ async function signHooks(options: { dir?: string; evidence?: CheckStageEvidence
192
192
  const signer = options.evidence.signer;
193
193
  const at = options.evidence.at ?? "HEAD";
194
194
  const wanted = passed.map((h) => ({ check: h.check, claim: JSON.stringify(h.runs) }));
195
- const signed = isLocalSigner(signer) ? signLocalChecks(repo, at, wanted, signer) : signChecks(repo, at, wanted, signer);
195
+ const signed = isLocalSigner(signer) ? signLocalChecks(repo, at, wanted, signer) : await signChecks(repo, at, wanted, signer);
196
196
  const push = { push: options.evidence.push !== false };
197
197
  const pushed = isLocalSigner(signer) ? await recordLocalChecks(repo, signed, push) : await recordChecks(repo, signed, push);
198
198
  for (const s of signed) log(`ci check: signed ${isLocalSigner(signer) ? "local " : ""}evidence for ${s.check} at ${s.commit.slice(0, 12)} as ${s.runner}`);
@@ -35,7 +35,7 @@ import type { ForgeKind } from "../pr-forge";
35
35
  import type { CiRunner } from "../ci-jobs";
36
36
  import type { CiProductWords } from "../ci-product-words";
37
37
  import type { PrPlanNoteWords } from "../pr-plan-note";
38
- import { assertPipelineEvidence, evidenceKeyEnv, planEvidenceLines, type PipelineEvidence } from "../ci-evidence-jobs";
38
+ import { assertPipelineEvidence, evidenceIdTokens, evidenceKeyEnv, evidenceKeyless, planEvidenceLines, type PipelineEvidence } from "../ci-evidence-jobs";
39
39
  import { gitlabPlanJobName, PR_LOOP_REPORT_DIR, PR_PLAN_NOTE_JOB, prLoopPassedEnv, prLoopPostJob, prLoopRunner, type PrLoopPipelineOptions } from "./pr-pipeline";
40
40
 
41
41
  /** The variable the plan-note job reads the product's note words from (#4799), as JSON. Set from the pipeline, never from the report. */
@@ -113,9 +113,11 @@ export interface ProductPlanJob {
113
113
  * job's `plan` and `policy` checks from its report, and their variables
114
114
  * (the runner key from its secret). GitHub and Forgejo run them in the
115
115
  * note job before `pr-post`; GitLab in a job of their own after the plan
116
- * job, `evidenceJobName`.
116
+ * job, `evidenceJobName`. Signing keyless (#4869), the job asks for an
117
+ * OIDC token: `idToken` (GitHub's `id-token: write`, Forgejo's
118
+ * `enable-openid-connect`) or GitLab's `idTokens`.
117
119
  */
118
- evidence?: { lines: string[]; env: Record<string, string>; jobName?: string };
120
+ evidence?: { lines: string[]; env: Record<string, string>; jobName?: string; idToken?: true; idTokens?: Record<string, { aud: string }> };
119
121
  }
120
122
 
121
123
  const TARGET_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
@@ -211,11 +213,13 @@ export function planEvidenceOf(forge: ForgeKind, evidence: PipelineEvidence, wor
211
213
  jobName: `${planJob}-evidence`,
212
214
  lines: planEvidenceLines({ dir: PR_LOOP_REPORT_DIR, at: '"$CI_COMMIT_SHA"', base: '"$CI_MERGE_REQUEST_DIFF_BASE_SHA"', result: "success", ...(bin ? { bin } : {}) }),
213
215
  env: key,
216
+ ...(evidenceKeyless(evidence) ? { idTokens: evidenceIdTokens(evidence) } : {}),
214
217
  };
215
218
  }
216
219
  return {
217
220
  lines: planEvidenceLines({ dir: PR_LOOP_REPORT_DIR, at: '"$HEAD_SHA"', base: '"$BASE_SHA"', result: '"$PLAN_RESULT"', ...(bin ? { bin } : {}) }),
218
221
  env: { HEAD_SHA: "${{ github.sha }}", BASE_SHA: "${{ github.event.pull_request.base.sha }}", PLAN_RESULT: `\${{ needs.${planJob}.result }}`, ...key },
222
+ ...(evidenceKeyless(evidence) ? { idToken: true as const } : {}),
219
223
  };
220
224
  }
221
225
 
@@ -155,6 +155,7 @@ export const FLOOR_ROWS: readonly FloorRow[] = [
155
155
  { name: "CLOUD_LOGIN_FLOOR", version: NEXT_RELEASE, gates: "The first chant with `@intentius/chant/ci-login`: `githubCloudLogin`, `gitlabCloudLogin` and `forgejoCloudLogin` render a job's AWS, GCP and Azure login from the OIDC token file, per target too (#4788).", issue: "#4788", file: "release-floors.ts", modules: ["@intentius/chant/release-floors"] },
156
156
  { name: "CHECK_EVIDENCE_FLOOR", version: NEXT_RELEASE, gates: "The first chant whose generated pipelines sign evidence for each named check they run, with `chant ci evidence`, `ci check` signing each hook, and an Op waves spec's `evidence.requires` (#4870).", issue: "#4870", file: "release-floors.ts", modules: ["@intentius/chant/ci-evidence-jobs","@intentius/chant/release-floors"] },
157
157
  { name: "LOCAL_EVIDENCE_FLOOR", version: NEXT_RELEASE, gates: "The first chant that accepts local evidence (#4868): `local` in `.chant/trust.json`, `chant ci evidence sign --local`, and `chant ci check` skipping a hook whose current local evidence the policy at base accepts.", issue: "#4868", file: "release-floors.ts", modules: ["@intentius/chant/ci-evidence-jobs","@intentius/chant/release-floors"] },
158
+ { name: "KEYLESS_EVIDENCE_FLOOR", version: NEXT_RELEASE, gates: "The first chant that signs runner statements keyless from the CI job's OIDC identity and verifies them against `keyless` in `.chant/trust.json`, with `evidence.identity: \"oidc\"` in the generators (#4869).", issue: "#4869", file: "release-floors.ts", modules: ["@intentius/chant/ci-evidence-jobs","@intentius/chant/release-floors"] },
158
159
  { name: "RUN_EVENT_FLOOR", version: "0.124.28", gates: "The first chant that writes contract version 1 of the run-event stream.", file: "run-event.ts", modules: ["@intentius/chant","@intentius/chant/index","@intentius/chant/run-event"] },
159
160
  { name: "RUN_EVENT_FAILURE_FLOOR", version: "0.124.30", gates: "The first chant that writes `failure` on `run-settle` (#4094).", issue: "#4094", file: "run-event.ts", modules: ["@intentius/chant","@intentius/chant/index","@intentius/chant/run-event"] },
160
161
  { name: "RUN_EVENT_COMPONENT_SKIP_FLOOR", version: "0.124.29", gates: "The first chant that writes `blocked`, `already-applied` and `blockedBy` on `component-settle` (#4007).", issue: "#4007", file: "run-event.ts", modules: ["@intentius/chant","@intentius/chant/index","@intentius/chant/run-event"] },
@@ -106,7 +106,7 @@ describe("evidence.requires (#4870)", () => {
106
106
 
107
107
  test("the same commit applies once its tree has current evidence for each required check", async () => {
108
108
  const { cwd, base, head, pem } = repo();
109
- await recordChecks(cwd, signChecks(cwd, head, [{ check: "plan" }, { check: "policy" }], runnerKeyEvidenceSigner(cwd, base, pem)), { push: false });
109
+ await recordChecks(cwd, await signChecks(cwd, head, [{ check: "plan" }, { check: "policy" }], runnerKeyEvidenceSigner(cwd, base, pem)), { push: false });
110
110
  const { result, ran } = await wave(cwd, head);
111
111
  expect(result.exitCode).toBe(0);
112
112
  expect(ran).toEqual(["network"]);
@@ -7,7 +7,8 @@
7
7
  * note job signed for the head's tree. A commit without it is refused,
8
8
  * and the refusal names each missing check. Read at base, so a change
9
9
  * cannot drop the rule for its own apply.
10
- * - With a runner key in `CHANT_RUNNER_KEY`, the deciding job signs its own
10
+ * - With a runner key in `CHANT_RUNNER_KEY`, or `CHANT_RUNNER_IDENTITY=oidc`
11
+ * to sign keyless from the job's OIDC identity (#4869), the deciding job signs its own
11
12
  * two named checks once the wave is planned: `plan:<wave>`, and
12
13
  * `policy:<wave>` when `ci.policy` ran over the plans and denied nothing.
13
14
  * They are attached under `refs/notes/chant/evidence` and pushed, where #4867's ref gate
@@ -19,7 +20,7 @@
19
20
  import { execFileSync } from "node:child_process";
20
21
  import type { OpRunPolicyRow } from "./runtime";
21
22
  export { opWavesEvidenceProblems, type OpWavesEvidence } from "./op-waves-evidence-spec";
22
- import { CHECK_EVIDENCE_KEY_ENV, missingCheckEvidence, recordChecks, runnerKeyEvidenceSigner, signChecks } from "../workspace/trust/check-evidence";
23
+ import { CHECK_EVIDENCE_KEY_ENV, missingCheckEvidence, recordChecks, RUNNER_IDENTITY_ENV, runnerEvidenceSigner, signChecks } from "../workspace/trust/check-evidence";
23
24
 
24
25
  function top(cwd: string): string {
25
26
  return execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
@@ -32,20 +33,20 @@ export async function opWaveEvidenceRefusal(cwd: string, head: string, base: str
32
33
  }
33
34
 
34
35
  /**
35
- * Sign the wave's plan and policy checks when the job holds a runner key.
36
- * Never fails the wave: a key the policy at base does not list, or a
36
+ * Sign the wave's plan and policy checks when the job has a runner identity.
37
+ * Never fails the wave: a key or identity the policy at base does not list, or a
37
38
  * notes push that does not land, is a line in the log.
38
39
  */
39
- export async function signOpWaveChecks(input: { cwd: string; head: string; base: string; wave: string; planDigest?: string; policyRows: ReadonlyMap<string, OpRunPolicyRow>; log: (line: string) => void; env?: NodeJS.ProcessEnv; push?: boolean }): Promise<string[]> {
40
- const pem = (input.env ?? process.env)[CHECK_EVIDENCE_KEY_ENV];
41
- if (!pem) return [];
40
+ export async function signOpWaveChecks(input: { cwd: string; head: string; base: string; wave: string; planDigest?: string; policyRows: ReadonlyMap<string, OpRunPolicyRow>; log: (line: string) => void; env?: NodeJS.ProcessEnv; push?: boolean; fetch?: typeof fetch }): Promise<string[]> {
41
+ const env = input.env ?? process.env;
42
+ if (!env[CHECK_EVIDENCE_KEY_ENV] && !env[RUNNER_IDENTITY_ENV]) return [];
42
43
  try {
43
44
  const repo = top(input.cwd);
44
- const signer = runnerKeyEvidenceSigner(repo, input.base, pem);
45
+ const signer = (await runnerEvidenceSigner(repo, input.base, { env, ...(input.fetch ? { fetch: input.fetch } : {}) }))!;
45
46
  const rows = [...input.policyRows.values()];
46
47
  const checks: Array<{ check: string; claim?: string }> = [{ check: `plan:${input.wave}`, ...(input.planDigest ? { claim: input.planDigest } : {}) }];
47
48
  if (rows.length > 0 && rows.every((r) => r.result !== "denied")) checks.push({ check: `policy:${input.wave}`, claim: JSON.stringify(rows) });
48
- const signed = signChecks(repo, input.head, checks, signer);
49
+ const signed = await signChecks(repo, input.head, checks, signer);
49
50
  const pushed = await recordChecks(repo, signed, { push: input.push !== false });
50
51
  if (input.push !== false && !pushed.pushed && pushed.pushWarning) input.log(`wave ${input.wave}: ${pushed.pushWarning}`);
51
52
  input.log(`wave ${input.wave}: signed evidence for ${signed.map((s) => s.check).join(", ")} as ${signer.principal}`);
@@ -19,7 +19,7 @@
19
19
  * this constant to the next patch (#4501). The check fails while a floor
20
20
  * still names this constant after its version shipped.
21
21
  */
22
- export const NEXT_RELEASE = "0.124.86";
22
+ export const NEXT_RELEASE = "0.124.87";
23
23
 
24
24
  /** The first chant with `chant dev local` and `chant dev bundle-check`, `@intentius/chant/local-chant` and `@intentius/chant/bundle-check` (`chantRuntimeTarget`, `chantExternalPlugin`, `checkBundle`): a product built against a chant checkout, and its bundle checked, without its own scripts (#4787). */
25
25
  export const LOCAL_CHANT_FLOOR = NEXT_RELEASE;
@@ -102,3 +102,6 @@ export const CHECK_EVIDENCE_FLOOR = NEXT_RELEASE;
102
102
 
103
103
  /** The first chant that accepts local evidence (#4868): `local` in `.chant/trust.json`, `chant ci evidence sign --local`, and `chant ci check` skipping a hook whose current local evidence the policy at base accepts. */
104
104
  export const LOCAL_EVIDENCE_FLOOR = NEXT_RELEASE;
105
+
106
+ /** The first chant that signs runner statements keyless from the CI job's OIDC identity and verifies them against `keyless` in `.chant/trust.json`, with `evidence.identity: "oidc"` in the generators (#4869). */
107
+ export const KEYLESS_EVIDENCE_FLOOR = NEXT_RELEASE;
@@ -70,7 +70,7 @@ import type { ReasonCode } from "./reason-codes";
70
70
  import { gitTop } from "./tree";
71
71
  import { locateWorkspace } from "./which-chant";
72
72
  import { gitRevisionSource } from "./record-source";
73
- import { emptyPolicy, readTrustPolicy } from "./trust/policy";
73
+ import { emptyPolicy, readTrustPolicy, runnersAt } from "./trust/policy";
74
74
  import { loadRunnerKey } from "./trust/dsse";
75
75
  import { signCiTagRecord, verifyCiTagStatement, CI_TAG_SIGNER_ROLE, type CiTagFailure, type CiTagRecord, type CiTagSigner } from "./trust/ci-tag-statement";
76
76
  import { COMPOSE_BRANCH_PREFIX, composedIncluding, isComposeBranch, remoteComposeBranches } from "../lifecycle/compose-refs";
@@ -513,7 +513,7 @@ export function readCiTags(top: string, green: CiGreen | null = null, base: stri
513
513
  const p = policyAtBase();
514
514
  // A tag the tick made walking a compose branch (#4168 4.3) is checked against that branch.
515
515
  const walked = isComposeBranch(t.record?.branch) ? (t.record!.branch as string) : green!.branch;
516
- const v = verifyCiTagStatement(t.record, { sha: t.sha, kind: t.kind, branch: walked, ...(lane !== undefined ? { lane } : {}) }, p.runners, p.roles);
516
+ const v = verifyCiTagStatement(t.record, { sha: t.sha, kind: t.kind, branch: walked, ...(lane !== undefined ? { lane } : {}) }, runnersAt(p, { repo: top, commit: t.sha }), p.roles);
517
517
  if (v.status === "signed") counted(v.signer);
518
518
  else ignore(v.status, `${v.reason}; ci.green.signedSince is ${green!.signedSince}, so a tag on a commit that is not a strict first-parent ancestor of it needs one`);
519
519
  }
@@ -1313,7 +1313,8 @@ export async function readOpRunSource(cwd: string, top: string, base: string, si
1313
1313
  if (!record.gitSha) continue;
1314
1314
  // #4161: a job `ci run --local` ran stays on the machine that ran it, and is never CI's verdict.
1315
1315
  if (record.runOrigin?.forge === "local") continue;
1316
- const v = verifyOpRunStatement(record, policy.runners, policy.roles);
1316
+ // #4869: a keyless identity's statement counts too; under keyless.since, a key's only for a commit before it.
1317
+ const v = verifyOpRunStatement(record, runnersAt(policy, { repo: top, commit: record.gitSha }), policy.roles);
1317
1318
  const counts = v.status === "signed" || (v.status === "unsigned" && (before === null || before.has(record.gitSha)));
1318
1319
  if (counts) byCommit.set(record.gitSha, [...(byCommit.get(record.gitSha) ?? []), opRunCheckRun(record, v.status === "signed" ? v.signer : null)]);
1319
1320
  else {
@@ -26,6 +26,15 @@ export const CHECK_EVIDENCE_KEY_ENV = "CHANT_RUNNER_KEY";
26
26
  /** The variable a developer's or an agent's local evidence key is read from, as PEM (#4868). A check hook never sees it. */
27
27
  export const LOCAL_EVIDENCE_KEY_ENV = "CHANT_LOCAL_EVIDENCE_KEY";
28
28
 
29
+ /**
30
+ * The variable a generated job sets to `oidc` when it signs keyless from
31
+ * its OIDC identity (#4869) instead of with a runner key.
32
+ */
33
+ export const RUNNER_IDENTITY_ENV = "CHANT_RUNNER_IDENTITY";
34
+
35
+ /** The GitLab `id_tokens` variable a keyless signing job's token comes in (#4869), with the signing audience. */
36
+ export const SIGNING_ID_TOKEN_VAR = "CHANT_ID_TOKEN_SIGSTORE";
37
+
29
38
  /** The file the signing step writes beside the plan report, which `pr-post` reads. */
30
39
  export const CHECK_EVIDENCE_FILE = "evidence.json";
31
40
 
@@ -50,7 +50,7 @@ describe("check evidence (#4870)", () => {
50
50
  test("a signed check is current for its commit, and for another commit with the same tree", async () => {
51
51
  const r = repo();
52
52
  const signer = runnerKeyEvidenceSigner(r.dir, r.base, r.ci.pem);
53
- const signed = signChecks(r.dir, r.head, [{ check: "plan", claim: "{}" }, { check: "policy" }], signer);
53
+ const signed = await signChecks(r.dir, r.head, [{ check: "plan", claim: "{}" }, { check: "policy" }], signer);
54
54
  expect(signed.map((s) => s.check)).toEqual(["plan", "policy"]);
55
55
  await recordChecks(r.dir, signed, { push: false });
56
56
  expect(await readCheckEvidence(r.dir, r.head, r.base, ["plan", "policy"])).toEqual([
@@ -68,7 +68,7 @@ describe("check evidence (#4870)", () => {
68
68
 
69
69
  test("a commit whose tree differs has none, and the refusal names each missing check and its command", async () => {
70
70
  const r = repo();
71
- await recordChecks(r.dir, signChecks(r.dir, r.head, [{ check: "plan" }], runnerKeyEvidenceSigner(r.dir, r.base, r.ci.pem)), { push: false });
71
+ await recordChecks(r.dir, await signChecks(r.dir, r.head, [{ check: "plan" }], runnerKeyEvidenceSigner(r.dir, r.base, r.ci.pem)), { push: false });
72
72
  expect((await readCheckEvidence(r.dir, r.base, r.base, ["plan"]))[0]!.status).toBe("missing");
73
73
  const refused = await missingCheckEvidence(r.dir, r.head, r.base, ["plan", "policy"]);
74
74
  expect(refused).toContain("policy");
@@ -85,7 +85,7 @@ describe("check evidence (#4870)", () => {
85
85
  const head = git(r.dir, "rev-parse", "HEAD");
86
86
  expect(() => runnerKeyEvidenceSigner(r.dir, r.base, added.pem)).toThrow(/lists no runner with this key/);
87
87
  // Signed against the change's own policy, and kept: the base still does not trust it.
88
- await recordChecks(r.dir, signChecks(r.dir, head, [{ check: "plan" }], runnerKeyEvidenceSigner(r.dir, head, added.pem)), { push: false });
88
+ await recordChecks(r.dir, await signChecks(r.dir, head, [{ check: "plan" }], runnerKeyEvidenceSigner(r.dir, head, added.pem)), { push: false });
89
89
  expect((await readCheckEvidence(r.dir, head, r.base, ["plan"]))[0]).toMatchObject({ status: "untrusted" });
90
90
  expect(await readCheckEvidence(r.dir, head, head, ["plan"])).toEqual([{ check: "plan", status: "current", runner: "mine", commit: head }]);
91
91
  });
@@ -18,26 +18,31 @@
18
18
  *
19
19
  * Who signs is an {@link EvidenceSigner}: today a runner key the policy at
20
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.
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.
25
26
  *
26
27
  * 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.
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.
29
31
  */
30
32
 
31
33
  import { execFileSync } from "node:child_process";
32
34
  import { createHash } from "node:crypto";
33
35
  import { canonicalJson } from "../../effect-receipt";
34
36
  import { gitRevisionSource } from "../record-source";
35
- import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, signEnvelope, type DsseEnvelope } from "./dsse";
37
+ import { X509Certificate } from "node:crypto";
38
+ import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey, pae, signEnvelope, type DsseEnvelope } from "./dsse";
36
39
  import { RUNNER_EVIDENCE_PREDICATE, STATEMENT_TYPE, verifyEvidence, type EvidenceStatement } from "./evidence";
37
- import { readTrustPolicy } from "./policy";
40
+ import { certificateIssuer, certificateSubjects, keylessSignature, requestCertificate, signingToken, subjectPattern, verifyKeylessSignature } from "./keyless";
41
+ import { readTrustPolicy, runnersAt } from "./policy";
38
42
  import { attachEvidence, EVIDENCE_NOTES_REF, parseEvidenceNote } from "./ref-gate";
43
+ import { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV } from "./check-evidence-report";
39
44
 
40
- export { CHECK_EVIDENCE_KEY_ENV } from "./check-evidence-report";
45
+ export { CHECK_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV };
41
46
 
42
47
  export { EVIDENCE_NOTES_REF };
43
48
 
@@ -46,13 +51,79 @@ export const PLAN_EVIDENCE_CHECKS = ["plan", "policy"] as const;
46
51
 
47
52
  /**
48
53
  * Who signs a check's statement (#4870). `sign` returns the DSSE envelope
49
- * of the in-toto payload it is given. The seam #4869's keyless signer plugs
50
- * into.
54
+ * of the in-toto payload it is given; a keyless signer (#4869) answers
55
+ * once its signature is timestamped.
51
56
  */
52
57
  export interface EvidenceSigner {
53
58
  /** The runner principal the statement names, as `.chant/trust.json` at base lists it. */
54
59
  principal: string;
55
- sign(payloadType: string, payload: Buffer): DsseEnvelope;
60
+ sign(payloadType: string, payload: Buffer): DsseEnvelope | Promise<DsseEnvelope>;
61
+ }
62
+
63
+ /**
64
+ * The signer of a job that signs keyless from its OIDC identity (#4869):
65
+ * it requests the job's token for the policy's audience, trades it at the
66
+ * policy's certificate authority for a certificate over a key made for this
67
+ * run, and signs each envelope with that key, each signature timestamped.
68
+ * The principal is the identity of `keyless.identities` at `base` the
69
+ * certificate matches. Throws when the policy at base lists no keyless
70
+ * identity, the job has no token, or the certificate names an identity the
71
+ * policy does not list, so a job never keeps evidence its readers would
72
+ * ignore. Each envelope is verified against the policy before it is
73
+ * returned.
74
+ */
75
+ export async function keylessEvidenceSigner(repo: string, base: string, opts: { env?: NodeJS.ProcessEnv; fetch?: typeof fetch } = {}): Promise<EvidenceSigner> {
76
+ const env = opts.env ?? process.env;
77
+ const fetchFn = opts.fetch ?? fetch;
78
+ const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
79
+ if (policy.problems.length > 0) throw new Error(`the policy at ${base.slice(0, 12)} cannot be read: ${policy.problems.join("; ")}`);
80
+ const identities = policy.runnerIdentities ?? [];
81
+ if (!policy.keyless || identities.length === 0) {
82
+ const why = policy.excludedRunners.map((r) => `${r.principal}: ${r.reason}`).join("; ");
83
+ 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})` : ""}`);
84
+ }
85
+ const { fulcio, timestamp, audience } = policy.keyless;
86
+ const token = await signingToken(env, audience, fetchFn);
87
+ const cert = await requestCertificate(token, fulcio, fetchFn);
88
+ const leaf = new X509Certificate(Buffer.from(cert.certificates[0]!, "base64"));
89
+ const issuer = certificateIssuer(leaf);
90
+ const subjects = certificateSubjects(leaf);
91
+ const listed = identities.find((i) => i.issuer === issuer && subjects.some((s) => subjectPattern(i.subject).test(s)));
92
+ if (!listed) {
93
+ 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`);
94
+ }
95
+ return {
96
+ principal: listed.principal,
97
+ sign: async (payloadType, payload) => {
98
+ const message = pae(payloadType, payload);
99
+ const signature = await keylessSignature(message, cert, timestamp, fetchFn);
100
+ const v = verifyKeylessSignature(message, signature, [listed]);
101
+ if (!v.ok) throw new Error(`the keyless signature does not verify against the policy at ${base.slice(0, 12)}: ${v.reason}`);
102
+ return { payloadType, payload: payload.toString("base64"), signatures: [signature] };
103
+ },
104
+ };
105
+ }
106
+
107
+ /**
108
+ * The job's signer, read from its environment in one place (#4869): the
109
+ * runner key in `key` or `CHANT_RUNNER_KEY` ({@link runnerKeyEvidenceSigner}),
110
+ * else, with `CHANT_RUNNER_IDENTITY=oidc`, the job's OIDC identity
111
+ * ({@link keylessEvidenceSigner}). Undefined when the job has neither, so
112
+ * a project with no runner identity gets the job it had. Throws as those do.
113
+ */
114
+ export async function runnerEvidenceSigner(repo: string, base: string, opts: { env?: NodeJS.ProcessEnv; key?: string; fetch?: typeof fetch } = {}): Promise<EvidenceSigner | undefined> {
115
+ const env = opts.env ?? process.env;
116
+ const pem = opts.key ?? env[CHECK_EVIDENCE_KEY_ENV];
117
+ if (pem) return runnerKeyEvidenceSigner(repo, base, pem);
118
+ const identity = env[RUNNER_IDENTITY_ENV];
119
+ if (!identity) return undefined;
120
+ if (identity !== "oidc") throw new Error(`${RUNNER_IDENTITY_ENV} is ${JSON.stringify(identity)}; the one runner identity chant signs with is oidc`);
121
+ return keylessEvidenceSigner(repo, base, { env, ...(opts.fetch ? { fetch: opts.fetch } : {}) });
122
+ }
123
+
124
+ /** What {@link runnerEvidenceSigner} would sign with, for a line saying why nothing was signed. */
125
+ export function noRunnerIdentity(): string {
126
+ return `no runner identity: neither ${CHECK_EVIDENCE_KEY_ENV} nor ${RUNNER_IDENTITY_ENV}=oidc is set`;
56
127
  }
57
128
 
58
129
  /**
@@ -115,18 +186,14 @@ export interface SignedCheck {
115
186
  }
116
187
 
117
188
  /** Sign each of `checks` over `at` with `signer`. Writes nothing. */
118
- export function signChecks(repo: string, at: string, checks: readonly { check: string; claim?: Buffer | string }[], signer: EvidenceSigner): SignedCheck[] {
189
+ export async function signChecks(repo: string, at: string, checks: readonly { check: string; claim?: Buffer | string }[], signer: EvidenceSigner): Promise<SignedCheck[]> {
119
190
  const { commit, tree } = commitAndTree(repo, at);
120
- return checks.map(({ check, claim }) => {
191
+ const out: SignedCheck[] = [];
192
+ for (const { check, claim } of checks) {
121
193
  const statement = checkStatement({ commit, tree, check, runner: signer.principal, ...(claim !== undefined ? { claim } : {}) });
122
- return {
123
- check,
124
- commit,
125
- tree,
126
- runner: signer.principal,
127
- envelope: signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")),
128
- };
129
- });
194
+ out.push({ check, commit, tree, runner: signer.principal, envelope: await signer.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8")) });
195
+ }
196
+ return out;
130
197
  }
131
198
 
132
199
  /** How many times {@link recordChecks} fetches, attaches and pushes when another job pushed the notes first. */
@@ -200,20 +267,23 @@ export type CheckEvidenceVerdict =
200
267
 
201
268
  /**
202
269
  * Read and verify the evidence for each of `checks` at `at`'s tree, against
203
- * the runner keys `.chant/trust.json` lists at `base`. `missing`: nothing is
270
+ * the runner keys and keyless identities `.chant/trust.json` lists at
271
+ * `base` (#4869). `missing`: nothing is
204
272
  * kept for the tree. `untrusted`: an envelope is kept, and no runner key at
205
273
  * base signed it, or it is not a check statement for that tree.
206
274
  */
207
275
  export async function readCheckEvidence(repo: string, at: string, base: string, checks: readonly string[]): Promise<CheckEvidenceVerdict[]> {
208
276
  const { tree, commit } = commitAndTree(repo, at);
209
277
  const policy = readTrustPolicy(gitRevisionSource(repo, base), base);
278
+ // #4869: the keys and the keyless identities; under keyless.since, the keys only for a commit before it.
279
+ const runners = runnersAt(policy, { repo, commit });
210
280
  const envelopes = envelopesForTree(repo, commit, tree);
211
281
  return checks.map((check): CheckEvidenceVerdict => {
212
282
  let untrusted: string | undefined;
213
283
  for (const envelope of envelopes) {
214
- const v = verifyEvidence(envelope, policy.runners, repo, commit);
284
+ const v = verifyEvidence(envelope, runners, repo, commit);
215
285
  if (!v.ok) {
216
- if (claimedCheck(envelope) === check) untrusted ??= `the evidence attached for check ${check} does not verify against the runner keys at ${base.slice(0, 12)}: ${v.reason}`;
286
+ if (claimedCheck(envelope) === check) untrusted ??= `the evidence attached for check ${check} does not verify against the runners at ${base.slice(0, 12)}: ${v.reason}`;
217
287
  continue;
218
288
  }
219
289
  if (v.statement.predicate.check !== check || v.statement.predicate.tree !== tree) continue;
@@ -32,7 +32,7 @@ import { canonicalJson } from "../../effect-receipt";
32
32
  import { IN_TOTO_PAYLOAD_TYPE, signEnvelope, verifyEnvelope, type DsseEnvelope } from "./dsse";
33
33
  import { STATEMENT_TYPE } from "./evidence";
34
34
  import type { KeyObject } from "node:crypto";
35
- import type { RunnerKey } from "./policy";
35
+ import type { Runner, RunnerKey } from "./policy";
36
36
 
37
37
  export const CI_TAG_PREDICATE = "https://intentius.io/chant/ci-tag/v1";
38
38
 
@@ -114,7 +114,7 @@ const normalise = (name: string): string => name.normalize("NFKC").trim().toLowe
114
114
  export function verifyCiTagStatement(
115
115
  record: Record<string, unknown> | null,
116
116
  expect: { sha: string; kind: "green" | "revoked"; branch: string; lane?: string },
117
- runners: readonly RunnerKey[],
117
+ runners: readonly Runner[],
118
118
  roles: Readonly<Record<string, readonly string[]>>,
119
119
  ): CiTagVerdict {
120
120
  const tag = `ci/${expect.kind}${expect.lane !== undefined ? `-${expect.lane}` : ""}/${expect.sha}`;
@@ -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
 
15
21
  import { createHash, createPrivateKey, createPublicKey, sign, verify, type KeyObject } from "node:crypto";
@@ -19,6 +25,10 @@ export const IN_TOTO_PAYLOAD_TYPE = "application/vnd.in-toto+json";
19
25
  export interface DsseSignature {
20
26
  keyid: string;
21
27
  sig: string;
28
+ /** Keyless (#4869): the certificate chain, base64 DER, the signing certificate first. */
29
+ certificates?: string[];
30
+ /** Keyless (#4869): the RFC 3161 timestamp token over the signature, base64 DER. */
31
+ timestamp?: string;
22
32
  }
23
33
 
24
34
  export interface DsseEnvelope {
@@ -96,18 +106,51 @@ export interface TrustedKey {
96
106
  key: string;
97
107
  }
98
108
 
109
+ /** What a keyless identity says of one signature (#4869). `named`: the certificate is this identity's, and something else failed. */
110
+ export type KeylessCheck = { ok: true; keyid: string; issuer: string; subject: string; signedAt: string } | { ok: false; named: boolean; reason: string };
111
+
112
+ /** A CI identity that signs keyless (#4869), as the policy at base reads it, with the verifier for its trusted root. */
113
+ export interface TrustedIdentity {
114
+ principal: string;
115
+ issuer: string;
116
+ verifyKeyless(message: Buffer, signature: DsseSignature): KeylessCheck;
117
+ }
118
+
119
+ /** Who may sign: a runner key, or a CI identity that signs keyless (#4869). */
120
+ export type TrustedSigner = TrustedKey | TrustedIdentity;
121
+
122
+ const isKeyless = (s: DsseSignature): boolean => Array.isArray(s.certificates) && typeof s.timestamp === "string";
123
+
99
124
  export type EnvelopeVerdict =
100
- | { ok: true; principal: string; keyid: string; payloadType: string; payload: Buffer }
125
+ | { ok: true; principal: string; keyid: string; payloadType: string; payload: Buffer; keyless?: { issuer: string; subject: string; signedAt: string } }
101
126
  | { ok: false; code: "envelope-invalid" | "envelope-untrusted"; reason: string };
102
127
 
103
- /** Verify an envelope against `trusted`. One valid signature by a trusted key is enough. */
104
- export function verifyEnvelope(envelope: unknown, trusted: readonly TrustedKey[]): EnvelopeVerdict {
128
+ /**
129
+ * Verify an envelope against `trusted`. One valid signature by a trusted
130
+ * key, or one keyless signature by a trusted identity (#4869), is enough.
131
+ */
132
+ export function verifyEnvelope(envelope: unknown, trusted: readonly TrustedSigner[]): EnvelopeVerdict {
105
133
  if (!isEnvelope(envelope)) return { ok: false, code: "envelope-invalid", reason: "not a DSSE envelope: it needs payloadType, payload and signatures" };
106
134
  const payload = Buffer.from(envelope.payload, "base64");
107
135
  if (payload.toString("base64") !== envelope.payload) return { ok: false, code: "envelope-invalid", reason: "the payload is not canonical base64" };
108
136
  const message = pae(envelope.payloadType, payload);
109
- const byId = new Map(trusted.map((t) => [sshFingerprint(t.key), t]));
137
+ const keys = trusted.filter((t): t is TrustedKey => typeof (t as TrustedKey).key === "string");
138
+ const identities = trusted.filter((t): t is TrustedIdentity => typeof (t as TrustedIdentity).verifyKeyless === "function");
139
+ const byId = new Map(keys.map((t) => [sshFingerprint(t.key), t]));
140
+ let keyless: string | undefined;
110
141
  for (const s of envelope.signatures) {
142
+ if (isKeyless(s)) {
143
+ if (identities.length === 0) keyless ??= "the signature is keyless, and the policy at base lists no keyless identity";
144
+ let named: string | undefined;
145
+ for (const id of identities) {
146
+ const k = id.verifyKeyless(message, s);
147
+ if (k.ok) return { ok: true, principal: id.principal, keyid: k.keyid, payloadType: envelope.payloadType, payload, keyless: { issuer: k.issuer, subject: k.subject, signedAt: k.signedAt } };
148
+ if (k.named) named ??= k.reason;
149
+ else keyless ??= k.reason;
150
+ }
151
+ if (named) keyless = named;
152
+ continue;
153
+ }
111
154
  const t = byId.get(s.keyid);
112
155
  if (!t) continue;
113
156
  let good = false;
@@ -119,6 +162,7 @@ export function verifyEnvelope(envelope: unknown, trusted: readonly TrustedKey[]
119
162
  if (good) return { ok: true, principal: t.principal, keyid: s.keyid, payloadType: envelope.payloadType, payload };
120
163
  }
121
164
  const ids = envelope.signatures.map((s) => s.keyid).join(", ") || "none";
165
+ if (keyless) return { ok: false, code: "envelope-untrusted", reason: keyless };
122
166
  return { ok: false, code: "envelope-untrusted", reason: `no signature verifies against a runner key the policy at base lists (key ids: ${ids})` };
123
167
  }
124
168
 
@@ -21,7 +21,7 @@ import { canonicalJson } from "../../effect-receipt";
21
21
  import type { ReasonCode } from "../reason-codes";
22
22
  import { IN_TOTO_PAYLOAD_TYPE, signEnvelope, verifyEnvelope, type DsseEnvelope } from "./dsse";
23
23
  import type { KeyObject } from "node:crypto";
24
- import type { RunnerKey } from "./policy";
24
+ import type { Runner, RunnerKey } from "./policy";
25
25
 
26
26
  export const STATEMENT_TYPE = "https://in-toto.io/Statement/v1";
27
27
  export const RUNNER_EVIDENCE_PREDICATE = "https://intentius.io/chant/runner-evidence/v1";
@@ -169,7 +169,7 @@ export type EvidenceVerdict =
169
169
  * Verify an envelope against the runner keys at base, then compare each
170
170
  * subject with the record as committed at `at`.
171
171
  */
172
- export function verifyEvidence(envelope: unknown, runners: readonly RunnerKey[], repo: string, at: string): EvidenceVerdict {
172
+ export function verifyEvidence(envelope: unknown, runners: readonly Runner[], repo: string, at: string): EvidenceVerdict {
173
173
  const v = verifyEnvelope(envelope, runners);
174
174
  if (!v.ok) return v;
175
175
  if (v.payloadType !== IN_TOTO_PAYLOAD_TYPE) return { ok: false, code: "evidence-payload-type", reason: `payload type ${v.payloadType} is not ${IN_TOTO_PAYLOAD_TYPE}` };