@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.
Files changed (286) hide show
  1. package/dist/bundle-check.d.ts +102 -0
  2. package/dist/bundle-check.d.ts.map +1 -0
  3. package/dist/bundle-check.js +310 -0
  4. package/dist/chant-install.d.ts +100 -0
  5. package/dist/chant-install.d.ts.map +1 -0
  6. package/dist/chant-install.js +158 -0
  7. package/dist/ci-commit.d.ts +19 -6
  8. package/dist/ci-commit.d.ts.map +1 -1
  9. package/dist/ci-commit.js +23 -4
  10. package/dist/ci-evidence-jobs.d.ts +78 -0
  11. package/dist/ci-evidence-jobs.d.ts.map +1 -0
  12. package/dist/ci-evidence-jobs.js +85 -0
  13. package/dist/ci-image.d.ts +274 -0
  14. package/dist/ci-image.d.ts.map +1 -0
  15. package/dist/ci-image.js +635 -0
  16. package/dist/ci-login.d.ts +150 -0
  17. package/dist/ci-login.d.ts.map +1 -0
  18. package/dist/ci-login.js +240 -0
  19. package/dist/ci-product.d.ts +16 -0
  20. package/dist/ci-product.d.ts.map +1 -1
  21. package/dist/ci-product.js +17 -0
  22. package/dist/cli/commands/import-index.js +2 -2
  23. package/dist/cli/handlers/build.d.ts +8 -0
  24. package/dist/cli/handlers/build.d.ts.map +1 -1
  25. package/dist/cli/handlers/build.js +22 -4
  26. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  27. package/dist/cli/handlers/ci-check.js +61 -2
  28. package/dist/cli/handlers/ci-evidence.d.ts +3 -0
  29. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
  30. package/dist/cli/handlers/ci-evidence.js +174 -0
  31. package/dist/cli/handlers/components.js +3 -3
  32. package/dist/cli/handlers/dead-guards.d.ts +3 -0
  33. package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
  34. package/dist/cli/handlers/dead-guards.js +35 -0
  35. package/dist/cli/handlers/graph.js +4 -4
  36. package/dist/cli/handlers/lifecycle.d.ts +2 -1
  37. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  38. package/dist/cli/handlers/lifecycle.js +5 -4
  39. package/dist/cli/handlers/local-chant.d.ts +16 -0
  40. package/dist/cli/handlers/local-chant.d.ts.map +1 -0
  41. package/dist/cli/handlers/local-chant.js +109 -0
  42. package/dist/cli/handlers/operator.js +2 -2
  43. package/dist/cli/handlers/search.js +5 -5
  44. package/dist/cli/main.d.ts.map +1 -1
  45. package/dist/cli/main.js +38 -0
  46. package/dist/cli/parse-args.d.ts.map +1 -1
  47. package/dist/cli/parse-args.js +28 -0
  48. package/dist/cli/registry.d.ts +16 -0
  49. package/dist/cli/registry.d.ts.map +1 -1
  50. package/dist/components/check-hooks.d.ts +49 -0
  51. package/dist/components/check-hooks.d.ts.map +1 -1
  52. package/dist/components/check-hooks.js +64 -4
  53. package/dist/components/check-steps.d.ts +17 -0
  54. package/dist/components/check-steps.d.ts.map +1 -1
  55. package/dist/components/check-steps.js +37 -5
  56. package/dist/components/product-pipeline.d.ts +23 -0
  57. package/dist/components/product-pipeline.d.ts.map +1 -1
  58. package/dist/components/product-pipeline.js +6 -2
  59. package/dist/components/product-plan.d.ts +143 -0
  60. package/dist/components/product-plan.d.ts.map +1 -0
  61. package/dist/components/product-plan.js +145 -0
  62. package/dist/components/release-compile.d.ts.map +1 -1
  63. package/dist/components/release-compile.js +2 -2
  64. package/dist/config.d.ts +39 -1
  65. package/dist/config.d.ts.map +1 -1
  66. package/dist/config.js +35 -3
  67. package/dist/dead-guards.d.ts +82 -0
  68. package/dist/dead-guards.d.ts.map +1 -0
  69. package/dist/dead-guards.js +436 -0
  70. package/dist/discovery/files.d.ts +3 -1
  71. package/dist/discovery/files.d.ts.map +1 -1
  72. package/dist/discovery/files.js +5 -3
  73. package/dist/drift-issue.d.ts +152 -0
  74. package/dist/drift-issue.d.ts.map +1 -0
  75. package/dist/drift-issue.js +167 -0
  76. package/dist/floor-table.d.ts +30 -0
  77. package/dist/floor-table.d.ts.map +1 -0
  78. package/dist/floor-table.data.d.ts +3 -0
  79. package/dist/floor-table.data.d.ts.map +1 -0
  80. package/dist/floor-table.data.js +179 -0
  81. package/dist/floor-table.js +56 -0
  82. package/dist/forge-flags.d.ts +90 -0
  83. package/dist/forge-flags.d.ts.map +1 -0
  84. package/dist/forge-flags.js +184 -0
  85. package/dist/lexicon.d.ts +69 -0
  86. package/dist/lexicon.d.ts.map +1 -1
  87. package/dist/lifecycle/gated-op.d.ts +7 -1
  88. package/dist/lifecycle/gated-op.d.ts.map +1 -1
  89. package/dist/lifecycle/gated-op.js +7 -4
  90. package/dist/local-chant.d.ts +98 -0
  91. package/dist/local-chant.d.ts.map +1 -0
  92. package/dist/local-chant.js +307 -0
  93. package/dist/op/activities/predict-behaviour.js +2 -2
  94. package/dist/op/op-waves-evidence-spec.d.ts +13 -0
  95. package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
  96. package/dist/op/op-waves-evidence-spec.js +21 -0
  97. package/dist/op/op-waves-evidence.d.ts +40 -0
  98. package/dist/op/op-waves-evidence.d.ts.map +1 -0
  99. package/dist/op/op-waves-evidence.js +58 -0
  100. package/dist/op/op-waves-run.d.ts +4 -0
  101. package/dist/op/op-waves-run.d.ts.map +1 -1
  102. package/dist/op/op-waves-run.js +24 -1
  103. package/dist/op/op-waves.d.ts +17 -1
  104. package/dist/op/op-waves.d.ts.map +1 -1
  105. package/dist/op/op-waves.js +23 -0
  106. package/dist/op/schedule-overdue.d.ts +41 -9
  107. package/dist/op/schedule-overdue.d.ts.map +1 -1
  108. package/dist/op/schedule-overdue.js +154 -25
  109. package/dist/plan-summary.d.ts +25 -0
  110. package/dist/plan-summary.d.ts.map +1 -1
  111. package/dist/plan-summary.js +31 -0
  112. package/dist/pr-plan-note.d.ts +35 -0
  113. package/dist/pr-plan-note.d.ts.map +1 -1
  114. package/dist/pr-plan-note.js +10 -0
  115. package/dist/pr-post.d.ts +23 -0
  116. package/dist/pr-post.d.ts.map +1 -1
  117. package/dist/pr-post.js +125 -3
  118. package/dist/release-floors.d.ts +33 -1
  119. package/dist/release-floors.d.ts.map +1 -1
  120. package/dist/release-floors.js +33 -1
  121. package/dist/state-migration.d.ts +24 -0
  122. package/dist/state-migration.d.ts.map +1 -1
  123. package/dist/state-migration.js +100 -5
  124. package/dist/wave-runtime.mjs +309 -302
  125. package/dist/workspace/ci-green.d.ts.map +1 -1
  126. package/dist/workspace/ci-green.js +4 -3
  127. package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
  128. package/dist/workspace/lexicon-outputs.js +21 -7
  129. package/dist/workspace/reason-codes.d.ts +3 -0
  130. package/dist/workspace/reason-codes.d.ts.map +1 -1
  131. package/dist/workspace/reason-codes.js +4 -0
  132. package/dist/workspace/ref-gate.schema.json +85 -0
  133. package/dist/workspace/search-contract.d.ts +1 -1
  134. package/dist/workspace/search-contract.d.ts.map +1 -1
  135. package/dist/workspace/trust/check-evidence-report.d.ts +58 -0
  136. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
  137. package/dist/workspace/trust/check-evidence-report.js +109 -0
  138. package/dist/workspace/trust/check-evidence.d.ts +160 -0
  139. package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
  140. package/dist/workspace/trust/check-evidence.js +309 -0
  141. package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
  142. package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
  143. package/dist/workspace/trust/dsse.d.ts +40 -2
  144. package/dist/workspace/trust/dsse.d.ts.map +1 -1
  145. package/dist/workspace/trust/dsse.js +34 -2
  146. package/dist/workspace/trust/evidence.d.ts +2 -2
  147. package/dist/workspace/trust/evidence.d.ts.map +1 -1
  148. package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
  149. package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
  150. package/dist/workspace/trust/keyless-fixture.js +161 -0
  151. package/dist/workspace/trust/keyless.d.ts +202 -0
  152. package/dist/workspace/trust/keyless.d.ts.map +1 -0
  153. package/dist/workspace/trust/keyless.js +488 -0
  154. package/dist/workspace/trust/local-evidence.d.ts +123 -0
  155. package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
  156. package/dist/workspace/trust/local-evidence.js +259 -0
  157. package/dist/workspace/trust/op-run-statement.d.ts +2 -2
  158. package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
  159. package/dist/workspace/trust/policy.d.ts +140 -1
  160. package/dist/workspace/trust/policy.d.ts.map +1 -1
  161. package/dist/workspace/trust/policy.js +197 -3
  162. package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
  163. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
  164. package/dist/workspace/trust/ref-gate-cli.js +234 -0
  165. package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
  166. package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
  167. package/dist/workspace/trust/ref-gate-fixture.js +97 -0
  168. package/dist/workspace/trust/ref-gate.d.ts +187 -0
  169. package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
  170. package/dist/workspace/trust/ref-gate.js +432 -0
  171. package/dist/workspace/trust/run-statement.d.ts +3 -3
  172. package/dist/workspace/trust/run-statement.d.ts.map +1 -1
  173. package/dist/workspace/trust/runner-identity.d.ts +56 -0
  174. package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
  175. package/dist/workspace/trust/runner-identity.js +65 -0
  176. package/dist/workspace/trust/trust-files.d.ts.map +1 -1
  177. package/dist/workspace/trust/trust-files.js +25 -1
  178. package/package.json +1 -1
  179. package/src/bundle-check.test.ts +140 -0
  180. package/src/bundle-check.ts +352 -0
  181. package/src/chant-install.test.ts +112 -0
  182. package/src/chant-install.ts +179 -0
  183. package/src/ci-commit.test.ts +45 -0
  184. package/src/ci-commit.ts +38 -4
  185. package/src/ci-evidence-jobs.ts +105 -0
  186. package/src/ci-image.test.ts +506 -0
  187. package/src/ci-image.ts +822 -0
  188. package/src/ci-login.test.ts +235 -0
  189. package/src/ci-login.ts +307 -0
  190. package/src/ci-product.ts +18 -0
  191. package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
  192. package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
  193. package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
  194. package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
  195. package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
  196. package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
  197. package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
  198. package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
  199. package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
  200. package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
  201. package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
  202. package/src/cli/commands/import-index.ts +2 -2
  203. package/src/cli/handlers/build-source-dir.test.ts +64 -0
  204. package/src/cli/handlers/build.ts +21 -4
  205. package/src/cli/handlers/ci-check.ts +60 -3
  206. package/src/cli/handlers/ci-evidence.ts +167 -0
  207. package/src/cli/handlers/components.ts +3 -3
  208. package/src/cli/handlers/dead-guards.ts +37 -0
  209. package/src/cli/handlers/graph.ts +4 -4
  210. package/src/cli/handlers/lifecycle.ts +5 -4
  211. package/src/cli/handlers/local-chant.ts +106 -0
  212. package/src/cli/handlers/operator.ts +2 -2
  213. package/src/cli/handlers/search.ts +5 -5
  214. package/src/cli/main.test.ts +7 -0
  215. package/src/cli/main.ts +38 -0
  216. package/src/cli/parse-args.ts +21 -0
  217. package/src/cli/registry.ts +16 -0
  218. package/src/components/check-evidence-stage.test.ts +80 -0
  219. package/src/components/check-hooks.ts +84 -4
  220. package/src/components/check-local-evidence-stage.test.ts +141 -0
  221. package/src/components/check-steps.ts +56 -6
  222. package/src/components/product-pipeline.ts +28 -3
  223. package/src/components/product-plan.test.ts +87 -0
  224. package/src/components/product-plan.ts +230 -0
  225. package/src/components/release-compile.ts +2 -2
  226. package/src/config.ts +44 -3
  227. package/src/dead-guards.test.ts +206 -0
  228. package/src/dead-guards.ts +446 -0
  229. package/src/discovery/files.ts +5 -3
  230. package/src/drift-issue-bundle.test.ts +31 -0
  231. package/src/drift-issue.test.ts +206 -0
  232. package/src/drift-issue.ts +274 -0
  233. package/src/fit-note.test.ts +44 -0
  234. package/src/floor-table.data.ts +181 -0
  235. package/src/floor-table.ts +77 -0
  236. package/src/forge-flags.test.ts +110 -0
  237. package/src/forge-flags.ts +208 -0
  238. package/src/gate-decision-bundle.test.ts +1 -0
  239. package/src/lexicon.ts +68 -0
  240. package/src/lifecycle/gated-op.ts +10 -5
  241. package/src/local-chant.e2e.test.ts +94 -0
  242. package/src/local-chant.test.ts +162 -0
  243. package/src/local-chant.ts +341 -0
  244. package/src/op/activities/predict-behaviour.ts +2 -2
  245. package/src/op/op-waves-evidence-spec.ts +24 -0
  246. package/src/op/op-waves-evidence.test.ts +130 -0
  247. package/src/op/op-waves-evidence.ts +58 -0
  248. package/src/op/op-waves-run.ts +25 -1
  249. package/src/op/op-waves.ts +31 -1
  250. package/src/op/schedule-overdue.test.ts +85 -0
  251. package/src/op/schedule-overdue.ts +162 -26
  252. package/src/plan-summary.ts +40 -0
  253. package/src/pr-plan-note.ts +34 -0
  254. package/src/pr-post-plan-note.test.ts +146 -0
  255. package/src/pr-post.ts +127 -3
  256. package/src/release-floors.ts +47 -1
  257. package/src/stage-hooks-bundle.test.ts +1 -0
  258. package/src/state-migration.test.ts +52 -1
  259. package/src/state-migration.ts +107 -5
  260. package/src/workspace/ci-green.ts +4 -3
  261. package/src/workspace/lexicon-outputs.ts +23 -6
  262. package/src/workspace/reason-codes.test.ts +3 -0
  263. package/src/workspace/reason-codes.ts +4 -0
  264. package/src/workspace/ref-gate.schema.json +85 -0
  265. package/src/workspace/trust/check-evidence-report.ts +115 -0
  266. package/src/workspace/trust/check-evidence.test.ts +133 -0
  267. package/src/workspace/trust/check-evidence.ts +327 -0
  268. package/src/workspace/trust/ci-tag-statement.ts +2 -2
  269. package/src/workspace/trust/dsse.ts +48 -4
  270. package/src/workspace/trust/evidence.ts +2 -2
  271. package/src/workspace/trust/keyless-fixture.ts +214 -0
  272. package/src/workspace/trust/keyless.test.ts +220 -0
  273. package/src/workspace/trust/keyless.ts +557 -0
  274. package/src/workspace/trust/local-evidence.test.ts +127 -0
  275. package/src/workspace/trust/local-evidence.ts +268 -0
  276. package/src/workspace/trust/op-run-statement.ts +2 -2
  277. package/src/workspace/trust/policy.ts +263 -3
  278. package/src/workspace/trust/ref-gate-cli.ts +244 -0
  279. package/src/workspace/trust/ref-gate-fixture.ts +125 -0
  280. package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
  281. package/src/workspace/trust/ref-gate.test.ts +247 -0
  282. package/src/workspace/trust/ref-gate.ts +539 -0
  283. package/src/workspace/trust/run-statement.ts +3 -3
  284. package/src/workspace/trust/runner-identity.ts +92 -0
  285. package/src/workspace/trust/trust-files.test.ts +22 -0
  286. package/src/workspace/trust/trust-files.ts +54 -1
