@rightkit/release 0.6.75 → 0.6.77

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.
@@ -4,6 +4,7 @@
4
4
  //
5
5
  // 1. optional payload archive: `createPortableArchive` zips `sourceDir` into `archive` for every asset that names a `sourceDir`;
6
6
  // 2. `collectReleaseAsset` binds each archive to its SLSA provenance and CycloneDX SBOM (both validated against the archive's sha256);
7
+ // an asset that omits `provenance` or `sbom` gets that file written first (see the config block below);
7
8
  // 3. `materializeDirectRelease` writes checksums.json, the release manifest and its detached Azure-signed catalog (Windows signing host);
8
9
  // 4. `renderPowerShellBootstrap` writes install.ps1 (the signer the manifest was just signed with is the one it accepts), checked by
9
10
  // `validatePowerShellBootstrap`, and `planBootstrapPublication` writes the bootstrap publication plan (publication is its own step).
@@ -14,7 +15,9 @@
14
15
  // outputDir: "dist/direct-release", // optional (default); --output-dir overrides
15
16
  // assets: [{ target: "windows-x86_64", name: "engine-win-x64.zip", archive: "dist/engine-win-x64.zip", sourceDir?: "dist/payload",
16
17
  // executablePath: "bin/engine.exe", nativeSignaturePolicy: "authenticode-valid",
17
- // provenance: "dist/engine-win-x64.intoto.jsonl", sbom: "dist/engine-win-x64.cdx.json" }],
18
+ // provenance?: "dist/engine-win-x64.intoto.jsonl", sbom?: "dist/engine-win-x64.cdx.json" }],
19
+ // // omit both: finalize writes provenance-<target>.intoto.jsonl and sbom-<target>.cdx.json in outputDir from the archive's sha256,
20
+ // // the source commit and the repository
18
21
  // bootstrap: { installRootSubdir, executablePath, activationArgs, statusArgs, preflightArgs?, expectedStatusKind? | healthAssertions?,
19
22
  // expectedStatus?, priorExecutableMinVersion?, allowLocalReleaseRoot? }
20
23
  // }
@@ -26,9 +29,10 @@ import path from "node:path";
26
29
  import { pathToFileURL } from "node:url";
27
30
  import { spawnSync } from "./background-process.mjs";
28
31
  import { CommandSpecError, loadAppConfig, relativeInside } from "./command-spec.mjs";
29
- import { collectReleaseAsset, createPortableArchive, materializeDirectRelease, planBootstrapPublication, renderPowerShellBootstrap, validatePowerShellBootstrap } from "./direct-bootstrap.mjs";
32
+ import { collectReleaseAsset, createPortableArchive, materializeDirectRelease, planBootstrapPublication, renderPowerShellBootstrap, sha256File, validatePowerShellBootstrap } from "./direct-bootstrap.mjs";
30
33
  import { defaultReleaseConfigFile } from "./release-config.mjs";
31
34
  import { assertCleanSource } from "./source-gate.mjs";
35
+ import { assertIdentity, materializeCycloneDxSbom, materializeInTotoSlsaProvenance } from "./supply-chain-evidence.mjs";
32
36
 
33
37
  const fail = (message) => { throw new CommandSpecError(message); };
34
38
  const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
@@ -51,10 +55,20 @@ export function resolveDirectReleaseOptions(config, flags = {}) {
51
55
  if (!isObject(asset)) fail(`${where} must be an object`);
52
56
  const bad = Object.keys(asset).filter((key) => !ASSET_KEYS.includes(key));
53
57
  if (bad.length) fail(`${where} has unknown key(s): ${bad.join(", ")} (allowed: ${ASSET_KEYS.join(", ")})`);
54
- for (const key of ["target", "name", "archive", "executablePath", "nativeSignaturePolicy", "provenance", "sbom"]) if (typeof asset[key] !== "string" || !asset[key]) fail(`${where}.${key} is required`);
58
+ for (const key of ["target", "name", "archive", "executablePath", "nativeSignaturePolicy"]) if (typeof asset[key] !== "string" || !asset[key]) fail(`${where}.${key} is required`);
55
59
  for (const key of ["archive", "sourceDir", "provenance", "sbom"]) if (asset[key] !== undefined) relativeInside(asset[key], `${where}.${key}`);
60
+ if (asset.provenance !== undefined && !asset.provenance.endsWith(".intoto.jsonl")) fail(`${where}.provenance must end in .intoto.jsonl`);
61
+ if (asset.sbom !== undefined && !asset.sbom.endsWith(".cdx.json")) fail(`${where}.sbom must end in .cdx.json`);
56
62
  return asset;
57
63
  });
