@xemahq/xema 0.26.0 → 0.28.0
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/README.md +70 -37
- package/dist/assets/distribution-assets.manifest.json +1 -2
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/dev.js +1 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +7 -1
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/edition.d.ts +3 -0
- package/dist/commands/edition.d.ts.map +1 -0
- package/dist/commands/edition.js +46 -0
- package/dist/commands/edition.js.map +1 -0
- package/dist/commands/init.js +2 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/serve.js +1 -0
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/up.js +1 -0
- package/dist/commands/up.js.map +1 -1
- package/dist/dev/env-defaults.d.ts.map +1 -1
- package/dist/dev/env-defaults.js +5 -2
- package/dist/dev/env-defaults.js.map +1 -1
- package/dist/dev/infra-preflight.d.ts +3 -2
- package/dist/dev/infra-preflight.d.ts.map +1 -1
- package/dist/dev/infra-preflight.js +18 -8
- package/dist/dev/infra-preflight.js.map +1 -1
- package/dist/edition/verify-image-evidence.bundle.mjs +54283 -0
- package/dist/edition/verify-image-evidence.bundle.provenance.json +2877 -0
- package/dist/runtime/config/schema.d.ts +1 -0
- package/dist/runtime/config/schema.d.ts.map +1 -1
- package/dist/runtime/custody/local-custody.d.ts +12 -0
- package/dist/runtime/custody/local-custody.d.ts.map +1 -0
- package/dist/runtime/custody/local-custody.js +22 -0
- package/dist/runtime/custody/local-custody.js.map +1 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.d.ts +18 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.js +50 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.js.map +1 -0
- package/dist/runtime/custody/openbao-custody-store.d.ts +18 -0
- package/dist/runtime/custody/openbao-custody-store.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-custody-store.js +55 -0
- package/dist/runtime/custody/openbao-custody-store.js.map +1 -0
- package/dist/runtime/custody/openbao-http-client.d.ts +34 -0
- package/dist/runtime/custody/openbao-http-client.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-http-client.js +154 -0
- package/dist/runtime/custody/openbao-http-client.js.map +1 -0
- package/dist/runtime/custody/openbao-local-constants.d.ts +22 -0
- package/dist/runtime/custody/openbao-local-constants.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-local-constants.js +48 -0
- package/dist/runtime/custody/openbao-local-constants.js.map +1 -0
- package/dist/runtime/custody/openbao-local-runner.d.ts +16 -0
- package/dist/runtime/custody/openbao-local-runner.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-local-runner.js +86 -0
- package/dist/runtime/custody/openbao-local-runner.js.map +1 -0
- package/dist/runtime/edition/run-entry.d.ts +9 -0
- package/dist/runtime/edition/run-entry.d.ts.map +1 -0
- package/dist/runtime/edition/run-entry.js +36 -0
- package/dist/runtime/edition/run-entry.js.map +1 -0
- package/dist/runtime/edition/verb-map.d.ts +60 -0
- package/dist/runtime/edition/verb-map.d.ts.map +1 -0
- package/dist/runtime/edition/verb-map.js +146 -0
- package/dist/runtime/edition/verb-map.js.map +1 -0
- package/dist/runtime/env-seeder.d.ts +2 -0
- package/dist/runtime/env-seeder.d.ts.map +1 -1
- package/dist/runtime/env-seeder.js +18 -3
- package/dist/runtime/env-seeder.js.map +1 -1
- package/dist/runtime/launch.d.ts +2 -1
- package/dist/runtime/launch.d.ts.map +1 -1
- package/dist/runtime/launch.js +31 -7
- package/dist/runtime/launch.js.map +1 -1
- package/dist/runtime/paths.d.ts +1 -2
- package/dist/runtime/paths.d.ts.map +1 -1
- package/dist/runtime/paths.js +0 -10
- package/dist/runtime/paths.js.map +1 -1
- package/dist/runtime/runner/chart-local-provenance.d.ts +20 -0
- package/dist/runtime/runner/chart-local-provenance.d.ts.map +1 -0
- package/dist/runtime/runner/chart-local-provenance.js +114 -0
- package/dist/runtime/runner/chart-local-provenance.js.map +1 -0
- package/dist/runtime/runner/chart-preflight.d.ts +8 -8
- package/dist/runtime/runner/chart-preflight.d.ts.map +1 -1
- package/dist/runtime/runner/chart-preflight.js +30 -69
- package/dist/runtime/runner/chart-preflight.js.map +1 -1
- package/dist/runtime/runner/chart-pull.d.ts +14 -0
- package/dist/runtime/runner/chart-pull.d.ts.map +1 -0
- package/dist/runtime/runner/chart-pull.js +96 -0
- package/dist/runtime/runner/chart-pull.js.map +1 -0
- package/dist/runtime/runner/chart-resolver.d.ts +4 -12
- package/dist/runtime/runner/chart-resolver.d.ts.map +1 -1
- package/dist/runtime/runner/chart-resolver.js +16 -62
- package/dist/runtime/runner/chart-resolver.js.map +1 -1
- package/dist/runtime/runner/chart-set-lock.d.ts +6 -20
- package/dist/runtime/runner/chart-set-lock.d.ts.map +1 -1
- package/dist/runtime/runner/chart-set-lock.js +55 -99
- package/dist/runtime/runner/chart-set-lock.js.map +1 -1
- package/dist/runtime/runner/helm-cli.d.ts +3 -1
- package/dist/runtime/runner/helm-cli.d.ts.map +1 -1
- package/dist/runtime/runner/helm-cli.js +9 -7
- package/dist/runtime/runner/helm-cli.js.map +1 -1
- package/dist/runtime/runner/helm-runner.d.ts +4 -4
- package/dist/runtime/runner/helm-runner.d.ts.map +1 -1
- package/dist/runtime/runner/helm-runner.js +18 -16
- package/dist/runtime/runner/helm-runner.js.map +1 -1
- package/dist/runtime/sources/kinds/git.d.ts +1 -2
- package/dist/runtime/sources/kinds/git.d.ts.map +1 -1
- package/dist/runtime/sources/kinds/git.js +8 -5
- package/dist/runtime/sources/kinds/git.js.map +1 -1
- package/dist/runtime/sources/manifest-walk.d.ts +3 -1
- package/dist/runtime/sources/manifest-walk.d.ts.map +1 -1
- package/dist/runtime/sources/manifest-walk.js +8 -3
- package/dist/runtime/sources/manifest-walk.js.map +1 -1
- package/dist/runtime/sources/schema.d.ts +3 -0
- package/dist/runtime/sources/schema.d.ts.map +1 -1
- package/dist/runtime/sources/schema.js +6 -1
- package/dist/runtime/sources/schema.js.map +1 -1
- package/dist/runtime/supervisor.d.ts +2 -0
- package/dist/runtime/supervisor.d.ts.map +1 -1
- package/dist/runtime/supervisor.js +1 -0
- package/dist/runtime/supervisor.js.map +1 -1
- package/edition/README.md +313 -0
- package/edition/assemble-producer-input.mjs +1251 -0
- package/edition/authorization-base.mjs +347 -0
- package/edition/biome-content.mjs +268 -0
- package/edition/build-biome-index.mjs +175 -0
- package/edition/build-platform-service-index.mjs +288 -0
- package/edition/build-runtime-image-source-index.mjs +821 -0
- package/edition/built-verifier.mjs +55 -0
- package/edition/catalogue-edition.mjs +49 -0
- package/edition/catalogue-fetch.mjs +64 -0
- package/edition/catalogue.mjs +135 -0
- package/edition/chart-set-source-commit.mjs +92 -0
- package/edition/check-committed-image-evidence.mjs +383 -0
- package/edition/checkout-indexed-source-repositories.mjs +105 -0
- package/edition/comment-blanker.mjs +75 -0
- package/edition/connector-source-authority.mjs +60 -0
- package/edition/customer-definition.mjs +183 -0
- package/edition/customer-flags.mjs +7 -0
- package/edition/develop-customer-edition.mjs +99 -0
- package/edition/develop-edition-resolve.mjs +65 -0
- package/edition/develop-edition.mjs +274 -0
- package/edition/develop-freeze.mjs +173 -0
- package/edition/develop-image-coordinate.mjs +54 -0
- package/edition/develop-seal.mjs +77 -0
- package/edition/develop-snapshot-inputs.mjs +104 -0
- package/edition/dist-check.mjs +986 -0
- package/edition/distribution-evidence-set.mjs +987 -0
- package/edition/distribution-paths.mjs +191 -0
- package/edition/edition-artifact.mjs +284 -0
- package/edition/edition-biome-manifests.mjs +85 -0
- package/edition/edition-channel.mjs +6 -0
- package/edition/edition-chart-set.mjs +93 -0
- package/edition/edition-config.mjs +205 -0
- package/edition/edition-constants.mjs +57 -0
- package/edition/edition-contract.json +30 -0
- package/edition/edition-list.mjs +35 -0
- package/edition/edition-locks.mjs +69 -0
- package/edition/edition-protocol.mjs +228 -0
- package/edition/edition-workspace.mjs +187 -0
- package/edition/evidence-checkout.mjs +439 -0
- package/edition/evidence-grammars.mjs +16 -0
- package/edition/evidence-trust-pin.mjs +304 -0
- package/edition/evidence-trust-policy.mjs +294 -0
- package/edition/external-source-walk.mjs +463 -0
- package/edition/first-party-source-ids.mjs +59 -0
- package/edition/fleet-coordinate-finality.mjs +350 -0
- package/edition/git-source-auth.mjs +52 -0
- package/edition/image-delivery-entitlement-descriptor.mjs +106 -0
- package/edition/image-evidence-replay-state.mjs +242 -0
- package/edition/image-evidence.mjs +1233 -0
- package/edition/kernel-contract-authority.mjs +443 -0
- package/edition/lib.mjs +3021 -0
- package/edition/no-follow-file.mjs +94 -0
- package/edition/oci-evidence-verbs.mjs +392 -0
- package/edition/oci-image-source-evidence.mjs +239 -0
- package/edition/oras.mjs +648 -0
- package/edition/pin-source.mjs +227 -0
- package/edition/plan-image-evidence-refresh.mjs +408 -0
- package/edition/platform-lock-readability.mjs +892 -0
- package/edition/platform-service-class.mjs +18 -0
- package/edition/platform-service-source-authority.mjs +105 -0
- package/edition/positive-closure.mjs +162 -0
- package/edition/produce-distribution-completeness-evidence.mjs +311 -0
- package/edition/produce-image-delivery-entitlement-evidence.mjs +294 -0
- package/edition/produce-image-source-evidence.mjs +765 -0
- package/edition/producer-evidence-bundle.mjs +157 -0
- package/edition/registry-credentials.mjs +193 -0
- package/edition/release-catalogue.mjs +39 -0
- package/edition/release-channel-guard.mjs +109 -0
- package/edition/release-edition-artifact.mjs +157 -0
- package/edition/remedy-command.mjs +89 -0
- package/edition/repin-evidence-trust.mjs +101 -0
- package/edition/required-resource-provider.mjs +58 -0
- package/edition/resolve-chart-set.mjs +415 -0
- package/edition/resolve-customer-edition.mjs +288 -0
- package/edition/resolve-distribution.mjs +2318 -0
- package/edition/resolve-edition.mjs +186 -0
- package/edition/resolve-images.mjs +1606 -0
- package/edition/seal-image-digests.mjs +855 -0
- package/edition/sealed-evidence-accept.mjs +82 -0
- package/edition/source-authority.mjs +725 -0
- package/edition/source-closure.mjs +116 -0
- package/edition/strict-json.mjs +121 -0
- package/edition/string-order.mjs +5 -0
- package/edition/trust-policy-arming.mjs +120 -0
- package/edition/trusted-executable.mjs +166 -0
- package/edition/verifier-binding.mjs +45 -0
- package/edition/verifier-files.mjs +8 -0
- package/edition/verifier-kernel-schemas.mjs +22 -0
- package/edition/verifier-provenance.mjs +64 -0
- package/edition/verify-image-evidence.mjs +458 -0
- package/edition/verify-image-platforms.mjs +495 -0
- package/edition/why.mjs +56 -0
- package/edition/workspace-sections.mjs +195 -0
- package/examples/06-biome-sources.yaml +1 -0
- package/package.json +14 -6
- package/dist/commands/dist.d.ts +0 -16
- package/dist/commands/dist.d.ts.map +0 -1
- package/dist/commands/dist.js +0 -182
- package/dist/commands/dist.js.map +0 -1
- package/dist/runtime/distribution/available-biome.d.ts +0 -10
- package/dist/runtime/distribution/available-biome.d.ts.map +0 -1
- package/dist/runtime/distribution/available-biome.js +0 -156
- package/dist/runtime/distribution/available-biome.js.map +0 -1
- package/dist/runtime/distribution/compose.d.ts +0 -23
- package/dist/runtime/distribution/compose.d.ts.map +0 -1
- package/dist/runtime/distribution/compose.js +0 -48
- package/dist/runtime/distribution/compose.js.map +0 -1
- package/dist/runtime/runner/chart-trust.d.ts +0 -57
- package/dist/runtime/runner/chart-trust.d.ts.map +0 -1
- package/dist/runtime/runner/chart-trust.js +0 -270
- package/dist/runtime/runner/chart-trust.js.map +0 -1
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// The data root's declared evidence trust policy and the PIN that binds it.
|
|
2
|
+
//
|
|
3
|
+
// `edition-workspace.json` may declare `evidenceTrustPolicy: {policy, pin}`. The
|
|
4
|
+
// policy is the offline Sigstore trust policy (who may sign, which binaries may
|
|
5
|
+
// verify); the pin is a reviewed data-root file that fixes the digest of that
|
|
6
|
+
// policy, the digests of the one verifier bundle and its provenance, the
|
|
7
|
+
// kernel contract authority every evidence statement is held to, and the oras
|
|
8
|
+
// binaries that may read a registry. So the policy cannot change, the verifier
|
|
9
|
+
// that enforces it cannot change, the kernel contract the evidence binds cannot
|
|
10
|
+
// change and the registry reader cannot change without a reviewed data-root
|
|
11
|
+
// commit.
|
|
12
|
+
//
|
|
13
|
+
// The kernel contract authority is pinned HERE because nothing else can hold
|
|
14
|
+
// it: `runtime-image-source-index.json` states the authority, and the image
|
|
15
|
+
// locks and statements are compared with what that file states. Comparing the
|
|
16
|
+
// file with itself decides nothing, so its authority is first held to this
|
|
17
|
+
// pin, and only the pinned authority is what evidence is compared with.
|
|
18
|
+
|
|
19
|
+
import { closeSync, constants as fsConstants, openSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
|
|
22
|
+
import { COMMIT_PATTERN } from './evidence-grammars.mjs';
|
|
23
|
+
import {
|
|
24
|
+
canonicalJsonBytes,
|
|
25
|
+
readCanonicalJsonFromRoot,
|
|
26
|
+
sha256Digest,
|
|
27
|
+
validatePinnedTrustedRoot,
|
|
28
|
+
} from './image-evidence.mjs';
|
|
29
|
+
import { readBoundedNoFollowFile } from './no-follow-file.mjs';
|
|
30
|
+
import { parseStrictJson } from './strict-json.mjs';
|
|
31
|
+
|
|
32
|
+
export const EVIDENCE_TRUST_PIN_SCHEMA_VERSION = 2;
|
|
33
|
+
export const RUNTIME_IMAGE_SOURCE_INDEX_FILE = 'runtime-image-source-index.json';
|
|
34
|
+
|
|
35
|
+
/** A data root that declares no evidence trust has no pin to hold the kernel contract authority to. */
|
|
36
|
+
export const KERNEL_CONTRACT_AUTHORITY_UNPINNED = 'KERNEL_CONTRACT_AUTHORITY_UNPINNED';
|
|
37
|
+
/** The data root's runtime image source index states another authority than the pin records. */
|
|
38
|
+
export const KERNEL_CONTRACT_AUTHORITY_NOT_PINNED_ONE = 'KERNEL_CONTRACT_AUTHORITY_NOT_PINNED_ONE';
|
|
39
|
+
|
|
40
|
+
export class KernelContractAuthorityPinError extends Error {
|
|
41
|
+
/** @param {string} code @param {string} message */
|
|
42
|
+
constructor(code, message) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = 'KernelContractAuthorityPinError';
|
|
45
|
+
this.code = code;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export const REPIN_COMMAND = 'xema edition repin-evidence-trust';
|
|
49
|
+
|
|
50
|
+
const MAX_PIN_BYTES = 64 * 1024;
|
|
51
|
+
const MAX_INDEX_BYTES = 16 * 1024 * 1024;
|
|
52
|
+
const SHA256_DIGEST = /^sha256:[a-f0-9]{64}$/;
|
|
53
|
+
const PIN_KEYS = Object.freeze([
|
|
54
|
+
'kernelContractAuthority',
|
|
55
|
+
'policyDigest',
|
|
56
|
+
'schemaVersion',
|
|
57
|
+
'trustedOrasBinaryDigests',
|
|
58
|
+
'verifier',
|
|
59
|
+
]);
|
|
60
|
+
const VERIFIER_KEYS = Object.freeze(['bundleDigest', 'provenanceDigest']);
|
|
61
|
+
const AUTHORITY_PIN_KEYS = Object.freeze(['digest', 'sourceCommit']);
|
|
62
|
+
const PIN_SHAPE =
|
|
63
|
+
'{schemaVersion, policyDigest, verifier: {bundleDigest, provenanceDigest}, ' +
|
|
64
|
+
'kernelContractAuthority: {sourceCommit, digest}, trustedOrasBinaryDigests: [sha256:…, …]}';
|
|
65
|
+
|
|
66
|
+
const exactKeys = (value, keys) =>
|
|
67
|
+
value !== null &&
|
|
68
|
+
typeof value === 'object' &&
|
|
69
|
+
!Array.isArray(value) &&
|
|
70
|
+
Object.keys(value).sort().join() === keys.join();
|
|
71
|
+
|
|
72
|
+
function requireDigest(value, what) {
|
|
73
|
+
if (typeof value !== 'string' || !SHA256_DIGEST.test(value)) {
|
|
74
|
+
throw new Error(`evidence trust pin: ${what} must be sha256:<64 hex>`);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Digest of the parsed policy in its canonical JSON form. */
|
|
80
|
+
export const trustPolicyDigest = (policy) =>
|
|
81
|
+
sha256Digest(canonicalJsonBytes(policy));
|
|
82
|
+
|
|
83
|
+
/** The verifier digests a pin records: the bundle's bytes and its provenance's bytes. */
|
|
84
|
+
export function verifierDigests({ bundleBytes, provenanceBytes }) {
|
|
85
|
+
return Object.freeze({
|
|
86
|
+
bundleDigest: sha256Digest(bundleBytes),
|
|
87
|
+
provenanceDigest: sha256Digest(provenanceBytes),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Read, parse and validate the declared policy: kernel schema, then the pinned
|
|
93
|
+
* Sigstore trusted root it names (resolved against the data root).
|
|
94
|
+
*/
|
|
95
|
+
export function loadDeclaredTrustPolicy({ dataRoot, declaration, schemas }) {
|
|
96
|
+
const policy = schemas.parseSigstoreOfflineTrustPolicy(
|
|
97
|
+
readCanonicalJsonFromRoot(
|
|
98
|
+
dataRoot,
|
|
99
|
+
declaration.policy,
|
|
100
|
+
'declared image evidence trust policy',
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
validatePinnedTrustedRoot(dataRoot, policy);
|
|
104
|
+
return Object.freeze({ policy, policyDigest: trustPolicyDigest(policy) });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Read the declared pin file: strict JSON, exact keys. */
|
|
108
|
+
export function readEvidenceTrustPin({ dataRoot, declaration }) {
|
|
109
|
+
const label = 'declared image evidence trust pin';
|
|
110
|
+
const { bytes } = readBoundedNoFollowFile(
|
|
111
|
+
dataRoot,
|
|
112
|
+
declaration.pin,
|
|
113
|
+
label,
|
|
114
|
+
MAX_PIN_BYTES,
|
|
115
|
+
);
|
|
116
|
+
const pin = parseStrictJson(bytes.toString('utf8'), declaration.pin);
|
|
117
|
+
if (
|
|
118
|
+
!exactKeys(pin, PIN_KEYS) ||
|
|
119
|
+
!exactKeys(pin.verifier, VERIFIER_KEYS) ||
|
|
120
|
+
!exactKeys(pin.kernelContractAuthority, AUTHORITY_PIN_KEYS) ||
|
|
121
|
+
!Array.isArray(pin.trustedOrasBinaryDigests)
|
|
122
|
+
) {
|
|
123
|
+
throw new Error(`${declaration.pin}: the pin is exactly ${PIN_SHAPE}`);
|
|
124
|
+
}
|
|
125
|
+
if (pin.schemaVersion !== EVIDENCE_TRUST_PIN_SCHEMA_VERSION) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`${declaration.pin}: schemaVersion must be ${EVIDENCE_TRUST_PIN_SCHEMA_VERSION}`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return Object.freeze({
|
|
131
|
+
schemaVersion: pin.schemaVersion,
|
|
132
|
+
policyDigest: requireDigest(pin.policyDigest, 'policyDigest'),
|
|
133
|
+
verifier: Object.freeze({
|
|
134
|
+
bundleDigest: requireDigest(pin.verifier.bundleDigest, 'verifier.bundleDigest'),
|
|
135
|
+
provenanceDigest: requireDigest(
|
|
136
|
+
pin.verifier.provenanceDigest,
|
|
137
|
+
'verifier.provenanceDigest',
|
|
138
|
+
),
|
|
139
|
+
}),
|
|
140
|
+
kernelContractAuthority: Object.freeze({
|
|
141
|
+
sourceCommit: requireCommit(pin.kernelContractAuthority.sourceCommit),
|
|
142
|
+
digest: requireDigest(pin.kernelContractAuthority.digest, 'kernelContractAuthority.digest'),
|
|
143
|
+
}),
|
|
144
|
+
trustedOrasBinaryDigests: requireOrasDigests(pin.trustedOrasBinaryDigests),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function requireCommit(value) {
|
|
149
|
+
if (typeof value !== 'string' || !COMMIT_PATTERN.test(value)) {
|
|
150
|
+
throw new Error('evidence trust pin: kernelContractAuthority.sourceCommit must be an exact 40-hex commit');
|
|
151
|
+
}
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** At least one digest, each canonical, none repeated: a pin that trusts no oras cannot read a registry. */
|
|
156
|
+
export function requireOrasDigests(value) {
|
|
157
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
'evidence trust pin: trustedOrasBinaryDigests must list at least one sha256 digest of an oras binary ' +
|
|
160
|
+
'(`shasum -a 256` of the real file); state it with --trusted-oras-digest when re-pinning',
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const digests = value.map((digest, index) => requireDigest(digest, `trustedOrasBinaryDigests[${index}]`));
|
|
164
|
+
if (new Set(digests).size !== digests.length) {
|
|
165
|
+
throw new Error('evidence trust pin: trustedOrasBinaryDigests repeats a digest');
|
|
166
|
+
}
|
|
167
|
+
return Object.freeze([...digests]);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** What a pin records of a kernel contract authority: its commit, and the digest of the whole authority. */
|
|
171
|
+
export function kernelContractAuthorityPin(authority) {
|
|
172
|
+
return Object.freeze({
|
|
173
|
+
sourceCommit: requireCommit(authority?.sourceCommit),
|
|
174
|
+
digest: sha256Digest(canonicalJsonBytes(authority)),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The kernel contract authority the data root's runtime image source index STATES; nothing is trusted yet. */
|
|
179
|
+
export function readStatedKernelContractAuthority({ dataRoot, schemas }) {
|
|
180
|
+
if (!schemas?.parseRuntimeImageSourceIndex) {
|
|
181
|
+
throw new Error('trusted kernel distribution schemas are required');
|
|
182
|
+
}
|
|
183
|
+
const { bytes } = readBoundedNoFollowFile(
|
|
184
|
+
dataRoot,
|
|
185
|
+
RUNTIME_IMAGE_SOURCE_INDEX_FILE,
|
|
186
|
+
'runtime image source index',
|
|
187
|
+
MAX_INDEX_BYTES,
|
|
188
|
+
);
|
|
189
|
+
return schemas.parseRuntimeImageSourceIndex(JSON.parse(bytes.toString('utf8'))).contractAuthority;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Refuse an authority that is not the one the pin records. */
|
|
193
|
+
export function assertPinnedKernelContractAuthority({ pin, authority, label }) {
|
|
194
|
+
const actual = kernelContractAuthorityPin(authority);
|
|
195
|
+
if (
|
|
196
|
+
actual.sourceCommit !== pin.kernelContractAuthority.sourceCommit ||
|
|
197
|
+
actual.digest !== pin.kernelContractAuthority.digest
|
|
198
|
+
) {
|
|
199
|
+
throw new KernelContractAuthorityPinError(
|
|
200
|
+
KERNEL_CONTRACT_AUTHORITY_NOT_PINNED_ONE,
|
|
201
|
+
`${label} states kernel contract authority ${actual.sourceCommit} (${actual.digest}) but the pin records ` +
|
|
202
|
+
`${pin.kernelContractAuthority.sourceCommit} (${pin.kernelContractAuthority.digest}); ` +
|
|
203
|
+
`review the kernel contract change, then re-pin with \`${REPIN_COMMAND}\``,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return authority;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The kernel contract authority evidence is held to: the one the data root's
|
|
211
|
+
* runtime image source index states, ONLY once it is the one the data root's
|
|
212
|
+
* evidence-trust pin records. A data root that declares no evidence trust has
|
|
213
|
+
* no pin, so it has no authority to hold evidence to and this refuses.
|
|
214
|
+
*
|
|
215
|
+
* @param {{dataRoot: string, declaration: {policy: string|null, pin: string|null}, schemas: object}} options
|
|
216
|
+
*/
|
|
217
|
+
export function readPinnedKernelContractAuthority({ dataRoot, declaration, schemas }) {
|
|
218
|
+
if (declaration.policy === null) {
|
|
219
|
+
throw new KernelContractAuthorityPinError(
|
|
220
|
+
KERNEL_CONTRACT_AUTHORITY_UNPINNED,
|
|
221
|
+
`${dataRoot} declares no evidenceTrustPolicy in edition-workspace.json, so no pin records the kernel contract ` +
|
|
222
|
+
'authority and no image evidence can be produced, planned or checked against it',
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
return assertPinnedKernelContractAuthority({
|
|
226
|
+
pin: readEvidenceTrustPin({ dataRoot, declaration }),
|
|
227
|
+
authority: readStatedKernelContractAuthority({ dataRoot, schemas }),
|
|
228
|
+
label: `${dataRoot}/${RUNTIME_IMAGE_SOURCE_INDEX_FILE}`,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Refuse a pin whose policy digest is not the declared policy's. */
|
|
233
|
+
export function assertPinnedPolicy({ pin, policyDigest }) {
|
|
234
|
+
if (pin.policyDigest !== policyDigest) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`the trust policy hashes to ${policyDigest} but the pin records ${pin.policyDigest}; ` +
|
|
237
|
+
`review the policy change, then re-pin it with \`${REPIN_COMMAND}\``,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The declared policy, held to the pin's record of it. Refuses a data root that
|
|
244
|
+
* declares none: there is no policy to produce or accept evidence under.
|
|
245
|
+
*/
|
|
246
|
+
export function loadPinnedDeclaredTrustPolicy({ dataRoot, declaration, schemas }) {
|
|
247
|
+
if (declaration.policy === null) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
`${dataRoot} declares no evidenceTrustPolicy in edition-workspace.json; there is no policy to produce evidence under`,
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
const { policy, policyDigest } = loadDeclaredTrustPolicy({ dataRoot, declaration, schemas });
|
|
253
|
+
assertPinnedPolicy({ pin: readEvidenceTrustPin({ dataRoot, declaration }), policyDigest });
|
|
254
|
+
return policy;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Refuse a pin whose verifier digests are not the verifier's actual ones. */
|
|
258
|
+
export function assertPinnedVerifier({ pin, actual }) {
|
|
259
|
+
for (const key of VERIFIER_KEYS) {
|
|
260
|
+
if (pin.verifier[key] !== actual[key]) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
`the verifier's ${key} is ${actual[key]} but the pin records ${pin.verifier[key]}; ` +
|
|
263
|
+
`this CLI's verifier is not the one the data root pinned. Install the pinned ` +
|
|
264
|
+
`CLI version, or review the verifier change and re-pin with \`${REPIN_COMMAND}\``,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Write the pin for the declared policy, the verifier digests, the kernel contract authority and the oras digests. */
|
|
271
|
+
export function writeEvidenceTrustPin({
|
|
272
|
+
dataRoot,
|
|
273
|
+
declaration,
|
|
274
|
+
policyDigest,
|
|
275
|
+
verifier,
|
|
276
|
+
kernelContractAuthority,
|
|
277
|
+
trustedOrasBinaryDigests,
|
|
278
|
+
}) {
|
|
279
|
+
const pin = {
|
|
280
|
+
schemaVersion: EVIDENCE_TRUST_PIN_SCHEMA_VERSION,
|
|
281
|
+
policyDigest,
|
|
282
|
+
verifier: {
|
|
283
|
+
bundleDigest: verifier.bundleDigest,
|
|
284
|
+
provenanceDigest: verifier.provenanceDigest,
|
|
285
|
+
},
|
|
286
|
+
kernelContractAuthority: { ...kernelContractAuthorityPin(kernelContractAuthority) },
|
|
287
|
+
trustedOrasBinaryDigests: [...requireOrasDigests(trustedOrasBinaryDigests)].sort(),
|
|
288
|
+
};
|
|
289
|
+
const text = `${JSON.stringify(pin, null, 2)}\n`;
|
|
290
|
+
const descriptor = openSync(
|
|
291
|
+
join(dataRoot, declaration.pin),
|
|
292
|
+
fsConstants.O_WRONLY |
|
|
293
|
+
fsConstants.O_CREAT |
|
|
294
|
+
fsConstants.O_TRUNC |
|
|
295
|
+
fsConstants.O_NOFOLLOW,
|
|
296
|
+
0o644,
|
|
297
|
+
);
|
|
298
|
+
try {
|
|
299
|
+
writeFileSync(descriptor, text);
|
|
300
|
+
} finally {
|
|
301
|
+
closeSync(descriptor);
|
|
302
|
+
}
|
|
303
|
+
return pin;
|
|
304
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// The evidence-trust part of `xema edition check`, and the state an edition
|
|
2
|
+
// records in its descriptor.
|
|
3
|
+
//
|
|
4
|
+
// A data root DECLARES an evidence trust policy (`evidenceTrustPolicy: {policy,
|
|
5
|
+
// pin}` in `edition-workspace.json`) or states that it declares none (`null`).
|
|
6
|
+
// No switch admits an ungated release:
|
|
7
|
+
//
|
|
8
|
+
// * a RELEASE edition is written only against a policy ARMED on the release
|
|
9
|
+
// channel. No policy, UNARMED or PARTIALLY ARMED there -> refused
|
|
10
|
+
// (EvidenceTrustRequiredError, code EVIDENCE_TRUST_REQUIRED_UNARMED);
|
|
11
|
+
// * a DEVELOP edition admits not-armed and says so in one line; a policy
|
|
12
|
+
// PARTIALLY ARMED on the develop channel is refused;
|
|
13
|
+
// * `xema edition check` FAILS when the editions tree holds a release
|
|
14
|
+
// edition (an edition directory holding a release lock) and the policy is
|
|
15
|
+
// not ARMED on the release channel (none declared, UNARMED or PARTIAL):
|
|
16
|
+
// that edition cannot be published as an artifact. A tree holding no
|
|
17
|
+
// release edition passes for develop-only use, with a notice saying so;
|
|
18
|
+
// * no policy declared but a policy file is present at the top level or under
|
|
19
|
+
// `trust/` -> refused: a policy nothing reads is a policy someone believes
|
|
20
|
+
// is enforced;
|
|
21
|
+
// * declared -> the policy parses with the kernel schema, its pinned Sigstore
|
|
22
|
+
// root matches, the data-root pin records the policy's digest AND this
|
|
23
|
+
// CLI's built verifier (a missing bundle is refused, never skipped), and
|
|
24
|
+
// the authority configuration is judged PER CHANNEL
|
|
25
|
+
// (trust-policy-arming.mjs); a channel that is partially armed is refused.
|
|
26
|
+
|
|
27
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
28
|
+
import { join } from 'node:path';
|
|
29
|
+
|
|
30
|
+
import { locateBuiltVerifier, readBuiltVerifierDigests } from './built-verifier.mjs';
|
|
31
|
+
import { EDITION_WORKSPACE_CONFIG_FILE, editionWorkspaceConfig } from './edition-config.mjs';
|
|
32
|
+
import { EDITION_CONTRACT, EditionChannel, EvidenceTrustState } from './edition-constants.mjs';
|
|
33
|
+
import { dataRoot as configuredDataRoot, editionsRoot as configuredEditionsRoot } from './edition-workspace.mjs';
|
|
34
|
+
import {
|
|
35
|
+
assertPinnedPolicy,
|
|
36
|
+
assertPinnedVerifier,
|
|
37
|
+
loadDeclaredTrustPolicy,
|
|
38
|
+
readEvidenceTrustPin,
|
|
39
|
+
} from './evidence-trust-pin.mjs';
|
|
40
|
+
import { loadKernelDistributionSchemas } from './lib.mjs';
|
|
41
|
+
import { heldReleaseLocks } from './release-channel-guard.mjs';
|
|
42
|
+
import {
|
|
43
|
+
TrustPolicyArmingState,
|
|
44
|
+
assertArmingChannel,
|
|
45
|
+
assessTrustPolicyArming,
|
|
46
|
+
} from './trust-policy-arming.mjs';
|
|
47
|
+
|
|
48
|
+
const TAG = '[dist:check]';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The stable code of the refusal to write a RELEASE edition without an armed
|
|
52
|
+
* evidence trust policy. Consumers (xema-deploy, workflows) match on the code,
|
|
53
|
+
* never on the message; it is also listed in edition-contract.json.
|
|
54
|
+
*/
|
|
55
|
+
export const EVIDENCE_TRUST_REQUIRED_UNARMED = EDITION_CONTRACT.evidenceTrust.refusal.code;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* What `xema edition check` says of a data root whose policy is not armed on
|
|
59
|
+
* the release channel. Sealing is not gated (nothing sealed leaves without
|
|
60
|
+
* `xema edition artifact`); publishing is.
|
|
61
|
+
*/
|
|
62
|
+
export const NO_RELEASE_ARTIFACT_NOTICE =
|
|
63
|
+
'no release edition of this data root can be published as an artifact (written by `xema edition artifact`) until the policy is armed on the release channel';
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The release editions of the configured editions tree: the edition directories
|
|
67
|
+
* (those holding `xema-distribution.json`) that hold a release lock. An edition
|
|
68
|
+
* that is only defined, with no lock resolved yet, is not one.
|
|
69
|
+
*/
|
|
70
|
+
export function releaseEditionIds() {
|
|
71
|
+
const root = configuredEditionsRoot();
|
|
72
|
+
if (!existsSync(root)) {return [];}
|
|
73
|
+
return readdirSync(root, { withFileTypes: true })
|
|
74
|
+
.filter(
|
|
75
|
+
(entry) =>
|
|
76
|
+
entry.isDirectory() &&
|
|
77
|
+
existsSync(join(root, entry.name, 'xema-distribution.json')) &&
|
|
78
|
+
heldReleaseLocks(join(root, entry.name)).length > 0,
|
|
79
|
+
)
|
|
80
|
+
.map((entry) => entry.name)
|
|
81
|
+
.sort();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The verdict of the check for a policy that is not armed on the release
|
|
86
|
+
* channel: red when the tree holds a release edition (it names them and the
|
|
87
|
+
* repair), green with the notice when it holds none.
|
|
88
|
+
*/
|
|
89
|
+
function notArmedOnReleaseVerdict(what, repair) {
|
|
90
|
+
const releaseEditions = releaseEditionIds();
|
|
91
|
+
if (releaseEditions.length === 0) {
|
|
92
|
+
console.warn(
|
|
93
|
+
`${TAG} image-evidence trust policy: NOT ARMED on the release channel — ${what}. ${configuredEditionsRoot()} holds no release edition, ` +
|
|
94
|
+
`so this passes for develop-only use: ${NO_RELEASE_ARTIFACT_NOTICE}.`,
|
|
95
|
+
);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
console.error(
|
|
99
|
+
`${TAG} image-evidence trust policy FAILED: ${what}, and ${configuredEditionsRoot()} holds ${String(releaseEditions.length)} release edition(s) ` +
|
|
100
|
+
`(${releaseEditions.join(', ')}): ${NO_RELEASE_ARTIFACT_NOTICE}. ${repair}`,
|
|
101
|
+
);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A release edition requires an armed evidence trust policy and this data root
|
|
107
|
+
* has none: it declares no policy, or declares one that is UNARMED or PARTIALLY
|
|
108
|
+
* ARMED on the release channel. Writing the release descriptor or artifact is
|
|
109
|
+
* refused with this error; a release edition never records `not-armed`.
|
|
110
|
+
*/
|
|
111
|
+
export class EvidenceTrustRequiredError extends Error {
|
|
112
|
+
/** @param {string} dataRoot @param {string} reason what is not armed, in words */
|
|
113
|
+
constructor(dataRoot, reason) {
|
|
114
|
+
super(
|
|
115
|
+
`a release edition requires an armed evidence trust policy, but ${join(dataRoot, EDITION_WORKSPACE_CONFIG_FILE)} ${reason}: ` +
|
|
116
|
+
'declare a policy ({"policy": ..., "pin": ...}) and arm it on the release channel (`xema edition check` says what is unmet).',
|
|
117
|
+
);
|
|
118
|
+
this.name = 'EvidenceTrustRequiredError';
|
|
119
|
+
this.code = EVIDENCE_TRUST_REQUIRED_UNARMED;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Load the declared policy and hold it to its data-root pin: the policy must
|
|
125
|
+
* hash to what the pin records, and this CLI's built verifier must be the one
|
|
126
|
+
* the pin records (a missing bundle is refused, never skipped).
|
|
127
|
+
*/
|
|
128
|
+
function loadPinnedPolicy({ dataRoot, declaration, schemas, locateVerifier }) {
|
|
129
|
+
const { policy, policyDigest } = loadDeclaredTrustPolicy({ dataRoot, declaration, schemas });
|
|
130
|
+
const pin = readEvidenceTrustPin({ dataRoot, declaration });
|
|
131
|
+
assertPinnedPolicy({ pin, policyDigest });
|
|
132
|
+
assertPinnedVerifier({ pin, actual: readBuiltVerifierDigests(locateVerifier) });
|
|
133
|
+
return { policy, policyDigest };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** What a develop edition says, once, when it is written or checked without an armed develop channel. */
|
|
137
|
+
export const DEVELOP_NOT_ARMED_NOTICE = 'develop channel: trust policy not armed, evidence is not signature-verified';
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The evidence state an edition of `channel` records in its descriptor. Arming
|
|
141
|
+
* is judged for that ONE channel (`assessTrustPolicyArming`): the signers of
|
|
142
|
+
* the other channel count for nothing.
|
|
143
|
+
*
|
|
144
|
+
* * `armed` - the data root declares a policy, the policy is pinned (the
|
|
145
|
+
* policy and this CLI's verifier match the data-root pin) and
|
|
146
|
+
* ARMED on `channel`;
|
|
147
|
+
* * `not-armed` - a DEVELOP edition only: its channel is not armed (no
|
|
148
|
+
* policy, or UNARMED there), and it says so in one stderr line.
|
|
149
|
+
*
|
|
150
|
+
* Every other state is refused. A RELEASE edition that is not ARMED on the
|
|
151
|
+
* release channel (no policy, UNARMED or PARTIAL there) throws
|
|
152
|
+
* EvidenceTrustRequiredError: this function never returns `not-armed` for it.
|
|
153
|
+
* A policy edited after pinning, a drifted verifier, and a policy PARTIALLY
|
|
154
|
+
* ARMED on `channel` are refused on either channel.
|
|
155
|
+
*
|
|
156
|
+
* @param {{ channel: string, locateVerifier?: () => {bundlePath: string, provenancePath: string} }} options
|
|
157
|
+
*/
|
|
158
|
+
export async function descriptorEvidenceTrust({ channel, locateVerifier = locateBuiltVerifier }) {
|
|
159
|
+
const declaration = editionWorkspaceConfig().evidenceTrustPolicy;
|
|
160
|
+
const root = configuredDataRoot();
|
|
161
|
+
const schemas = await loadKernelDistributionSchemas();
|
|
162
|
+
assertArmingChannel(schemas, channel);
|
|
163
|
+
const release = channel === EditionChannel.Release;
|
|
164
|
+
const developNotArmed = () => {
|
|
165
|
+
console.error(DEVELOP_NOT_ARMED_NOTICE);
|
|
166
|
+
return EvidenceTrustState.NotArmed;
|
|
167
|
+
};
|
|
168
|
+
if (declaration.policy === null) {
|
|
169
|
+
if (release) {throw new EvidenceTrustRequiredError(root, 'declares no policy');}
|
|
170
|
+
return developNotArmed();
|
|
171
|
+
}
|
|
172
|
+
const { policy } = loadPinnedPolicy({ dataRoot: root, declaration, schemas, locateVerifier });
|
|
173
|
+
const { state, unmet } = assessTrustPolicyArming(policy, schemas, channel);
|
|
174
|
+
if (state === TrustPolicyArmingState.ARMED) {return EvidenceTrustState.Armed;}
|
|
175
|
+
if (state === TrustPolicyArmingState.PARTIAL) {
|
|
176
|
+
if (release) {throw new EvidenceTrustRequiredError(root, `declares a policy that is PARTIALLY ARMED on the ${channel} channel (${unmet.join('; ')})`);}
|
|
177
|
+
throw new Error(`the declared evidence trust policy is PARTIALLY ARMED on the ${channel} channel (${unmet.join('; ')}); an edition cannot be written against it`);
|
|
178
|
+
}
|
|
179
|
+
if (release) {throw new EvidenceTrustRequiredError(root, `declares a policy that is UNARMED on the ${channel} channel`);}
|
|
180
|
+
return developNotArmed();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export const UNDECLARED_TRUST_DIRECTORY = 'trust';
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Policy files the data root holds without declaring them: a top-level `*.json`
|
|
187
|
+
* the kernel parses as an offline trust policy, or a `trust/` directory. A file
|
|
188
|
+
* the kernel schema does not accept is not a policy, which is the whole test.
|
|
189
|
+
*/
|
|
190
|
+
function undeclaredPolicyArtifacts(dataRoot, schemas) {
|
|
191
|
+
const found = [];
|
|
192
|
+
for (const entry of readdirSync(dataRoot, { withFileTypes: true })) {
|
|
193
|
+
if (entry.isDirectory() && entry.name === UNDECLARED_TRUST_DIRECTORY) {
|
|
194
|
+
found.push(`${UNDECLARED_TRUST_DIRECTORY}/`);
|
|
195
|
+
} else if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
196
|
+
if (isTrustPolicy(join(dataRoot, entry.name), schemas)) {
|
|
197
|
+
found.push(entry.name);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return found.sort();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function isTrustPolicy(path, schemas) {
|
|
205
|
+
try {
|
|
206
|
+
schemas.parseSigstoreOfflineTrustPolicy(JSON.parse(readFileSync(path, 'utf8')));
|
|
207
|
+
return true;
|
|
208
|
+
} catch {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Run the gate against the configured data root. Returns true when green; every
|
|
215
|
+
* refusal is printed, naming the repair.
|
|
216
|
+
*
|
|
217
|
+
* @param {{ locateVerifier?: () => {bundlePath: string, provenancePath: string} }} [options]
|
|
218
|
+
* `locateVerifier` is a parameter so a test can supply a fixture bundle.
|
|
219
|
+
*/
|
|
220
|
+
export async function checkEvidenceTrustPolicy({
|
|
221
|
+
locateVerifier = locateBuiltVerifier,
|
|
222
|
+
} = {}) {
|
|
223
|
+
try {
|
|
224
|
+
const dataRoot = configuredDataRoot();
|
|
225
|
+
const declaration = editionWorkspaceConfig().evidenceTrustPolicy;
|
|
226
|
+
const schemas = await loadKernelDistributionSchemas();
|
|
227
|
+
if (declaration.policy === null) {
|
|
228
|
+
const undeclared = undeclaredPolicyArtifacts(dataRoot, schemas);
|
|
229
|
+
if (undeclared.length > 0) {
|
|
230
|
+
console.error(
|
|
231
|
+
`${TAG} image-evidence trust policy FAILED: ${dataRoot} holds ${undeclared.join(', ')} ` +
|
|
232
|
+
`but ${EDITION_WORKSPACE_CONFIG_FILE} declares no evidenceTrustPolicy, so nothing reads it. ` +
|
|
233
|
+
'Declare it ({"policy": ..., "pin": ...}) or remove it.',
|
|
234
|
+
);
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
return notArmedOnReleaseVerdict(
|
|
238
|
+
`${join(dataRoot, EDITION_WORKSPACE_CONFIG_FILE)} declares no evidenceTrustPolicy (its develop editions are not evidence-gated)`,
|
|
239
|
+
'Declare a policy ({"policy": ..., "pin": ...}), authorize the release signers in it, pin it with `xema edition repin-evidence-trust`, and re-run `xema edition check` until it reports ARMED on the release channel.',
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const { policy, policyDigest } = loadPinnedPolicy({ dataRoot, declaration, schemas, locateVerifier });
|
|
244
|
+
console.log(
|
|
245
|
+
`${TAG} image-evidence trust policy pin: green — ${declaration.pin} pins ${declaration.policy} ` +
|
|
246
|
+
`at ${policyDigest} and this CLI's verifier.`,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
console.log(
|
|
250
|
+
`${TAG} image-evidence trust policy: schema green — pinned ${policy.cosignVersion}, ` +
|
|
251
|
+
`${policy.policies.length} authorized signer identities, ` +
|
|
252
|
+
`${policy.trustedCosignBinaryDigests.length} cosign / ` +
|
|
253
|
+
`${policy.trustedGitBinaryDigests.length} git binary pins.`,
|
|
254
|
+
);
|
|
255
|
+
// Each channel is judged on its own signers. The develop channel admits
|
|
256
|
+
// not-armed and says so; a release channel that is not armed fails the
|
|
257
|
+
// check as soon as the tree holds a release edition.
|
|
258
|
+
const partial = (channel, unmet) => {
|
|
259
|
+
console.error(
|
|
260
|
+
`${TAG} image-evidence trust policy is PARTIALLY ARMED on the ${channel} channel — this mixed state is invalid ` +
|
|
261
|
+
`and no ${channel} image evidence can verify against it:`,
|
|
262
|
+
);
|
|
263
|
+
for (const reason of unmet) {
|
|
264
|
+
console.error(`${TAG} - ${reason}`);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const develop = assessTrustPolicyArming(policy, schemas, EditionChannel.Develop);
|
|
268
|
+
if (develop.state === TrustPolicyArmingState.PARTIAL) {
|
|
269
|
+
partial(EditionChannel.Develop, develop.unmet);
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
const release = assessTrustPolicyArming(policy, schemas, EditionChannel.Release);
|
|
273
|
+
if (release.state === TrustPolicyArmingState.PARTIAL) {
|
|
274
|
+
partial(EditionChannel.Release, release.unmet);
|
|
275
|
+
console.error(
|
|
276
|
+
`${TAG} ${NO_RELEASE_ARTIFACT_NOTICE}. Complete the release channel in ${declaration.policy} (every line above), ` +
|
|
277
|
+
're-pin with `xema edition repin-evidence-trust`, and re-run `xema edition check`.',
|
|
278
|
+
);
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
if (develop.state === TrustPolicyArmingState.UNARMED) {console.error(`${TAG} ${DEVELOP_NOT_ARMED_NOTICE}`);}
|
|
282
|
+
if (release.state === TrustPolicyArmingState.UNARMED) {
|
|
283
|
+
return notArmedOnReleaseVerdict(
|
|
284
|
+
`${declaration.policy} is declared but UNARMED on the release channel (it authorizes no release signer)`,
|
|
285
|
+
`Authorize the release signers and pin the cosign and git binaries in ${declaration.policy}, re-pin with \`xema edition repin-evidence-trust\`, and re-run \`xema edition check\` until it reports ARMED on the release channel.`,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
console.log(`${TAG} image-evidence trust policy: ARMED on the release channel${develop.armed ? ' and on the develop channel' : ''}.`);
|
|
289
|
+
return true;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
console.error(`${TAG} image-evidence trust policy FAILED: ${error.message}`);
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|