@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.
- package/dist/ci-commit.d.ts +1 -1
- package/dist/ci-evidence-jobs.d.ts +31 -7
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +35 -5
- package/dist/ci-product.d.ts +1 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +17 -13
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +11 -8
- package/dist/components/check-hooks.js +3 -3
- package/dist/components/check-steps.js +1 -1
- package/dist/components/product-plan.d.ts +7 -1
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +3 -1
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +1 -0
- package/dist/op/op-waves-evidence.d.ts +5 -3
- package/dist/op/op-waves-evidence.d.ts.map +1 -1
- package/dist/op/op-waves-evidence.js +9 -8
- package/dist/release-floors.d.ts +18 -16
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +3 -1
- package/dist/state-migration.d.ts +1 -1
- package/dist/wave-runtime.mjs +299 -299
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +4 -3
- package/dist/workspace/trust/check-evidence-report.d.ts +7 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +7 -0
- package/dist/workspace/trust/check-evidence.d.ts +46 -12
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence.js +94 -22
- package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
- package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.d.ts +40 -2
- package/dist/workspace/trust/dsse.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.js +34 -2
- package/dist/workspace/trust/evidence.d.ts +2 -2
- package/dist/workspace/trust/evidence.d.ts.map +1 -1
- package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
- package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/keyless-fixture.js +161 -0
- package/dist/workspace/trust/keyless.d.ts +202 -0
- package/dist/workspace/trust/keyless.d.ts.map +1 -0
- package/dist/workspace/trust/keyless.js +488 -0
- package/dist/workspace/trust/local-evidence.d.ts +3 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/op-run-statement.d.ts +2 -2
- package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/policy.d.ts +56 -1
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +103 -2
- package/dist/workspace/trust/ref-gate.d.ts +1 -1
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate.js +3 -1
- package/dist/workspace/trust/run-statement.d.ts +3 -3
- package/dist/workspace/trust/run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/runner-identity.d.ts +56 -0
- package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
- package/dist/workspace/trust/runner-identity.js +65 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +8 -1
- package/package.json +1 -1
- package/src/ci-evidence-jobs.ts +45 -7
- package/src/cli/handlers/ci-check.ts +16 -12
- package/src/cli/handlers/ci-evidence.ts +13 -8
- package/src/components/check-hooks.ts +3 -3
- package/src/components/check-steps.ts +1 -1
- package/src/components/product-plan.ts +7 -3
- package/src/floor-table.data.ts +1 -0
- package/src/op/op-waves-evidence.test.ts +1 -1
- package/src/op/op-waves-evidence.ts +10 -9
- package/src/release-floors.ts +4 -1
- package/src/workspace/ci-green.ts +4 -3
- package/src/workspace/trust/check-evidence-report.ts +9 -0
- package/src/workspace/trust/check-evidence.test.ts +3 -3
- package/src/workspace/trust/check-evidence.ts +95 -25
- package/src/workspace/trust/ci-tag-statement.ts +2 -2
- package/src/workspace/trust/dsse.ts +48 -4
- package/src/workspace/trust/evidence.ts +2 -2
- package/src/workspace/trust/keyless-fixture.ts +214 -0
- package/src/workspace/trust/keyless.test.ts +220 -0
- package/src/workspace/trust/keyless.ts +557 -0
- package/src/workspace/trust/local-evidence.ts +3 -1
- package/src/workspace/trust/op-run-statement.ts +2 -2
- package/src/workspace/trust/policy.ts +129 -2
- package/src/workspace/trust/ref-gate.ts +3 -2
- package/src/workspace/trust/run-statement.ts +3 -3
- package/src/workspace/trust/runner-identity.ts +92 -0
- package/src/workspace/trust/trust-files.test.ts +6 -0
- package/src/workspace/trust/trust-files.ts +14 -1
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
import { posix } from "node:path";
|
|
24
24
|
import { z } from "zod";
|
|
25
25
|
import { DEFAULT_SIGNERS_PATH, TRUST_CONFIG_PATH, parseAllowedSigners } from "./trust-files.js";
|
|
26
|
+
import { execFileSync } from "node:child_process";
|
|
27
|
+
import { DEFAULT_FULCIO_URL, DEFAULT_SIGNING_AUDIENCE, DEFAULT_TIMESTAMP_URL, keylessVerifier, parseTrustedRoot } from "./keyless.js";
|
|
26
28
|
export { DEFAULT_SIGNERS_PATH, TRUST_CONFIG_PATH, parseAllowedSigners, renderAllowedSigners, } from "./trust-files.js";
|
|
27
29
|
// ── trust.json ───────────────────────────────────────────────────────────────
|
|
28
30
|
const fullCommit = z.string().regex(/^[0-9a-f]{40}([0-9a-f]{24})?$/, "a full commit id");
|
|
@@ -33,6 +35,8 @@ const repoPath = z
|
|
|
33
35
|
.refine((p) => !p.startsWith("/") && !p.includes("\\") && posix.normalize(p) === p && !p.split("/").includes(".."), {
|
|
34
36
|
message: "a path inside the repository, with / separators and no ..",
|
|
35
37
|
});
|
|
38
|
+
/** An http or https URL (#4869): an OIDC issuer, a certificate or timestamp authority. */
|
|
39
|
+
const httpUrl = z.string().regex(/^https?:\/\/[^\s]+$/, "an http or https URL");
|
|
36
40
|
/** A check name a ref rule requires (#4867): it is also part of an override's subject. */
|
|
37
41
|
export const REF_CHECK_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
38
42
|
/** A ref pattern (#4867): a full ref name, where `*` matches within one `/` segment and `**` matches across them. */
|
|
@@ -79,6 +83,38 @@ export const trustConfigSchema = z
|
|
|
79
83
|
})
|
|
80
84
|
.strict())
|
|
81
85
|
.optional(),
|
|
86
|
+
/**
|
|
87
|
+
* CI identities that sign runner statements keyless (#4869): each an
|
|
88
|
+
* OIDC issuer and a pattern over the subject alternative name of the
|
|
89
|
+
* certificate the job's token was traded for, which names the
|
|
90
|
+
* repository, the workflow and the ref. `trustedRoot` is a file in
|
|
91
|
+
* sigstore's `trusted_root.json` format with the certificate and
|
|
92
|
+
* timestamp authorities. `fulcio`, `timestamp` and `audience` tell a
|
|
93
|
+
* signing job where to trade its token; sigstore's public instances by
|
|
94
|
+
* default. With `since`, a statement over that commit or any commit not
|
|
95
|
+
* a strict ancestor of it counts only when signed keyless; a runner key's
|
|
96
|
+
* statement over an earlier commit still counts.
|
|
97
|
+
*/
|
|
98
|
+
keyless: z
|
|
99
|
+
.object({
|
|
100
|
+
trustedRoot: repoPath,
|
|
101
|
+
identities: z
|
|
102
|
+
.array(z
|
|
103
|
+
.object({
|
|
104
|
+
principal: z.string().min(1),
|
|
105
|
+
class: z.enum(["runner", "service"]),
|
|
106
|
+
issuer: httpUrl,
|
|
107
|
+
subject: z.string().min(1),
|
|
108
|
+
})
|
|
109
|
+
.strict())
|
|
110
|
+
.min(1),
|
|
111
|
+
since: fullCommit.optional(),
|
|
112
|
+
fulcio: httpUrl.optional(),
|
|
113
|
+
timestamp: httpUrl.optional(),
|
|
114
|
+
audience: z.string().min(1).optional(),
|
|
115
|
+
})
|
|
116
|
+
.strict()
|
|
117
|
+
.optional(),
|
|
82
118
|
/**
|
|
83
119
|
* Passkeys that sign gate approvals for people (#4646): a WebAuthn
|
|
84
120
|
* credential's id, its public key as base64url DER SubjectPublicKeyInfo,
|
|
@@ -182,10 +218,39 @@ export const trustConfigSchema = z
|
|
|
182
218
|
.strict();
|
|
183
219
|
/** The role whose holders may change the policy. Without any grant of it, every signer may. */
|
|
184
220
|
export const ADMIN_ROLE = "admin";
|
|
185
|
-
/** Paths whose change is a protected write under `policy`: the config, the signers file and its rotation file (#2553). */
|
|
221
|
+
/** Paths whose change is a protected write under `policy`: the config, the signers file and its rotation file (#2553), and the keyless trusted root (#4869). */
|
|
186
222
|
export function protectedPaths(policy) {
|
|
187
223
|
const s = policy.signersPath;
|
|
188
|
-
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`)])].sort();
|
|
224
|
+
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`), ...(policy.keyless ? [policy.keyless.trustedRoot] : [])])].sort();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The runners whose statements over `commit` count (#4869): the runner keys
|
|
228
|
+
* and the keyless identities. With `keyless.since`, a runner key counts
|
|
229
|
+
* only for a commit that is a strict ancestor of `since`, the way
|
|
230
|
+
* `ci.green.signedSince` judges tags by position in history; a `since` the
|
|
231
|
+
* clone does not have leaves the keys out. Without `at`, under `since`, only
|
|
232
|
+
* the identities.
|
|
233
|
+
*/
|
|
234
|
+
export function runnersAt(policy, at) {
|
|
235
|
+
const ids = policy.runnerIdentities ?? [];
|
|
236
|
+
const since = policy.keyless?.since;
|
|
237
|
+
if (!since)
|
|
238
|
+
return [...policy.runners, ...ids];
|
|
239
|
+
if (!at || !strictAncestor(at.repo, at.commit, since))
|
|
240
|
+
return ids;
|
|
241
|
+
return [...policy.runners, ...ids];
|
|
242
|
+
}
|
|
243
|
+
function strictAncestor(repo, commit, of) {
|
|
244
|
+
try {
|
|
245
|
+
const full = execFileSync("git", ["rev-parse", "--verify", "--quiet", `${commit}^{commit}`], { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
246
|
+
if (full === of)
|
|
247
|
+
return false;
|
|
248
|
+
execFileSync("git", ["merge-base", "--is-ancestor", full, of], { cwd: repo, stdio: "ignore" });
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
189
254
|
}
|
|
190
255
|
/** Principals allowed to change the policy: the admins when any are granted, otherwise every signer. */
|
|
191
256
|
export function policyWriters(policy) {
|
|
@@ -242,6 +307,7 @@ export function readTrustPolicy(source, base) {
|
|
|
242
307
|
runners.push(r);
|
|
243
308
|
}
|
|
244
309
|
}
|
|
310
|
+
const { runnerIdentities, keyless } = keylessOf(config, source, humanNames, excludedRunners);
|
|
245
311
|
return {
|
|
246
312
|
base,
|
|
247
313
|
signersPath,
|
|
@@ -252,6 +318,7 @@ export function readTrustPolicy(source, base) {
|
|
|
252
318
|
adopted: config.adopted ?? [],
|
|
253
319
|
runners,
|
|
254
320
|
excludedRunners,
|
|
321
|
+
...(keyless ? { runnerIdentities, keyless } : {}),
|
|
255
322
|
passkeys: config.passkeys ?? [],
|
|
256
323
|
admitted: admittedOf(config),
|
|
257
324
|
refs: (config.refs ?? []).map((r) => ({ ...r, checks: r.checks.map((c) => ({ ...c, action: c.action ?? "block" })) })),
|
|
@@ -275,6 +342,40 @@ function localOf(config, runners) {
|
|
|
275
342
|
}
|
|
276
343
|
return { keys, excluded, checks: (config.local?.checks ?? []).map((c) => ({ check: c.check, from: c.from ?? ["person"] })) };
|
|
277
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* The keyless identities (#4869), each with the trusted root read through
|
|
347
|
+
* `source`. A trusted root that cannot be read leaves every identity out,
|
|
348
|
+
* with the reason in `excluded`; the runner keys still count.
|
|
349
|
+
*/
|
|
350
|
+
function keylessOf(config, source, humanNames, excluded) {
|
|
351
|
+
const k = config.keyless;
|
|
352
|
+
if (!k)
|
|
353
|
+
return { runnerIdentities: [] };
|
|
354
|
+
// Kept when the root does not read, so `since` still leaves the keys out: fail closed.
|
|
355
|
+
const keyless = { ...(k.since ? { since: k.since } : {}), fulcio: k.fulcio ?? DEFAULT_FULCIO_URL, timestamp: k.timestamp ?? DEFAULT_TIMESTAMP_URL, audience: k.audience ?? DEFAULT_SIGNING_AUDIENCE, trustedRoot: k.trustedRoot };
|
|
356
|
+
let roots;
|
|
357
|
+
try {
|
|
358
|
+
const text = readOptional(source, k.trustedRoot);
|
|
359
|
+
if (text === undefined)
|
|
360
|
+
throw new Error("the file is not there");
|
|
361
|
+
roots = parseTrustedRoot(text);
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
for (const i of k.identities)
|
|
365
|
+
excluded.push({ principal: i.principal, reason: `the keyless trusted root ${k.trustedRoot} cannot be read: ${err instanceof Error ? err.message : String(err)}` });
|
|
366
|
+
return { runnerIdentities: [], keyless };
|
|
367
|
+
}
|
|
368
|
+
const runnerIdentities = [];
|
|
369
|
+
for (const i of k.identities) {
|
|
370
|
+
if (humanNames.has(i.principal))
|
|
371
|
+
excluded.push({ principal: i.principal, reason: "the signers file lists this principal; a keyless identity is a CI job's, never a signer's" });
|
|
372
|
+
else {
|
|
373
|
+
const verify = keylessVerifier({ ...i, roots });
|
|
374
|
+
runnerIdentities.push({ ...i, roots, verifyKeyless: (message, signature) => verify(message, signature) });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return { runnerIdentities, keyless };
|
|
378
|
+
}
|
|
278
379
|
/** The admitted signers, by return id. Two entries for one return add up. */
|
|
279
380
|
function admittedOf(config) {
|
|
280
381
|
const out = {};
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* ledger, a JSON-lines file in the git directory ({@link refGateLedgerPath}),
|
|
32
32
|
* since a pre-receive hook may not move a ref.
|
|
33
33
|
*/
|
|
34
|
-
import type
|
|
34
|
+
import { type RefRule, type TrustPolicy } from "./policy.js";
|
|
35
35
|
import { type AppliedOverrideRecord } from "../../override-gate.js";
|
|
36
36
|
/** Where runner evidence for a commit is kept (#4867): a git note on the commit, one DSSE envelope per line. */
|
|
37
37
|
export declare const EVIDENCE_NOTES_REF = "refs/notes/chant/evidence";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref-gate.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ref-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAQH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ref-gate.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ref-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAQH,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAQL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAK7B,gHAAgH;AAChH,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAC9D,6DAA6D;AAC7D,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAC1D,mEAAmE;AACnE,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAIhD,kGAAkG;AAClG,eAAO,MAAM,oBAAoB,wGAAyI,CAAC;AAC3K,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,uGAAuG;AACvG,eAAO,MAAM,oBAAoB,sLAQS,CAAC;AAC3C,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,6GAA6G;AAC7G,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;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MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,UAAU,CAsBnH;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;CAAO,GAAG,UAAU,CAUxJ;AAMD,oHAAoH;AACpH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE,CAyBzD"}
|
|
@@ -36,6 +36,7 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
|
36
36
|
import { dirname, isAbsolute, join } from "node:path";
|
|
37
37
|
import { verifyEvidence } from "./evidence.js";
|
|
38
38
|
import { policyAtBase } from "./provenance.js";
|
|
39
|
+
import { runnersAt } from "./policy.js";
|
|
39
40
|
import { OVERRIDE_APPLIED, OVERRIDE_LEDGER, OVERRIDERS_PATH, decideOverride, overrideCommand, overridersAt, parseAppliedOverrides, } from "../../override-gate.js";
|
|
40
41
|
import { parseGateLedger } from "../../lifecycle/gate-ledger.js";
|
|
41
42
|
import { gateSignersAt } from "../../gate-decision.js";
|
|
@@ -186,7 +187,8 @@ function judgeCheck(repo, policy, envelopes, check, commit, tree) {
|
|
|
186
187
|
let stale;
|
|
187
188
|
let bad;
|
|
188
189
|
for (const env of envelopes) {
|
|
189
|
-
|
|
190
|
+
// #4869: keys and keyless identities; under keyless.since, keys only for a commit before it.
|
|
191
|
+
const v = verifyEvidence(env, runnersAt(policy, { repo, commit }), repo, commit);
|
|
190
192
|
if (!v.ok) {
|
|
191
193
|
if (claimedCheck(env) === check && !bad)
|
|
192
194
|
bad = { code: v.code, reason: v.reason };
|
|
@@ -25,7 +25,7 @@ import { z } from "zod";
|
|
|
25
25
|
import type { RunEndLine, RunStartLine, RunView } from "../runs.js";
|
|
26
26
|
import { type DsseEnvelope } from "./dsse.js";
|
|
27
27
|
import type { KeyObject } from "node:crypto";
|
|
28
|
-
import type { RunnerKey } from "./policy.js";
|
|
28
|
+
import type { Runner, RunnerKey } from "./policy.js";
|
|
29
29
|
export declare const AGENT_RUN_PREDICATE = "https://intentius.io/chant/agent-run/v1";
|
|
30
30
|
/** The statement a runner signs for a run. Strict, so a verifier never acts on a field it does not know. */
|
|
31
31
|
export declare const runStatementSchema: z.ZodObject<{
|
|
@@ -103,7 +103,7 @@ export type RunStatementVerdict = {
|
|
|
103
103
|
* well-formed statement whose signer is that key's principal, for this run,
|
|
104
104
|
* and agreeing with its record. Never throws.
|
|
105
105
|
*/
|
|
106
|
-
export declare function verifyRunStatement(envelope: unknown, runners: readonly
|
|
106
|
+
export declare function verifyRunStatement(envelope: unknown, runners: readonly Runner[], run: RunView): RunStatementVerdict;
|
|
107
107
|
/** A run's attestation: its best statement, or why it has none. */
|
|
108
108
|
export interface RunAttestation {
|
|
109
109
|
/**
|
|
@@ -124,5 +124,5 @@ export interface RunAttestation {
|
|
|
124
124
|
statements: RunStatementVerdict[];
|
|
125
125
|
}
|
|
126
126
|
/** Judge every statement the ledger holds for `run`. */
|
|
127
|
-
export declare function attestRun(run: RunView, runners: readonly
|
|
127
|
+
export declare function attestRun(run: RunView, runners: readonly Runner[]): RunAttestation;
|
|
128
128
|
//# sourceMappingURL=run-statement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-statement.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/run-statement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAsD,KAAK,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AAmB,EAAE,CAAC;CACnC;AAID,wDAAwD;AACxD,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,CAqBlF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runner identity an init writes into `.chant/trust.json` (#4869).
|
|
3
|
+
*
|
|
4
|
+
* None of the CI products' inits wrote `.chant/trust.json`, a runner key
|
|
5
|
+
* or an identity, so a keyless runner had nowhere to come from. These are
|
|
6
|
+
* the pieces an init calls: {@link ciRunnerIdentity} names the identity the
|
|
7
|
+
* generated workflow signs as, on the forge it runs on, and
|
|
8
|
+
* {@link withRunnerIdentity} adds it to the file's text under `keyless`,
|
|
9
|
+
* with the principal in `roles.runner`, which ci tags and Op runs need.
|
|
10
|
+
*
|
|
11
|
+
* The subject is the certificate's subject alternative name the
|
|
12
|
+
* certificate authority writes for that job: on GitHub the workflow file at
|
|
13
|
+
* a ref (`https://github.com/<owner>/<repo>/<workflow path>@<ref>`), on
|
|
14
|
+
* GitLab the CI config at a ref (`<server>/<project>//<config path>@<ref>`).
|
|
15
|
+
* A Forgejo job's certificate comes from a private authority, whose
|
|
16
|
+
* issuer and subject the project names itself.
|
|
17
|
+
*/
|
|
18
|
+
/** The trusted root an init points `keyless.trustedRoot` at, unless told. */
|
|
19
|
+
export declare const DEFAULT_TRUSTED_ROOT_PATH = ".chant/trusted_root.json";
|
|
20
|
+
/** One entry of `keyless.identities`. */
|
|
21
|
+
export interface KeylessIdentityEntry {
|
|
22
|
+
principal: string;
|
|
23
|
+
class: "runner" | "service";
|
|
24
|
+
issuer: string;
|
|
25
|
+
subject: string;
|
|
26
|
+
}
|
|
27
|
+
export interface CiRunnerIdentityInput {
|
|
28
|
+
forge: "github" | "gitlab" | "forgejo";
|
|
29
|
+
/** `owner/repo` on GitHub and Forgejo, the project path on GitLab. */
|
|
30
|
+
repository: string;
|
|
31
|
+
/** The workflow file (GitHub, Forgejo), such as `.github/workflows/chant-pr.yml`, or the CI config path (GitLab, default `.gitlab-ci.yml`). A `*` matches within the file name. */
|
|
32
|
+
workflow?: string;
|
|
33
|
+
/** The ref the job runs at. Default `refs/heads/main`. A pull request job runs at another ref, such as `refs/pull/*\/merge`. */
|
|
34
|
+
ref?: string;
|
|
35
|
+
/** The forge's URL. Default `https://github.com` or `https://gitlab.com`; required on Forgejo. */
|
|
36
|
+
server?: string;
|
|
37
|
+
/** The OIDC issuer. Default GitHub's or the GitLab server; required on Forgejo. */
|
|
38
|
+
issuer?: string;
|
|
39
|
+
/** The subject pattern, instead of the one the forge's job would have. Required on Forgejo. */
|
|
40
|
+
subject?: string;
|
|
41
|
+
/** Default `ci`. */
|
|
42
|
+
principal?: string;
|
|
43
|
+
}
|
|
44
|
+
/** The `keyless.identities` entry for the generated workflow's jobs on `forge`. Throws when the forge's identity cannot be worked out. */
|
|
45
|
+
export declare function ciRunnerIdentity(input: CiRunnerIdentityInput): KeylessIdentityEntry;
|
|
46
|
+
/**
|
|
47
|
+
* `.chant/trust.json`'s text (or none, for a new file) with `identity` under
|
|
48
|
+
* `keyless.identities` and its principal in `roles.runner`. An identity
|
|
49
|
+
* with the same issuer and subject is not added twice. `trustedRoot` is
|
|
50
|
+
* written when the file sets none. Throws when the result is not a valid
|
|
51
|
+
* trust config.
|
|
52
|
+
*/
|
|
53
|
+
export declare function withRunnerIdentity(text: string | undefined, identity: KeylessIdentityEntry, opts?: {
|
|
54
|
+
trustedRoot?: string;
|
|
55
|
+
}): string;
|
|
56
|
+
//# sourceMappingURL=runner-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-identity.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/runner-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,6EAA6E;AAC7E,eAAO,MAAM,yBAAyB,6BAA6B,CAAC;AAEpE,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IACvC,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,mLAAmL;IACnL,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gIAAgI;IAChI,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kGAAkG;IAClG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,0IAA0I;AAC1I,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,oBAAoB,CAiBnF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,oBAAoB,EAAE,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAaxI"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runner identity an init writes into `.chant/trust.json` (#4869).
|
|
3
|
+
*
|
|
4
|
+
* None of the CI products' inits wrote `.chant/trust.json`, a runner key
|
|
5
|
+
* or an identity, so a keyless runner had nowhere to come from. These are
|
|
6
|
+
* the pieces an init calls: {@link ciRunnerIdentity} names the identity the
|
|
7
|
+
* generated workflow signs as, on the forge it runs on, and
|
|
8
|
+
* {@link withRunnerIdentity} adds it to the file's text under `keyless`,
|
|
9
|
+
* with the principal in `roles.runner`, which ci tags and Op runs need.
|
|
10
|
+
*
|
|
11
|
+
* The subject is the certificate's subject alternative name the
|
|
12
|
+
* certificate authority writes for that job: on GitHub the workflow file at
|
|
13
|
+
* a ref (`https://github.com/<owner>/<repo>/<workflow path>@<ref>`), on
|
|
14
|
+
* GitLab the CI config at a ref (`<server>/<project>//<config path>@<ref>`).
|
|
15
|
+
* A Forgejo job's certificate comes from a private authority, whose
|
|
16
|
+
* issuer and subject the project names itself.
|
|
17
|
+
*/
|
|
18
|
+
import { trustConfigSchema } from "./policy.js";
|
|
19
|
+
/** The trusted root an init points `keyless.trustedRoot` at, unless told. */
|
|
20
|
+
export const DEFAULT_TRUSTED_ROOT_PATH = ".chant/trusted_root.json";
|
|
21
|
+
const trim = (u) => u.replace(/\/+$/, "");
|
|
22
|
+
/** The `keyless.identities` entry for the generated workflow's jobs on `forge`. Throws when the forge's identity cannot be worked out. */
|
|
23
|
+
export function ciRunnerIdentity(input) {
|
|
24
|
+
const ref = input.ref ?? "refs/heads/main";
|
|
25
|
+
const principal = input.principal ?? "ci";
|
|
26
|
+
if (!/^[^\s/][^\s]*\/[^\s]+$/.test(input.repository))
|
|
27
|
+
throw new Error(`repository ${JSON.stringify(input.repository)} is not an owner/name path`);
|
|
28
|
+
if (input.forge === "github") {
|
|
29
|
+
if (!input.workflow)
|
|
30
|
+
throw new Error("a GitHub runner identity names its workflow file, such as .github/workflows/chant-pr.yml");
|
|
31
|
+
const server = trim(input.server ?? "https://github.com");
|
|
32
|
+
return { principal, class: "runner", issuer: input.issuer ?? "https://token.actions.githubusercontent.com", subject: input.subject ?? `${server}/${input.repository}/${input.workflow}@${ref}` };
|
|
33
|
+
}
|
|
34
|
+
if (input.forge === "gitlab") {
|
|
35
|
+
const server = trim(input.server ?? "https://gitlab.com");
|
|
36
|
+
return { principal, class: "runner", issuer: input.issuer ?? server, subject: input.subject ?? `${server}/${input.repository}//${input.workflow ?? ".gitlab-ci.yml"}@${ref}` };
|
|
37
|
+
}
|
|
38
|
+
if (!input.issuer || !input.subject) {
|
|
39
|
+
throw new Error("a Forgejo job's certificate comes from the certificate authority the project runs, so its runner identity names that authority's issuer and the subject it writes");
|
|
40
|
+
}
|
|
41
|
+
return { principal, class: "runner", issuer: input.issuer, subject: input.subject };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `.chant/trust.json`'s text (or none, for a new file) with `identity` under
|
|
45
|
+
* `keyless.identities` and its principal in `roles.runner`. An identity
|
|
46
|
+
* with the same issuer and subject is not added twice. `trustedRoot` is
|
|
47
|
+
* written when the file sets none. Throws when the result is not a valid
|
|
48
|
+
* trust config.
|
|
49
|
+
*/
|
|
50
|
+
export function withRunnerIdentity(text, identity, opts = {}) {
|
|
51
|
+
const config = text === undefined || text.trim() === "" ? { schema: 1 } : JSON.parse(text);
|
|
52
|
+
const keyless = config.keyless ?? { trustedRoot: opts.trustedRoot ?? DEFAULT_TRUSTED_ROOT_PATH, identities: [] };
|
|
53
|
+
if (!keyless.identities.some((i) => i.issuer === identity.issuer && i.subject === identity.subject))
|
|
54
|
+
keyless.identities = [...keyless.identities, identity];
|
|
55
|
+
const runners = config.roles?.runner ?? [];
|
|
56
|
+
const next = {
|
|
57
|
+
...config,
|
|
58
|
+
roles: { ...(config.roles ?? {}), runner: runners.includes(identity.principal) ? runners : [...runners, identity.principal] },
|
|
59
|
+
keyless,
|
|
60
|
+
};
|
|
61
|
+
const parsed = trustConfigSchema.safeParse(next);
|
|
62
|
+
if (!parsed.success)
|
|
63
|
+
throw new Error(`the trust config with the runner identity is invalid: ${parsed.error.issues.map((i) => `${i.path.join(".") || "/"}: ${i.message}`).join("; ")}`);
|
|
64
|
+
return `${JSON.stringify(next, null, 2)}\n`;
|
|
65
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trust-files.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/trust-files.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,0GAA0G;AAC1G,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;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xC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,4DAA4D;AAC5D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,cAAc,EAAE,CAAC;CAC5B;AAmDD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAkD3D;AAED,8FAA8F;AAC9F,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAM9D;AASD,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAElD;AAOD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAiH1D"}
|
|
@@ -175,7 +175,7 @@ export function trustConfigProblems(raw) {
|
|
|
175
175
|
if (!ok)
|
|
176
176
|
problems.push(`${field}: ${message}`);
|
|
177
177
|
};
|
|
178
|
-
check("/", only(raw, ["schema", "signers", "roles", "adopted", "runners", "passkeys", "admitted", "refs", "local"]), "unknown key");
|
|
178
|
+
check("/", only(raw, ["schema", "signers", "roles", "adopted", "runners", "keyless", "passkeys", "admitted", "refs", "local"]), "unknown key");
|
|
179
179
|
check("schema", raw.schema === 1, "expected 1");
|
|
180
180
|
check("signers", optional(raw.signers, isRepoPath), "a path inside the repository, with / separators and no ..");
|
|
181
181
|
check("roles", optional(raw.roles, (r) => isObject(r) && Object.entries(r).every(([k, v]) => /^[a-z][a-z0-9-]*$/.test(k) && Array.isArray(v) && v.every(nonEmpty))), "role names to lists of principals");
|
|
@@ -183,6 +183,13 @@ export function trustConfigProblems(raw) {
|
|
|
183
183
|
a.every((e) => isObject(e) && only(e, ["from", "to", "note"]) && optional(e.from, (f) => typeof f === "string" && FULL_COMMIT.test(f)) && typeof e.to === "string" && FULL_COMMIT.test(e.to) && optional(e.note, (n) => typeof n === "string"))), "commit ranges of full commit ids");
|
|
184
184
|
check("runners", optional(raw.runners, (a) => Array.isArray(a) &&
|
|
185
185
|
a.every((e) => isObject(e) && only(e, ["principal", "class", "key"]) && nonEmpty(e.principal) && (e.class === "runner" || e.class === "service") && typeof e.key === "string" && SSH_ED25519.test(e.key))), "runner keys: a principal, a class and an ssh-ed25519 key");
|
|
186
|
+
const httpUrl = (v) => typeof v === "string" && /^https?:\/\/[^\s]+$/.test(v);
|
|
187
|
+
check("keyless", optional(raw.keyless, (k) => isObject(k) && only(k, ["trustedRoot", "identities", "since", "fulcio", "timestamp", "audience"]) &&
|
|
188
|
+
isRepoPath(k.trustedRoot) &&
|
|
189
|
+
optional(k.since, (f) => typeof f === "string" && FULL_COMMIT.test(f)) &&
|
|
190
|
+
optional(k.fulcio, httpUrl) && optional(k.timestamp, httpUrl) && optional(k.audience, nonEmpty) &&
|
|
191
|
+
Array.isArray(k.identities) && k.identities.length > 0 &&
|
|
192
|
+
k.identities.every((e) => isObject(e) && only(e, ["principal", "class", "issuer", "subject"]) && nonEmpty(e.principal) && (e.class === "runner" || e.class === "service") && httpUrl(e.issuer) && nonEmpty(e.subject))), "keyless identities (#4869): a trusted root path and identities, each a principal, a class, an issuer URL and a subject pattern");
|
|
186
193
|
const b64url = (v) => typeof v === "string" && /^[A-Za-z0-9_-]+$/.test(v);
|
|
187
194
|
check("passkeys", optional(raw.passkeys, (a) => Array.isArray(a) &&
|
|
188
195
|
a.every((e) => isObject(e) && only(e, ["principal", "id", "publicKey", "rpId", "origins"]) &&
|
package/package.json
CHANGED
package/src/ci-evidence-jobs.ts
CHANGED
|
@@ -22,8 +22,13 @@
|
|
|
22
22
|
* - A product's check job runs `chant ci check` with the key in
|
|
23
23
|
* `CHANT_RUNNER_KEY`; the check runner signs each hook (./components/check-steps.ts).
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
* identity:
|
|
25
|
+
* With `identity: "oidc"` (#4869) the same steps sign keyless from the
|
|
26
|
+
* job's OIDC identity: no secret, `CHANT_RUNNER_IDENTITY=oidc` on the
|
|
27
|
+
* signing step, and the job asks the forge for a token, so no product adds
|
|
28
|
+
* that itself: `id-token: write` on GitHub (Forgejo's dialect turns it into
|
|
29
|
+
* `enable-openid-connect: true`), and on GitLab `id_tokens:` with
|
|
30
|
+
* `CHANT_ID_TOKEN_SIGSTORE` for the signing audience. `.chant/trust.json`
|
|
31
|
+
* at base lists the workflow's identity under `keyless`.
|
|
27
32
|
*/
|
|
28
33
|
|
|
29
34
|
import type { ForgeKind } from "./pr-forge";
|
|
@@ -31,24 +36,57 @@ import type { ForgeKind } from "./pr-forge";
|
|
|
31
36
|
/** The variable the signing steps read the key from. */
|
|
32
37
|
export const EVIDENCE_KEY_ENV = "CHANT_RUNNER_KEY";
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
/** The variable that makes a signing step sign keyless (#4869). */
|
|
40
|
+
export const EVIDENCE_IDENTITY_ENV = "CHANT_RUNNER_IDENTITY";
|
|
35
41
|
|
|
36
|
-
/**
|
|
42
|
+
/** The GitLab `id_tokens` variable a keyless signing job's token comes in (#4869). */
|
|
43
|
+
export const EVIDENCE_ID_TOKEN_VAR = "CHANT_ID_TOKEN_SIGSTORE";
|
|
44
|
+
|
|
45
|
+
/** The audience a keyless signing job's token is requested for unless told: sigstore's. */
|
|
46
|
+
export const EVIDENCE_DEFAULT_AUDIENCE = "sigstore";
|
|
47
|
+
|
|
48
|
+
export { CHECK_EVIDENCE_FLOOR, KEYLESS_EVIDENCE_FLOOR, LOCAL_EVIDENCE_FLOOR } from "./release-floors";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A pipeline's runner identity (#4870): a runner key's secret, or (#4869)
|
|
52
|
+
* the job's own OIDC identity. Exactly one.
|
|
53
|
+
*/
|
|
37
54
|
export interface PipelineEvidence {
|
|
38
55
|
/** The secret (GitHub, Forgejo) or CI/CD variable (GitLab) holding the runner key as PEM. */
|
|
39
|
-
runnerKeySecret
|
|
56
|
+
runnerKeySecret?: string;
|
|
57
|
+
/** `oidc` (#4869): sign keyless from the job's OIDC identity, which `.chant/trust.json` at base lists under `keyless.identities`. */
|
|
58
|
+
identity?: "oidc";
|
|
59
|
+
/** With `identity`: the token's audience, as `keyless.audience` in `.chant/trust.json` says. Default `sigstore`. */
|
|
60
|
+
audience?: string;
|
|
40
61
|
}
|
|
41
62
|
|
|
42
63
|
const SECRET_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
43
64
|
|
|
44
|
-
/** Refuse a secret name the forge could not hold. */
|
|
65
|
+
/** Refuse a secret name the forge could not hold, and an evidence block that names both identities or neither. */
|
|
45
66
|
export function assertPipelineEvidence(evidence: PipelineEvidence | undefined): void {
|
|
46
67
|
if (evidence === undefined) return;
|
|
68
|
+
if (evidence.identity !== undefined) {
|
|
69
|
+
if (evidence.runnerKeySecret !== undefined) throw new Error("evidence names a runnerKeySecret and an identity; a pipeline signs with one of them (#4869)");
|
|
70
|
+
if (evidence.identity !== "oidc") throw new Error(`evidence.identity ${JSON.stringify(evidence.identity)} is not oidc, the one identity chant signs with keyless`);
|
|
71
|
+
if (evidence.audience !== undefined && !/^[\x21-\x7e]+$/.test(evidence.audience)) throw new Error(`evidence.audience ${JSON.stringify(evidence.audience)} is not printable ASCII with no space`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
47
74
|
if (!SECRET_NAME.test(evidence.runnerKeySecret ?? "")) throw new Error(`evidence.runnerKeySecret ${JSON.stringify(evidence.runnerKeySecret)} is not a secret name: letters, digits and _, not starting with a digit`);
|
|
48
75
|
}
|
|
49
76
|
|
|
50
|
-
/**
|
|
77
|
+
/** Whether the pipeline signs keyless (#4869), so its signing jobs ask the forge for an OIDC token. */
|
|
78
|
+
export function evidenceKeyless(evidence: PipelineEvidence | undefined): boolean {
|
|
79
|
+
return evidence?.identity === "oidc";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The GitLab `id_tokens:` a keyless signing job requests (#4869); empty with a runner key. */
|
|
83
|
+
export function evidenceIdTokens(evidence: PipelineEvidence | undefined): Record<string, { aud: string }> {
|
|
84
|
+
return evidenceKeyless(evidence) ? { [EVIDENCE_ID_TOKEN_VAR]: { aud: evidence!.audience ?? EVIDENCE_DEFAULT_AUDIENCE } } : {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The signing step's variables: the key from the forge's secret, or (#4869) `CHANT_RUNNER_IDENTITY=oidc`. */
|
|
51
88
|
export function evidenceKeyEnv(forge: ForgeKind, evidence: PipelineEvidence): Record<string, string> {
|
|
89
|
+
if (evidenceKeyless(evidence)) return { [EVIDENCE_IDENTITY_ENV]: "oidc" };
|
|
52
90
|
return { [EVIDENCE_KEY_ENV]: forge === "gitlab" ? `$${evidence.runnerKeySecret}` : `\${{ secrets.${evidence.runnerKeySecret} }}` };
|
|
53
91
|
}
|
|
54
92
|
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
* failed. See `../../components/check-hooks.ts` and
|
|
11
11
|
* `../../components/check-steps.ts`.
|
|
12
12
|
*
|
|
13
|
-
* With a runner key in `CHANT_RUNNER_KEY` (#4870),
|
|
13
|
+
* With a runner key in `CHANT_RUNNER_KEY` (#4870), or `CHANT_RUNNER_IDENTITY=oidc`
|
|
14
|
+
* to sign keyless from the job's OIDC identity (#4869), each hook that passed is
|
|
14
15
|
* signed as a named check over `HEAD` and attached under `refs/notes/chant/evidence`, which
|
|
15
|
-
* is pushed unless `--no-push`; the key
|
|
16
|
+
* is pushed unless `--no-push`; neither the key nor the token request reaches a hook.
|
|
16
17
|
*
|
|
17
18
|
* #4868: with a local key in `CHANT_LOCAL_EVIDENCE_KEY` (a developer's or an
|
|
18
19
|
* agent session's, listed under `local.keys` at base) each hook that passed
|
|
@@ -47,24 +48,27 @@ async function lexiconCheckSteps(ctx: CommandContext, cwd: string): Promise<Chec
|
|
|
47
48
|
const USAGE = "chant ci check --base <rev> [<target>...] [--output <dir>] [--no-push] [--json]";
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
|
-
* The check stage's signer (#4870), when the job
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* The check stage's signer (#4870), when the job has a runner identity: a
|
|
52
|
+
* runner key in `CHANT_RUNNER_KEY`, or its OIDC identity with
|
|
53
|
+
* `CHANT_RUNNER_IDENTITY=oidc` (#4869), as `.chant/trust.json` at `base`
|
|
54
|
+
* lists it. Throws when the job has one and the policy at base does not
|
|
55
|
+
* list it, so a job asked to sign never passes while signing nothing.
|
|
54
56
|
*/
|
|
55
57
|
async function checkEvidenceSigner(base: string, noPush: boolean): Promise<CheckStageEvidence | undefined> {
|
|
56
|
-
const { CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV } = await import("../../workspace/trust/check-evidence-report");
|
|
57
|
-
const
|
|
58
|
+
const { CHECK_EVIDENCE_KEY_ENV, LOCAL_EVIDENCE_KEY_ENV, RUNNER_IDENTITY_ENV } = await import("../../workspace/trust/check-evidence-report");
|
|
59
|
+
const runner = process.env[CHECK_EVIDENCE_KEY_ENV] || process.env[RUNNER_IDENTITY_ENV];
|
|
58
60
|
const localPem = process.env[LOCAL_EVIDENCE_KEY_ENV];
|
|
59
|
-
if (!
|
|
60
|
-
if (
|
|
61
|
+
if (!runner && !localPem) return undefined;
|
|
62
|
+
if (runner && localPem) throw new Error(`${process.env[CHECK_EVIDENCE_KEY_ENV] ? CHECK_EVIDENCE_KEY_ENV : RUNNER_IDENTITY_ENV} and ${LOCAL_EVIDENCE_KEY_ENV} are both set; a job signs as a runner or as a person or agent, never both`);
|
|
61
63
|
const { top, commit } = await baseCommit(base);
|
|
62
64
|
if (localPem) {
|
|
63
65
|
const { localKeyEvidenceSigner } = await import("../../workspace/trust/local-evidence");
|
|
64
66
|
return { signer: localKeyEvidenceSigner(top, commit, localPem), ...(noPush ? { push: false } : {}) };
|
|
65
67
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
// #4869: the runner key, or the job's OIDC identity, read in one place.
|
|
69
|
+
const { runnerEvidenceSigner } = await import("../../workspace/trust/check-evidence");
|
|
70
|
+
const signer = await runnerEvidenceSigner(top, commit);
|
|
71
|
+
return signer ? { signer, ...(noPush ? { push: false } : {}) } : undefined;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
async function baseCommit(base: string): Promise<{ top: string; commit: string }> {
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* - `sign --check-id <id>[,<id>...]` signs that each check passed at `--at`
|
|
8
8
|
* (default `HEAD`), with the runner key in `--key <file>` or
|
|
9
|
-
* `CHANT_RUNNER_KEY`,
|
|
9
|
+
* `CHANT_RUNNER_KEY`, or keyless from the job's OIDC identity with
|
|
10
|
+
* `CHANT_RUNNER_IDENTITY=oidc` (#4869), and pushes the notes unless
|
|
11
|
+
* `--no-push`.
|
|
10
12
|
* - `sign --from-report <dir> --result <result>` is the plan note job's
|
|
11
13
|
* form: it signs `plan` when the plan job succeeded and left a report in
|
|
12
14
|
* `<dir>`, and `policy` when the policy evaluated inside that plan did not
|
|
@@ -17,7 +19,7 @@
|
|
|
17
19
|
* and verifies it against the runner keys at `--base`; exits 1 when one
|
|
18
20
|
* is not current.
|
|
19
21
|
*
|
|
20
|
-
* Without a runner
|
|
22
|
+
* Without a runner identity, `sign` signs nothing and says so: a project that
|
|
21
23
|
* declares no runner identity gets the same job it had.
|
|
22
24
|
*
|
|
23
25
|
* `--local` (#4868) is the developer's or agent session's form: `sign
|
|
@@ -34,9 +36,11 @@ import { gitRoot } from "../../workspace/record-source";
|
|
|
34
36
|
import { resolveBase } from "../../workspace/trust/provenance";
|
|
35
37
|
import {
|
|
36
38
|
CHECK_EVIDENCE_KEY_ENV,
|
|
39
|
+
noRunnerIdentity,
|
|
37
40
|
readCheckEvidence,
|
|
38
41
|
recordChecks,
|
|
39
|
-
|
|
42
|
+
RUNNER_IDENTITY_ENV,
|
|
43
|
+
runnerEvidenceSigner,
|
|
40
44
|
signChecks,
|
|
41
45
|
type EvidenceSigner,
|
|
42
46
|
} from "../../workspace/trust/check-evidence";
|
|
@@ -111,6 +115,7 @@ async function sign(ctx: CommandContext, repo: string, base: string, at: string)
|
|
|
111
115
|
const fromReport = args.fromReport;
|
|
112
116
|
if (!fromReport && idsOf(args.checkId).length === 0) return usage("sign needs --check-id <id>, or --from-report <dir> in a plan note job");
|
|
113
117
|
const pem = args.key ? readFileSync(args.key, "utf-8") : process.env[CHECK_EVIDENCE_KEY_ENV];
|
|
118
|
+
const identity = pem !== undefined && pem !== "" ? "key" : process.env[RUNNER_IDENTITY_ENV] ? "oidc" : undefined;
|
|
114
119
|
const note: CheckEvidenceNote = { signed: [], skipped: [] };
|
|
115
120
|
let wanted: Array<{ check: string; claim?: Buffer | string }>;
|
|
116
121
|
if (fromReport) {
|
|
@@ -126,21 +131,21 @@ async function sign(ctx: CommandContext, repo: string, base: string, at: string)
|
|
|
126
131
|
if (args.json) console.log(JSON.stringify(note, null, 2));
|
|
127
132
|
return code;
|
|
128
133
|
};
|
|
129
|
-
if (!
|
|
130
|
-
note.skipped.push(...wanted.map((w) => ({ check: w.check, reason:
|
|
131
|
-
console.error(`ci evidence:
|
|
134
|
+
if (!identity) {
|
|
135
|
+
note.skipped.push(...wanted.map((w) => ({ check: w.check, reason: noRunnerIdentity() })));
|
|
136
|
+
console.error(`ci evidence: ${noRunnerIdentity()}, so no check was signed`);
|
|
132
137
|
return finish(CHANT_EXIT.done);
|
|
133
138
|
}
|
|
134
139
|
let signer: EvidenceSigner;
|
|
135
140
|
try {
|
|
136
|
-
signer =
|
|
141
|
+
signer = (await runnerEvidenceSigner(repo, base, pem ? { key: pem } : {}))!;
|
|
137
142
|
} catch (err) {
|
|
138
143
|
console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: USAGE }));
|
|
139
144
|
return finish(CHANT_EXIT.failed);
|
|
140
145
|
}
|
|
141
146
|
for (const s of note.skipped) console.error(`ci evidence: ${s.check} not signed: ${s.reason}`);
|
|
142
147
|
if (wanted.length === 0) return finish(CHANT_EXIT.done);
|
|
143
|
-
const signed = signChecks(repo, at, wanted, signer);
|
|
148
|
+
const signed = await signChecks(repo, at, wanted, signer);
|
|
144
149
|
const pushed = await recordChecks(repo, signed, { push: !args.noPush });
|
|
145
150
|
for (const s of signed) {
|
|
146
151
|
note.signed.push({ check: s.check, runner: s.runner, commit: s.commit, tree: s.tree });
|