64
+ for (const key of ["provenance", "sbom"]) {
65
+ const seen = new Set();
66
+ for (const asset of assets) {
67
+ if (asset[key] !== undefined) continue;
68
+ if (seen.has(asset.target)) fail(`directRelease.assets share target ${asset.target} and omit provenance or sbom: their materialized file names would collide; name provenance and sbom for each`);
69
+ seen.add(asset.target);
70
+ }
71
+ }
58
72
  if (!isObject(declared.bootstrap)) fail("directRelease.bootstrap is required (installRootSubdir, executablePath, activationArgs, statusArgs, health)");
59
73
  const badBootstrap = Object.keys(declared.bootstrap).filter((key) => !BOOTSTRAP_KEYS.includes(key));
60
74
  if (badBootstrap.length) fail(`directRelease.bootstrap has unknown key(s): ${badBootstrap.join(", ")} (allowed: ${BOOTSTRAP_KEYS.join(", ")})`);
@@ -71,28 +85,43 @@ const gitText = (cwd, args) => {
71
85
  export function finalizeDirectRelease({ appRoot, config, flags = {}, dryRun = false, repoRoot = gitText(appRoot, ["rev-parse", "--show-toplevel"]).trim() }) {
72
86
  const options = resolveDirectReleaseOptions(config, flags);
73
87
  const inApp = (relative) => path.join(appRoot, relative);
88
+ const sourceCommit = gitText(repoRoot, ["rev-parse", "HEAD"]).trim();
74
89
  for (const asset of options.assets) {
75
90
  if (asset.sourceDir !== undefined && !(existsSync(inApp(asset.sourceDir)) && statSync(inApp(asset.sourceDir)).isDirectory())) fail(`${asset.name}: sourceDir ${asset.sourceDir} is not a directory`);
76
91
  if (asset.sourceDir === undefined && !existsSync(inApp(asset.archive))) fail(`${asset.name}: archive ${asset.archive} does not exist (name a sourceDir to have it built)`);
77
- for (const key of ["provenance", "sbom"]) if (!existsSync(inApp(asset[key]))) fail(`${asset.name}: ${key} ${asset[key]} does not exist`);
92
+ for (const key of ["provenance", "sbom"]) if (asset[key] !== undefined && !existsSync(inApp(asset[key]))) fail(`${asset.name}: ${key} ${asset[key]} does not exist`);
93
+ if (asset.provenance === undefined || asset.sbom === undefined) {
94
+ try {
95
+ assertIdentity({ product: options.product, version: options.version, target: asset.target, sourceCommit });
96
+ } catch (error) {
97
+ fail(`${asset.name}: ${error.message}`);
98
+ }
99
+ }
78
100
  }
79
101
  if (dryRun) return { dryRun: true, product: options.product, version: options.version, assets: options.assets.map((asset) => asset.name), outputDir: inApp(options.outputDir) };
80
102
  assertCleanSource({ status: gitText(repoRoot, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]), commandId: "right-release direct-release finalize" });
81
- const sourceCommit = gitText(repoRoot, ["rev-parse", "HEAD"]).trim();
82
103
  const outputDir = inApp(options.outputDir);
83
104
  mkdirSync(outputDir, { recursive: true });
84
105
  const tag = `v${options.version}`;
106
+ const evidence = [];
85
107
  const assets = options.assets.map((asset) => {
86
108
  if (asset.sourceDir !== undefined) createPortableArchive({ sourceDir: inApp(asset.sourceDir), outputPath: inApp(asset.archive) });
109
+ const archivePath = inApp(asset.archive);
110
+ const archiveFile = { name: asset.name, sha256: sha256File(archivePath), size: statSync(archivePath).size };
111
+ const provenancePath = asset.provenance ? inApp(asset.provenance) : path.join(outputDir, `provenance-${asset.target}.intoto.jsonl`);
112
+ const sbomPath = asset.sbom ? inApp(asset.sbom) : path.join(outputDir, `sbom-${asset.target}.cdx.json`);
113
+ if (!asset.provenance) materializeInTotoSlsaProvenance({ outputPath: provenancePath, product: options.product, version: options.version, target: asset.target, sourceCommit, sourceRepository: `https://github.com/${options.repository}`, subjects: [archiveFile] });
114
+ if (!asset.sbom) materializeCycloneDxSbom({ outputPath: sbomPath, product: options.product, version: options.version, target: asset.target, sourceCommit, files: [archiveFile] });
115
+ evidence.push({ target: asset.target, provenancePath, sbomPath, materialized: !asset.provenance || !asset.sbom });
87
116
  return collectReleaseAsset({
88
117
  target: asset.target,
89
118
  name: asset.name,
90
119
  url: `https://github.com/${options.repository}/releases/download/${tag}/${asset.name}`,
91
- archivePath: inApp(asset.archive),
120
+ archivePath,
92
121
  executablePath: asset.executablePath,
93
122
  nativeSignaturePolicy: asset.nativeSignaturePolicy,
94
- provenancePath: inApp(asset.provenance),
95
- sbomPath: inApp(asset.sbom),
123
+ provenancePath,
124
+ sbomPath,
96
125
  });
97
126
  });
98
127
  const release = materializeDirectRelease({
@@ -106,14 +135,14 @@ export function finalizeDirectRelease({ appRoot, config, flags = {}, dryRun = fa
106
135
  acceptedManifestSigners: [release.signing.signer],
107
136
  ...options.bootstrap,
108
137
  });
109
- const validation = validatePowerShellBootstrap(script, { product: options.product, acceptedSignerIds: [release.signing.signer.id] });
138
+ const validation = validatePowerShellBootstrap(script, { product: options.product, acceptedSignerIds: [release.signing.signer.id], allowLocalReleaseRoot: options.bootstrap.allowLocalReleaseRoot === true });
110
139
  if (!validation.valid) throw new Error(`generated bootstrap violates its own contract: ${validation.errors.join("; ")}`);
111
140
  const scriptPath = path.join(outputDir, "install.ps1");
112
141
  writeFileSync(scriptPath, script);
113
142
  const plan = planBootstrapPublication({ product: options.product, bootstrapVersion: options.bootstrapVersion, scriptPath });
114
143
  const planPath = path.join(outputDir, "bootstrap-publication-plan.json");
115
144
  writeFileSync(planPath, `${JSON.stringify(plan, null, 2)}\n`);
116
- return { dryRun: false, product: options.product, version: options.version, sourceCommit, outputDir, manifestPath: release.manifestPath, signaturePath: release.signaturePath, scriptPath, planPath, bootstrapSha256: plan.sha256 };
145
+ return { dryRun: false, product: options.product, version: options.version, sourceCommit, outputDir, manifestPath: release.manifestPath, signaturePath: release.signaturePath, scriptPath, planPath, bootstrapSha256: plan.sha256, evidence };
117
146
  }
118
147
 
119
148
  export function parseDirectReleaseArgs(argv) {
@@ -143,6 +172,7 @@ export async function main(argv = process.argv.slice(2)) {
143
172
  }
144
173
  console.log(`right-release direct-release finalize: ${outcome.product} ${outcome.version} at ${outcome.sourceCommit.slice(0, 12)}`);
145
174
  console.log(`manifest: ${outcome.manifestPath}\nsignature: ${outcome.signaturePath}\nbootstrap: ${outcome.scriptPath} (sha256 ${outcome.bootstrapSha256})\nplan: ${outcome.planPath}`);
175
+ for (const item of outcome.evidence) console.log(`evidence: ${item.provenancePath} and ${item.sbomPath} (${item.materialized ? "materialized" : "given"})`);
146
176
  return 0;
147
177
  }
148
178
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rightkit/release",
3
- "version": "0.6.75",
3
+ "version": "0.6.77",
4
4
  "description": "Portable release CLI/SDK with fail-closed public GitHub Releases and private R2 + RightApps distribution.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",