@intentius/chant 0.124.99 → 0.124.101
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/bin/chant +3 -3
- package/dist/action-pins.d.ts +2 -0
- package/dist/action-pins.js +3 -0
- package/dist/ci-detect.d.ts +13 -0
- package/dist/ci-detect.js +12 -0
- package/dist/ci-system.d.ts +66 -0
- package/dist/ci-system.js +61 -0
- package/dist/cli/commands/carve-emit.js +2 -2
- package/dist/cli/commands/check-lexicon-plugin.d.ts +2 -2
- package/dist/cli/commands/check-lexicon-plugin.js +3 -3
- package/dist/cli/commands/check-lexicon.js +4 -4
- package/dist/cli/commands/init-lexicon/templates/project.d.ts +1 -1
- package/dist/cli/commands/init-lexicon/templates/project.js +4 -4
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.js +30 -2
- package/dist/cli/handlers/build.js +27 -0
- package/dist/cli/handlers/release-doctor.d.ts +12 -0
- package/dist/cli/handlers/release-doctor.js +118 -0
- package/dist/cli/handlers/release-init.d.ts +10 -0
- package/dist/cli/handlers/release-init.js +342 -0
- package/dist/cli/handlers/release.d.ts +50 -1
- package/dist/cli/handlers/release.js +688 -30
- package/dist/cli/handlers/run-generate.js +11 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +45 -97
- package/dist/cli/parse-args.js +55 -0
- package/dist/cli/registry.d.ts +18 -0
- package/dist/cli/release-commands/artifacts.d.ts +3 -0
- package/dist/cli/release-commands/artifacts.js +14 -0
- package/dist/cli/release-commands/candidates.d.ts +3 -0
- package/dist/cli/release-commands/candidates.js +16 -0
- package/dist/cli/release-commands/changed.d.ts +3 -0
- package/dist/cli/release-commands/changed.js +14 -0
- package/dist/cli/release-commands/compose.d.ts +3 -0
- package/dist/cli/release-commands/compose.js +16 -0
- package/dist/cli/release-commands/cut.d.ts +3 -0
- package/dist/cli/release-commands/cut.js +49 -0
- package/dist/cli/release-commands/doctor.d.ts +3 -0
- package/dist/cli/release-commands/doctor.js +14 -0
- package/dist/cli/release-commands/export.d.ts +3 -0
- package/dist/cli/release-commands/export.js +12 -0
- package/dist/cli/release-commands/images.d.ts +3 -0
- package/dist/cli/release-commands/images.js +13 -0
- package/dist/cli/release-commands/index.d.ts +8 -0
- package/dist/cli/release-commands/index.js +52 -0
- package/dist/cli/release-commands/init.d.ts +3 -0
- package/dist/cli/release-commands/init.js +16 -0
- package/dist/cli/release-commands/list.d.ts +3 -0
- package/dist/cli/release-commands/list.js +10 -0
- package/dist/cli/release-commands/next.d.ts +3 -0
- package/dist/cli/release-commands/next.js +13 -0
- package/dist/cli/release-commands/publish.d.ts +3 -0
- package/dist/cli/release-commands/publish.js +22 -0
- package/dist/cli/release-commands/stamp.d.ts +3 -0
- package/dist/cli/release-commands/stamp.js +15 -0
- package/dist/cli/release-commands/status.d.ts +3 -0
- package/dist/cli/release-commands/status.js +17 -0
- package/dist/cli/release-commands/tag.d.ts +3 -0
- package/dist/cli/release-commands/tag.js +12 -0
- package/dist/cli/release-commands/types.d.ts +20 -0
- package/dist/cli/release-commands/types.js +1 -0
- package/dist/cli/release-commands/verify.d.ts +3 -0
- package/dist/cli/release-commands/verify.js +15 -0
- package/dist/cli/release-commands/workflow.d.ts +3 -0
- package/dist/cli/release-commands/workflow.js +13 -0
- package/dist/codegen/pinned-upgrade.js +1 -1
- package/dist/components/capability-plugin.d.ts +1 -1
- package/dist/components/capability-plugin.js +1 -1
- package/dist/components/cli-support.d.ts +1 -1
- package/dist/components/cli-support.js +1 -1
- package/dist/config-environments.d.ts +8 -1
- package/dist/config-environments.js +2 -0
- package/dist/config.d.ts +299 -6
- package/dist/config.js +102 -5
- package/dist/dead-guards.d.ts +5 -1
- package/dist/dead-guards.js +34 -23
- package/dist/discovery/sandbox/driver.js +1 -1
- package/dist/discovery/specifier-resolve.js +1 -1
- package/dist/floor-table.d.ts +3 -1
- package/dist/floor-table.data.js +23 -3
- package/dist/floor-table.js +4 -3
- package/dist/forge-remote.d.ts +13 -0
- package/dist/forge-remote.js +15 -0
- package/dist/lexicon.d.ts +41 -2
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
- package/dist/lifecycle/publish-attachments.d.ts +2 -1
- package/dist/lifecycle/publish-attachments.js +19 -2
- package/dist/lifecycle/publish-cargo.d.ts +99 -0
- package/dist/lifecycle/publish-cargo.js +412 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.js +8 -0
- package/dist/lifecycle/publish-declaration.d.ts +199 -4
- package/dist/lifecycle/publish-declaration.js +200 -9
- package/dist/lifecycle/publish-forge.d.ts +45 -2
- package/dist/lifecycle/publish-forge.js +434 -34
- package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
- package/dist/lifecycle/publish-git-ssh.js +30 -4
- package/dist/lifecycle/publish-github.d.ts +40 -2
- package/dist/lifecycle/publish-github.js +100 -3
- package/dist/lifecycle/publish-homebrew.d.ts +7 -9
- package/dist/lifecycle/publish-homebrew.js +34 -197
- package/dist/lifecycle/publish-index.d.ts +141 -0
- package/dist/lifecycle/publish-index.js +719 -0
- package/dist/lifecycle/publish-marketplace.js +77 -0
- package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
- package/dist/lifecycle/publish-mcp-registry.js +306 -0
- package/dist/lifecycle/publish-npm.js +165 -2
- package/dist/lifecycle/publish-oci.d.ts +34 -1
- package/dist/lifecycle/publish-oci.js +246 -7
- package/dist/lifecycle/publish-pypi.d.ts +136 -0
- package/dist/lifecycle/publish-pypi.js +657 -0
- package/dist/lifecycle/publish-record.d.ts +6 -3
- package/dist/lifecycle/publish-record.js +6 -3
- package/dist/lifecycle/publish-signing.d.ts +147 -0
- package/dist/lifecycle/publish-signing.js +257 -0
- package/dist/lifecycle/publish-targets.d.ts +27 -1
- package/dist/lifecycle/publish-targets.js +80 -0
- package/dist/lifecycle/publish-tauri.js +43 -0
- package/dist/lifecycle/publish-train-names.d.ts +54 -0
- package/dist/lifecycle/publish-train-names.js +118 -0
- package/dist/lifecycle/publish-verify.d.ts +121 -0
- package/dist/lifecycle/publish-verify.js +130 -0
- package/dist/lifecycle/query.js +8 -0
- package/dist/lifecycle/release-artifacts.d.ts +212 -0
- package/dist/lifecycle/release-artifacts.js +571 -0
- package/dist/lifecycle/release-changelog.d.ts +13 -1
- package/dist/lifecycle/release-changelog.js +35 -2
- package/dist/lifecycle/release-cut.d.ts +58 -3
- package/dist/lifecycle/release-cut.js +132 -34
- package/dist/lifecycle/release-doctor.d.ts +113 -0
- package/dist/lifecycle/release-doctor.js +996 -0
- package/dist/lifecycle/release-green.d.ts +86 -0
- package/dist/lifecycle/release-green.js +286 -0
- package/dist/lifecycle/release-init.d.ts +255 -0
- package/dist/lifecycle/release-init.js +859 -0
- package/dist/lifecycle/release-intents.d.ts +73 -0
- package/dist/lifecycle/release-intents.js +128 -0
- package/dist/lifecycle/release-next.d.ts +111 -0
- package/dist/lifecycle/release-next.js +252 -0
- package/dist/lifecycle/release-prerelease.d.ts +19 -0
- package/dist/lifecycle/release-prerelease.js +30 -0
- package/dist/lifecycle/release-publish.d.ts +256 -10
- package/dist/lifecycle/release-publish.js +246 -34
- package/dist/lifecycle/release-status-change.d.ts +226 -0
- package/dist/lifecycle/release-status-change.js +478 -0
- package/dist/lifecycle/release-status.d.ts +11 -0
- package/dist/lifecycle/release-status.js +1 -1
- package/dist/lifecycle/release-store.d.ts +73 -2
- package/dist/lifecycle/release-store.js +32 -1
- package/dist/lifecycle/release-tag.d.ts +142 -0
- package/dist/lifecycle/release-tag.js +323 -0
- package/dist/lifecycle/release-verify.d.ts +73 -1
- package/dist/lifecycle/release-verify.js +117 -2
- package/dist/lifecycle/release-version-formats.d.ts +73 -0
- package/dist/lifecycle/release-version-formats.js +570 -0
- package/dist/lifecycle/release-version.d.ts +58 -10
- package/dist/lifecycle/release-version.js +164 -36
- package/dist/lifecycle/release-workstation.d.ts +3 -2
- package/dist/lifecycle/release-workstation.js +3 -2
- package/dist/module-source.d.ts +2 -2
- package/dist/module-source.js +8 -8
- package/dist/op/generate-pipeline.js +1 -1
- package/dist/pr-forge-base.js +4 -2
- package/dist/pr-forge.d.ts +20 -2
- package/dist/pr-forge.js +46 -10
- package/dist/release-floors.d.ts +10 -1
- package/dist/release-floors.js +10 -1
- package/dist/tool-pins.d.ts +38 -0
- package/dist/tool-pins.js +54 -0
- package/dist/ts-loader.d.ts +1 -1
- package/dist/ts-loader.js +6 -6
- package/dist/wave-runtime.mjs +337 -334
- package/dist/workspace/ci-forge.d.ts +17 -0
- package/dist/workspace/ci-forge.js +17 -0
- package/dist/workspace/ci-init.js +1 -1
- package/dist/workspace/composites.schema.json +1 -0
- package/dist/workspace/declaration.d.ts +8 -0
- package/dist/workspace/declaration.js +12 -0
- package/dist/workspace/declaration.schema.json +8 -0
- package/dist/workspace/environments.d.ts +2 -0
- package/dist/workspace/environments.js +1 -1
- package/dist/workspace/identity-gate-rule.d.ts +61 -5
- package/dist/workspace/identity-gate-rule.js +81 -12
- package/dist/workspace/member-pipeline.d.ts +2 -1
- package/dist/workspace/member-pipeline.js +5 -2
- package/dist/workspace/reason-codes.d.ts +6 -0
- package/dist/workspace/reason-codes.js +8 -1
- package/dist/workspace/release-changed.d.ts +179 -0
- package/dist/workspace/release-changed.js +625 -0
- package/dist/workspace/release-changed.schema.json +206 -0
- package/dist/workspace/release-steps/artifacts.d.ts +7 -0
- package/dist/workspace/release-steps/artifacts.js +45 -0
- package/dist/workspace/release-steps/builds.d.ts +12 -0
- package/dist/workspace/release-steps/builds.js +38 -0
- package/dist/workspace/release-steps/doctor.d.ts +8 -0
- package/dist/workspace/release-steps/doctor.js +14 -0
- package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
- package/dist/workspace/release-steps/goreleaser.js +36 -0
- package/dist/workspace/release-steps/green.d.ts +3 -0
- package/dist/workspace/release-steps/green.js +6 -0
- package/dist/workspace/release-steps/images.d.ts +22 -0
- package/dist/workspace/release-steps/images.js +59 -0
- package/dist/workspace/release-steps/index.d.ts +9 -0
- package/dist/workspace/release-steps/index.js +46 -0
- package/dist/workspace/release-steps/pypi.d.ts +15 -0
- package/dist/workspace/release-steps/pypi.js +21 -0
- package/dist/workspace/release-steps/qemu.d.ts +21 -0
- package/dist/workspace/release-steps/qemu.js +35 -0
- package/dist/workspace/release-steps/signing.d.ts +18 -0
- package/dist/workspace/release-steps/signing.js +30 -0
- package/dist/workspace/release-steps/stamp.d.ts +3 -0
- package/dist/workspace/release-steps/stamp.js +4 -0
- package/dist/workspace/release-steps/targets.d.ts +31 -0
- package/dist/workspace/release-steps/targets.js +40 -0
- package/dist/workspace/release-steps/types.d.ts +104 -0
- package/dist/workspace/release-steps/types.js +2 -0
- package/dist/workspace/release-steps/verify.d.ts +3 -0
- package/dist/workspace/release-steps/verify.js +4 -0
- package/dist/workspace/release-toolchains.d.ts +59 -0
- package/dist/workspace/release-toolchains.js +133 -0
- package/dist/workspace/release-train-workflow.d.ts +29 -0
- package/dist/workspace/release-train-workflow.js +85 -0
- package/dist/workspace/release-train.d.ts +3 -1
- package/dist/workspace/release-train.js +20 -3
- package/dist/workspace/release-workflow.d.ts +160 -61
- package/dist/workspace/release-workflow.js +539 -193
- package/dist/workspace/releases.schema.json +70 -1
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/security.js +9 -2
- package/dist/workspace/train-cut.d.ts +182 -0
- package/dist/workspace/train-cut.js +482 -0
- package/dist/workspace/train-prepare.d.ts +61 -0
- package/dist/workspace/train-prepare.js +267 -0
- package/dist/workspace/train-publish.d.ts +177 -0
- package/dist/workspace/train-publish.js +575 -0
- package/dist/workspace/train-range-labels.d.ts +33 -0
- package/dist/workspace/train-range-labels.js +109 -0
- package/dist/workspace/trust/seal.d.ts +13 -3
- package/dist/workspace/trust/seal.js +14 -4
- package/dist/workspace/work-cli.d.ts +3 -2
- package/dist/workspace/work-cli.js +3 -2
- package/dist/workspace/workspace-ledger.d.ts +14 -1
- package/dist/workspace/workspace-ledger.js +33 -7
- package/package.json +26 -26
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
* `chant/lifecycle`, under the member's prefix like `cuts.jsonl` beside it,
|
|
8
8
|
* append-only. A target that staged gets a `staged` line with its items and
|
|
9
9
|
* the state its reveal needs (a draft release's id); one that revealed gets
|
|
10
|
-
* a `revealed` line.
|
|
10
|
+
* a `revealed` line. The `release.verify` commands (#5157) get a `verified`
|
|
11
|
+
* or `verify-failed` line, under the target `verify:<hex>` of kind `verify`,
|
|
12
|
+
* with the failing command's name and exit status in its state; the lines of
|
|
13
|
+
* targets are what a resume reads. Each line is pushed as soon as it is written, so a CI
|
|
11
14
|
* job that resumes on a fresh checkout reads it after `fetchLifecycle`.
|
|
12
15
|
*
|
|
13
16
|
* Why a record and not only the registries: a registry says whether a version
|
|
@@ -33,10 +36,10 @@ export interface PublishRecord {
|
|
|
33
36
|
label: string | null;
|
|
34
37
|
/** The target's key ({@link PublishTarget.key}). */
|
|
35
38
|
target: string;
|
|
36
|
-
kind: PublishTarget["kind"];
|
|
39
|
+
kind: PublishTarget["kind"] | "verify";
|
|
37
40
|
/** The target's name, for a reader. */
|
|
38
41
|
name: string;
|
|
39
|
-
step: "staged" | "revealed";
|
|
42
|
+
step: "staged" | "revealed" | "verified" | "verify-failed";
|
|
40
43
|
items: PublishItem[];
|
|
41
44
|
/** What the reveal needs, on a `staged` line; `{}` on a `revealed` one. */
|
|
42
45
|
state: Record<string, string>;
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
* `chant/lifecycle`, under the member's prefix like `cuts.jsonl` beside it,
|
|
8
8
|
* append-only. A target that staged gets a `staged` line with its items and
|
|
9
9
|
* the state its reveal needs (a draft release's id); one that revealed gets
|
|
10
|
-
* a `revealed` line.
|
|
10
|
+
* a `revealed` line. The `release.verify` commands (#5157) get a `verified`
|
|
11
|
+
* or `verify-failed` line, under the target `verify:<hex>` of kind `verify`,
|
|
12
|
+
* with the failing command's name and exit status in its state; the lines of
|
|
13
|
+
* targets are what a resume reads. Each line is pushed as soon as it is written, so a CI
|
|
11
14
|
* job that resumes on a fresh checkout reads it after `fetchLifecycle`.
|
|
12
15
|
*
|
|
13
16
|
* Why a record and not only the registries: a registry says whether a version
|
|
@@ -37,7 +40,7 @@ export function parsePublishRecords(text) {
|
|
|
37
40
|
r.version === 1 &&
|
|
38
41
|
typeof r.releaseDigest === "string" &&
|
|
39
42
|
typeof r.target === "string" &&
|
|
40
|
-
(r.step === "staged" || r.step === "revealed") &&
|
|
43
|
+
(r.step === "staged" || r.step === "revealed" || r.step === "verified" || r.step === "verify-failed") &&
|
|
41
44
|
Array.isArray(r.items) &&
|
|
42
45
|
typeof r.timestamp === "string";
|
|
43
46
|
if (!ok) {
|
|
@@ -64,7 +67,7 @@ export function publishProgress(records) {
|
|
|
64
67
|
for (const r of records) {
|
|
65
68
|
if (r.step === "staged")
|
|
66
69
|
staged.set(r.target, { target: r.name, destination: "", items: r.items, state: r.state });
|
|
67
|
-
else
|
|
70
|
+
else if (r.step === "revealed")
|
|
68
71
|
revealed.set(r.target, { target: r.name, destination: "", items: r.items });
|
|
69
72
|
}
|
|
70
73
|
return { staged, revealed };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sigstore signing at publish (#5164): keyless signatures and OIDC-signed
|
|
3
|
+
* SLSA provenance for what the OCI and forge targets publish, beside the
|
|
4
|
+
* release's own provenance statement and the cut's ssh signature, which stay
|
|
5
|
+
* as they are (./publish-attachments.ts).
|
|
6
|
+
*
|
|
7
|
+
* In a CI job with an OIDC token, a target's stage signs before anything is
|
|
8
|
+
* revealed:
|
|
9
|
+
*
|
|
10
|
+
* - an image gets a cosign signature, a Sigstore bundle over an in-toto
|
|
11
|
+
* statement whose predicate type is `https://sigstore.dev/cosign/sign/v1`,
|
|
12
|
+
* and SLSA provenance (`https://slsa.dev/provenance/v1`), each pushed as
|
|
13
|
+
* an OCI referrer of the image with the artifact type
|
|
14
|
+
* `application/vnd.dev.sigstore.bundle.v0.3+json`, the layout `cosign sign`
|
|
15
|
+
* and `actions/attest-build-provenance` push. `cosign verify` and `cosign
|
|
16
|
+
* verify-attestation --type slsaprovenance1` check them.
|
|
17
|
+
* - a forge release gets `<file>.sigstore.json` beside each file it holds (a
|
|
18
|
+
* `cosign sign-blob` bundle, checked with `cosign verify-blob`) and
|
|
19
|
+
* {@link SLSA_BUNDLE_FILE}, SLSA provenance over the declared assets.
|
|
20
|
+
*
|
|
21
|
+
* chant writes the statements and runs `cosign` (version 3, the binary
|
|
22
|
+
* `CHANT_COSIGN` names, else `cosign` on `PATH`) to sign them with the job's
|
|
23
|
+
* token: `cosign sign-blob` for a file and `cosign attest-blob --statement`
|
|
24
|
+
* for a statement. It pushes and uploads the bundles itself, with the
|
|
25
|
+
* target's own credentials. The generated release workflow downloads cosign
|
|
26
|
+
* pinned by SHA-256 (../tool-pins.ts).
|
|
27
|
+
*
|
|
28
|
+
* Signing is off unless `release.signing` in `chant.config.ts` turns it on
|
|
29
|
+
* or the workspace opts into the `supply-chain` group, where `signing: false`
|
|
30
|
+
* turns it off with a warning. When it is on and the run can't sign (no OIDC
|
|
31
|
+
* token cosign takes, or no cosign), the publish is refused before anything
|
|
32
|
+
* is sent.
|
|
33
|
+
*/
|
|
34
|
+
import type { Redactor } from "./publish-credentials.js";
|
|
35
|
+
import type { SecurityGroup } from "../workspace/security.js";
|
|
36
|
+
import { type PublishContext } from "./release-publish.js";
|
|
37
|
+
/** The media type of a Sigstore bundle, and the artifact type of a referrer that holds one. */
|
|
38
|
+
export declare const SIGSTORE_BUNDLE_MEDIA_TYPE = "application/vnd.dev.sigstore.bundle.v0.3+json";
|
|
39
|
+
/** The predicate type of cosign's image signature statement. */
|
|
40
|
+
export declare const COSIGN_SIGN_PREDICATE = "https://sigstore.dev/cosign/sign/v1";
|
|
41
|
+
/** The predicate type of SLSA provenance v1. */
|
|
42
|
+
export declare const SLSA_PROVENANCE_PREDICATE = "https://slsa.dev/provenance/v1";
|
|
43
|
+
/** What a file's signature bundle is named after: `<file>.sigstore.json`. */
|
|
44
|
+
export declare const SIGSTORE_BUNDLE_SUFFIX = ".sigstore.json";
|
|
45
|
+
/** The forge asset that holds SLSA provenance over the release's assets. */
|
|
46
|
+
export declare const SLSA_BUNDLE_FILE = "release.slsa.sigstore.json";
|
|
47
|
+
/** The OCI annotation a bundle referrer names its predicate type under. */
|
|
48
|
+
export declare const BUNDLE_PREDICATE_ANNOTATION = "dev.sigstore.bundle.predicateType";
|
|
49
|
+
/** The buildType of SLSA provenance written in GitHub Actions, the one `actions/attest-build-provenance` writes. */
|
|
50
|
+
export declare const GITHUB_BUILD_TYPE = "https://actions.github.io/buildtypes/workflow/v1";
|
|
51
|
+
/** The buildType of SLSA provenance written in GitLab CI. */
|
|
52
|
+
export declare const GITLAB_BUILD_TYPE = "https://intentius.io/chant/release/build/gitlab-ci/v1";
|
|
53
|
+
/** The cosign major version chant runs: 3 writes Sigstore bundles by default. */
|
|
54
|
+
export declare const COSIGN_MAJOR = 3;
|
|
55
|
+
/** `release.signing` in `chant.config.ts`. */
|
|
56
|
+
export type SigningConfig = boolean | {
|
|
57
|
+
identity?: string;
|
|
58
|
+
issuer?: string;
|
|
59
|
+
};
|
|
60
|
+
/** Whether a publish signs, and why. */
|
|
61
|
+
export interface SigningSetting {
|
|
62
|
+
on: boolean;
|
|
63
|
+
/** `config` (release.signing), `supply-chain` (the group), or `off`. */
|
|
64
|
+
from: "config" | "supply-chain" | "off";
|
|
65
|
+
/** Set when the group asks for signing and `signing: false` turns it off. */
|
|
66
|
+
warning: string | null;
|
|
67
|
+
/** The certificate identity (a regular expression) and issuer a verify expects, when the config names them. */
|
|
68
|
+
identity?: string;
|
|
69
|
+
issuer?: string;
|
|
70
|
+
}
|
|
71
|
+
/** Whether a publish signs: `release.signing` first, then the `supply-chain` group. */
|
|
72
|
+
export declare function resolveSigning(config: SigningConfig | undefined, groups: ReadonlySet<SecurityGroup>): SigningSetting;
|
|
73
|
+
/** Who a keyless signature names: the OIDC issuer and a regular expression the certificate's identity matches. */
|
|
74
|
+
export interface SigstoreIdentity {
|
|
75
|
+
issuer: string;
|
|
76
|
+
identity: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether this run can sign keylessly, and the identity its certificate will
|
|
80
|
+
* name: in GitHub Actions, a job with `id-token: write`, whose certificate
|
|
81
|
+
* names a workflow of the repository; in GitLab CI, an ID token named
|
|
82
|
+
* `SIGSTORE_ID_TOKEN` with the audience `sigstore`, whose certificate names
|
|
83
|
+
* the project's pipeline. Anywhere else there is none.
|
|
84
|
+
*/
|
|
85
|
+
export declare function signingIdentity(env: NodeJS.ProcessEnv): {
|
|
86
|
+
identity: SigstoreIdentity;
|
|
87
|
+
} | {
|
|
88
|
+
reason: string;
|
|
89
|
+
};
|
|
90
|
+
/** An in-toto Statement v1. */
|
|
91
|
+
export interface InTotoStatement {
|
|
92
|
+
_type: string;
|
|
93
|
+
subject: Array<{
|
|
94
|
+
name: string;
|
|
95
|
+
digest: Record<string, string>;
|
|
96
|
+
}>;
|
|
97
|
+
predicateType: string;
|
|
98
|
+
predicate: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
/** The statement cosign signs for an image: its digest under `https://sigstore.dev/cosign/sign/v1`, with an empty predicate. */
|
|
101
|
+
export declare function cosignSignStatement(subject: {
|
|
102
|
+
name: string;
|
|
103
|
+
digest: string;
|
|
104
|
+
}): InTotoStatement;
|
|
105
|
+
/**
|
|
106
|
+
* SLSA provenance v1 over `subjects`, from the CI job's environment. In
|
|
107
|
+
* GitHub Actions it is the predicate `actions/attest-build-provenance`
|
|
108
|
+
* writes: the workflow, the event, the repository's ids, the commit and the
|
|
109
|
+
* run. In GitLab CI it names the project, its CI config, the pipeline source
|
|
110
|
+
* and the job. Either adds `internalParameters.chant`, the release's digest,
|
|
111
|
+
* label and member, and the source it resolves is the release's commit.
|
|
112
|
+
*/
|
|
113
|
+
export declare function slsaProvenanceStatement(ctx: Pick<PublishContext, "env" | "release" | "label">, subjects: ReadonlyArray<{
|
|
114
|
+
name: string;
|
|
115
|
+
digest: string;
|
|
116
|
+
}>): InTotoStatement;
|
|
117
|
+
/** Signs with Sigstore. Injected, so tests sign with a fake. */
|
|
118
|
+
export interface Signer {
|
|
119
|
+
/** What signs, for messages, such as `cosign v3.1.4`. */
|
|
120
|
+
readonly name: string;
|
|
121
|
+
/** Null when it can sign here, else why not, in a sentence. */
|
|
122
|
+
unavailable(): string | null;
|
|
123
|
+
/** A bundle with a signature over `bytes` (`cosign sign-blob`). */
|
|
124
|
+
signBlob(bytes: Uint8Array, name: string): Promise<Uint8Array>;
|
|
125
|
+
/** A bundle with `statement` signed as a DSSE envelope (`cosign attest-blob --statement`). */
|
|
126
|
+
signStatement(statement: InTotoStatement): Promise<Uint8Array>;
|
|
127
|
+
}
|
|
128
|
+
/** Checks Sigstore signatures. Injected, so tests check with a fake. Each check gives null when it verifies, else why not. */
|
|
129
|
+
export interface SigstoreVerifier {
|
|
130
|
+
readonly name: string;
|
|
131
|
+
unavailable(): string | null;
|
|
132
|
+
verifyBlob(bundle: Uint8Array, digest: string, id: SigstoreIdentity): Promise<string | null>;
|
|
133
|
+
verifyBlobAttestation(bundle: Uint8Array, digest: string, predicateType: string, id: SigstoreIdentity): Promise<string | null>;
|
|
134
|
+
verifyImage(ref: string, id: SigstoreIdentity): Promise<string | null>;
|
|
135
|
+
verifyImageAttestation(ref: string, predicateType: string, id: SigstoreIdentity): Promise<string | null>;
|
|
136
|
+
}
|
|
137
|
+
/** The cosign a run uses: `CHANT_COSIGN`, else `cosign` on `PATH`. */
|
|
138
|
+
export declare function cosignPath(env: NodeJS.ProcessEnv): string;
|
|
139
|
+
/** A {@link Signer} that runs cosign keylessly, with `env`, which carries the job's OIDC token. */
|
|
140
|
+
export declare function cosignSigner(env: NodeJS.ProcessEnv, redactor: Redactor, cosign?: string): Signer;
|
|
141
|
+
/** A {@link SigstoreVerifier} that runs cosign. Image checks read the registry with docker's credentials. */
|
|
142
|
+
export declare function cosignVerifier(env: NodeJS.ProcessEnv, cosign?: string): SigstoreVerifier;
|
|
143
|
+
/** What a target signs with, in the publish context: the signer and the identity its certificate names. */
|
|
144
|
+
export interface SigningContext {
|
|
145
|
+
signer: Signer;
|
|
146
|
+
identity: SigstoreIdentity;
|
|
147
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sigstore signing at publish (#5164): keyless signatures and OIDC-signed
|
|
3
|
+
* SLSA provenance for what the OCI and forge targets publish, beside the
|
|
4
|
+
* release's own provenance statement and the cut's ssh signature, which stay
|
|
5
|
+
* as they are (./publish-attachments.ts).
|
|
6
|
+
*
|
|
7
|
+
* In a CI job with an OIDC token, a target's stage signs before anything is
|
|
8
|
+
* revealed:
|
|
9
|
+
*
|
|
10
|
+
* - an image gets a cosign signature, a Sigstore bundle over an in-toto
|
|
11
|
+
* statement whose predicate type is `https://sigstore.dev/cosign/sign/v1`,
|
|
12
|
+
* and SLSA provenance (`https://slsa.dev/provenance/v1`), each pushed as
|
|
13
|
+
* an OCI referrer of the image with the artifact type
|
|
14
|
+
* `application/vnd.dev.sigstore.bundle.v0.3+json`, the layout `cosign sign`
|
|
15
|
+
* and `actions/attest-build-provenance` push. `cosign verify` and `cosign
|
|
16
|
+
* verify-attestation --type slsaprovenance1` check them.
|
|
17
|
+
* - a forge release gets `<file>.sigstore.json` beside each file it holds (a
|
|
18
|
+
* `cosign sign-blob` bundle, checked with `cosign verify-blob`) and
|
|
19
|
+
* {@link SLSA_BUNDLE_FILE}, SLSA provenance over the declared assets.
|
|
20
|
+
*
|
|
21
|
+
* chant writes the statements and runs `cosign` (version 3, the binary
|
|
22
|
+
* `CHANT_COSIGN` names, else `cosign` on `PATH`) to sign them with the job's
|
|
23
|
+
* token: `cosign sign-blob` for a file and `cosign attest-blob --statement`
|
|
24
|
+
* for a statement. It pushes and uploads the bundles itself, with the
|
|
25
|
+
* target's own credentials. The generated release workflow downloads cosign
|
|
26
|
+
* pinned by SHA-256 (../tool-pins.ts).
|
|
27
|
+
*
|
|
28
|
+
* Signing is off unless `release.signing` in `chant.config.ts` turns it on
|
|
29
|
+
* or the workspace opts into the `supply-chain` group, where `signing: false`
|
|
30
|
+
* turns it off with a warning. When it is on and the run can't sign (no OIDC
|
|
31
|
+
* token cosign takes, or no cosign), the publish is refused before anything
|
|
32
|
+
* is sent.
|
|
33
|
+
*/
|
|
34
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
35
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
36
|
+
import { tmpdir } from "node:os";
|
|
37
|
+
import { join } from "node:path";
|
|
38
|
+
import { promisify } from "node:util";
|
|
39
|
+
import { IN_TOTO_STATEMENT_TYPE } from "./publish-attachments.js";
|
|
40
|
+
import { PublishTargetError } from "./release-publish.js";
|
|
41
|
+
/** The media type of a Sigstore bundle, and the artifact type of a referrer that holds one. */
|
|
42
|
+
export const SIGSTORE_BUNDLE_MEDIA_TYPE = "application/vnd.dev.sigstore.bundle.v0.3+json";
|
|
43
|
+
/** The predicate type of cosign's image signature statement. */
|
|
44
|
+
export const COSIGN_SIGN_PREDICATE = "https://sigstore.dev/cosign/sign/v1";
|
|
45
|
+
/** The predicate type of SLSA provenance v1. */
|
|
46
|
+
export const SLSA_PROVENANCE_PREDICATE = "https://slsa.dev/provenance/v1";
|
|
47
|
+
/** What a file's signature bundle is named after: `<file>.sigstore.json`. */
|
|
48
|
+
export const SIGSTORE_BUNDLE_SUFFIX = ".sigstore.json";
|
|
49
|
+
/** The forge asset that holds SLSA provenance over the release's assets. */
|
|
50
|
+
export const SLSA_BUNDLE_FILE = "release.slsa.sigstore.json";
|
|
51
|
+
/** The OCI annotation a bundle referrer names its predicate type under. */
|
|
52
|
+
export const BUNDLE_PREDICATE_ANNOTATION = "dev.sigstore.bundle.predicateType";
|
|
53
|
+
/** The buildType of SLSA provenance written in GitHub Actions, the one `actions/attest-build-provenance` writes. */
|
|
54
|
+
export const GITHUB_BUILD_TYPE = "https://actions.github.io/buildtypes/workflow/v1";
|
|
55
|
+
/** The buildType of SLSA provenance written in GitLab CI. */
|
|
56
|
+
export const GITLAB_BUILD_TYPE = "https://intentius.io/chant/release/build/gitlab-ci/v1";
|
|
57
|
+
/** The cosign major version chant runs: 3 writes Sigstore bundles by default. */
|
|
58
|
+
export const COSIGN_MAJOR = 3;
|
|
59
|
+
/** Whether a publish signs: `release.signing` first, then the `supply-chain` group. */
|
|
60
|
+
export function resolveSigning(config, groups) {
|
|
61
|
+
const named = typeof config === "object" ? { ...(config.identity ? { identity: config.identity } : {}), ...(config.issuer ? { issuer: config.issuer } : {}) } : {};
|
|
62
|
+
if (config === false) {
|
|
63
|
+
return {
|
|
64
|
+
on: false,
|
|
65
|
+
from: "off",
|
|
66
|
+
warning: groups.has("supply-chain") ? "the workspace opts into supply-chain, and release.signing: false publishes images and forge assets without Sigstore signatures or SLSA provenance" : null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (config !== undefined)
|
|
70
|
+
return { on: true, from: "config", warning: null, ...named };
|
|
71
|
+
return groups.has("supply-chain") ? { on: true, from: "supply-chain", warning: null } : { on: false, from: "off", warning: null };
|
|
72
|
+
}
|
|
73
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
74
|
+
/**
|
|
75
|
+
* Whether this run can sign keylessly, and the identity its certificate will
|
|
76
|
+
* name: in GitHub Actions, a job with `id-token: write`, whose certificate
|
|
77
|
+
* names a workflow of the repository; in GitLab CI, an ID token named
|
|
78
|
+
* `SIGSTORE_ID_TOKEN` with the audience `sigstore`, whose certificate names
|
|
79
|
+
* the project's pipeline. Anywhere else there is none.
|
|
80
|
+
*/
|
|
81
|
+
export function signingIdentity(env) {
|
|
82
|
+
if (env.GITHUB_ACTIONS === "true") {
|
|
83
|
+
if (!env.ACTIONS_ID_TOKEN_REQUEST_URL || !env.ACTIONS_ID_TOKEN_REQUEST_TOKEN)
|
|
84
|
+
return { reason: "this GitHub Actions job has no OIDC token; give the job permissions: id-token: write" };
|
|
85
|
+
const server = (env.GITHUB_SERVER_URL ?? "https://github.com").replace(/\/+$/, "");
|
|
86
|
+
const repo = env.GITHUB_REPOSITORY;
|
|
87
|
+
if (!repo)
|
|
88
|
+
return { reason: "this GitHub Actions job has no GITHUB_REPOSITORY" };
|
|
89
|
+
return { identity: { issuer: "https://token.actions.githubusercontent.com", identity: `^${escape(server)}/${escape(repo)}/` } };
|
|
90
|
+
}
|
|
91
|
+
if (env.GITLAB_CI === "true") {
|
|
92
|
+
if (!env.SIGSTORE_ID_TOKEN)
|
|
93
|
+
return { reason: "this GitLab CI job has no SIGSTORE_ID_TOKEN; declare it under the job's id_tokens with aud: sigstore" };
|
|
94
|
+
const server = (env.CI_SERVER_URL ?? "https://gitlab.com").replace(/\/+$/, "");
|
|
95
|
+
const project = env.CI_PROJECT_PATH;
|
|
96
|
+
if (!project)
|
|
97
|
+
return { reason: "this GitLab CI job has no CI_PROJECT_PATH" };
|
|
98
|
+
return { identity: { issuer: server, identity: `^${escape(server)}/${escape(project)}//` } };
|
|
99
|
+
}
|
|
100
|
+
return { reason: "this run is not in GitHub Actions or GitLab CI, and keyless signing needs a CI job's OIDC token" };
|
|
101
|
+
}
|
|
102
|
+
const subjectOf = (s) => {
|
|
103
|
+
const [alg, hex] = s.digest.includes(":") ? s.digest.split(":") : ["sha256", s.digest];
|
|
104
|
+
return { name: s.name, digest: { [alg]: hex } };
|
|
105
|
+
};
|
|
106
|
+
/** The statement cosign signs for an image: its digest under `https://sigstore.dev/cosign/sign/v1`, with an empty predicate. */
|
|
107
|
+
export function cosignSignStatement(subject) {
|
|
108
|
+
return { _type: IN_TOTO_STATEMENT_TYPE, subject: [subjectOf(subject)], predicateType: COSIGN_SIGN_PREDICATE, predicate: {} };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* SLSA provenance v1 over `subjects`, from the CI job's environment. In
|
|
112
|
+
* GitHub Actions it is the predicate `actions/attest-build-provenance`
|
|
113
|
+
* writes: the workflow, the event, the repository's ids, the commit and the
|
|
114
|
+
* run. In GitLab CI it names the project, its CI config, the pipeline source
|
|
115
|
+
* and the job. Either adds `internalParameters.chant`, the release's digest,
|
|
116
|
+
* label and member, and the source it resolves is the release's commit.
|
|
117
|
+
*/
|
|
118
|
+
export function slsaProvenanceStatement(ctx, subjects) {
|
|
119
|
+
const env = ctx.env;
|
|
120
|
+
const chant = { releaseDigest: ctx.release.releaseDigest, label: ctx.label, member: ctx.release.member };
|
|
121
|
+
let predicate;
|
|
122
|
+
if (env.GITLAB_CI === "true") {
|
|
123
|
+
const server = (env.CI_SERVER_URL ?? "https://gitlab.com").replace(/\/+$/, "");
|
|
124
|
+
const project = `${server}/${env.CI_PROJECT_PATH ?? ""}`;
|
|
125
|
+
const ref = env.CI_COMMIT_TAG ? `refs/tags/${env.CI_COMMIT_TAG}` : `refs/heads/${env.CI_COMMIT_REF_NAME ?? ""}`;
|
|
126
|
+
predicate = {
|
|
127
|
+
buildDefinition: {
|
|
128
|
+
buildType: GITLAB_BUILD_TYPE,
|
|
129
|
+
externalParameters: { project, ref, configPath: env.CI_CONFIG_PATH ?? ".gitlab-ci.yml" },
|
|
130
|
+
internalParameters: { gitlab: { pipelineSource: env.CI_PIPELINE_SOURCE ?? null, projectId: env.CI_PROJECT_ID ?? null, runnerEnvironment: env.CI_RUNNER_EXECUTABLE_ARCH ?? null }, chant },
|
|
131
|
+
resolvedDependencies: [{ uri: `git+${project}@${ref}`, digest: { gitCommit: ctx.release.commit } }],
|
|
132
|
+
},
|
|
133
|
+
runDetails: {
|
|
134
|
+
builder: { id: `${project}//${env.CI_CONFIG_PATH ?? ".gitlab-ci.yml"}@${ref}` },
|
|
135
|
+
metadata: { invocationId: env.CI_JOB_URL ?? `${project}/-/jobs/${env.CI_JOB_ID ?? ""}` },
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const server = (env.GITHUB_SERVER_URL ?? "https://github.com").replace(/\/+$/, "");
|
|
141
|
+
const repo = env.GITHUB_REPOSITORY ?? "";
|
|
142
|
+
const workflowRef = env.GITHUB_WORKFLOW_REF ?? "";
|
|
143
|
+
const path = workflowRef.startsWith(`${repo}/`) ? workflowRef.slice(repo.length + 1).split("@")[0] : workflowRef.split("@")[0];
|
|
144
|
+
const ref = env.GITHUB_REF ?? "";
|
|
145
|
+
predicate = {
|
|
146
|
+
buildDefinition: {
|
|
147
|
+
buildType: GITHUB_BUILD_TYPE,
|
|
148
|
+
externalParameters: { workflow: { ref, repository: `${server}/${repo}`, path } },
|
|
149
|
+
internalParameters: {
|
|
150
|
+
github: { event_name: env.GITHUB_EVENT_NAME ?? null, repository_id: env.GITHUB_REPOSITORY_ID ?? null, repository_owner_id: env.GITHUB_REPOSITORY_OWNER_ID ?? null, runner_environment: env.RUNNER_ENVIRONMENT ?? null },
|
|
151
|
+
chant,
|
|
152
|
+
},
|
|
153
|
+
resolvedDependencies: [{ uri: `git+${server}/${repo}@${ref}`, digest: { gitCommit: ctx.release.commit } }],
|
|
154
|
+
},
|
|
155
|
+
runDetails: {
|
|
156
|
+
builder: { id: `${server}/${workflowRef}` },
|
|
157
|
+
metadata: { invocationId: `${server}/${repo}/actions/runs/${env.GITHUB_RUN_ID ?? ""}/attempts/${env.GITHUB_RUN_ATTEMPT ?? "1"}` },
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return { _type: IN_TOTO_STATEMENT_TYPE, subject: subjects.map(subjectOf), predicateType: SLSA_PROVENANCE_PREDICATE, predicate };
|
|
162
|
+
}
|
|
163
|
+
/** The cosign a run uses: `CHANT_COSIGN`, else `cosign` on `PATH`. */
|
|
164
|
+
export function cosignPath(env) {
|
|
165
|
+
return env.CHANT_COSIGN && env.CHANT_COSIGN !== "" ? env.CHANT_COSIGN : "cosign";
|
|
166
|
+
}
|
|
167
|
+
/** Null when `cosign` runs and is version {@link COSIGN_MAJOR} or later, else why not. */
|
|
168
|
+
function cosignUnavailable(cosign, env) {
|
|
169
|
+
let out;
|
|
170
|
+
try {
|
|
171
|
+
out = execFileSync(cosign, ["version"], { encoding: "utf-8", env, stdio: ["ignore", "pipe", "pipe"] });
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
const e = err;
|
|
175
|
+
if (e.code === "ENOENT")
|
|
176
|
+
return { version: null, reason: `${cosign} is not there: install cosign ${COSIGN_MAJOR} on PATH, or set CHANT_COSIGN to it` };
|
|
177
|
+
out = String(e.stdout ?? "");
|
|
178
|
+
if (!out)
|
|
179
|
+
return { version: null, reason: `${cosign} version failed: ${e.message}` };
|
|
180
|
+
}
|
|
181
|
+
const v = /GitVersion:\s*v?(\d+)\.(\d+)\.(\d+)/.exec(out);
|
|
182
|
+
if (!v)
|
|
183
|
+
return { version: null, reason: `${cosign} version printed no GitVersion, so chant can't tell it is cosign ${COSIGN_MAJOR}` };
|
|
184
|
+
const version = `v${v[1]}.${v[2]}.${v[3]}`;
|
|
185
|
+
return Number(v[1]) < COSIGN_MAJOR ? { version, reason: `${cosign} is cosign ${version}, and chant signs with cosign ${COSIGN_MAJOR} or later` } : { version, reason: null };
|
|
186
|
+
}
|
|
187
|
+
const run = promisify(execFile);
|
|
188
|
+
/** Run cosign with `args`; a failure is a {@link PublishTargetError} with `code` and the end of its stderr, redacted. */
|
|
189
|
+
async function cosignRun(cosign, args, env, redactor, code, what) {
|
|
190
|
+
try {
|
|
191
|
+
await run(cosign, args, { env, maxBuffer: 16 * 1024 * 1024 });
|
|
192
|
+
return { ok: true };
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
const e = err;
|
|
196
|
+
const tail = String(e.stderr ?? e.message).trim().split("\n").filter(Boolean).slice(-3).join("; ");
|
|
197
|
+
const reason = redactor ? redactor.redact(tail) : tail;
|
|
198
|
+
if (code)
|
|
199
|
+
throw new PublishTargetError(code, `${what} failed: ${reason}`, "Check that the job's OIDC token reaches cosign and that Fulcio and Rekor are reachable, then run the publish again.");
|
|
200
|
+
return { ok: false, reason };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function withTemp(fn) {
|
|
204
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-sign-"));
|
|
205
|
+
return fn(dir).finally(() => rmSync(dir, { recursive: true, force: true }));
|
|
206
|
+
}
|
|
207
|
+
/** A {@link Signer} that runs cosign keylessly, with `env`, which carries the job's OIDC token. */
|
|
208
|
+
export function cosignSigner(env, redactor, cosign = cosignPath(env)) {
|
|
209
|
+
let checked = null;
|
|
210
|
+
const check = () => (checked ?? (checked = cosignUnavailable(cosign, env)));
|
|
211
|
+
return {
|
|
212
|
+
get name() {
|
|
213
|
+
return `cosign${check().version ? ` ${check().version}` : ""}`;
|
|
214
|
+
},
|
|
215
|
+
unavailable: () => check().reason,
|
|
216
|
+
signBlob: (bytes, name) => withTemp(async (dir) => {
|
|
217
|
+
const file = join(dir, "blob");
|
|
218
|
+
writeFileSync(file, bytes);
|
|
219
|
+
await cosignRun(cosign, ["sign-blob", "--yes", "--new-bundle-format=true", "--bundle", join(dir, "out.json"), file], env, redactor, "publish-signing-failed", `cosign sign-blob for ${name}`);
|
|
220
|
+
return new Uint8Array(readFileSync(join(dir, "out.json")));
|
|
221
|
+
}),
|
|
222
|
+
signStatement: (statement) => withTemp(async (dir) => {
|
|
223
|
+
const file = join(dir, "statement.json");
|
|
224
|
+
writeFileSync(file, JSON.stringify(statement));
|
|
225
|
+
await cosignRun(cosign, ["attest-blob", "--yes", "--new-bundle-format=true", "--statement", file, "--bundle", join(dir, "out.json")], env, redactor, "publish-signing-failed", `cosign attest-blob for ${statement.predicateType}`);
|
|
226
|
+
return new Uint8Array(readFileSync(join(dir, "out.json")));
|
|
227
|
+
}),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/** The `--type` cosign takes for a predicate type: its short name for SLSA provenance v1, else the URI. */
|
|
231
|
+
const cosignType = (predicateType) => (predicateType === SLSA_PROVENANCE_PREDICATE ? "slsaprovenance1" : predicateType);
|
|
232
|
+
const idFlags = (id) => ["--certificate-identity-regexp", id.identity, "--certificate-oidc-issuer", id.issuer];
|
|
233
|
+
const hexOf = (digest) => (digest.includes(":") ? digest.split(":")[1] : digest);
|
|
234
|
+
/** A {@link SigstoreVerifier} that runs cosign. Image checks read the registry with docker's credentials. */
|
|
235
|
+
export function cosignVerifier(env, cosign = cosignPath(env)) {
|
|
236
|
+
let checked = null;
|
|
237
|
+
const check = () => (checked ?? (checked = cosignUnavailable(cosign, env)));
|
|
238
|
+
const go = async (args) => {
|
|
239
|
+
const r = await cosignRun(cosign, args, env, null, "", "");
|
|
240
|
+
return r.ok ? null : r.reason;
|
|
241
|
+
};
|
|
242
|
+
const blob = (bundle, args) => withTemp(async (dir) => {
|
|
243
|
+
const file = join(dir, "bundle.json");
|
|
244
|
+
writeFileSync(file, bundle);
|
|
245
|
+
return go(args(file));
|
|
246
|
+
});
|
|
247
|
+
return {
|
|
248
|
+
get name() {
|
|
249
|
+
return `cosign${check().version ? ` ${check().version}` : ""}`;
|
|
250
|
+
},
|
|
251
|
+
unavailable: () => check().reason,
|
|
252
|
+
verifyBlob: (bundle, digest, id) => blob(bundle, (f) => ["verify-blob", "--bundle", f, ...idFlags(id), `sha256:${hexOf(digest)}`]),
|
|
253
|
+
verifyBlobAttestation: (bundle, digest, predicateType, id) => blob(bundle, (f) => ["verify-blob-attestation", "--bundle", f, "--type", cosignType(predicateType), "--digest", hexOf(digest), "--digestAlg", "sha256", ...idFlags(id)]),
|
|
254
|
+
verifyImage: (ref, id) => go(["verify", ...idFlags(id), ref]),
|
|
255
|
+
verifyImageAttestation: (ref, predicateType, id) => go(["verify-attestation", "--type", cosignType(predicateType), ...idFlags(id), ref]),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
@@ -15,14 +15,25 @@
|
|
|
15
15
|
* Marketplace (through `vsce`) or Open VSX (through its REST API).
|
|
16
16
|
* - `tauri-updater` (./publish-tauri.ts): a Tauri updater manifest and the
|
|
17
17
|
* app's bundles on a rolling GitHub release, replaced on each publish.
|
|
18
|
+
* - `pypi` (./publish-pypi.ts): wheels and sdists uploaded to PyPI, TestPyPI
|
|
19
|
+
* or another index, with a token or PyPI's trusted publishing (#5167).
|
|
20
|
+
* - `cargo` (./publish-cargo.ts): `cargo publish` per crate of a workspace,
|
|
21
|
+
* in dependency order, to crates.io or another registry (#5167).
|
|
22
|
+
* - `mcp-registry` (./publish-mcp-registry.ts): a `server.json` on the
|
|
23
|
+
* official MCP Registry, revealed after every other target.
|
|
24
|
+
* - `index` (./publish-index.ts): manifests in an index repository such as
|
|
25
|
+
* krew-index or winget-pkgs, committed or proposed in a pull request,
|
|
26
|
+
* revealed after every other target. `homebrew` is its tap preset.
|
|
18
27
|
*
|
|
19
28
|
* A file a target reads that the release records as an artifact at the same
|
|
20
29
|
* path is checked against the release's digest, and a file that differs is
|
|
21
30
|
* refused (`publish-artifact-digest-mismatch`). Other files are the commit's
|
|
22
31
|
* by the checkout check (`checkCheckoutIsRelease` in ./release-publish.ts).
|
|
32
|
+
* A forge, homebrew or index target's `assets` may name `artifact:<name>`, every
|
|
33
|
+
* file the release records for that `release.artifacts` entry (#5151).
|
|
23
34
|
*/
|
|
24
35
|
import type { PublishDeclaration } from "./publish-declaration.js";
|
|
25
|
-
import { type PublishDeps, type PublishTarget } from "./release-publish.js";
|
|
36
|
+
import { type PublishContextBase, type PublishDeps, type PublishFetch, type PublishTarget } from "./release-publish.js";
|
|
26
37
|
import type { Release, ReleaseArtifact } from "./release-store.js";
|
|
27
38
|
/** Make each declaration a target, in the order declared. */
|
|
28
39
|
export declare function createPublishTargets(decls: readonly PublishDeclaration[], deps?: PublishDeps): Promise<PublishTarget[]>;
|
|
@@ -48,3 +59,18 @@ export declare function releaseArtifactAt(release: Release, kind: ReleaseArtifac
|
|
|
48
59
|
* and for an image its manifest and config digests).
|
|
49
60
|
*/
|
|
50
61
|
export declare function checkReleaseDigest(release: Release, kind: ReleaseArtifact["kind"], cwd: string, path: string, digests: readonly string[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* A target's `assets` with each `artifact:<name>` (#5151) made the paths the
|
|
64
|
+
* release records for that `release.artifacts` entry, in path order. A name
|
|
65
|
+
* the release records no file for is refused.
|
|
66
|
+
*/
|
|
67
|
+
export declare function expandArtifactAssets(release: Release, assets: readonly string[]): string[];
|
|
68
|
+
/** True when the run can get an OIDC ID token: a GitHub Actions job with `id-token: write`, or one in `variable`. */
|
|
69
|
+
export declare function hasIdToken(env: NodeJS.ProcessEnv, variable: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The run's OIDC ID token for `audience` (#5167): the value of `variable`
|
|
72
|
+
* when it is set, as a GitLab job's `id_tokens` entry gives it, else one
|
|
73
|
+
* GitHub Actions issues. Masked by the context's redactor. Throws `code`
|
|
74
|
+
* when there is none.
|
|
75
|
+
*/
|
|
76
|
+
export declare function runIdToken(ctx: PublishContextBase, fetchImpl: PublishFetch, audience: string, variable: string, code: string): Promise<string>;
|
|
@@ -15,11 +15,22 @@
|
|
|
15
15
|
* Marketplace (through `vsce`) or Open VSX (through its REST API).
|
|
16
16
|
* - `tauri-updater` (./publish-tauri.ts): a Tauri updater manifest and the
|
|
17
17
|
* app's bundles on a rolling GitHub release, replaced on each publish.
|
|
18
|
+
* - `pypi` (./publish-pypi.ts): wheels and sdists uploaded to PyPI, TestPyPI
|
|
19
|
+
* or another index, with a token or PyPI's trusted publishing (#5167).
|
|
20
|
+
* - `cargo` (./publish-cargo.ts): `cargo publish` per crate of a workspace,
|
|
21
|
+
* in dependency order, to crates.io or another registry (#5167).
|
|
22
|
+
* - `mcp-registry` (./publish-mcp-registry.ts): a `server.json` on the
|
|
23
|
+
* official MCP Registry, revealed after every other target.
|
|
24
|
+
* - `index` (./publish-index.ts): manifests in an index repository such as
|
|
25
|
+
* krew-index or winget-pkgs, committed or proposed in a pull request,
|
|
26
|
+
* revealed after every other target. `homebrew` is its tap preset.
|
|
18
27
|
*
|
|
19
28
|
* A file a target reads that the release records as an artifact at the same
|
|
20
29
|
* path is checked against the release's digest, and a file that differs is
|
|
21
30
|
* refused (`publish-artifact-digest-mismatch`). Other files are the commit's
|
|
22
31
|
* by the checkout check (`checkCheckoutIsRelease` in ./release-publish.ts).
|
|
32
|
+
* A forge, homebrew or index target's `assets` may name `artifact:<name>`, every
|
|
33
|
+
* file the release records for that `release.artifacts` entry (#5151).
|
|
23
34
|
*/
|
|
24
35
|
import { createHash } from "node:crypto";
|
|
25
36
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
@@ -49,6 +60,18 @@ export async function createPublishTargets(decls, deps = {}) {
|
|
|
49
60
|
case "tauri-updater":
|
|
50
61
|
out.push((await import("./publish-tauri.js")).tauriUpdaterTarget(d, deps));
|
|
51
62
|
break;
|
|
63
|
+
case "pypi":
|
|
64
|
+
out.push((await import("./publish-pypi.js")).pypiTarget(d, deps));
|
|
65
|
+
break;
|
|
66
|
+
case "cargo":
|
|
67
|
+
out.push((await import("./publish-cargo.js")).cargoTarget(d, deps));
|
|
68
|
+
break;
|
|
69
|
+
case "mcp-registry":
|
|
70
|
+
out.push((await import("./publish-mcp-registry.js")).mcpRegistryTarget(d, deps));
|
|
71
|
+
break;
|
|
72
|
+
case "index":
|
|
73
|
+
out.push((await import("./publish-index.js")).indexTarget(d, deps));
|
|
74
|
+
break;
|
|
52
75
|
}
|
|
53
76
|
}
|
|
54
77
|
return out;
|
|
@@ -98,3 +121,60 @@ export function checkReleaseDigest(release, kind, cwd, path, digests) {
|
|
|
98
121
|
return;
|
|
99
122
|
throw new PublishTargetError("publish-artifact-digest-mismatch", `${path} is not the ${kind} release ${release.releaseDigest} built: the release records ${recorded.digest}, and the file here is ${digests[0]}`, "Publish the files the cut built. A publish never builds, so restore them from the cut's build, or cut a new release.");
|
|
100
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* A target's `assets` with each `artifact:<name>` (#5151) made the paths the
|
|
126
|
+
* release records for that `release.artifacts` entry, in path order. A name
|
|
127
|
+
* the release records no file for is refused.
|
|
128
|
+
*/
|
|
129
|
+
export function expandArtifactAssets(release, assets) {
|
|
130
|
+
return assets.flatMap((a) => {
|
|
131
|
+
if (!a.startsWith("artifact:"))
|
|
132
|
+
return [a];
|
|
133
|
+
const name = a.slice("artifact:".length);
|
|
134
|
+
const paths = release.artifactDigests
|
|
135
|
+
.filter((f) => f.kind === "asset" && f.component === name)
|
|
136
|
+
.map((f) => f.path)
|
|
137
|
+
.sort();
|
|
138
|
+
if (paths.length === 0) {
|
|
139
|
+
throw new PublishTargetError("publish-artifact-not-recorded", `assets names ${a}, and release ${release.releaseDigest} records no file for an artifact "${name}"`, "Name an entry of release.artifacts the release was cut with, or cut a new release.");
|
|
140
|
+
}
|
|
141
|
+
return paths;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/** True when the run can get an OIDC ID token: a GitHub Actions job with `id-token: write`, or one in `variable`. */
|
|
145
|
+
export function hasIdToken(env, variable) {
|
|
146
|
+
return Boolean(env[variable] || (env.ACTIONS_ID_TOKEN_REQUEST_URL && env.ACTIONS_ID_TOKEN_REQUEST_TOKEN));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The run's OIDC ID token for `audience` (#5167): the value of `variable`
|
|
150
|
+
* when it is set, as a GitLab job's `id_tokens` entry gives it, else one
|
|
151
|
+
* GitHub Actions issues. Masked by the context's redactor. Throws `code`
|
|
152
|
+
* when there is none.
|
|
153
|
+
*/
|
|
154
|
+
export async function runIdToken(ctx, fetchImpl, audience, variable, code) {
|
|
155
|
+
const direct = ctx.env[variable];
|
|
156
|
+
if (direct) {
|
|
157
|
+
ctx.redactor.add(direct);
|
|
158
|
+
return direct;
|
|
159
|
+
}
|
|
160
|
+
if (!(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL && ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN)) {
|
|
161
|
+
throw new PublishTargetError(code, `this run has no OIDC ID token: not a GitHub Actions job with id-token: write, and ${variable} is not set`, `In GitHub Actions, give the job permissions: id-token: write. Elsewhere, put an ID token whose audience is ${audience} in ${variable}.`);
|
|
162
|
+
}
|
|
163
|
+
ctx.redactor.add(ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN);
|
|
164
|
+
const url = new URL(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL);
|
|
165
|
+
url.searchParams.set("audience", audience);
|
|
166
|
+
const res = await fetchImpl(url.toString(), { method: "GET", headers: { authorization: `Bearer ${ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN}`, accept: "application/json" } });
|
|
167
|
+
const text = await res.text().catch(() => "");
|
|
168
|
+
let value;
|
|
169
|
+
try {
|
|
170
|
+
value = res.status === 200 ? JSON.parse(text).value : undefined;
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
value = undefined;
|
|
174
|
+
}
|
|
175
|
+
if (typeof value !== "string" || !value) {
|
|
176
|
+
throw new PublishTargetError(code, `GitHub Actions gave no OIDC ID token for ${audience}: it answered ${res.status}`, "Give the job permissions: id-token: write.");
|
|
177
|
+
}
|
|
178
|
+
ctx.redactor.add(value);
|
|
179
|
+
return value;
|
|
180
|
+
}
|