@@ -0,0 +1,220 @@
1
+ /**
2
+ * #4869: runner statements signed keyless from the CI job's OIDC identity.
3
+ * A fake forge token, a fake certificate authority and a fake timestamp
4
+ * authority (./keyless-fixture.ts); nothing reaches sigstore or a forge.
5
+ *
6
+ * Done when: a green tag, an Op run and a piece of runner evidence signed
7
+ * by a listed workflow identity verify offline, and one signed by another
8
+ * workflow is reported and ignored; verification works after the
9
+ * certificate expired; key-signed statements from before `keyless.since`
10
+ * still count.
11
+ */
12
+
13
+ import { execFileSync } from "node:child_process";
14
+ import { generateKeyPairSync } from "node:crypto";
15
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
16
+ import { tmpdir } from "node:os";
17
+ import { join } from "node:path";
18
+ import { describe, expect, test } from "vitest";
19
+ import { canonicalJson } from "../../effect-receipt";
20
+ import { gitRevisionSource } from "../record-source";
21
+ import { keylessEvidenceSigner, readCheckEvidence, recordChecks, runnerEvidenceSigner, runnerKeyEvidenceSigner, signChecks, type EvidenceSigner } from "./check-evidence";
22
+ import { buildCiTagStatement, verifyCiTagStatement, type CiTagRecord } from "./ci-tag-statement";
23
+ import { IN_TOTO_PAYLOAD_TYPE, loadRunnerKey } from "./dsse";
24
+ import { githubClaims, sigstoreFake, FAKE_FULCIO_URL, FAKE_GITHUB_ISSUER, FAKE_TSA_URL, type SigstoreFake } from "./keyless-fixture";
25
+ import { subjectPattern } from "./keyless";
26
+ import { buildOpRunStatement, verifyOpRunStatement } from "./op-run-statement";
27
+ import { protectedPaths, readTrustPolicy, runnersAt } from "./policy";
28
+ import type { OpRunRecord } from "../../op/runtime";
29
+
30
+ function git(cwd: string, ...args: string[]): string {
31
+ return execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.invalid", "-c", "init.defaultBranch=main", "-c", "commit.gpgsign=false", ...args], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
32
+ }
33
+
34
+ const REPO = "acme/infra";
35
+ const LISTED = `https://github.com/${REPO}/.github/workflows/chant-*.yml@refs/heads/main`;
36
+
37
+ function runnerKey(): { pem: string; pub: string } {
38
+ const { privateKey } = generateKeyPairSync("ed25519");
39
+ const pem = privateKey.export({ format: "pem", type: "pkcs8" }).toString();
40
+ return { pem, pub: loadRunnerKey(pem).publicKey };
41
+ }
42
+
43
+ /** A repository whose base lists `ci` keyless (and, with `key`, by a runner key too), and a change on top. */
44
+ function repo(fake: SigstoreFake, opts: { key?: string; since?: (dir: string) => string } = {}): { dir: string; base: string; head: string } {
45
+ const dir = mkdtempSync(join(tmpdir(), "chant-4869-"));
46
+ git(dir, "init", "--quiet");
47
+ mkdirSync(join(dir, ".chant"));
48
+ writeFileSync(join(dir, "main.tf"), "# one\n");
49
+ git(dir, "add", ".");
50
+ git(dir, "commit", "--quiet", "-m", "one");
51
+ const trust = (since?: string) =>
52
+ JSON.stringify({
53
+ schema: 1,
54
+ roles: { runner: ["ci"] },
55
+ ...(opts.key ? { runners: [{ principal: "ci", class: "runner", key: opts.key }] } : {}),
56
+ keyless: {
57
+ trustedRoot: ".chant/trusted_root.json",
58
+ fulcio: FAKE_FULCIO_URL,
59
+ timestamp: FAKE_TSA_URL,
60
+ identities: [{ principal: "ci", class: "runner", issuer: FAKE_GITHUB_ISSUER, subject: LISTED }],
61
+ ...(since ? { since } : {}),
62
+ },
63
+ });
64
+ writeFileSync(join(dir, ".chant/trusted_root.json"), fake.trustedRoot);
65
+ writeFileSync(join(dir, ".chant/trust.json"), trust());
66
+ git(dir, "add", ".");
67
+ git(dir, "commit", "--quiet", "-m", "trust");
68
+ if (opts.since) {
69
+ writeFileSync(join(dir, ".chant/trust.json"), trust(opts.since(dir)));
70
+ git(dir, "commit", "--quiet", "-am", "since");
71
+ }
72
+ const base = git(dir, "rev-parse", "HEAD");
73
+ writeFileSync(join(dir, "main.tf"), "# change\n");
74
+ git(dir, "commit", "--quiet", "-am", "change");
75
+ return { dir, base, head: git(dir, "rev-parse", "HEAD") };
76
+ }
77
+
78
+ const listedJob = (fake: SigstoreFake) => fake.jobEnv(githubClaims(REPO, "chant-pr.yml", "refs/heads/main"));
79
+ const otherJob = (fake: SigstoreFake) => fake.jobEnv(githubClaims(REPO, "deploy.yml", "refs/heads/main"));
80
+
81
+ /** A signer for another workflow's job: it gets a certificate, which the policy does not list, so it signs as `ci` regardless. */
82
+ async function rogueSigner(fake: SigstoreFake, r: { dir: string; base: string }): Promise<EvidenceSigner> {
83
+ const listed = await keylessEvidenceSigner(r.dir, r.base, { env: listedJob(fake), fetch: fake.fetch });
84
+ const { requestCertificate, keylessSignature, signingToken } = await import("./keyless");
85
+ const { pae } = await import("./dsse");
86
+ const cert = await requestCertificate(await signingToken(otherJob(fake), "sigstore", fake.fetch), FAKE_FULCIO_URL, fake.fetch);
87
+ return {
88
+ principal: listed.principal,
89
+ sign: async (payloadType, payload) => ({ payloadType, payload: payload.toString("base64"), signatures: [await keylessSignature(pae(payloadType, payload), cert, FAKE_TSA_URL, fake.fetch)] }),
90
+ };
91
+ }
92
+
93
+ describe("keyless runner statements (#4869)", () => {
94
+ test("runner evidence signed by a listed workflow identity verifies offline; another workflow's is reported and ignored", async () => {
95
+ const fake = sigstoreFake();
96
+ const r = repo(fake);
97
+ const signer = await keylessEvidenceSigner(r.dir, r.base, { env: listedJob(fake), fetch: fake.fetch });
98
+ expect(signer.principal).toBe("ci");
99
+ expect(fake.log.tokens).toEqual(["sigstore"]);
100
+ await recordChecks(r.dir, await signChecks(r.dir, r.head, [{ check: "plan" }], signer), { push: false });
101
+ expect(await readCheckEvidence(r.dir, r.head, r.base, ["plan"])).toEqual([{ check: "plan", status: "current", runner: "ci", commit: r.head }]);
102
+
103
+ // Another workflow of the same repository: its own certificate, which the policy does not list.
104
+ const rogue = await rogueSigner(fake, r);
105
+ await recordChecks(r.dir, await signChecks(r.dir, r.head, [{ check: "policy" }], rogue), { push: false });
106
+ const [v] = await readCheckEvidence(r.dir, r.head, r.base, ["policy"]);
107
+ expect(v!.status).toBe("untrusted");
108
+ expect(v).toMatchObject({ reason: expect.stringContaining(`https://github.com/${REPO}/.github/workflows/deploy.yml@refs/heads/main`) });
109
+ expect(v).toMatchObject({ reason: expect.stringContaining("not one the policy at base lists under keyless.identities") });
110
+ });
111
+
112
+ test("the signer refuses a job whose identity the policy does not list, before it signs anything", async () => {
113
+ const fake = sigstoreFake();
114
+ const r = repo(fake);
115
+ await expect(keylessEvidenceSigner(r.dir, r.base, { env: otherJob(fake), fetch: fake.fetch })).rejects.toThrow(/lists no keyless identity for this job .*deploy\.yml/);
116
+ expect(fake.log.timestamps).toBe(0);
117
+ await expect(keylessEvidenceSigner(r.dir, r.base, { env: {}, fetch: fake.fetch })).rejects.toThrow(/id-token: write/);
118
+ });
119
+
120
+ test("a green tag and an Op run signed keyless verify offline, and another workflow's are ignored", async () => {
121
+ const fake = sigstoreFake();
122
+ const r = repo(fake);
123
+ const policy = readTrustPolicy(gitRevisionSource(r.dir, r.base), r.base);
124
+ const runners = runnersAt(policy, { repo: r.dir, commit: r.head });
125
+ const signer = await keylessEvidenceSigner(r.dir, r.base, { env: listedJob(fake), fetch: fake.fetch });
126
+ const rogue = await rogueSigner(fake, r);
127
+ const sign = (s: EvidenceSigner, statement: unknown) => s.sign(IN_TOTO_PAYLOAD_TYPE, Buffer.from(canonicalJson(statement), "utf8"));
128
+
129
+ const tag: CiTagRecord = { schema: 1, tag: "green", commit: r.head, branch: "main", at: "2026-11-09T00:00:00Z" };
130
+ const signedTag = { ...tag, statement: await sign(signer, buildCiTagStatement(tag, "ci")) };
131
+ expect(verifyCiTagStatement(signedTag, { sha: r.head, kind: "green", branch: "main" }, runners, policy.roles)).toMatchObject({ status: "signed", signer: "ci" });
132
+ const rogueTag = { ...tag, statement: await sign(rogue, buildCiTagStatement(tag, "ci")) };
133
+ expect(verifyCiTagStatement(rogueTag, { sha: r.head, kind: "green", branch: "main" }, runners, policy.roles)).toMatchObject({ status: "untrusted", reason: expect.stringContaining("deploy.yml") });
134
+
135
+ const run = { id: "run-1", op: "apply", env: "prod", status: "ok", gitSha: r.head } as unknown as OpRunRecord;
136
+ const signedRun = { ...run, statement: await sign(signer, buildOpRunStatement(run, "ci")) } as OpRunRecord;
137
+ expect(verifyOpRunStatement(signedRun, runners, policy.roles)).toMatchObject({ status: "signed", signer: "ci" });
138
+ const rogueRun = { ...run, statement: await sign(rogue, buildOpRunStatement(run, "ci")) } as OpRunRecord;
139
+ expect(verifyOpRunStatement(rogueRun, runners, policy.roles)).toMatchObject({ status: "untrusted" });
140
+ });
141
+
142
+ test("a statement verifies after its certificate expired: validity is judged at the timestamp's time", async () => {
143
+ // The authorities' clock is in 2021; the certificate lived ten minutes then. Verification runs now.
144
+ const fake = sigstoreFake({ now: new Date("2021-03-01T12:00:00Z") });
145
+ const r = repo(fake);
146
+ const signer = await keylessEvidenceSigner(r.dir, r.base, { env: listedJob(fake), fetch: fake.fetch });
147
+ await recordChecks(r.dir, await signChecks(r.dir, r.head, [{ check: "plan" }], signer), { push: false });
148
+ expect(await readCheckEvidence(r.dir, r.head, r.base, ["plan"])).toEqual([{ check: "plan", status: "current", runner: "ci", commit: r.head }]);
149
+
150
+ // A timestamp from after the certificate expired does not count.
151
+ const late = await keylessEvidenceSigner(r.dir, r.base, { env: listedJob(fake), fetch: fake.fetch });
152
+ fake.setNow(new Date("2021-03-01T12:30:00Z"));
153
+ await expect(signChecks(r.dir, r.head, [{ check: "policy" }], late)).rejects.toThrow(/does not chain to a certificate authority of the trusted root, valid at 2021-03-01T12:30/);
154
+ });
155
+
156
+ test("key-signed evidence before keyless.since still counts, and after it does not", async () => {
157
+ const fake = sigstoreFake();
158
+ const key = runnerKey();
159
+ let first = "";
160
+ const r = repo(fake, {
161
+ key: key.pub,
162
+ since: (dir) => {
163
+ first = git(dir, "rev-parse", "HEAD~1");
164
+ return git(dir, "rev-parse", "HEAD");
165
+ },
166
+ });
167
+ const keySigner = runnerKeyEvidenceSigner(r.dir, r.base, key.pem);
168
+ await recordChecks(r.dir, await signChecks(r.dir, first, [{ check: "plan" }], keySigner), { push: false });
169
+ await recordChecks(r.dir, await signChecks(r.dir, r.head, [{ check: "plan" }], keySigner), { push: false });
170
+ expect(await readCheckEvidence(r.dir, first, r.base, ["plan"])).toEqual([{ check: "plan", status: "current", runner: "ci", commit: first }]);
171
+ expect((await readCheckEvidence(r.dir, r.head, r.base, ["plan"]))[0]!.status).toBe("untrusted");
172
+ // The same commit signed keyless counts.
173
+ const keyless = await runnerEvidenceSigner(r.dir, r.base, { env: { ...listedJob(fake), CHANT_RUNNER_IDENTITY: "oidc" }, fetch: fake.fetch });
174
+ await recordChecks(r.dir, await signChecks(r.dir, r.head, [{ check: "plan" }], keyless!), { push: false });
175
+ expect(await readCheckEvidence(r.dir, r.head, r.base, ["plan"])).toEqual([{ check: "plan", status: "current", runner: "ci", commit: r.head }]);
176
+ });
177
+
178
+ test("a trusted root that does not read leaves the identities out, and since still leaves the keys out", () => {
179
+ const fake = sigstoreFake();
180
+ const r = repo(fake, { key: runnerKey().pub, since: (dir) => git(dir, "rev-parse", "HEAD") });
181
+ writeFileSync(join(r.dir, ".chant/trusted_root.json"), "{}");
182
+ git(r.dir, "commit", "--quiet", "-am", "break the root");
183
+ const at = git(r.dir, "rev-parse", "HEAD");
184
+ const policy = readTrustPolicy(gitRevisionSource(r.dir, at), at);
185
+ expect(policy.runnerIdentities).toEqual([]);
186
+ expect(policy.excludedRunners[0]!.reason).toMatch(/trusted root .chant\/trusted_root.json cannot be read/);
187
+ expect(runnersAt(policy, { repo: r.dir, commit: at })).toEqual([]);
188
+ expect(protectedPaths(policy)).toContain(".chant/trusted_root.json");
189
+ });
190
+
191
+ test("a subject pattern's * stays within a path segment, ** crosses them", () => {
192
+ expect(subjectPattern(LISTED).test(`https://github.com/${REPO}/.github/workflows/chant-pr.yml@refs/heads/main`)).toBe(true);
193
+ expect(subjectPattern(LISTED).test(`https://github.com/${REPO}/.github/workflows/sub/chant-pr.yml@refs/heads/main`)).toBe(false);
194
+ expect(subjectPattern("https://gitlab.com/acme/**@refs/heads/main").test("https://gitlab.com/acme/infra//.gitlab-ci.yml@refs/heads/main")).toBe(true);
195
+ });
196
+ });
197
+
198
+ describe("the runner identity an init writes (#4869)", () => {
199
+ test("a GitHub workflow's identity goes under keyless, and its principal under roles.runner, once", async () => {
200
+ const { ciRunnerIdentity, withRunnerIdentity } = await import("./runner-identity");
201
+ const id = ciRunnerIdentity({ forge: "github", repository: REPO, workflow: ".github/workflows/chant-pr.yml" });
202
+ expect(id).toEqual({ principal: "ci", class: "runner", issuer: FAKE_GITHUB_ISSUER, subject: `https://github.com/${REPO}/.github/workflows/chant-pr.yml@refs/heads/main` });
203
+ const once = withRunnerIdentity(JSON.stringify({ schema: 1, roles: { admin: ["alice"] } }), id);
204
+ expect(withRunnerIdentity(once, id)).toBe(once);
205
+ expect(JSON.parse(once)).toEqual({ schema: 1, roles: { admin: ["alice"], runner: ["ci"] }, keyless: { trustedRoot: ".chant/trusted_root.json", identities: [id] } });
206
+ expect(ciRunnerIdentity({ forge: "gitlab", repository: "acme/infra" }).subject).toBe("https://gitlab.com/acme/infra//.gitlab-ci.yml@refs/heads/main");
207
+ expect(() => ciRunnerIdentity({ forge: "forgejo", repository: "acme/infra", workflow: "x.yml" })).toThrow(/certificate authority the project runs/);
208
+ });
209
+ });
210
+
211
+ describe("DER INTEGERs (#4869)", () => {
212
+ test("a serial with leading zero bytes is written in minimal form, so OpenSSL reads the certificate", async () => {
213
+ const { derInt } = await import("./keyless");
214
+ expect(derInt(Buffer.from("003a2d0f26856400", "hex")).toString("hex")).toBe("02073a2d0f26856400");
215
+ expect(derInt(Buffer.from("0000ff", "hex")).toString("hex")).toBe("020200ff");
216
+ expect(derInt(Buffer.from("80", "hex")).toString("hex")).toBe("02020080");
217
+ expect(derInt(Buffer.from("0000", "hex")).toString("hex")).toBe("020100");
218
+ expect(derInt(3).toString("hex")).toBe("020103");
219
+ });
220
+ });