@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,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":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAOH,OAAO,EAA0D,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AACnG,OAAO,EAA6D,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/G,OAAO,EAAkB,kBAAkB,EAAqB,MAAM,YAAY,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEtF,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,sGAAsG;AACtG,eAAO,MAAM,oBAAoB,YAAI,MAAM,EAAE,QAAQ,CAAU,CAAC;AAEhE;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAClF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CA8B7J;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC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 @@
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 { RunnerKey } from "./policy.js";
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 RunnerKey[], roles: Readonly<Record<string, readonly string[]>>): CiTagVerdict;
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,C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jH,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
- /** Verify an envelope against `trusted`. One valid signature by a trusted key is enough. */
57
- export declare function verifyEnvelope(envelope: unknown, trusted: readonly TrustedKey[]): EnvelopeVerdict;
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;;;;;;;;;;;;GAYG;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;CACb;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,EAA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D,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
- /** Verify an envelope against `trusted`. One valid signature by a trusted key is enough. */
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 byId = new Map(trusted.map((t) => [sshFingerprint(t.key), t]));
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) {