@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
|
@@ -26,6 +26,9 @@ import { z } from "zod";
|
|
|
26
26
|
import type { RecordSource } from "../record-source";
|
|
27
27
|
import { DEFAULT_SIGNERS_PATH, TRUST_CONFIG_PATH, parseAllowedSigners, type ExcludedSigner, type Signer } from "./trust-files";
|
|
28
28
|
import type { PasskeySigner } from "../../lifecycle/gate-webauthn";
|
|
29
|
+
import { execFileSync } from "node:child_process";
|
|
30
|
+
import { DEFAULT_FULCIO_URL, DEFAULT_SIGNING_AUDIENCE, DEFAULT_TIMESTAMP_URL, keylessVerifier, parseTrustedRoot, type KeylessRoots } from "./keyless";
|
|
31
|
+
import type { DsseSignature, KeylessCheck } from "./dsse";
|
|
29
32
|
|
|
30
33
|
export {
|
|
31
34
|
DEFAULT_SIGNERS_PATH,
|
|
@@ -49,6 +52,9 @@ const repoPath = z
|
|
|
49
52
|
message: "a path inside the repository, with / separators and no ..",
|
|
50
53
|
});
|
|
51
54
|
|
|
55
|
+
/** An http or https URL (#4869): an OIDC issuer, a certificate or timestamp authority. */
|
|
56
|
+
const httpUrl = z.string().regex(/^https?:\/\/[^\s]+$/, "an http or https URL");
|
|
57
|
+
|
|
52
58
|
/** A check name a ref rule requires (#4867): it is also part of an override's subject. */
|
|
53
59
|
export const REF_CHECK_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
54
60
|
/** A ref pattern (#4867): a full ref name, where `*` matches within one `/` segment and `**` matches across them. */
|
|
@@ -102,6 +108,40 @@ export const trustConfigSchema = z
|
|
|
102
108
|
.strict(),
|
|
103
109
|
)
|
|
104
110
|
.optional(),
|
|
111
|
+
/**
|
|
112
|
+
* CI identities that sign runner statements keyless (#4869): each an
|
|
113
|
+
* OIDC issuer and a pattern over the subject alternative name of the
|
|
114
|
+
* certificate the job's token was traded for, which names the
|
|
115
|
+
* repository, the workflow and the ref. `trustedRoot` is a file in
|
|
116
|
+
* sigstore's `trusted_root.json` format with the certificate and
|
|
117
|
+
* timestamp authorities. `fulcio`, `timestamp` and `audience` tell a
|
|
118
|
+
* signing job where to trade its token; sigstore's public instances by
|
|
119
|
+
* default. With `since`, a statement over that commit or any commit not
|
|
120
|
+
* a strict ancestor of it counts only when signed keyless; a runner key's
|
|
121
|
+
* statement over an earlier commit still counts.
|
|
122
|
+
*/
|
|
123
|
+
keyless: z
|
|
124
|
+
.object({
|
|
125
|
+
trustedRoot: repoPath,
|
|
126
|
+
identities: z
|
|
127
|
+
.array(
|
|
128
|
+
z
|
|
129
|
+
.object({
|
|
130
|
+
principal: z.string().min(1),
|
|
131
|
+
class: z.enum(["runner", "service"]),
|
|
132
|
+
issuer: httpUrl,
|
|
133
|
+
subject: z.string().min(1),
|
|
134
|
+
})
|
|
135
|
+
.strict(),
|
|
136
|
+
)
|
|
137
|
+
.min(1),
|
|
138
|
+
since: fullCommit.optional(),
|
|
139
|
+
fulcio: httpUrl.optional(),
|
|
140
|
+
timestamp: httpUrl.optional(),
|
|
141
|
+
audience: z.string().min(1).optional(),
|
|
142
|
+
})
|
|
143
|
+
.strict()
|
|
144
|
+
.optional(),
|
|
105
145
|
/**
|
|
106
146
|
* Passkeys that sign gate approvals for people (#4646): a WebAuthn
|
|
107
147
|
* credential's id, its public key as base64url DER SubjectPublicKeyInfo,
|
|
@@ -256,6 +296,30 @@ export interface RunnerKey {
|
|
|
256
296
|
key: string;
|
|
257
297
|
}
|
|
258
298
|
|
|
299
|
+
/** A CI identity that signs runner statements keyless (#4869), with the trusted root it is verified against. */
|
|
300
|
+
export interface RunnerIdentity {
|
|
301
|
+
principal: string;
|
|
302
|
+
class: "runner" | "service";
|
|
303
|
+
issuer: string;
|
|
304
|
+
/** A pattern over the certificate's subject alternative name: `*` within a `/` segment, `**` across. */
|
|
305
|
+
subject: string;
|
|
306
|
+
roots: KeylessRoots;
|
|
307
|
+
/** Verifies one keyless signature against this identity and its trusted root (./dsse.ts's `TrustedIdentity`). */
|
|
308
|
+
verifyKeyless(message: Buffer, signature: DsseSignature): KeylessCheck;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** A runner as a statement's verifier takes it: a key, or a keyless identity. */
|
|
312
|
+
export type Runner = RunnerKey | RunnerIdentity;
|
|
313
|
+
|
|
314
|
+
/** Where a keyless signing job trades its token (#4869), and from which commit only keyless statements count. */
|
|
315
|
+
export interface KeylessPolicy {
|
|
316
|
+
since?: string;
|
|
317
|
+
fulcio: string;
|
|
318
|
+
timestamp: string;
|
|
319
|
+
audience: string;
|
|
320
|
+
trustedRoot: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
259
323
|
/** The policy a check applies, as read at base. */
|
|
260
324
|
export interface TrustPolicy {
|
|
261
325
|
/** The full commit id the policy was read at, or null when there is no base. */
|
|
@@ -270,6 +334,10 @@ export interface TrustPolicy {
|
|
|
270
334
|
adopted: Array<{ from?: string; to: string }>;
|
|
271
335
|
/** Runner and service keys that may sign runner evidence (#2553). */
|
|
272
336
|
runners: RunnerKey[];
|
|
337
|
+
/** CI identities that sign runner statements keyless (#4869). Absent on a policy built by hand: none. */
|
|
338
|
+
runnerIdentities?: RunnerIdentity[];
|
|
339
|
+
/** The keyless settings (#4869), when `keyless` is set and its trusted root reads. */
|
|
340
|
+
keyless?: KeylessPolicy;
|
|
273
341
|
/** Runner entries that are not used, and why. */
|
|
274
342
|
excludedRunners: Array<{ principal: string; reason: string }>;
|
|
275
343
|
/** Passkeys that sign people's gate approvals (#4646). Absent on a policy built by hand: none. */
|
|
@@ -296,10 +364,37 @@ export interface TrustPolicy {
|
|
|
296
364
|
signersAt?: (commit: string) => { version: number; signers: Signer[] } | null;
|
|
297
365
|
}
|
|
298
366
|
|
|
299
|
-
/** Paths whose change is a protected write under `policy`: the config, the signers file and its rotation file (#2553). */
|
|
367
|
+
/** 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). */
|
|
300
368
|
export function protectedPaths(policy: TrustPolicy): string[] {
|
|
301
369
|
const s = policy.signersPath;
|
|
302
|
-
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`)])].sort();
|
|
370
|
+
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`), ...(policy.keyless ? [policy.keyless.trustedRoot] : [])])].sort();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The runners whose statements over `commit` count (#4869): the runner keys
|
|
375
|
+
* and the keyless identities. With `keyless.since`, a runner key counts
|
|
376
|
+
* only for a commit that is a strict ancestor of `since`, the way
|
|
377
|
+
* `ci.green.signedSince` judges tags by position in history; a `since` the
|
|
378
|
+
* clone does not have leaves the keys out. Without `at`, under `since`, only
|
|
379
|
+
* the identities.
|
|
380
|
+
*/
|
|
381
|
+
export function runnersAt(policy: TrustPolicy, at?: { repo: string; commit: string }): Runner[] {
|
|
382
|
+
const ids = policy.runnerIdentities ?? [];
|
|
383
|
+
const since = policy.keyless?.since;
|
|
384
|
+
if (!since) return [...policy.runners, ...ids];
|
|
385
|
+
if (!at || !strictAncestor(at.repo, at.commit, since)) return ids;
|
|
386
|
+
return [...policy.runners, ...ids];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function strictAncestor(repo: string, commit: string, of: string): boolean {
|
|
390
|
+
try {
|
|
391
|
+
const full = execFileSync("git", ["rev-parse", "--verify", "--quiet", `${commit}^{commit}`], { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
392
|
+
if (full === of) return false;
|
|
393
|
+
execFileSync("git", ["merge-base", "--is-ancestor", full, of], { cwd: repo, stdio: "ignore" });
|
|
394
|
+
return true;
|
|
395
|
+
} catch {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
303
398
|
}
|
|
304
399
|
|
|
305
400
|
/** Principals allowed to change the policy: the admins when any are granted, otherwise every signer. */
|
|
@@ -355,6 +450,7 @@ export function readTrustPolicy(source: RecordSource, base: string | null): Trus
|
|
|
355
450
|
runners.push(r);
|
|
356
451
|
}
|
|
357
452
|
}
|
|
453
|
+
const { runnerIdentities, keyless } = keylessOf(config, source, humanNames, excludedRunners);
|
|
358
454
|
return {
|
|
359
455
|
base,
|
|
360
456
|
signersPath,
|
|
@@ -365,6 +461,7 @@ export function readTrustPolicy(source: RecordSource, base: string | null): Trus
|
|
|
365
461
|
adopted: config.adopted ?? [],
|
|
366
462
|
runners,
|
|
367
463
|
excludedRunners,
|
|
464
|
+
...(keyless ? { runnerIdentities, keyless } : {}),
|
|
368
465
|
passkeys: config.passkeys ?? [],
|
|
369
466
|
admitted: admittedOf(config),
|
|
370
467
|
refs: (config.refs ?? []).map((r) => ({ ...r, checks: r.checks.map((c) => ({ ...c, action: c.action ?? "block" })) })),
|
|
@@ -387,6 +484,36 @@ function localOf(config: TrustConfig, runners: readonly RunnerKey[]): LocalEvide
|
|
|
387
484
|
return { keys, excluded, checks: (config.local?.checks ?? []).map((c) => ({ check: c.check, from: c.from ?? ["person"] })) };
|
|
388
485
|
}
|
|
389
486
|
|
|
487
|
+
/**
|
|
488
|
+
* The keyless identities (#4869), each with the trusted root read through
|
|
489
|
+
* `source`. A trusted root that cannot be read leaves every identity out,
|
|
490
|
+
* with the reason in `excluded`; the runner keys still count.
|
|
491
|
+
*/
|
|
492
|
+
function keylessOf(config: TrustConfig, source: RecordSource, humanNames: Set<string>, excluded: Array<{ principal: string; reason: string }>): { runnerIdentities: RunnerIdentity[]; keyless?: KeylessPolicy } {
|
|
493
|
+
const k = config.keyless;
|
|
494
|
+
if (!k) return { runnerIdentities: [] };
|
|
495
|
+
// Kept when the root does not read, so `since` still leaves the keys out: fail closed.
|
|
496
|
+
const keyless: KeylessPolicy = { ...(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 };
|
|
497
|
+
let roots: KeylessRoots;
|
|
498
|
+
try {
|
|
499
|
+
const text = readOptional(source, k.trustedRoot);
|
|
500
|
+
if (text === undefined) throw new Error("the file is not there");
|
|
501
|
+
roots = parseTrustedRoot(text);
|
|
502
|
+
} catch (err) {
|
|
503
|
+
for (const i of k.identities) excluded.push({ principal: i.principal, reason: `the keyless trusted root ${k.trustedRoot} cannot be read: ${err instanceof Error ? err.message : String(err)}` });
|
|
504
|
+
return { runnerIdentities: [], keyless };
|
|
505
|
+
}
|
|
506
|
+
const runnerIdentities: RunnerIdentity[] = [];
|
|
507
|
+
for (const i of k.identities) {
|
|
508
|
+
if (humanNames.has(i.principal)) excluded.push({ principal: i.principal, reason: "the signers file lists this principal; a keyless identity is a CI job's, never a signer's" });
|
|
509
|
+
else {
|
|
510
|
+
const verify = keylessVerifier({ ...i, roots });
|
|
511
|
+
runnerIdentities.push({ ...i, roots, verifyKeyless: (message, signature) => verify(message, signature) });
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return { runnerIdentities, keyless };
|
|
515
|
+
}
|
|
516
|
+
|
|
390
517
|
/** The admitted signers, by return id. Two entries for one return add up. */
|
|
391
518
|
function admittedOf(config: TrustConfig): Record<string, Signer[]> {
|
|
392
519
|
const out: Record<string, Signer[]> = {};
|
|
@@ -38,7 +38,7 @@ import { dirname, isAbsolute, join } from "node:path";
|
|
|
38
38
|
import type { ReasonCode } from "../reason-codes";
|
|
39
39
|
import { verifyEvidence, type EvidenceErrorCode } from "./evidence";
|
|
40
40
|
import { policyAtBase } from "./provenance";
|
|
41
|
-
import type
|
|
41
|
+
import { runnersAt, type RefRule, type TrustPolicy } from "./policy";
|
|
42
42
|
import {
|
|
43
43
|
OVERRIDE_APPLIED,
|
|
44
44
|
OVERRIDE_LEDGER,
|
|
@@ -256,7 +256,8 @@ function judgeCheck(repo: string, policy: TrustPolicy, envelopes: readonly unkno
|
|
|
256
256
|
let stale: string | undefined;
|
|
257
257
|
let bad: { code: EvidenceErrorCode; reason: string } | undefined;
|
|
258
258
|
for (const env of envelopes) {
|
|
259
|
-
|
|
259
|
+
// #4869: keys and keyless identities; under keyless.since, keys only for a commit before it.
|
|
260
|
+
const v = verifyEvidence(env, runnersAt(policy, { repo, commit }), repo, commit);
|
|
260
261
|
if (!v.ok) {
|
|
261
262
|
if (claimedCheck(env) === check && !bad) bad = { code: v.code, reason: v.reason };
|
|
262
263
|
continue;
|
|
@@ -30,7 +30,7 @@ import type { RunEndLine, RunStartLine, RunView } from "../runs";
|
|
|
30
30
|
import { IN_TOTO_PAYLOAD_TYPE, signEnvelope, verifyEnvelope, type DsseEnvelope } from "./dsse";
|
|
31
31
|
import { STATEMENT_TYPE } from "./evidence";
|
|
32
32
|
import type { KeyObject } from "node:crypto";
|
|
33
|
-
import type { RunnerKey } from "./policy";
|
|
33
|
+
import type { Runner, RunnerKey } from "./policy";
|
|
34
34
|
|
|
35
35
|
export const AGENT_RUN_PREDICATE = "https://intentius.io/chant/agent-run/v1";
|
|
36
36
|
|
|
@@ -138,7 +138,7 @@ const same = (a: unknown, b: unknown) => canonicalJson(a ?? null) === canonicalJ
|
|
|
138
138
|
* well-formed statement whose signer is that key's principal, for this run,
|
|
139
139
|
* and agreeing with its record. Never throws.
|
|
140
140
|
*/
|
|
141
|
-
export function verifyRunStatement(envelope: unknown, runners: readonly
|
|
141
|
+
export function verifyRunStatement(envelope: unknown, runners: readonly Runner[], run: RunView): RunStatementVerdict {
|
|
142
142
|
const v = verifyEnvelope(envelope, runners);
|
|
143
143
|
if (!v.ok) return { status: v.code === "envelope-untrusted" ? "untrusted" : "invalid", code: v.code, reason: v.reason };
|
|
144
144
|
const runner = runners.find((r) => r.principal === v.principal)!;
|
|
@@ -202,7 +202,7 @@ export interface RunAttestation {
|
|
|
202
202
|
const RANK = { mismatch: 0, untrusted: 1, invalid: 2 } as const;
|
|
203
203
|
|
|
204
204
|
/** Judge every statement the ledger holds for `run`. */
|
|
205
|
-
export function attestRun(run: RunView, runners: readonly
|
|
205
|
+
export function attestRun(run: RunView, runners: readonly Runner[]): RunAttestation {
|
|
206
206
|
const verdicts = run.statements.map((s) => verifyRunStatement(s.envelope, runners, run));
|
|
207
207
|
const good = verdicts.find((v): v is Extract<RunStatementVerdict, { status: "verified" }> => v.status === "verified");
|
|
208
208
|
if (good) {
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
|
|
19
|
+
import { trustConfigSchema, type TrustConfig } from "./policy";
|
|
20
|
+
|
|
21
|
+
/** The trusted root an init points `keyless.trustedRoot` at, unless told. */
|
|
22
|
+
export const DEFAULT_TRUSTED_ROOT_PATH = ".chant/trusted_root.json";
|
|
23
|
+
|
|
24
|
+
/** One entry of `keyless.identities`. */
|
|
25
|
+
export interface KeylessIdentityEntry {
|
|
26
|
+
principal: string;
|
|
27
|
+
class: "runner" | "service";
|
|
28
|
+
issuer: string;
|
|
29
|
+
subject: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CiRunnerIdentityInput {
|
|
33
|
+
forge: "github" | "gitlab" | "forgejo";
|
|
34
|
+
/** `owner/repo` on GitHub and Forgejo, the project path on GitLab. */
|
|
35
|
+
repository: string;
|
|
36
|
+
/** 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. */
|
|
37
|
+
workflow?: string;
|
|
38
|
+
/** The ref the job runs at. Default `refs/heads/main`. A pull request job runs at another ref, such as `refs/pull/*\/merge`. */
|
|
39
|
+
ref?: string;
|
|
40
|
+
/** The forge's URL. Default `https://github.com` or `https://gitlab.com`; required on Forgejo. */
|
|
41
|
+
server?: string;
|
|
42
|
+
/** The OIDC issuer. Default GitHub's or the GitLab server; required on Forgejo. */
|
|
43
|
+
issuer?: string;
|
|
44
|
+
/** The subject pattern, instead of the one the forge's job would have. Required on Forgejo. */
|
|
45
|
+
subject?: string;
|
|
46
|
+
/** Default `ci`. */
|
|
47
|
+
principal?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const trim = (u: string): string => u.replace(/\/+$/, "");
|
|
51
|
+
|
|
52
|
+
/** The `keyless.identities` entry for the generated workflow's jobs on `forge`. Throws when the forge's identity cannot be worked out. */
|
|
53
|
+
export function ciRunnerIdentity(input: CiRunnerIdentityInput): KeylessIdentityEntry {
|
|
54
|
+
const ref = input.ref ?? "refs/heads/main";
|
|
55
|
+
const principal = input.principal ?? "ci";
|
|
56
|
+
if (!/^[^\s/][^\s]*\/[^\s]+$/.test(input.repository)) throw new Error(`repository ${JSON.stringify(input.repository)} is not an owner/name path`);
|
|
57
|
+
if (input.forge === "github") {
|
|
58
|
+
if (!input.workflow) throw new Error("a GitHub runner identity names its workflow file, such as .github/workflows/chant-pr.yml");
|
|
59
|
+
const server = trim(input.server ?? "https://github.com");
|
|
60
|
+
return { principal, class: "runner", issuer: input.issuer ?? "https://token.actions.githubusercontent.com", subject: input.subject ?? `${server}/${input.repository}/${input.workflow}@${ref}` };
|
|
61
|
+
}
|
|
62
|
+
if (input.forge === "gitlab") {
|
|
63
|
+
const server = trim(input.server ?? "https://gitlab.com");
|
|
64
|
+
return { principal, class: "runner", issuer: input.issuer ?? server, subject: input.subject ?? `${server}/${input.repository}//${input.workflow ?? ".gitlab-ci.yml"}@${ref}` };
|
|
65
|
+
}
|
|
66
|
+
if (!input.issuer || !input.subject) {
|
|
67
|
+
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");
|
|
68
|
+
}
|
|
69
|
+
return { principal, class: "runner", issuer: input.issuer, subject: input.subject };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* `.chant/trust.json`'s text (or none, for a new file) with `identity` under
|
|
74
|
+
* `keyless.identities` and its principal in `roles.runner`. An identity
|
|
75
|
+
* with the same issuer and subject is not added twice. `trustedRoot` is
|
|
76
|
+
* written when the file sets none. Throws when the result is not a valid
|
|
77
|
+
* trust config.
|
|
78
|
+
*/
|
|
79
|
+
export function withRunnerIdentity(text: string | undefined, identity: KeylessIdentityEntry, opts: { trustedRoot?: string } = {}): string {
|
|
80
|
+
const config: TrustConfig = text === undefined || text.trim() === "" ? { schema: 1 } : (JSON.parse(text) as TrustConfig);
|
|
81
|
+
const keyless = config.keyless ?? { trustedRoot: opts.trustedRoot ?? DEFAULT_TRUSTED_ROOT_PATH, identities: [] };
|
|
82
|
+
if (!keyless.identities.some((i) => i.issuer === identity.issuer && i.subject === identity.subject)) keyless.identities = [...keyless.identities, identity];
|
|
83
|
+
const runners = config.roles?.runner ?? [];
|
|
84
|
+
const next: TrustConfig = {
|
|
85
|
+
...config,
|
|
86
|
+
roles: { ...(config.roles ?? {}), runner: runners.includes(identity.principal) ? runners : [...runners, identity.principal] },
|
|
87
|
+
keyless,
|
|
88
|
+
};
|
|
89
|
+
const parsed = trustConfigSchema.safeParse(next);
|
|
90
|
+
if (!parsed.success) throw new Error(`the trust config with the runner identity is invalid: ${parsed.error.issues.map((i) => `${i.path.join(".") || "/"}: ${i.message}`).join("; ")}`);
|
|
91
|
+
return `${JSON.stringify(next, null, 2)}\n`;
|
|
92
|
+
}
|
|
@@ -32,6 +32,12 @@ const cases: Array<[string, unknown]> = [
|
|
|
32
32
|
["a local key of a runner's class", { schema: 1, local: { keys: [{ principal: "ci", class: "runner", key: ed }] } }],
|
|
33
33
|
["local evidence from nobody", { schema: 1, local: { checks: [{ check: "fmt", from: [] }] } }],
|
|
34
34
|
["local with an extra key", { schema: 1, local: { checks: [], skip: true } }],
|
|
35
|
+
["keyless identities", { schema: 1, keyless: { trustedRoot: ".chant/trusted_root.json", since: commit, fulcio: "https://fulcio.example", timestamp: "https://tsa.example/ts", audience: "sigstore", identities: [{ principal: "ci", class: "runner", issuer: "https://token.actions.githubusercontent.com", subject: "https://github.com/acme/infra/.github/workflows/*@refs/heads/main" }] } }],
|
|
36
|
+
["keyless with no identities", { schema: 1, keyless: { trustedRoot: ".chant/trusted_root.json", identities: [] } }],
|
|
37
|
+
["keyless with no trusted root", { schema: 1, keyless: { identities: [{ principal: "ci", class: "runner", issuer: "https://x.example", subject: "s" }] } }],
|
|
38
|
+
["a keyless identity whose issuer is not a URL", { schema: 1, keyless: { trustedRoot: "r.json", identities: [{ principal: "ci", class: "runner", issuer: "github", subject: "s" }] } }],
|
|
39
|
+
["a keyless identity with a key", { schema: 1, keyless: { trustedRoot: "r.json", identities: [{ principal: "ci", class: "runner", issuer: "https://x.example", subject: "s", key: ed }] } }],
|
|
40
|
+
["a short keyless since", { schema: 1, keyless: { trustedRoot: "r.json", since: "abc", identities: [{ principal: "ci", class: "runner", issuer: "https://x.example", subject: "s" }] } }],
|
|
35
41
|
["a ref rule with no checks", { schema: 1, refs: [{ ref: "refs/heads/main", checks: [] }] }],
|
|
36
42
|
["a ref rule on a short ref name", { schema: 1, refs: [{ ref: "main", checks: [{ check: "plan", command: "x" }] }] }],
|
|
37
43
|
["a ref check with no command", { schema: 1, refs: [{ ref: "refs/heads/main", checks: [{ check: "plan" }] }] }],
|
|
@@ -202,7 +202,7 @@ export function trustConfigProblems(raw: unknown): string[] {
|
|
|
202
202
|
const check = (field: string, ok: boolean, message: string) => {
|
|
203
203
|
if (!ok) problems.push(`${field}: ${message}`);
|
|
204
204
|
};
|
|
205
|
-
check("/", only(raw, ["schema", "signers", "roles", "adopted", "runners", "passkeys", "admitted", "refs", "local"]), "unknown key");
|
|
205
|
+
check("/", only(raw, ["schema", "signers", "roles", "adopted", "runners", "keyless", "passkeys", "admitted", "refs", "local"]), "unknown key");
|
|
206
206
|
check("schema", raw.schema === 1, "expected 1");
|
|
207
207
|
check("signers", optional(raw.signers, isRepoPath), "a path inside the repository, with / separators and no ..");
|
|
208
208
|
check(
|
|
@@ -226,6 +226,19 @@ export function trustConfigProblems(raw: unknown): string[] {
|
|
|
226
226
|
),
|
|
227
227
|
"runner keys: a principal, a class and an ssh-ed25519 key",
|
|
228
228
|
);
|
|
229
|
+
const httpUrl = (v: unknown): boolean => typeof v === "string" && /^https?:\/\/[^\s]+$/.test(v);
|
|
230
|
+
check(
|
|
231
|
+
"keyless",
|
|
232
|
+
optional(raw.keyless, (k) =>
|
|
233
|
+
isObject(k) && only(k, ["trustedRoot", "identities", "since", "fulcio", "timestamp", "audience"]) &&
|
|
234
|
+
isRepoPath(k.trustedRoot) &&
|
|
235
|
+
optional(k.since, (f) => typeof f === "string" && FULL_COMMIT.test(f)) &&
|
|
236
|
+
optional(k.fulcio, httpUrl) && optional(k.timestamp, httpUrl) && optional(k.audience, nonEmpty) &&
|
|
237
|
+
Array.isArray(k.identities) && k.identities.length > 0 &&
|
|
238
|
+
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)),
|
|
239
|
+
),
|
|
240
|
+
"keyless identities (#4869): a trusted root path and identities, each a principal, a class, an issuer URL and a subject pattern",
|
|
241
|
+
);
|
|
229
242
|
const b64url = (v: unknown): boolean => typeof v === "string" && /^[A-Za-z0-9_-]+$/.test(v);
|
|
230
243
|
check(
|
|
231
244
|
"passkeys",
|