@xemahq/xema 0.48.0 → 0.49.1
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/assets/appliance-base/distribution.lock.json +3936 -1515
- package/dist/assets/appliance-base/images.lock.json +878 -1161
- package/dist/assets/appliance-lean/distribution.lock.json +3663 -916
- package/dist/assets/appliance-lean/images.lock.json +825 -924
- package/dist/assets/boot-graph.json +398 -93
- package/dist/assets/distribution-assets.manifest.json +10 -10
- package/dist/commands/edition.d.ts.map +1 -1
- package/dist/commands/edition.js +5 -3
- package/dist/commands/edition.js.map +1 -1
- package/dist/dev/env-defaults.d.ts.map +1 -1
- package/dist/dev/env-defaults.js +0 -1
- package/dist/dev/env-defaults.js.map +1 -1
- package/dist/edition/verify-image-evidence.bundle.mjs +4386 -2503
- package/dist/edition/verify-image-evidence.bundle.provenance.json +590 -488
- package/dist/runtime/auth/cli-application.d.ts +18 -0
- package/dist/runtime/auth/cli-application.d.ts.map +1 -0
- package/dist/runtime/auth/cli-application.js +39 -0
- package/dist/runtime/auth/cli-application.js.map +1 -0
- package/dist/runtime/edition/verb-map.d.ts +3 -1
- package/dist/runtime/edition/verb-map.d.ts.map +1 -1
- package/dist/runtime/edition/verb-map.js +5 -1
- package/dist/runtime/edition/verb-map.js.map +1 -1
- package/dist/runtime/env-seeder.d.ts.map +1 -1
- package/dist/runtime/env-seeder.js +21 -0
- package/dist/runtime/env-seeder.js.map +1 -1
- package/dist/runtime/launch.d.ts.map +1 -1
- package/dist/runtime/launch.js +0 -18
- package/dist/runtime/launch.js.map +1 -1
- package/edition/README.md +20 -3
- package/edition/biome-content.mjs +5 -2
- package/edition/build-runtime-image-source-index.mjs +79 -5
- package/edition/canonical-evidence-json.mjs +82 -0
- package/edition/catalogue-evidence.mjs +8 -5
- package/edition/customer-edition-verbs.mjs +9 -3
- package/edition/develop-coverage-run.mjs +2 -1
- package/edition/develop-coverage.mjs +12 -1
- package/edition/develop-edition-resolve.mjs +3 -2
- package/edition/develop-edition.mjs +15 -3
- package/edition/develop-record-verify.mjs +216 -0
- package/edition/develop-select-records.mjs +24 -225
- package/edition/develop-verify-image-record.mjs +90 -0
- package/edition/dist-check.mjs +24 -3
- package/edition/distribution-evidence-set.mjs +30 -2
- package/edition/edition-artifact.mjs +110 -22
- package/edition/edition-ceiling.mjs +180 -0
- package/edition/edition-config.mjs +91 -0
- package/edition/edition-constants.mjs +21 -3
- package/edition/edition-contract-parse.mjs +88 -3
- package/edition/edition-contract.json +47 -4
- package/edition/edition-image-seal.mjs +9 -2
- package/edition/edition-kind.mjs +10 -0
- package/edition/edition-protocol.mjs +7 -1
- package/edition/edition-publisher.mjs +21 -0
- package/edition/edition-seal.mjs +257 -0
- package/edition/evidence-grammars.mjs +2 -0
- package/edition/evidence-trust-pin.mjs +66 -10
- package/edition/evidence-trust-policy.mjs +39 -29
- package/edition/external-source-walk.mjs +16 -3
- package/edition/fleet-coordinate-finality.mjs +18 -5
- package/edition/fulcio-certificate-extensions.mjs +231 -0
- package/edition/image-evidence.mjs +34 -79
- package/edition/locked-bundle-signer.mjs +241 -0
- package/edition/oci-evidence-verbs.mjs +7 -1
- package/edition/pinned-cosign.mjs +70 -0
- package/edition/plan-image-evidence-refresh.mjs +3 -1
- package/edition/producer-evidence-bundle.mjs +3 -1
- package/edition/producer-evidence-index-file.mjs +4 -0
- package/edition/release-edition-artifact.mjs +3 -3
- package/edition/repin-evidence-trust.mjs +6 -1
- package/edition/resolve-distribution.mjs +90 -7
- package/edition/resolve-edition.mjs +1 -1
- package/edition/resolve-images.mjs +53 -7
- package/edition/seal-image-digests.mjs +19 -8
- package/edition/sealed-distribution-lock.mjs +2 -2
- package/edition/third-party-admission.mjs +91 -0
- package/edition/third-party-bundle-registry.mjs +147 -0
- package/edition/third-party-certificate-extensions.mjs +21 -0
- package/edition/third-party-image-pins.mjs +41 -0
- package/edition/third-party-pins-trusted.mjs +24 -0
- package/edition/third-party-producer-evidence.mjs +76 -0
- package/edition/third-party-source-check.mjs +28 -0
- package/edition/third-party-source-context.mjs +41 -0
- package/edition/third-party-source-evidence.mjs +255 -0
- package/edition/third-party-source-flags.mjs +134 -0
- package/edition/third-party-source-pins.mjs +259 -0
- package/edition/third-party-source-uniqueness.mjs +54 -0
- package/edition/third-party-source-walk.mjs +115 -0
- package/edition/third-party-source-writer.mjs +229 -0
- package/edition/third-party-subjects.mjs +128 -0
- package/edition/trust-policy-image-ownership.mjs +85 -0
- package/edition/verify-catalogue-evidence.mjs +2 -0
- package/edition/verify-image-evidence.mjs +2 -0
- package/edition/verify-image-platforms.mjs +33 -9
- package/package.json +5 -5
- package/dist/runtime/auth/client-bootstrap.d.ts +0 -11
- package/dist/runtime/auth/client-bootstrap.d.ts.map +0 -1
- package/dist/runtime/auth/client-bootstrap.js +0 -60
- package/dist/runtime/auth/client-bootstrap.js.map +0 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// The registry side of the third-party writer (XEMA-1611 design section 3 (a)): the biome bundle, by digest, and the
|
|
2
|
+
// sigstore bundle of its SLSA provenance, read as an OCI referrer. Nothing here is trusted: every byte it returns is
|
|
3
|
+
// verified by cosign (`third-party-source-evidence.mjs`) before it is committed.
|
|
4
|
+
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
import { certificateConstraintArgs } from './cosign-certificate-constraints.mjs';
|
|
8
|
+
import { COSIGN_ENV, decodeExactUtf8, sha256Digest, validatePinnedTrustedRoot } from './image-evidence.mjs';
|
|
9
|
+
import { splitImageRef } from './registry-credentials.mjs';
|
|
10
|
+
import { BUNDLE_MEDIA_TYPE } from './sigstore-bundle-media-type.mjs';
|
|
11
|
+
import { SLSA_PROVENANCE_V1, decodeJsonStatement, digestOfOciRef } from './third-party-source-evidence.mjs';
|
|
12
|
+
import { assertPreparedExecutable } from './trusted-executable.mjs';
|
|
13
|
+
|
|
14
|
+
const BIOME_MANIFEST_FILE = 'xema-biome.json';
|
|
15
|
+
const BIOME_GENERATED_INDEX_FILE = 'xema-biome.index.json';
|
|
16
|
+
const OCI_TITLE_ANNOTATION = 'org.opencontainers.image.title';
|
|
17
|
+
const MAX_BIOME_MANIFEST_BYTES = 4 * 1024 * 1024;
|
|
18
|
+
const MAX_BUNDLE_BYTES = 16 * 1024 * 1024;
|
|
19
|
+
const REGISTRY_COSIGN_TIMEOUT_MS = 120_000;
|
|
20
|
+
/** What `cosign verify-attestation --type` calls the SLSA v1 provenance predicate. */
|
|
21
|
+
const COSIGN_SLSA_PROVENANCE_ALIAS = 'slsaprovenance1';
|
|
22
|
+
|
|
23
|
+
const repositoryOf = (ociRef) => splitImageRef(ociRef.slice(0, ociRef.indexOf('@')));
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The biome bundle manifest JSON (`xema-biome.json`) of an OCI artifact, fetched by digest.
|
|
27
|
+
*
|
|
28
|
+
* @returns {Promise<{manifest: object, bytes: Buffer}>}
|
|
29
|
+
*/
|
|
30
|
+
export async function fetchBundleManifest({ clientFor, ociRef }) {
|
|
31
|
+
const bytes = await fetchTitledLayer({ clientFor, ociRef, title: BIOME_MANIFEST_FILE });
|
|
32
|
+
return { manifest: decodeJsonStatement(bytes, `${ociRef} ${BIOME_MANIFEST_FILE}`), bytes };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The committed generated index (`xema-biome.index.json`) of an OCI biome bundle, fetched by digest: the authority for
|
|
37
|
+
* the biomes the bundle requires, read from the same bundle bytes as its manifest, so it cannot describe another revision.
|
|
38
|
+
*/
|
|
39
|
+
export async function fetchBundleGeneratedIndex({ clientFor, ociRef }) {
|
|
40
|
+
const bytes = await fetchTitledLayer({ clientFor, ociRef, title: BIOME_GENERATED_INDEX_FILE });
|
|
41
|
+
return decodeJsonStatement(bytes, `${ociRef} ${BIOME_GENERATED_INDEX_FILE}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The one layer of the bundle manifest at `ociRef` (by digest) annotated with `title`. */
|
|
45
|
+
async function fetchTitledLayer({ clientFor, ociRef, title }) {
|
|
46
|
+
const { authority, repository } = repositoryOf(ociRef);
|
|
47
|
+
const client = clientFor(authority);
|
|
48
|
+
const { document } = await client.getManifestByDigest(repository, digestOfOciRef(ociRef));
|
|
49
|
+
const layers = (document.layers ?? []).filter((layer) => layer.annotations?.[OCI_TITLE_ANNOTATION] === title);
|
|
50
|
+
if (layers.length !== 1) {
|
|
51
|
+
throw new Error(`${ociRef} has ${layers.length} layers titled ${title}; a biome bundle has exactly one`);
|
|
52
|
+
}
|
|
53
|
+
const bytes = await client.getBlob(repository, layers[0].digest, MAX_BIOME_MANIFEST_BYTES);
|
|
54
|
+
if (sha256Digest(bytes) !== layers[0].digest) {
|
|
55
|
+
throw new Error(`${ociRef} layer titled ${title} does not match its descriptor`);
|
|
56
|
+
}
|
|
57
|
+
return bytes;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The image names a biome manifest ships: its service and worker components with an `oci-image` artifact, named the way
|
|
62
|
+
* the index builder names them (a service by `protocol.serviceName`, a worker by its component `key`).
|
|
63
|
+
*/
|
|
64
|
+
export function bundleImageNames(manifest) {
|
|
65
|
+
const components = Array.isArray(manifest?.xema?.components) ? manifest.xema.components : [];
|
|
66
|
+
return new Set(
|
|
67
|
+
components
|
|
68
|
+
.filter((component) => (component?.kind === 'service' || component?.kind === 'worker') && component.artifact?.kind === 'oci-image')
|
|
69
|
+
.map((component) => (component.kind === 'service' ? component.protocol?.serviceName : component.key)),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function provenanceOf(bundleBytes, bundleDigest) {
|
|
74
|
+
const bundle = JSON.parse(decodeExactUtf8(bundleBytes, 'sigstore bundle'));
|
|
75
|
+
if (bundle?.dsseEnvelope === undefined) {
|
|
76
|
+
return null; // a message-signature bundle (the artifact signature): not an attestation
|
|
77
|
+
}
|
|
78
|
+
const payload = Buffer.from(bundle.dsseEnvelope.payload, 'base64');
|
|
79
|
+
const statement = decodeJsonStatement(payload, 'DSSE payload');
|
|
80
|
+
if (statement.predicateType !== SLSA_PROVENANCE_V1) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (`sha256:${statement.subject?.[0]?.digest?.sha256}` !== bundleDigest) {
|
|
84
|
+
throw new Error(`a SLSA provenance referrer attests ${statement.subject?.[0]?.digest?.sha256}, not ${bundleDigest}`);
|
|
85
|
+
}
|
|
86
|
+
return { statementBytes: payload, bundleBytes };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The SLSA provenance attestation of the bundle: the one sigstore-bundle referrer of `ociRef` whose DSSE statement is a
|
|
91
|
+
* `https://slsa.dev/provenance/v1` attestation over exactly this digest. None, or more than one, is refused.
|
|
92
|
+
*
|
|
93
|
+
* @returns {Promise<{statementBytes: Buffer, bundleBytes: Buffer}>}
|
|
94
|
+
*/
|
|
95
|
+
export async function fetchBundleProvenance({ clientFor, ociRef }) {
|
|
96
|
+
const { authority, repository } = repositoryOf(ociRef);
|
|
97
|
+
const client = clientFor(authority);
|
|
98
|
+
const subjectDigest = digestOfOciRef(ociRef);
|
|
99
|
+
const referrers = await client.listReferrers(repository, subjectDigest, BUNDLE_MEDIA_TYPE);
|
|
100
|
+
const found = [];
|
|
101
|
+
for (const referrer of referrers) {
|
|
102
|
+
const { document } = await client.getManifestByDigest(repository, referrer.digest);
|
|
103
|
+
for (const layer of document.layers ?? []) {
|
|
104
|
+
if (layer.mediaType !== BUNDLE_MEDIA_TYPE) {continue;}
|
|
105
|
+
const bytes = await client.getBlob(repository, layer.digest, MAX_BUNDLE_BYTES);
|
|
106
|
+
if (sha256Digest(bytes) !== layer.digest) {
|
|
107
|
+
throw new Error(`${ociRef} referrer ${referrer.digest} layer does not match its descriptor`);
|
|
108
|
+
}
|
|
109
|
+
const provenance = provenanceOf(bytes, subjectDigest);
|
|
110
|
+
if (provenance !== null) {found.push(provenance);}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (found.length === 0) {
|
|
114
|
+
throw new Error(`${ociRef} has no SLSA provenance attestation (${SLSA_PROVENANCE_V1}) among its ${referrers.length} sigstore-bundle referrers; the bundle must be published with provenance`);
|
|
115
|
+
}
|
|
116
|
+
if (found.length > 1) {
|
|
117
|
+
throw new Error(`${ociRef} has ${found.length} SLSA provenance attestations; exactly one is required, so the evidence is unambiguous`);
|
|
118
|
+
}
|
|
119
|
+
return found[0];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const tail = (error) => String(error?.stderr ?? error?.message ?? error).trim().split('\n').slice(-4).join(' | ').slice(0, 1024);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* (a) against the registry: keyless `cosign verify` and `cosign verify-attestation --type slsaprovenance1` of the bundle
|
|
126
|
+
* artifact under EXACTLY the signer row's identity and issuer, the row's workflow repository, ref and the stated
|
|
127
|
+
* commit, the pinned trusted root and the trusted cosign binary. `--offline` verifies the tlog inclusion proof carried
|
|
128
|
+
* with the signature; the tlog is never ignored. The registry credential is the operator's (HOME / DOCKER_CONFIG).
|
|
129
|
+
*/
|
|
130
|
+
export function verifyBundleOnRegistry({ trustedCosign, policy, policyRoot, row, workflowSha, ociRef, env = process.env }) {
|
|
131
|
+
const root = validatePinnedTrustedRoot(policyRoot, policy);
|
|
132
|
+
const common = ['--offline', '--trusted-root', root.path, ...certificateConstraintArgs(row, workflowSha)];
|
|
133
|
+
const environment = {
|
|
134
|
+
...COSIGN_ENV,
|
|
135
|
+
...(env.HOME === undefined ? {} : { HOME: env.HOME }),
|
|
136
|
+
...(env.DOCKER_CONFIG === undefined ? {} : { DOCKER_CONFIG: env.DOCKER_CONFIG }),
|
|
137
|
+
};
|
|
138
|
+
const run = (command, args) => {
|
|
139
|
+
try {
|
|
140
|
+
execFileSync(assertPreparedExecutable(trustedCosign, 'cosign'), [command, ...args], { env: environment, stdio: ['ignore', 'ignore', 'pipe'], timeout: REGISTRY_COSIGN_TIMEOUT_MS });
|
|
141
|
+
} catch (error) {
|
|
142
|
+
throw new Error(`cosign ${command} refused ${ociRef} under row "${row.policyId}": ${tail(error)}`);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
run('verify', [...common, ociRef]);
|
|
146
|
+
run('verify-attestation', ['--type', COSIGN_SLSA_PROVENANCE_ALIAS, ...common, ociRef]);
|
|
147
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// (d) of the third-party checks: the Fulcio extensions of a bundle's leaf certificate, held to a source pin. Its own module
|
|
2
|
+
// (it imports no evidence module) because admission in `image-evidence.mjs` and the pin verifier both use it.
|
|
3
|
+
|
|
4
|
+
import { FulcioExtensionOid, GITHUB_HOSTED_RUNNER_ENVIRONMENT, readFulcioExtensionsFromBundle } from './fulcio-certificate-extensions.mjs';
|
|
5
|
+
|
|
6
|
+
/** The leaf certificate of a parsed Sigstore `bundle` states the pinned repository id, owner id and a GitHub-hosted runner. */
|
|
7
|
+
export function assertCertificateExtensions({ bundle, source, label }) {
|
|
8
|
+
const read = readFulcioExtensionsFromBundle(bundle);
|
|
9
|
+
const expectations = [
|
|
10
|
+
[FulcioExtensionOid.SourceRepositoryIdentifier, 'Source Repository Identifier', read.sourceRepositoryIdentifier, source.repositoryId, 'repositoryId'],
|
|
11
|
+
[FulcioExtensionOid.SourceRepositoryOwnerIdentifier, 'Source Repository Owner Identifier', read.sourceRepositoryOwnerIdentifier, source.repositoryOwnerId, 'repositoryOwnerId'],
|
|
12
|
+
[FulcioExtensionOid.RunnerEnvironment, 'Runner Environment', read.runnerEnvironment, GITHUB_HOSTED_RUNNER_ENVIRONMENT, GITHUB_HOSTED_RUNNER_ENVIRONMENT],
|
|
13
|
+
];
|
|
14
|
+
for (const [oid, name, actual, expected, pinned] of expectations) {
|
|
15
|
+
if (actual !== expected) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`${label} certificate ${name} (${oid}) is ${JSON.stringify(actual)}, but the pin requires ${JSON.stringify(expected)} (${pinned})`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// The pinned images of the third-party subjects of an images lock (XEMA-1611 design sections 3 and 4).
|
|
2
|
+
//
|
|
3
|
+
// A third-party subject's `contentHash` is the PUBLISHER'S `sourceTreeHash` (publisher-attested): it is never a registry
|
|
4
|
+
// tag. Every seal, coverage and evidence-set path that serves such a subject goes to the pin instead: the image is read
|
|
5
|
+
// BY the pin's `manifestDigest` and its evidence is the committed evidence the pin's `statementDigest` and `bundleDigest`
|
|
6
|
+
// bind. This module is the one place a subject is joined to its pinned image.
|
|
7
|
+
|
|
8
|
+
/** The `kind:id` key of an image subject, as the seal reports and the digest plans spell it. */
|
|
9
|
+
export const imageSubjectKey = (subject) => `${subject.kind}:${subject.id}`;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The pinned image of every third-party subject of `subjects`, by `kind:id`. A subject is third-party when its `repo` is a
|
|
13
|
+
* pinned third-party repository. Refuses a third-party subject the pin pins no image for, and one whose `imageRef` or
|
|
14
|
+
* `contentHash` is not the pin image's `imageRef` and `sourceTreeHash`.
|
|
15
|
+
*
|
|
16
|
+
* @param {{pins: {byRepository: (repository: string) => object|undefined}, subjects: readonly object[]}} request
|
|
17
|
+
* @returns {Map<string, object>}
|
|
18
|
+
*/
|
|
19
|
+
export function thirdPartyImagePins({ pins, subjects }) {
|
|
20
|
+
const pinned = new Map();
|
|
21
|
+
for (const subject of subjects) {
|
|
22
|
+
const pin = pins.byRepository(subject.repo);
|
|
23
|
+
if (pin === undefined) {continue;}
|
|
24
|
+
const key = imageSubjectKey(subject);
|
|
25
|
+
const image = pin.images.find((candidate) => candidate.subjectKind === subject.kind && candidate.subjectId === subject.id);
|
|
26
|
+
if (image === undefined) {
|
|
27
|
+
throw new Error(`${key} is a subject of the third-party repository "${subject.repo}" (source "${pin.name}"), but the pin pins no image for ${key}`);
|
|
28
|
+
}
|
|
29
|
+
if (subject.imageRef !== image.imageRef) {
|
|
30
|
+
throw new Error(`${key} (third-party source "${pin.name}") has imageRef ${subject.imageRef}, but the pin pins ${image.imageRef}`);
|
|
31
|
+
}
|
|
32
|
+
if (subject.contentHash !== image.sourceTreeHash) {
|
|
33
|
+
throw new Error(`${key} (third-party source "${pin.name}") has contentHash ${subject.contentHash}, but the pin's publisher-attested sourceTreeHash is ${image.sourceTreeHash}`);
|
|
34
|
+
}
|
|
35
|
+
pinned.set(key, image);
|
|
36
|
+
}
|
|
37
|
+
return pinned;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The `kind:id` -> manifestDigest map the platform verifier reads pinned subjects by. */
|
|
41
|
+
export const pinnedManifestDigests = (pinnedImages) => new Map([...pinnedImages].map(([key, image]) => [key, image.manifestDigest]));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The data root's third-party source pins, read by a consumer that does not run the full evidence verification (the
|
|
2
|
+
// develop and release seals): held to the evidence trust pin's record of the pin file's digest exactly as the verifiers
|
|
3
|
+
// hold it (`assertPinnedThirdPartySourcePins`), so a pin file changed after the trust pin was last taken is refused.
|
|
4
|
+
|
|
5
|
+
import { editionWorkspaceConfig } from './edition-config.mjs';
|
|
6
|
+
import { assertPinnedThirdPartySourcePins, readEvidenceTrustPin } from './evidence-trust-pin.mjs';
|
|
7
|
+
import { THIRD_PARTY_SOURCE_PINS_FILE, loadThirdPartySourcePins, thirdPartySourcePinsDigest } from './third-party-source-pins.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} dataRoot
|
|
11
|
+
* @returns the loaded third-party source pins, or an empty set when the data root has none and declares no trust pin
|
|
12
|
+
*/
|
|
13
|
+
export function loadTrustedThirdPartySourcePins(dataRoot) {
|
|
14
|
+
const declaration = editionWorkspaceConfig().evidenceTrustPolicy;
|
|
15
|
+
if (declaration.policy === null) {
|
|
16
|
+
const digest = thirdPartySourcePinsDigest(dataRoot);
|
|
17
|
+
if (digest !== null) {
|
|
18
|
+
throw new Error(`the data root holds ${THIRD_PARTY_SOURCE_PINS_FILE} (${digest}) but declares no evidenceTrustPolicy, so there is no trust pin to hold it to`);
|
|
19
|
+
}
|
|
20
|
+
return loadThirdPartySourcePins(dataRoot);
|
|
21
|
+
}
|
|
22
|
+
assertPinnedThirdPartySourcePins({ pin: readEvidenceTrustPin({ dataRoot, declaration }), dataRoot });
|
|
23
|
+
return loadThirdPartySourcePins(dataRoot);
|
|
24
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// The producer record of one third-party image subject in an evidence set (XEMA-1611 design section 4).
|
|
2
|
+
//
|
|
3
|
+
// A first-party subject's evidence is read from the registry (the OCI referrer of `<imageRef>:<contentHash>`). A
|
|
4
|
+
// third-party subject has no such tag: its `contentHash` is the publisher's attested `sourceTreeHash`. Its evidence is
|
|
5
|
+
// the COMMITTED evidence of the data root (`evidence/sha256-<manifest hex>/producer-evidence.json` + statements/ +
|
|
6
|
+
// bundles/) that its pin binds by `statementDigest` and `bundleDigest`. This reads that evidence, holds it to the pin
|
|
7
|
+
// and to the subject, and returns the SAME record shape the first-party branch of `resolveProducerEvidence` builds.
|
|
8
|
+
// It makes no registry call.
|
|
9
|
+
|
|
10
|
+
import { canonicalJson, decodeExactUtf8, evidenceDirectoryForDigest, sha256Digest } from './image-evidence.mjs';
|
|
11
|
+
import { readBoundedNoFollowFile } from './no-follow-file.mjs';
|
|
12
|
+
import { validateProducedBundle } from './produce-image-source-evidence.mjs';
|
|
13
|
+
import { BUNDLE_MEDIA_TYPE } from './sigstore-bundle-media-type.mjs';
|
|
14
|
+
import { committedImageDescriptor } from './third-party-source-evidence.mjs';
|
|
15
|
+
|
|
16
|
+
/** The bound committed evidence files are read at (the same as the first-party committed reads). */
|
|
17
|
+
const MAX_EVIDENCE_FILE_BYTES = 4 * 1024 * 1024;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {object} request
|
|
21
|
+
* @param {object} request.subject the third-party image subject (sealed or not)
|
|
22
|
+
* @param {object} request.pinImage its image in the third-party source pin
|
|
23
|
+
* @param {string} request.dataRoot the data root holding the committed evidence
|
|
24
|
+
* @param {object} request.schemas trusted kernel distribution schemas
|
|
25
|
+
* @param {object} request.expectedSource the canonical `predicate.source` the statement must attest
|
|
26
|
+
* @param {string} request.stem the producer's staging stem
|
|
27
|
+
*/
|
|
28
|
+
export function thirdPartyProducerRecord({ subject, pinImage, dataRoot, schemas, expectedSource, stem }) {
|
|
29
|
+
const key = `${subject.kind}:${subject.id}`;
|
|
30
|
+
const label = `third-party ${key} committed evidence`;
|
|
31
|
+
const descriptor = committedImageDescriptor({ image: pinImage, evidenceRoot: dataRoot, label });
|
|
32
|
+
const statementBytes = readBoundedNoFollowFile(dataRoot, descriptor.statementPath, `${label} statement`, MAX_EVIDENCE_FILE_BYTES).bytes;
|
|
33
|
+
const bundleBytes = readBoundedNoFollowFile(dataRoot, descriptor.bundlePath, `${label} bundle`, MAX_EVIDENCE_FILE_BYTES).bytes;
|
|
34
|
+
if (sha256Digest(statementBytes) !== pinImage.statementDigest) {
|
|
35
|
+
throw new Error(`${label}: the committed statement ${descriptor.statementPath} is ${sha256Digest(statementBytes)}, not the pin's statementDigest ${pinImage.statementDigest}`);
|
|
36
|
+
}
|
|
37
|
+
if (sha256Digest(bundleBytes) !== pinImage.bundleDigest) {
|
|
38
|
+
throw new Error(`${label}: the committed bundle ${descriptor.bundlePath} is ${sha256Digest(bundleBytes)}, not the pin's bundleDigest ${pinImage.bundleDigest}`);
|
|
39
|
+
}
|
|
40
|
+
validateProducedBundle(statementBytes, bundleBytes);
|
|
41
|
+
const statement = schemas.parseImageProducerStatement(JSON.parse(decodeExactUtf8(statementBytes, 'committed statement')));
|
|
42
|
+
if (canonicalJson(statement.predicate.source) !== canonicalJson(expectedSource)) {
|
|
43
|
+
throw new Error(`${label}: the committed statement attests another source than the one ${key} is locked at (${subject.repo}@${subject.sourceCommit}, publisher-attested source tree ${subject.contentHash})`);
|
|
44
|
+
}
|
|
45
|
+
const { artifact } = statement.predicate;
|
|
46
|
+
if (artifact.imageRepository !== subject.imageRef || statement.subject[0].name !== subject.imageRef) {
|
|
47
|
+
throw new Error(`${label}: it attests image "${artifact.imageRepository}" (statement subject "${statement.subject[0].name}"), not the locked "${subject.imageRef}"`);
|
|
48
|
+
}
|
|
49
|
+
if (`sha256:${statement.subject[0].digest.sha256}` !== artifact.manifestDigest) {
|
|
50
|
+
throw new Error(`${label}: its statement subject digest sha256:${statement.subject[0].digest.sha256} is not its artifact.manifestDigest ${artifact.manifestDigest}`);
|
|
51
|
+
}
|
|
52
|
+
if (artifact.manifestDigest !== pinImage.manifestDigest) {
|
|
53
|
+
throw new Error(`${label}: the committed statement attests manifest ${artifact.manifestDigest}, not the pin's manifestDigest ${pinImage.manifestDigest}`);
|
|
54
|
+
}
|
|
55
|
+
if (subject.imageDigest !== undefined && subject.imageDigest !== artifact.manifestDigest) {
|
|
56
|
+
throw new Error(`${label}: ${key} is sealed at ${subject.imageDigest}, but the committed statement attests manifest ${artifact.manifestDigest}`);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
stem,
|
|
60
|
+
subjectKind: subject.kind,
|
|
61
|
+
subjectId: subject.id,
|
|
62
|
+
imageRepository: subject.imageRef,
|
|
63
|
+
manifestDigest: artifact.manifestDigest,
|
|
64
|
+
statement,
|
|
65
|
+
sourceDirectory: evidenceDirectoryForDigest(pinImage.manifestDigest),
|
|
66
|
+
statementBytes,
|
|
67
|
+
bundleBytes,
|
|
68
|
+
evidence: {
|
|
69
|
+
statementPath: `producers/${stem}/statement.json`,
|
|
70
|
+
statementDigest: sha256Digest(statementBytes),
|
|
71
|
+
bundlePath: `producers/${stem}/bundle.sigstore.json`,
|
|
72
|
+
bundleDigest: sha256Digest(bundleBytes),
|
|
73
|
+
bundleMediaType: BUNDLE_MEDIA_TYPE,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// `xema edition index runtime-image-source --check-third-party` (XEMA-1611 design section 3, `--check`): re-run checks
|
|
2
|
+
// (a) to (e) for every pin of `third-party-source-pins.json` from the COMMITTED evidence, offline. A data root with no
|
|
3
|
+
// pin file has no third-party source and passes trivially (zero-config); a pin file that is present but wrong throws.
|
|
4
|
+
|
|
5
|
+
import { loadThirdPartySourceContext } from './third-party-source-context.mjs';
|
|
6
|
+
import { verifyThirdPartySourceEvidence } from './third-party-source-evidence.mjs';
|
|
7
|
+
import { loadThirdPartySourcePins } from './third-party-source-pins.mjs';
|
|
8
|
+
import { assertThirdPartyUniqueness } from './third-party-source-uniqueness.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @returns {Promise<{checked: number, absence: string|null}>}
|
|
12
|
+
*/
|
|
13
|
+
export async function checkThirdPartySourcePins({ dataRoot, schemas, cosignBinary }) {
|
|
14
|
+
const pins = loadThirdPartySourcePins(dataRoot);
|
|
15
|
+
if (pins.sources.length === 0) {
|
|
16
|
+
return { checked: 0, absence: pins.absence };
|
|
17
|
+
}
|
|
18
|
+
const context = loadThirdPartySourceContext({ dataRoot, schemas, cosignBinary });
|
|
19
|
+
try {
|
|
20
|
+
assertThirdPartyUniqueness({ sources: pins.sources, ...context });
|
|
21
|
+
for (const source of pins.sources) {
|
|
22
|
+
verifyThirdPartySourceEvidence({ source, evidenceRoot: dataRoot, context });
|
|
23
|
+
}
|
|
24
|
+
} finally {
|
|
25
|
+
context.dispose();
|
|
26
|
+
}
|
|
27
|
+
return { checked: pins.sources.length, absence: null };
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// What the third-party writer and `--check-third-party` verify a pin AGAINST: the data root's pinned trust policy, its
|
|
2
|
+
// pinned kernel contract authority, its committed indexes and a cosign binary held to the policy's digest pins.
|
|
3
|
+
// One loader, so the two cannot be given different trust.
|
|
4
|
+
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { editionWorkspaceConfig } from './edition-config.mjs';
|
|
8
|
+
import { RUNTIME_IMAGE_SOURCE_INDEX_FILE, loadPinnedDeclaredTrustPolicy, readPinnedKernelContractAuthority } from './evidence-trust-pin.mjs';
|
|
9
|
+
import { prepareTrustedCosignBinary } from './image-evidence.mjs';
|
|
10
|
+
import { readStrictJsonFile } from './strict-json.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Load the verification context of `dataRoot`. Throws when the data root declares no evidence trust policy, when the
|
|
14
|
+
* policy or the third-party pin file is not the one the evidence trust pin records (review, then
|
|
15
|
+
* `xema edition repin-evidence-trust`), or when the cosign binary is not one the policy pins.
|
|
16
|
+
*
|
|
17
|
+
* @returns {{policy, policyRoot, schemas, expectedContractAuthority, runtimeSourceIndex, biomeIndex, platformServiceIndex, trustedCosign, dispose: () => void}}
|
|
18
|
+
*/
|
|
19
|
+
export function loadThirdPartySourceContext({ dataRoot, schemas, cosignBinary }) {
|
|
20
|
+
if (cosignBinary === undefined) {
|
|
21
|
+
throw new Error('verifying a third-party source needs a cosign binary: pass --cosign <absolute path> (`dist-check` reads XEMA_COSIGN_BIN); it must be one the trust policy pins by digest');
|
|
22
|
+
}
|
|
23
|
+
const declaration = editionWorkspaceConfig().evidenceTrustPolicy;
|
|
24
|
+
const policy = loadPinnedDeclaredTrustPolicy({ dataRoot, declaration, schemas });
|
|
25
|
+
const expectedContractAuthority = readPinnedKernelContractAuthority({ dataRoot, declaration, schemas });
|
|
26
|
+
const runtimeSourceIndex = schemas.parseRuntimeImageSourceIndex(readStrictJsonFile(join(dataRoot, RUNTIME_IMAGE_SOURCE_INDEX_FILE)));
|
|
27
|
+
const biomeIndex = readStrictJsonFile(join(dataRoot, 'biome-index.json'));
|
|
28
|
+
const platformServiceIndex = readStrictJsonFile(join(dataRoot, 'platform-service-index.json'));
|
|
29
|
+
const trustedCosign = prepareTrustedCosignBinary({ cosignBinary, policy });
|
|
30
|
+
return {
|
|
31
|
+
policy,
|
|
32
|
+
policyRoot: dataRoot,
|
|
33
|
+
schemas,
|
|
34
|
+
expectedContractAuthority,
|
|
35
|
+
runtimeSourceIndex,
|
|
36
|
+
biomeIndex,
|
|
37
|
+
platformServiceIndex,
|
|
38
|
+
trustedCosign,
|
|
39
|
+
dispose: () => trustedCosign.dispose(),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// Re-verification of ONE third-party source pin from its COMMITTED evidence (XEMA-1611 design section 3, checks
|
|
2
|
+
// (a) to (d)). The trusted writer runs it on the evidence it is about to commit, and `--check-third-party` runs it
|
|
3
|
+
// on the committed tree, so the two cannot disagree about what a pin proves. Nothing here reads a network: the
|
|
4
|
+
// signatures are verified by `verifySigstoreEvidenceDescriptor` (cosign `verify-blob-attestation --offline` against the
|
|
5
|
+
// pinned trusted root, the tlog inclusion proof taken from the committed bundle, never `--insecure-ignore-tlog`).
|
|
6
|
+
//
|
|
7
|
+
// Where the evidence lives, relative to the data root:
|
|
8
|
+
// third-party-provenance/sha256-<bundle manifest hex>/{statement.json,bundle.sigstore.json}
|
|
9
|
+
// the SLSA provenance attestation of the biome bundle (the bytes cosign signed, which are not canonical JSON);
|
|
10
|
+
// evidence/sha256-<image manifest hex>/producer-evidence.json (+ statements/, bundles/)
|
|
11
|
+
// the image-source/v2 evidence, stored the way a first-party producer commits it.
|
|
12
|
+
|
|
13
|
+
import { decodeExactUtf8, evidenceDirectoryForDigest, verifySigstoreEvidenceDescriptor } from './image-evidence.mjs';
|
|
14
|
+
import { assertKernelContractAuthorityEqual } from './kernel-contract-authority.mjs';
|
|
15
|
+
import { readBoundedNoFollowFile } from './no-follow-file.mjs';
|
|
16
|
+
import { PRODUCER_EVIDENCE_INDEX_FILE } from './producer-evidence-index-file.mjs';
|
|
17
|
+
import { BUNDLE_MEDIA_TYPE } from './sigstore-bundle-media-type.mjs';
|
|
18
|
+
import { assertCertificateExtensions } from './third-party-certificate-extensions.mjs';
|
|
19
|
+
|
|
20
|
+
export const THIRD_PARTY_PROVENANCE_ROOT = 'third-party-provenance';
|
|
21
|
+
export const PROVENANCE_STATEMENT_FILE = 'statement.json';
|
|
22
|
+
export const PROVENANCE_BUNDLE_FILE = 'bundle.sigstore.json';
|
|
23
|
+
/** The SLSA v1 provenance predicate a biome bundle is attested with (what the fetcher's `verify-attestation --type` matches). */
|
|
24
|
+
export const SLSA_PROVENANCE_V1 = 'https://slsa.dev/provenance/v1';
|
|
25
|
+
export const GITHUB_ACTIONS_OIDC_ISSUER = 'https://token.actions.githubusercontent.com';
|
|
26
|
+
/** The only channel a third-party source is admitted on: signed from refs/heads/main. */
|
|
27
|
+
export const THIRD_PARTY_EVIDENCE_CHANNEL = 'release';
|
|
28
|
+
|
|
29
|
+
const MAX_EVIDENCE_INDEX_BYTES = 4 * 1024 * 1024;
|
|
30
|
+
const IN_TOTO_STATEMENT_TYPE = 'https://in-toto.io/Statement/v1';
|
|
31
|
+
|
|
32
|
+
/** `third-party-provenance/sha256-<hex>` of an OCI manifest digest. */
|
|
33
|
+
export function provenanceDirectoryForDigest(manifestDigest) {
|
|
34
|
+
return `${THIRD_PARTY_PROVENANCE_ROOT}/${evidenceDirectoryForDigest(manifestDigest).split('/')[1]}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The digest of an `<oci repository>@sha256:<hex>` reference. */
|
|
38
|
+
export const digestOfOciRef = (ociRef) => ociRef.slice(ociRef.indexOf('@') + 1);
|
|
39
|
+
|
|
40
|
+
/** The statement bytes are the DSSE payload cosign signed: exact UTF-8 JSON, not this CLI's canonical form. */
|
|
41
|
+
export function decodeJsonStatement(bytes, label) {
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(decodeExactUtf8(bytes, label));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new Error(`${label} is not exact UTF-8 JSON: ${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The in-toto statement of a provenance attestation, held to the shape this plane reads (subject digest, predicate type). */
|
|
50
|
+
export function parseProvenanceStatement(value) {
|
|
51
|
+
const digest = value?.subject?.[0]?.digest?.sha256;
|
|
52
|
+
if (
|
|
53
|
+
value?._type !== IN_TOTO_STATEMENT_TYPE ||
|
|
54
|
+
value.predicateType !== SLSA_PROVENANCE_V1 ||
|
|
55
|
+
!Array.isArray(value.subject) ||
|
|
56
|
+
value.subject.length !== 1 ||
|
|
57
|
+
typeof digest !== 'string'
|
|
58
|
+
) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`the bundle provenance is not an in-toto v1 statement of ${SLSA_PROVENANCE_V1} over exactly one subject`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const readEvidenceFile = (root, path, label, maxBytes) => readBoundedNoFollowFile(root, path, label, maxBytes);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The trust-policy row `policyId` names, held to everything a third-party signer row must be: one row, the release
|
|
70
|
+
* channel signed from refs/heads/main, the GitHub Actions issuer, the exact identity of its own workflow, and the
|
|
71
|
+
* pinned repository and workflow. Throws naming the row and the field.
|
|
72
|
+
*/
|
|
73
|
+
export function thirdPartySignerRow({ policy, policyId, source, schemas, label }) {
|
|
74
|
+
const rows = policy.policies.filter((row) => row.policyId === policyId);
|
|
75
|
+
if (rows.length !== 1) {
|
|
76
|
+
throw new Error(`${label}: the trust policy has ${rows.length} rows with policyId "${policyId}"; exactly one is required`);
|
|
77
|
+
}
|
|
78
|
+
const [row] = rows;
|
|
79
|
+
const ref = schemas.EVIDENCE_CHANNEL_REFS[THIRD_PARTY_EVIDENCE_CHANNEL];
|
|
80
|
+
if (row.channel !== THIRD_PARTY_EVIDENCE_CHANNEL || row.githubWorkflow?.ref !== ref) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`${label}: row "${policyId}" is not a ${THIRD_PARTY_EVIDENCE_CHANNEL} row signed from ${ref} ` +
|
|
83
|
+
`(channel ${JSON.stringify(row.channel)}, ref ${JSON.stringify(row.githubWorkflow?.ref)})`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (row.oidcIssuer !== GITHUB_ACTIONS_OIDC_ISSUER) {
|
|
87
|
+
throw new Error(`${label}: row "${policyId}" oidcIssuer ${JSON.stringify(row.oidcIssuer)} is not ${GITHUB_ACTIONS_OIDC_ISSUER}`);
|
|
88
|
+
}
|
|
89
|
+
const { repository, path } = row.githubWorkflow;
|
|
90
|
+
const identity = `https://github.com/${repository}/${path}@${ref}`;
|
|
91
|
+
if (row.certificateIdentity !== identity) {
|
|
92
|
+
throw new Error(`${label}: row "${policyId}" certificateIdentity ${JSON.stringify(row.certificateIdentity)} is not the exact workflow identity ${identity}`);
|
|
93
|
+
}
|
|
94
|
+
if (repository !== source.repository) {
|
|
95
|
+
throw new Error(`${label}: row "${policyId}" signs for ${repository}, but the source is pinned to ${source.repository}`);
|
|
96
|
+
}
|
|
97
|
+
if (path !== source.producerWorkflow.path) {
|
|
98
|
+
throw new Error(`${label}: row "${policyId}" signs workflow ${path}, but the source pins one workflow, ${source.producerWorkflow.path}`);
|
|
99
|
+
}
|
|
100
|
+
return row;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The policy narrowed to ONE row, so cosign is run with exactly that row's identity and issuer. */
|
|
104
|
+
const exactRowPolicy = (policy, row) => ({ ...policy, policies: [row] });
|
|
105
|
+
|
|
106
|
+
function verifiedBundleProvenance({ source, evidenceRoot, context, hold }) {
|
|
107
|
+
const label = `third-party source "${source.name}" bundle ${source.bundle.ociRef}`;
|
|
108
|
+
const row = thirdPartySignerRow({ policy: context.policy, policyId: source.bundle.signerPolicyId, source, schemas: context.schemas, label });
|
|
109
|
+
if (!row.predicateTypes.includes(SLSA_PROVENANCE_V1)) {
|
|
110
|
+
throw new Error(`${label}: row "${row.policyId}" does not authorize ${SLSA_PROVENANCE_V1}, so it is not a bundle signer`);
|
|
111
|
+
}
|
|
112
|
+
const directory = provenanceDirectoryForDigest(digestOfOciRef(source.bundle.ociRef));
|
|
113
|
+
let verified;
|
|
114
|
+
try {
|
|
115
|
+
verified = verifySigstoreEvidenceDescriptor({
|
|
116
|
+
evidenceRoot,
|
|
117
|
+
descriptor: {
|
|
118
|
+
statementPath: `${directory}/${PROVENANCE_STATEMENT_FILE}`,
|
|
119
|
+
statementDigest: source.bundle.statementDigest,
|
|
120
|
+
bundlePath: `${directory}/${PROVENANCE_BUNDLE_FILE}`,
|
|
121
|
+
bundleDigest: source.bundle.bundleDigest,
|
|
122
|
+
bundleMediaType: BUNDLE_MEDIA_TYPE,
|
|
123
|
+
},
|
|
124
|
+
policy: exactRowPolicy(context.policy, row),
|
|
125
|
+
policyRoot: context.policyRoot,
|
|
126
|
+
predicateType: SLSA_PROVENANCE_V1,
|
|
127
|
+
channel: THIRD_PARTY_EVIDENCE_CHANNEL,
|
|
128
|
+
expectedWorkflowSha: source.sourceCommit,
|
|
129
|
+
parseStatement: parseProvenanceStatement,
|
|
130
|
+
decodeStatement: decodeJsonStatement,
|
|
131
|
+
trustedCosign: context.trustedCosign,
|
|
132
|
+
holdProducerWorkflow: hold,
|
|
133
|
+
});
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error(`${label}: ${error.message}`);
|
|
136
|
+
}
|
|
137
|
+
const attested = `sha256:${verified.statement.subject[0].digest.sha256}`;
|
|
138
|
+
if (attested !== digestOfOciRef(source.bundle.ociRef)) {
|
|
139
|
+
throw new Error(`${label}: the provenance attests ${attested}, not the pinned bundle digest ${digestOfOciRef(source.bundle.ociRef)}`);
|
|
140
|
+
}
|
|
141
|
+
const bundleBytes = readEvidenceFile(evidenceRoot, `${directory}/${PROVENANCE_BUNDLE_FILE}`, `${label} bundle`, 16 * 1024 * 1024).bytes;
|
|
142
|
+
assertCertificateExtensions({ bundle: JSON.parse(decodeExactUtf8(bundleBytes, `${label} bundle`)), source, label });
|
|
143
|
+
return { row, statement: verified.statement };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The `statementPath`/`bundlePath` the committed `producer-evidence.json` of an image's evidence directory gives its subject. */
|
|
147
|
+
export function committedImageDescriptor({ image, evidenceRoot, label }) {
|
|
148
|
+
const directory = evidenceDirectoryForDigest(image.manifestDigest);
|
|
149
|
+
const index = JSON.parse(
|
|
150
|
+
decodeExactUtf8(readEvidenceFile(evidenceRoot, `${directory}/${PRODUCER_EVIDENCE_INDEX_FILE}`, `${label} producer evidence index`, MAX_EVIDENCE_INDEX_BYTES).bytes, `${label} producer evidence index`),
|
|
151
|
+
);
|
|
152
|
+
const entries = Array.isArray(index?.producerEvidence) ? index.producerEvidence : [];
|
|
153
|
+
const entry = entries.find((candidate) => candidate?.subjectKind === image.subjectKind && candidate?.subjectId === image.subjectId);
|
|
154
|
+
if (entry === undefined) {
|
|
155
|
+
throw new Error(`${label}: ${directory}/${PRODUCER_EVIDENCE_INDEX_FILE} carries no evidence for ${image.subjectKind}:${image.subjectId}`);
|
|
156
|
+
}
|
|
157
|
+
const { statementPath, bundlePath } = entry.evidence;
|
|
158
|
+
return {
|
|
159
|
+
statementPath: `${directory}/${statementPath}`,
|
|
160
|
+
statementDigest: image.statementDigest,
|
|
161
|
+
bundlePath: `${directory}/${bundlePath}`,
|
|
162
|
+
bundleDigest: image.bundleDigest,
|
|
163
|
+
bundleMediaType: BUNDLE_MEDIA_TYPE,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const repositoryPathOf = (repositoryUrl) => new URL(repositoryUrl).pathname.replace(/^\//u, '').replace(/\.git$/u, '');
|
|
168
|
+
|
|
169
|
+
/** (c) for one image statement: one repository, one commit, the pinned subject and authority. */
|
|
170
|
+
export function assertImageStatementBindsPin({ statement, source, image, expectedContractAuthority, label }) {
|
|
171
|
+
const { predicate } = statement;
|
|
172
|
+
const claimed = predicate.source;
|
|
173
|
+
const mismatch = (what, actual, expected) => {
|
|
174
|
+
throw new Error(`${label}: ${what} is ${JSON.stringify(actual)}, but the pin requires ${JSON.stringify(expected)}`);
|
|
175
|
+
};
|
|
176
|
+
assertKernelContractAuthorityEqual(predicate.contractAuthority, expectedContractAuthority, label);
|
|
177
|
+
if (repositoryPathOf(claimed.repositoryUrl) !== source.repository) {
|
|
178
|
+
mismatch('predicate source.repositoryUrl repository', repositoryPathOf(claimed.repositoryUrl), source.repository);
|
|
179
|
+
}
|
|
180
|
+
if (claimed.repo !== source.repository) {mismatch('predicate source.repo', claimed.repo, source.repository);}
|
|
181
|
+
if (claimed.path !== claimed.repo && !claimed.path.startsWith(`${claimed.repo}/`)) {
|
|
182
|
+
mismatch('predicate source.path (it must be the repository or a directory of it)', claimed.path, `${source.repository}[/<directory>]`);
|
|
183
|
+
}
|
|
184
|
+
if (predicate.producerRun.producerWorkflowSha !== source.sourceCommit) {
|
|
185
|
+
mismatch('predicate producerRun.producerWorkflowSha (the certificate workflow commit)', predicate.producerRun.producerWorkflowSha, source.sourceCommit);
|
|
186
|
+
}
|
|
187
|
+
if (claimed.sourceCommit !== predicate.producerRun.producerWorkflowSha) {
|
|
188
|
+
mismatch('predicate source.sourceCommit (it must be the commit the certificate was issued for)', claimed.sourceCommit, predicate.producerRun.producerWorkflowSha);
|
|
189
|
+
}
|
|
190
|
+
if (claimed.sourceManifestHash !== source.bundle.sourceManifestHash) {
|
|
191
|
+
mismatch('predicate source.sourceManifestHash', claimed.sourceManifestHash, source.bundle.sourceManifestHash);
|
|
192
|
+
}
|
|
193
|
+
if (claimed.kind !== image.subjectKind || claimed.id !== image.subjectId) {
|
|
194
|
+
mismatch('predicate source kind/id', `${claimed.kind}:${claimed.id}`, `${image.subjectKind}:${image.subjectId}`);
|
|
195
|
+
}
|
|
196
|
+
if (claimed.sourceTreeHash !== image.sourceTreeHash) {mismatch('predicate source.sourceTreeHash', claimed.sourceTreeHash, image.sourceTreeHash);}
|
|
197
|
+
if (claimed.sourceHashAlgorithm !== image.sourceHashAlgorithm) {
|
|
198
|
+
mismatch('predicate source.sourceHashAlgorithm', claimed.sourceHashAlgorithm, image.sourceHashAlgorithm);
|
|
199
|
+
}
|
|
200
|
+
if (predicate.artifact.imageRepository !== image.imageRef || statement.subject[0].name !== image.imageRef) {
|
|
201
|
+
mismatch('predicate artifact.imageRepository', predicate.artifact.imageRepository, image.imageRef);
|
|
202
|
+
}
|
|
203
|
+
if (predicate.artifact.manifestDigest !== image.manifestDigest) {
|
|
204
|
+
mismatch('predicate artifact.manifestDigest', predicate.artifact.manifestDigest, image.manifestDigest);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function verifiedImageEvidence({ source, image, evidenceRoot, context, hold, bundleRow }) {
|
|
209
|
+
const label = `third-party source "${source.name}" image ${image.imageRef}@${image.manifestDigest}`;
|
|
210
|
+
const row = thirdPartySignerRow({ policy: context.policy, policyId: image.policyId, source, schemas: context.schemas, label });
|
|
211
|
+
if (!row.imageRepositories?.includes(image.imageRef)) {
|
|
212
|
+
throw new Error(`${label}: row "${row.policyId}" does not list ${image.imageRef} in its imageRepositories`);
|
|
213
|
+
}
|
|
214
|
+
if (row.githubWorkflow.repository !== bundleRow.githubWorkflow.repository || row.githubWorkflow.path !== bundleRow.githubWorkflow.path) {
|
|
215
|
+
throw new Error(`${label}: row "${row.policyId}" signs a different workflow than the bundle signer "${bundleRow.policyId}"; a source has one workflow`);
|
|
216
|
+
}
|
|
217
|
+
const descriptor = committedImageDescriptor({ image, evidenceRoot, label });
|
|
218
|
+
let verified;
|
|
219
|
+
try {
|
|
220
|
+
verified = verifySigstoreEvidenceDescriptor({
|
|
221
|
+
evidenceRoot,
|
|
222
|
+
descriptor,
|
|
223
|
+
policy: exactRowPolicy(context.policy, row),
|
|
224
|
+
policyRoot: context.policyRoot,
|
|
225
|
+
predicateType: context.schemas.IMAGE_PRODUCER_PREDICATE_TYPE,
|
|
226
|
+
channel: THIRD_PARTY_EVIDENCE_CHANNEL,
|
|
227
|
+
imageRepository: image.imageRef,
|
|
228
|
+
expectedWorkflowSha: source.sourceCommit,
|
|
229
|
+
parseStatement: context.schemas.parseImageProducerStatement,
|
|
230
|
+
trustedCosign: context.trustedCosign,
|
|
231
|
+
holdProducerWorkflow: hold,
|
|
232
|
+
});
|
|
233
|
+
} catch (error) {
|
|
234
|
+
throw new Error(`${label}: ${error.message}`);
|
|
235
|
+
}
|
|
236
|
+
assertImageStatementBindsPin({ statement: verified.statement, source, image, expectedContractAuthority: context.expectedContractAuthority, label });
|
|
237
|
+
const bundleBytes = readEvidenceFile(evidenceRoot, descriptor.bundlePath, `${label} bundle`, 16 * 1024 * 1024).bytes;
|
|
238
|
+
assertCertificateExtensions({ bundle: JSON.parse(decodeExactUtf8(bundleBytes, `${label} bundle`)), source, label });
|
|
239
|
+
return verified.statement;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Checks (a) to (d) for one pin, from the evidence under `evidenceRoot`. `context` is
|
|
244
|
+
* `{policy, policyRoot, schemas, trustedCosign, expectedContractAuthority, runtimeSourceIndex}`; the runtime
|
|
245
|
+
* image source index must already carry `{repository, workflowCommit: sourceCommit}` in its `producerWorkflowPins`
|
|
246
|
+
* (the writer passes the index it is about to write), which `holdProducerWorkflow` then enforces unchanged.
|
|
247
|
+
*/
|
|
248
|
+
export function verifyThirdPartySourceEvidence({ source, evidenceRoot, context }) {
|
|
249
|
+
const hold = (producer) => context.schemas.producerWorkflowPinRefusal(context.runtimeSourceIndex, producer);
|
|
250
|
+
const bundle = verifiedBundleProvenance({ source, evidenceRoot, context, hold });
|
|
251
|
+
const images = source.images.map((image) =>
|
|
252
|
+
verifiedImageEvidence({ source, image, evidenceRoot, context, hold, bundleRow: bundle.row }),
|
|
253
|
+
);
|
|
254
|
+
return { bundle, images };
|
|
255
|
+
}
|