@rightkit/release 0.6.52 → 0.6.55
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 +6 -1
- package/adapter-env.mjs +16 -105
- package/admission-host.mjs +14 -1
- package/bin/darwin/rightkit-swap +0 -0
- package/bin/rightkit-gate.mjs +585 -404
- package/broker-admission.mjs +122 -2
- package/build-launch.mjs +52 -58
- package/build-release.mjs +2 -2
- package/cargo-ledger.mjs +24 -5
- package/cargo-target-shim.mjs +54 -23
- package/cargo-target.mjs +2 -2
- package/carried-adapter-run.mjs +7 -8
- package/carried-cargo-run.mjs +1 -1
- package/ci-compile-admission.mjs +1 -1
- package/clippy-route.mjs +65 -18
- package/compile-inputs.mjs +91 -15
- package/cross-targets.mjs +5 -3
- package/deps-cargo-lock.mjs +1 -1
- package/deterministic-scans.mjs +789 -259
- package/development.mjs +33 -7
- package/direct-receipt.mjs +3 -5
- package/feature-coverage.mjs +45 -9
- package/feature-partition.mjs +204 -0
- package/feature-sets.mjs +113 -0
- package/gate-acceptance.mjs +187 -115
- package/gate-seam.mjs +352 -0
- package/gate-serve.mjs +34 -2
- package/gate-stages.mjs +6 -2
- package/ghsa-audit.mjs +19 -4
- package/heavy-command.mjs +5 -4
- package/install-tauri-authenticode.mjs +73 -4
- package/ios-dev.mjs +3 -3
- package/ios-package-recipe.mjs +6 -6
- package/linux-setup.mjs +3 -2
- package/local-publish.mjs +113 -17
- package/lock-identity.mjs +24 -100
- package/managed-cargo.mjs +3 -3
- package/managed-root-guard.mjs +2 -2
- package/managed-roots.mjs +3 -3
- package/native-adapters.mjs +41 -244
- package/native-helpers.mjs +1 -1
- package/ownership-mandatory-set.json +16 -0
- package/pack-digest.mjs +1 -1
- package/package-recipe-targets.mjs +19 -11
- package/package.json +2 -2
- package/publication-gate.mjs +29 -6
- package/publish-cargo.mjs +4 -5
- package/publish-local-cargo.mjs +77 -1
- package/qualification-verify.mjs +76 -49
- package/receipt-signature.mjs +104 -0
- package/recipe-build.mjs +15 -2
- package/release-switch-registry.json +4 -0
- package/release-switch-scan.mjs +13 -10
- package/rightkit-versions.json +184 -170
- package/scan-digest.mjs +43 -14
- package/seam-broker.mjs +168 -0
- package/snapshot-check.mjs +4 -1
- package/snapshot-dependency-reuse.mjs +1 -1
- package/snapshot-metadata.mjs +24 -35
- package/snapshot.mjs +328 -49
- package/stage-commands.mjs +59 -5
- package/stage-ledger.mjs +2 -2
- package/{carried-cargo.mjs → stage-seam.mjs} +118 -70
- package/stage-sidecar.mjs +9 -7
- package/tauri-bundle-marker.mjs +5 -2
- package/tauri-locked.mjs +1 -1
- package/tool-build.mjs +8 -6
- package/unit-gate.mjs +40 -10
- package/broker-handshake.mjs +0 -160
- package/broker-wire.mjs +0 -278
- package/build-ownership.mjs +0 -1578
- package/cargo-shapes.mjs +0 -332
- package/cargo-width.mjs +0 -49
- package/carrier-census.mjs +0 -124
- package/clippy-equivalence.mjs +0 -202
- package/freshness-census.mjs +0 -405
- package/handle-revocation.mjs +0 -100
- package/handle-revocation.rust-vector.json +0 -1
- package/handle-revocation.vectors.json +0 -53
- package/legion-freeze-consumer.mjs +0 -241
- package/linux-qualifier.mjs +0 -83
- package/native-tool-planning.mjs +0 -94
- package/owner-process-proof.mjs +0 -14
- package/ownership-mark.mjs +0 -191
- package/ownership-recover.mjs +0 -78
- package/pnpm-adapter-grammar.mjs +0 -226
- package/provenance-verify.mjs +0 -413
- package/snapshot-broker.mjs +0 -808
- package/snapshot-request.mjs +0 -722
- package/unit-list-compile.mjs +0 -356
package/snapshot-request.mjs
DELETED
|
@@ -1,722 +0,0 @@
|
|
|
1
|
-
// The gate's half of a broker snapshot build (joint plan step 4d; GATE-CONTRACT "Broker interface"; the reader is RustRight's
|
|
2
|
-
// rustright-cli shims.rs `snapshot_carrier`, the verifier rustright-protocol attestation.rs `verify_receipt`).
|
|
3
|
-
//
|
|
4
|
-
// For each `rustright cargo` request that builds the commit snapshot on a broker host the gate:
|
|
5
|
-
// 1. picks a fresh nonce (RUSTRIGHT_ATTEST_NONCE: an attested request; the carrier must carry the same nonce);
|
|
6
|
-
// 2. writes the carrier `rustright.snapshot-request/1` as an owner-only file under `<control root>/snapshot-requests/` (the
|
|
7
|
-
// directory the client accepts, never a link) and points RUSTRIGHT_SNAPSHOT_REQUEST at it as `{"path","sha256"}` (at most
|
|
8
|
-
// 4096 bytes; the file at most 4 MiB). The carrier binds the commit and tree, the snapshot and its expected tree, the
|
|
9
|
-
// declared inputs, the build-ownership handle, the cargo working directory (primaryCwd) and sha256 of the canonical cargo
|
|
10
|
-
// argv (without `cargo`), so it cannot be replayed onto another request;
|
|
11
|
-
// 3. after the run, verifies the signed receipt: the provenance signature against this host's enrolled pins (never from the
|
|
12
|
-
// receipt), the job id, the nonce, the signed result (SUCCEEDED, exit 0), the request digest it recomputes over the EXTENDED core (the base core plus commit,
|
|
13
|
-
// snapshot, declaredInputs and ownership), and the signed snapshotEvidence: the receipt's copies equal the signed ones,
|
|
14
|
-
// the commit and handle are the carrier's, and the snapshot held the expected tree at START and at exit.
|
|
15
|
-
// The carrier is set only on that one cargo invocation and is removed after it; nothing the gate exports carries it.
|
|
16
|
-
// A pnpm, node or QA step of a snapshot stage is carried the same way as an ADAPTER request (`rustright run <adapter> -- <args>`,
|
|
17
|
-
// rustright#190: snapshot-adapter-v1): the same carrier, the adapter's name in the request core, and a signed `nestedChildren` list (in snapshotEvidence, mirrored on the receipt) of the
|
|
18
|
-
// compiles that job's own children made (the Tauri CLI's Cargo calls), which the gate verifies as it does the call (rightkit#1301).
|
|
19
|
-
|
|
20
|
-
import crypto from "node:crypto";
|
|
21
|
-
import fs from "node:fs";
|
|
22
|
-
import path from "node:path";
|
|
23
|
-
import { REQUEST_OVER_CAP_CODE, requestOverCap } from "./broker-wire.mjs";
|
|
24
|
-
import { ownerFileOf, writeCarrierOwner } from "./carrier-census.mjs";
|
|
25
|
-
import { BROKER_COMPILE_COMMANDS, CARGO_COMMAND_ALIASES, cargoCommandIndex, cargoSubcommandOf, expandCargoAliases, isCompileCommand, isPackageObservation } from "./cargo-shapes.mjs";
|
|
26
|
-
import { canonicalJson, CAUSE_EVIDENCE_SCHEMA, CAUSE_UNEXPLAINED, CAUSE_UNKNOWN, ProvenanceError, verifyBr19Evidence, verifyCauseEvidence, verifyFailureClass, verifyPostChecks, verifyProvenance, verifyReceiptCoverage, verifyResultEvidence } from "./provenance-verify.mjs";
|
|
27
|
-
|
|
28
|
-
export const SNAPSHOT_REQUEST_SCHEMA = "rustright.snapshot-request/1";
|
|
29
|
-
// One spelling per variable, the current one (rustright-cli shims.rs reads RUSTRIGHT_* first, then the legacy RIGHTKIT_* spelling, which task
|
|
30
|
-
// L-1 removes): the gate never sets both.
|
|
31
|
-
export const SNAPSHOT_REQUEST_ENV = "RUSTRIGHT_SNAPSHOT_REQUEST";
|
|
32
|
-
export const ATTEST_NONCE_ENV = "RUSTRIGHT_ATTEST_NONCE";
|
|
33
|
-
export const REQUEST_ID_FILE_ENV = "RUSTRIGHT_REQUEST_ID_FILE";
|
|
34
|
-
export const REQUEST_REF_SCHEMA = "rustright.request-ref.v1";
|
|
35
|
-
export const DESCRIPTOR_MAX_BYTES = 4096;
|
|
36
|
-
export const CARRIER_MAX_BYTES = 4 * 1024 * 1024;
|
|
37
|
-
/** rustright-cli shims.rs MANAGED_RUST_ENVIRONMENT_KEYS: what the client records as `observedEnv` for a cargo request. */
|
|
38
|
-
export const MANAGED_RUST_ENVIRONMENT_KEYS = Object.freeze([
|
|
39
|
-
"CARGO_HOME", "CARGO_TARGET_DIR", "CARGO_BUILD_TARGET", "CARGO_BUILD_TARGET_DIR", "CARGO_BUILD_BUILD_DIR", "CARGO_BUILD_RUSTC",
|
|
40
|
-
"CARGO_BUILD_RUSTDOC", "CARGO_BUILD_RUSTC_WRAPPER", "CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER", "CARGO_BUILD_RUSTFLAGS",
|
|
41
|
-
"CARGO_ENCODED_RUSTFLAGS", "CARGO_INSTALL_ROOT", "RUSTUP_HOME", "RUSTC", "RUSTDOC", "RUSTFLAGS", "RUSTDOCFLAGS", "RUSTC_WRAPPER",
|
|
42
|
-
"RUSTC_WORKSPACE_WRAPPER",
|
|
43
|
-
]);
|
|
44
|
-
/** The fields the broker copies onto the receipt and signs in payload.snapshotEvidence (attestation.rs). */
|
|
45
|
-
export const SNAPSHOT_EVIDENCE_FIELDS = Object.freeze(["requestId", "brokerVersion", "executor", "commit", "snapshot", "declaredInputDigests", "ownership", "outputDir"]);
|
|
46
|
-
/** The stage evidence the broker signs in payload.stageEvidence and copies onto the receipt (attestation.rs STAGE_EVIDENCE_FIELDS). */
|
|
47
|
-
export const STAGE_EVIDENCE_FIELDS = Object.freeze(["freshness", "attribution", "toolchain"]);
|
|
48
|
-
/** The result fields the broker signs in payload.resultEvidence and mirrors on the receipt (attestation.rs RESULT_EVIDENCE_FIELDS). */
|
|
49
|
-
export const RESULT_EVIDENCE_FIELDS = Object.freeze(["exit", "signal", "timingsMs", "diagnosticsPath"]);
|
|
50
|
-
const TIMING_KEYS =Object.freeze(["admission", "queue", "bind", "cargo", "afterExitBind", "diagnostics"]);
|
|
51
|
-
/** The broker's code for a compile whose toolchain identity cannot be built (checked_toolchain_identity), and the gate's typed error code for it. */
|
|
52
|
-
export const TOOLCHAIN_UNAVAILABLE_CODE = "RK_TOOLCHAIN_IDENTITY_UNAVAILABLE";
|
|
53
|
-
export const TOOLCHAIN_UNAVAILABLE = "toolchain-unavailable";
|
|
54
|
-
/** `{"state":"UNKNOWN","reason":<non-empty string>}` exactly: the one spelling of an identity the broker could not establish (BR19). */
|
|
55
|
-
export const isToolchainUnknown = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 2 && v.state === "UNKNOWN" && typeof v.reason === "string" && v.reason !== "";
|
|
56
|
-
/** `<toolchain>|cargo:<sha256>|rustc:<sha256>` (rustright toolchain_identity). */
|
|
57
|
-
const TOOLCHAIN_FORMAT = /^[^|\s][^|]*\|cargo:[0-9a-f]{64}\|rustc:[0-9a-f]{64}$/;
|
|
58
|
-
|
|
59
|
-
// GB-01/GB-02: the command-shape table is cargo-shapes.mjs (one versioned table, exercised against RustRight's cargo-shapes vector); these names
|
|
60
|
-
// are its views for the carried call. `isCompileClass` decides which evidence a receipt must carry from the broker's own compile rule (the `compile`
|
|
61
|
-
// column of the vector), so bench, run, rustdoc and a compiling `package` owe it too and a read-only metadata or `package --list` legitimately carries none.
|
|
62
|
-
export { BROKER_COMPILE_COMMANDS, CARGO_COMMAND_ALIASES, cargoSubcommandOf, isPackageObservation };
|
|
63
|
-
/** Whether the broker classifies this argv (without the tool name) as a compile. `package` is one unless it is the observation listing. */
|
|
64
|
-
export const isCompileClass = (argv) => isCompileCommand(argv);
|
|
65
|
-
/** The commands that build or run, and so can rewrite Cargo.lock inside a snapshot unless they are locked (rightkit#1301): the same table as `isCompileClass`. */
|
|
66
|
-
export const isLockBound = (argv) => isCompileClass(argv);
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* The argv a carried call sends: a build or run command with neither `--locked` nor `--frozen` (before any `--`) gets `--locked` right
|
|
70
|
-
* after its subcommand. RustRight refuses an unlocked grant-minted build, and an unlocked build could rewrite Cargo.lock in the snapshot.
|
|
71
|
-
* Adding it, not refusing, is the less surprising rule: the call runs as the caller meant it, except that a stale lock fails instead of
|
|
72
|
-
* being rewritten. The ledger and the signed request digest both carry the argv as sent.
|
|
73
|
-
*/
|
|
74
|
-
/** cargo-ndk's own options that take a value (outer grammar): `cargo ndk [-t <abi>] [-p|--platform <api>] [-o <dir>] ... <cargo subcommand> [cargo args]`. */
|
|
75
|
-
const NDK_VALUE_OPTIONS = new Set(["-t", "--target", "-o", "--output-dir", "-p", "--platform"]);
|
|
76
|
-
const NDK_INNER_LOCKED = new Set(["build", "b", "check", "c", "test", "t", "bench", "clippy", "doc", "rustc", "rustdoc", "run", "r"]);
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* GB-62: `cargo ndk <outer options> build <cargo args>` is two grammars. The immutable-dependency flag belongs to the INNER Cargo command, so it is
|
|
80
|
-
* inserted right after that inner subcommand (never after `ndk`, where cargo-ndk would read it as its own option, and never before it). Returns the argv
|
|
81
|
-
* unchanged when the inner command is not a locked-class command, already carries `--locked`/`--frozen` before `--`, or cannot be found.
|
|
82
|
-
*/
|
|
83
|
-
function lockedNdkArgv(words) {
|
|
84
|
-
const end = words.indexOf("--");
|
|
85
|
-
const own = end < 0 ? words : words.slice(0, end);
|
|
86
|
-
let i = words.findIndex((w) => w === "ndk");
|
|
87
|
-
if (i < 0) return words;
|
|
88
|
-
for (i += 1; i < own.length; i += 1) {
|
|
89
|
-
const w = own[i];
|
|
90
|
-
if (NDK_VALUE_OPTIONS.has(w)) { i += 1; continue; }
|
|
91
|
-
if (w.startsWith("-")) continue;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (i >= own.length || !NDK_INNER_LOCKED.has(own[i])) return words;
|
|
95
|
-
if (own.slice(i + 1).some((w) => w === "--locked" || w === "--frozen")) return words;
|
|
96
|
-
return [...words.slice(0, i + 1), "--locked", ...words.slice(i + 1)];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function lockedArgv(argv) {
|
|
100
|
-
// GB-01: the standard aliases are expanded BEFORE locking and hashing, so what the gate sends, signs and digests is what the broker classifies
|
|
101
|
-
// (a committed `.cargo/config.toml` [alias] can never redefine it). Only the subcommand token changes.
|
|
102
|
-
const words = expandCargoAliases(argv);
|
|
103
|
-
if (cargoSubcommandOf(words) === "ndk") return lockedNdkArgv(words);
|
|
104
|
-
if (!isLockBound(words)) return words;
|
|
105
|
-
const end = words.indexOf("--");
|
|
106
|
-
if ((end < 0 ? words : words.slice(0, end)).some((w) => w === "--locked" || w === "--frozen")) return words;
|
|
107
|
-
const i = cargoCommandIndex(words);
|
|
108
|
-
if (i === null) return words;
|
|
109
|
-
return [...words.slice(0, i + 1), "--locked", ...words.slice(i + 1)];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const CARRIED_REDIRECT = /^(--config|-Z|-C)(=|$)|^-[A-Za-z]*[CZ]/;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* The one place that turns a caller's cargo arguments (without `cargo`) into the arguments a carried call sends (carried-cargo.mjs
|
|
116
|
-
* `runCarriedCargo`; stage-commands.mjs derives what a stage's signed receipts must show from the same function, so the two cannot drift):
|
|
117
|
-
* `--manifest-path <p>` or `--manifest-path=<p>` before any `--` is removed (the client refuses to rewrite an attested call; the call
|
|
118
|
-
* runs from the manifest's directory instead, the last one wins) and returned as `manifestPath`; `--target-dir` and the redirecting
|
|
119
|
-
* options are refused. Returns `{ words, manifestPath }` (`manifestPath` null when none) or `{ refusal: { code, message } }`.
|
|
120
|
-
* `words` are not yet locked: the signed request carries `lockedArgv(words)` (carryBrokerCargo).
|
|
121
|
-
*/
|
|
122
|
-
export function splitCarriedArgs(args) {
|
|
123
|
-
const original = [...args];
|
|
124
|
-
const words = [];
|
|
125
|
-
let manifestPath = null;
|
|
126
|
-
let atSeparator = false;
|
|
127
|
-
for (let i = 0; i < original.length; i += 1) {
|
|
128
|
-
const w = original[i];
|
|
129
|
-
if (atSeparator) { words.push(w); continue; }
|
|
130
|
-
if (w === "--") { atSeparator = true; words.push(w); continue; }
|
|
131
|
-
if (w === "--manifest-path" || w.startsWith("--manifest-path=")) {
|
|
132
|
-
const value = w === "--manifest-path" ? original[i + 1] : w.slice("--manifest-path=".length);
|
|
133
|
-
if (w === "--manifest-path") i += 1;
|
|
134
|
-
if (typeof value !== "string" || !value) return { refusal: { code: "RK_CARGO_BROKER_MANIFEST_PATH", message: "--manifest-path names no manifest" } };
|
|
135
|
-
manifestPath = value;
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
if (w === "--target-dir" || w.startsWith("--target-dir=")) return { refusal: { code: "RK_CARGO_REDIRECT", message: `\`cargo ${original.join(" ")}\` passes --target-dir; the broker pins a carried call's output directory` } };
|
|
139
|
-
if (CARRIED_REDIRECT.test(w)) return { refusal: { code: "RK_CARGO_REDIRECT", message: `\`cargo ${original.join(" ")}\` passes ${w}, which moves its working directory, configuration or output` } };
|
|
140
|
-
words.push(w);
|
|
141
|
-
}
|
|
142
|
-
return { words, manifestPath };
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* What a carried call sends the broker for `args` run from `cwd` (a posix path relative to the workspace root, "." for the root): the
|
|
147
|
-
* argv as signed (`requestedArgv`: no --manifest-path, `--locked` added to a build or run) and the directory it runs in (`cwd` joined
|
|
148
|
-
* with the manifest's directory). Returns `{ argv, cwd }` or null when the call would be refused.
|
|
149
|
-
*/
|
|
150
|
-
export function carriedRequestOf(args, cwd = ".") {
|
|
151
|
-
const split = splitCarriedArgs(args);
|
|
152
|
-
if (split.refusal) return null;
|
|
153
|
-
const dir = split.manifestPath === null ? cwd : path.posix.normalize(path.posix.join(cwd, path.posix.dirname(split.manifestPath.replaceAll("\\", "/"))));
|
|
154
|
-
return { argv: lockedArgv(split.words), cwd: dir === "" ? "." : dir };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Where the declared compile inputs are listed, as read from the snapshot (the broker's COMPILE_INPUTS; GB-49): `.rustright/compile-inputs.json` first,
|
|
159
|
-
* `.rightkit/compile-inputs.json` ONLY when the canonical file is absent. A present but invalid canonical declaration is an error, never a fallback.
|
|
160
|
-
*/
|
|
161
|
-
export const COMPILE_INPUTS_CANONICAL = ".rustright/compile-inputs.json";
|
|
162
|
-
export const COMPILE_INPUTS_LEGACY = ".rightkit/compile-inputs.json";
|
|
163
|
-
export const COMPILE_INPUTS = COMPILE_INPUTS_CANONICAL;
|
|
164
|
-
export const COMPILE_INPUT_DECLARATIONS = Object.freeze([COMPILE_INPUTS_CANONICAL, COMPILE_INPUTS_LEGACY]);
|
|
165
|
-
export const MAX_DECLARATION_BYTES = 4 * 1024 * 1024;
|
|
166
|
-
const MAX_INPUT_FILES = 200_000;
|
|
167
|
-
const MAX_INPUT_BYTES = 4 * 1024 * 1024 * 1024;
|
|
168
|
-
|
|
169
|
-
export class SnapshotRequestError extends Error {
|
|
170
|
-
constructor(code, message) { super(message); this.name = "SnapshotRequestError"; this.code = code; }
|
|
171
|
-
}
|
|
172
|
-
const fail = (code, message) => { throw new SnapshotRequestError(code, message); };
|
|
173
|
-
const sha256 = (data) => crypto.createHash("sha256").update(data).digest("hex");
|
|
174
|
-
const objectId = (s) => typeof s === "string" && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(s);
|
|
175
|
-
|
|
176
|
-
/** A fresh attestation nonce: 64 lowercase hex characters. */
|
|
177
|
-
export const freshNonce = () => crypto.randomBytes(32).toString("hex");
|
|
178
|
-
|
|
179
|
-
/** sha256 of the canonical JSON of the cargo argv (without `cargo`), as the client computes it. */
|
|
180
|
-
export const argvSha256 = (argv) => sha256(canonicalJson([...argv]));
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* The managed Rust variables the client will report as observedEnv, from the environment the gate runs it with. RustRight's
|
|
184
|
-
* capture_managed_rust_environment (shims.rs) matches the name case-insensitively on every platform and keeps the key exactly as
|
|
185
|
-
* spelled (`Cargo_Home` stays `Cargo_Home`), so the digest binds that spelling. On Windows the child sees only one of several
|
|
186
|
-
* names that differ by case: Node passes the first in sorted order (child_process "env" on Windows), so the rest are not observed.
|
|
187
|
-
*/
|
|
188
|
-
export function observedEnvOf(env, platform = process.platform) {
|
|
189
|
-
const out = {};
|
|
190
|
-
const entries = Object.entries(env ?? {});
|
|
191
|
-
if (platform === "win32") entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
192
|
-
const seen = new Set();
|
|
193
|
-
for (const [key, value] of entries) {
|
|
194
|
-
const upper = key.toUpperCase();
|
|
195
|
-
if (platform === "win32") { if (seen.has(upper)) continue; seen.add(upper); }
|
|
196
|
-
if (MANAGED_RUST_ENVIRONMENT_KEYS.includes(upper) && typeof value === "string") out[key] = value;
|
|
197
|
-
}
|
|
198
|
-
return out;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* The next per-call lease handle of a build ownership: `<ownership-handle>#<uuid>`. A workspace index or a per-process counter is not unique
|
|
203
|
-
* (metadata, check and test reuse a workspace; wrapper children are separate processes), so each invocation draws its own random UUID. The broker accepts one
|
|
204
|
-
* completion per handle on a snapshot, and its status for the bare ownership handle covers every `#` sub-handle.
|
|
205
|
-
*/
|
|
206
|
-
export const nextCallHandle = (handle) => `${handle}#${crypto.randomUUID()}`;
|
|
207
|
-
/** Whether `callHandle` is exactly one sub-handle of the ownership `handle` (`<handle>#<token>`, never the bare handle or another's). */
|
|
208
|
-
export const isCallHandleOf = (callHandle, handle) => typeof callHandle === "string" && typeof handle === "string" && handle !== "" && callHandle.length > handle.length + 1 && callHandle.startsWith(`${handle}#`) && /^[A-Za-z0-9._-]+$/.test(callHandle.slice(handle.length + 1));
|
|
209
|
-
/** The ownership handle a signed (sub-)handle belongs to: everything before the first `#`. */
|
|
210
|
-
export const ownershipOfHandle = (handle) => (typeof handle === "string" ? handle.split("#")[0] : handle);
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Writes the carrier for one cargo request and returns `{ file, sha256, descriptor, carrier, env }`; `env` is what that one
|
|
214
|
-
* invocation adds (carrier descriptor, nonce, request-id file). Refuses before writing anything the reader would refuse.
|
|
215
|
-
*/
|
|
216
|
-
export function writeSnapshotRequest({ controlRoot, commit, snapshot, declaredInputs = [], handle, callHandle, primaryCwd, argv, nonce = freshNonce(), requestIdFile, uuid = crypto.randomUUID }) {
|
|
217
|
-
if (!objectId(commit?.sha) || !objectId(commit?.tree)) fail("invalid", "commit sha and tree must be full lowercase object ids");
|
|
218
|
-
if (!snapshot?.path || !path.isAbsolute(snapshot.path) || snapshot.expectedTree !== commit.tree) fail("invalid", "the snapshot needs an absolute path and the commit's tree as expectedTree");
|
|
219
|
-
if (typeof handle !== "string" || !handle.trim()) fail("invalid", "the build-ownership handle is missing");
|
|
220
|
-
if (callHandle !== undefined && !isCallHandleOf(callHandle, handle)) fail("invalid", `the call handle ${JSON.stringify(callHandle)} is not a sub-handle (<ownership-handle>#<n>) of the build ownership`);
|
|
221
|
-
if (!primaryCwd || !path.isAbsolute(primaryCwd)) fail("invalid", "primaryCwd must be the cargo request's absolute working directory");
|
|
222
|
-
if (!Array.isArray(argv) || !argv.every((a) => typeof a === "string")) fail("invalid", "argv must be the cargo arguments (without cargo)");
|
|
223
|
-
if (typeof nonce !== "string" || !/^[0-9a-f]{64,128}$/.test(nonce)) fail("invalid", "the nonce must be 64 to 128 lowercase hex characters");
|
|
224
|
-
if (!Array.isArray(declaredInputs) || declaredInputs.some((p) => typeof p !== "string" || !p || path.isAbsolute(p) || path.posix.isAbsolute(p))) fail("invalid", "declared inputs must be relative paths");
|
|
225
|
-
if (!controlRoot || !path.isAbsolute(controlRoot)) fail("invalid", "the control root must be absolute");
|
|
226
|
-
const dir = path.join(controlRoot, "snapshot-requests");
|
|
227
|
-
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
228
|
-
const meta = fs.lstatSync(dir);
|
|
229
|
-
if (meta.isSymbolicLink() || !meta.isDirectory()) fail("invalid", `${dir} is not a real directory`);
|
|
230
|
-
const carrier = {
|
|
231
|
-
schema: SNAPSHOT_REQUEST_SCHEMA,
|
|
232
|
-
commit: { sha: commit.sha, tree: commit.tree },
|
|
233
|
-
snapshot: { path: snapshot.path, expectedTree: snapshot.expectedTree },
|
|
234
|
-
declaredInputs: { inputs: [...declaredInputs] },
|
|
235
|
-
// One completion per (snapshot, lease handle) at the broker (rustright snapshot.rs:330-343): each carried request names its own
|
|
236
|
-
// sub-handle `<ownership-handle>#<n>`, which the broker's bare-handle lease status aggregates (snapshot.rs:469).
|
|
237
|
-
ownership: { handle: callHandle ?? nextCallHandle(handle) },
|
|
238
|
-
primaryCwd,
|
|
239
|
-
argvSha256: argvSha256(argv),
|
|
240
|
-
nonce,
|
|
241
|
-
};
|
|
242
|
-
const bytes = Buffer.from(JSON.stringify(carrier), "utf8");
|
|
243
|
-
if (bytes.length > CARRIER_MAX_BYTES) fail("too-large", `the snapshot request is ${bytes.length} bytes, more than ${CARRIER_MAX_BYTES}`);
|
|
244
|
-
// GB-53: the request line is 1 MiB, newline included, one unit with the response limit. The declared inputs ride in it with the envelope: a request that cannot fit is
|
|
245
|
-
// refused here, before the carrier is written, before it counts as sent, so no job exists.
|
|
246
|
-
const overCap = requestOverCap(Buffer.byteLength(JSON.stringify(carrier.declaredInputs)) + Buffer.byteLength(JSON.stringify({ commit: carrier.commit, snapshot: carrier.snapshot, ownership: carrier.ownership, primaryCwd, argv })));
|
|
247
|
-
if (overCap) fail(REQUEST_OVER_CAP_CODE, overCap);
|
|
248
|
-
const file = path.join(dir, `${uuid()}.json`);
|
|
249
|
-
const digest = sha256(bytes);
|
|
250
|
-
const descriptor = JSON.stringify({ path: file, sha256: digest });
|
|
251
|
-
if (Buffer.byteLength(descriptor) > DESCRIPTOR_MAX_BYTES) fail("too-large", "the snapshot request descriptor exceeds 4096 bytes");
|
|
252
|
-
// GB-76 (BROKER-CONTRACT section 16): the creator is recorded FIRST, in `<carrier>.owner.json` (the gate's identity as RustRight reads it, the call's nonce and sub-handle, the creation time), then
|
|
253
|
-
// the carrier; both are removed in the call's `finally`. A broker sweep retires a leftover only on proof that the gate is gone and nothing is held under the handle, never on age alone. A
|
|
254
|
-
// record that cannot be written leaves no carrier.
|
|
255
|
-
try { writeCarrierOwner({ file, handle: carrier.ownership.handle, nonce }); } catch (e) { if (e.code !== "EEXIST") fs.rmSync(ownerFileOf(file), { force: true }); fail("invalid", `the carrier's owner record cannot be written (${e.code ?? e.message}), so no carrier is left behind`); }
|
|
256
|
-
try { fs.writeFileSync(file, bytes, { flag: "wx", mode: 0o600 }); } catch (e) { fs.rmSync(ownerFileOf(file), { force: true }); throw e; }
|
|
257
|
-
const env = { [SNAPSHOT_REQUEST_ENV]: descriptor, [ATTEST_NONCE_ENV]: nonce, ...(requestIdFile ? { [REQUEST_ID_FILE_ENV]: requestIdFile } : {}) };
|
|
258
|
-
return { file, sha256: digest, descriptor, carrier, env };
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* The request core the broker digests for a snapshot request: the base core plus commit, snapshot, declaredInputs and ownership. A cargo
|
|
263
|
-
* request has `shim: "cargo"` and no adapter; a carried adapter request (rustright#190 D2) has `shim: "adapter"`, the registered adapter's
|
|
264
|
-
* name, no observed environment (the client captures none for an adapter), and `env`: the request's own environment object, exactly the
|
|
265
|
-
* variables RUSTRIGHT_ADAPTER_ENV names (rustright-protocol attestation.rs request_core `environment`; adapter-env.mjs), always empty for Cargo.
|
|
266
|
-
* The adapter spelling is RustRight's; see snapshot-broker.mjs carryBrokerAdapter.
|
|
267
|
-
*/
|
|
268
|
-
export function snapshotRequestCore({ argv, workspace, observedEnv = {}, carrier, adapter = null, adapterEnv = {} }) {
|
|
269
|
-
return {
|
|
270
|
-
adapter, env: adapter === null ? {} : { ...adapterEnv }, inputManifest: null, nonce: carrier.nonce, observedEnv: adapter === null ? observedEnv : {}, outputs: [], requestedArgv: [...argv], shim: adapter === null ? "cargo" : "adapter", workspace,
|
|
271
|
-
commit: carrier.commit, snapshot: carrier.snapshot, declaredInputs: carrier.declaredInputs, ownership: carrier.ownership,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
export const requestDigestOf = (core) => sha256(canonicalJson(core));
|
|
275
|
-
|
|
276
|
-
/** The request reference the client writes at submit (RUSTRIGHT_REQUEST_ID_FILE), or a throw. */
|
|
277
|
-
export function readRequestRef(file) {
|
|
278
|
-
let ref;
|
|
279
|
-
try { ref = JSON.parse(fs.readFileSync(file, "utf8")); } catch (e) { fail("request", `no request reference at ${file} (${e.message})`); }
|
|
280
|
-
if (ref?.schema !== REQUEST_REF_SCHEMA || typeof ref.requestId !== "string" || !ref.requestId || typeof ref.workspace !== "string" || !path.isAbsolute(ref.workspace)) fail("request", `${file} is not a ${REQUEST_REF_SCHEMA}`);
|
|
281
|
-
return ref;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const same = (a, b) => canonicalJson(a ?? null) === canonicalJson(b ?? null);
|
|
285
|
-
|
|
286
|
-
// ---- declared compile inputs, read and digested the way the broker does (check_admission.rs declared_inputs / snapshot_inputs) ----
|
|
287
|
-
|
|
288
|
-
const lstatOrNull = (p) => { try { return fs.lstatSync(p); } catch (e) { if (e.code === "ENOENT") return null; throw e; } };
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* The declared inputs of a snapshot, read FROM THE SNAPSHOT, never the checkout, by the one rule every RightKit reader shares (the broker's, vector
|
|
292
|
-
* docs/contracts/declared-inputs.fixtures.json): `.rustright/compile-inputs.json` when it exists, else `.rightkit/compile-inputs.json`, else none. Either file
|
|
293
|
-
* is judged by the same checks: no link on its path, a regular file of at most 4 MiB, JSON with `inputs` a list of plain relative paths (not absolute, no `.`,
|
|
294
|
-
* `..` or empty component, not inside `.git`) and no input that is, or holds, either declaration file. A present but invalid canonical declaration is an
|
|
295
|
-
* error: it is never read as the legacy one.
|
|
296
|
-
*/
|
|
297
|
-
/** Host platform names a declared input may scope itself to (`{ path, platforms }`). */
|
|
298
|
-
export const DECLARED_INPUT_PLATFORMS = Object.freeze({ darwin: "mac", win32: "win", linux: "linux" });
|
|
299
|
-
|
|
300
|
-
export function readDeclaredInputs(snapshotRoot, { platform = process.platform } = {}) {
|
|
301
|
-
let file = null; let at = null; let meta = null;
|
|
302
|
-
for (const candidate of COMPILE_INPUT_DECLARATIONS) {
|
|
303
|
-
let here = snapshotRoot; let found = true;
|
|
304
|
-
for (const part of candidate.split("/")) {
|
|
305
|
-
here = path.join(here, part);
|
|
306
|
-
const m = lstatOrNull(here);
|
|
307
|
-
if (m === null) { found = false; break; }
|
|
308
|
-
if (m.isSymbolicLink()) fail("declared-inputs", `${candidate} runs through a link at ${here}`);
|
|
309
|
-
meta = m;
|
|
310
|
-
}
|
|
311
|
-
if (found) { file = candidate; at = here; break; }
|
|
312
|
-
}
|
|
313
|
-
if (file === null) return [];
|
|
314
|
-
if (!meta.isFile()) fail("declared-inputs", `${file} is not a regular file`);
|
|
315
|
-
if (meta.size > MAX_DECLARATION_BYTES) fail("declared-inputs", `${file} is larger than ${MAX_DECLARATION_BYTES} bytes`);
|
|
316
|
-
let value;
|
|
317
|
-
try { value = JSON.parse(fs.readFileSync(at, "utf8")); } catch (e) { fail("declared-inputs", `${file} is not JSON (${e.message})`); }
|
|
318
|
-
if (!value || typeof value !== "object" || !Array.isArray(value.inputs)) fail("declared-inputs", `${file}: \`inputs\` must be a list of paths`);
|
|
319
|
-
// An entry is a path (every platform) or { path, platforms }: a platform-scoped input (a Windows-only identity package) is declared
|
|
320
|
-
// only on the hosts it names, so another host neither requires nor digests it. Unknown keys or platform names refuse.
|
|
321
|
-
const host = DECLARED_INPUT_PLATFORMS[platform] ?? platform;
|
|
322
|
-
const kept = [];
|
|
323
|
-
for (const entry of value.inputs) {
|
|
324
|
-
let input = entry;
|
|
325
|
-
if (entry && typeof entry === "object" && !Array.isArray(entry)) {
|
|
326
|
-
const extra = Object.keys(entry).filter((k) => k !== "path" && k !== "platforms");
|
|
327
|
-
if (extra.length) fail("declared-inputs", `${file}: an input object has only path and platforms (found ${extra.join(", ")})`);
|
|
328
|
-
const names = Object.values(DECLARED_INPUT_PLATFORMS);
|
|
329
|
-
if (!Array.isArray(entry.platforms) || !entry.platforms.length || entry.platforms.some((x) => !names.includes(x))) fail("declared-inputs", `${file}: ${JSON.stringify(entry.path)}: platforms must be a non-empty list of ${names.join(", ")}`);
|
|
330
|
-
input = entry.path;
|
|
331
|
-
}
|
|
332
|
-
if (typeof input !== "string" || !input) fail("declared-inputs", `${file}: every input is a non-empty relative path`);
|
|
333
|
-
const here = !(entry && typeof entry === "object") || entry.platforms.includes(host);
|
|
334
|
-
const components = input.split(/[\\/]/);
|
|
335
|
-
if (path.isAbsolute(input) || path.posix.isAbsolute(input) || path.win32.isAbsolute(input) || components.some((c) => c === "" || c === "." || c === "..")) fail("declared-inputs", `${file}: ${input} is not a plain relative path inside the snapshot`);
|
|
336
|
-
if (components.some((c) => c.toLowerCase() === ".git")) fail("declared-inputs", `${file}: ${input} is inside .git; repository metadata is never a compile input`);
|
|
337
|
-
for (const declaration of COMPILE_INPUT_DECLARATIONS) {
|
|
338
|
-
const parts = declaration.split("/");
|
|
339
|
-
if (components.length <= parts.length && components.every((c, i) => c === parts[i])) fail("declared-inputs", `${file}: ${input} overlaps the declaration file itself (${declaration})`);
|
|
340
|
-
}
|
|
341
|
-
if (here) kept.push(input);
|
|
342
|
-
}
|
|
343
|
-
return kept;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** The inputs a request supplied must be exactly the declaration the snapshot holds (the broker's check): a throw naming the difference. */
|
|
347
|
-
export function assertSuppliedInputs(snapshotRoot, supplied) {
|
|
348
|
-
const declared = readDeclaredInputs(snapshotRoot);
|
|
349
|
-
if (!same(declared, supplied)) fail("declared-inputs", "the snapshot's declared inputs are not the ones this request carried (declaredInputs differs from the snapshot declaration)");
|
|
350
|
-
return declared;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* The `declaredInputDigests` the broker records for these inputs, computed here from the snapshot: per input, sha256 over, for each
|
|
355
|
-
* regular file in directory order (names sorted by their bytes), the file's relative name, a NUL, its bytes and a NUL. A link
|
|
356
|
-
* anywhere, a special file, or a limit breach is a refusal. The name is the input's path components joined by `/` on EVERY platform (GB-49: RustRight hashes
|
|
357
|
-
* `/` on Windows too, so a `\` in a declaration or a platform separator never reaches the hash), UTF-8, no Unicode normalisation.
|
|
358
|
-
*
|
|
359
|
-
* `allowAbsent` makes a declared input that does not exist in the snapshot (ENOENT/ENOTDIR on a component; a link is still refused) the entry
|
|
360
|
-
* `{ path, absent: true }` (no `sha256`, 0 files, 0 bytes), the wire form RustRight signs. The broker admits every request with an absent input
|
|
361
|
-
* (a compile is refused at exit only if an input CHANGED while it ran, rustright d378d32), so the receipt check digests with it for every class.
|
|
362
|
-
*/
|
|
363
|
-
export function declaredInputDigestsOf(snapshotRoot, inputs, { allowAbsent = false } = {}) {
|
|
364
|
-
let files = 0; let bytes = 0;
|
|
365
|
-
const walk = (full, name, hasher) => {
|
|
366
|
-
const meta = fs.lstatSync(full);
|
|
367
|
-
if (meta.isSymbolicLink()) fail("declared-inputs", `declared compile input holds a link at ${name}`);
|
|
368
|
-
if (meta.isDirectory()) {
|
|
369
|
-
const children = fs.readdirSync(full).sort((a, b) => Buffer.compare(Buffer.from(a, "utf8"), Buffer.from(b, "utf8")));
|
|
370
|
-
for (const child of children) walk(path.join(full, child), `${name}/${child}`, hasher);
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
if (!meta.isFile()) fail("declared-inputs", `declared compile input ${name} is not a regular file or directory`);
|
|
374
|
-
files += 1;
|
|
375
|
-
if (files > MAX_INPUT_FILES) fail("declared-inputs", `the declared compile inputs exceed ${MAX_INPUT_FILES} files`);
|
|
376
|
-
hasher.update(name); hasher.update(Buffer.from([0]));
|
|
377
|
-
const fd = fs.openSync(full, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
|
|
378
|
-
try {
|
|
379
|
-
const after = fs.fstatSync(fd);
|
|
380
|
-
if (!after.isFile() || (process.platform !== "win32" && (after.dev !== meta.dev || after.ino !== meta.ino))) fail("declared-inputs", `${name} changed while it was read`);
|
|
381
|
-
const chunk = Buffer.allocUnsafe(64 * 1024);
|
|
382
|
-
for (;;) {
|
|
383
|
-
const n = fs.readSync(fd, chunk, 0, chunk.length, null);
|
|
384
|
-
if (n === 0) break;
|
|
385
|
-
bytes += n;
|
|
386
|
-
if (bytes > MAX_INPUT_BYTES) fail("declared-inputs", `the declared compile inputs exceed ${MAX_INPUT_BYTES} bytes`);
|
|
387
|
-
hasher.update(chunk.subarray(0, n));
|
|
388
|
-
}
|
|
389
|
-
} finally { fs.closeSync(fd); }
|
|
390
|
-
hasher.update(Buffer.from([0]));
|
|
391
|
-
};
|
|
392
|
-
return inputs.map((input) => {
|
|
393
|
-
// Every component of the declared path is walked without following a link.
|
|
394
|
-
let at = snapshotRoot;
|
|
395
|
-
for (const part of input.split(/[\\/]/)) {
|
|
396
|
-
at = path.join(at, part);
|
|
397
|
-
let meta;
|
|
398
|
-
try { meta = fs.lstatSync(at); } catch (e) {
|
|
399
|
-
if (allowAbsent && (e.code === "ENOENT" || e.code === "ENOTDIR")) return { path: input, absent: true };
|
|
400
|
-
fail("declared-inputs", `${input}: ${e.message}`);
|
|
401
|
-
}
|
|
402
|
-
if (meta.isSymbolicLink()) fail("declared-inputs", `${input} runs through a link at ${at}`);
|
|
403
|
-
}
|
|
404
|
-
const hasher = crypto.createHash("sha256");
|
|
405
|
-
walk(at, input.split(/[\\/]/).join("/"), hasher);
|
|
406
|
-
return { path: input, sha256: hasher.digest("hex") };
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// ---- the receipt ----
|
|
411
|
-
|
|
412
|
-
const inside = (child, parent, platform) => {
|
|
413
|
-
const norm = (p) => (platform === "win32" ? path.win32.resolve(p).toLowerCase() : path.resolve(p));
|
|
414
|
-
const rel = (platform === "win32" ? path.win32 : path).relative(norm(parent), norm(child));
|
|
415
|
-
return rel === "" || !(rel === ".." || /^\.\.[\\/]/.test(rel) || path.isAbsolute(rel) || path.win32.isAbsolute(rel));
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* The leaf names of a managed generation (`g/<gen>/<leaf>`). The leaf is per GENERATION, not per platform (rustright-state lib.rs:52-62 and
|
|
420
|
-
* :422-461): a generation keeps the leaf it was created with, and only new generations default to `t` on Windows and `target` elsewhere, so
|
|
421
|
-
* either may appear on either platform. The gate takes the leaf from the signed outputDir; it never infers it and never picks a directory.
|
|
422
|
-
*/
|
|
423
|
-
export const GENERATION_LEAVES = Object.freeze(["target", "t"]);
|
|
424
|
-
const isGenerationLeaf = (segment) => GENERATION_LEAVES.includes(segment);
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* The generation target the broker pins an app's outputs to: `<root>/<12 hex>/g/<NNN>/<leaf>` (leaf `target` or `t`, GENERATION_LEAVES) under one of the managed `ws` roots
|
|
428
|
-
* (`<external data root>/rightkit-build-control/ws`; BROKER-CONTRACT "Source identity", output pinning). The 12-hex key is
|
|
429
|
-
* rustright-state's workspace_key, which the gate never computes (the snapshot's own key is `snapshots/<sha256(repo path)[:16]>`, a
|
|
430
|
-
* different thing); it reads the receipt's outputDir and checks only this shape. The generation number (3+ digits) is the broker's.
|
|
431
|
-
*/
|
|
432
|
-
export function isGenerationTarget(outputDir, outputRoots, platform = process.platform) {
|
|
433
|
-
const mod = platform === "win32" ? path.win32 : path;
|
|
434
|
-
for (const root of outputRoots) {
|
|
435
|
-
const rel = mod.relative(platform === "win32" ? mod.resolve(root).toLowerCase() : mod.resolve(root), platform === "win32" ? mod.resolve(outputDir).toLowerCase() : mod.resolve(outputDir));
|
|
436
|
-
const segments = rel.split(/[\\/]/);
|
|
437
|
-
if (segments.length === 4 && segments[0] !== ".." && !mod.isAbsolute(rel) && /^[0-9a-f]{12}$/.test(segments[0]) && segments[1] === "g" && /^[0-9]{3,}$/.test(segments[2]) && isGenerationLeaf(segments[3])) return true;
|
|
438
|
-
}
|
|
439
|
-
return false;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
443
|
-
|
|
444
|
-
/** Whether `dir` is a managed generation target or a directory inside one (a nested compile's own directory under the adapter job's target). */
|
|
445
|
-
export function isInsideGenerationTarget(dir, outputRoots, platform = process.platform) {
|
|
446
|
-
const mod = platform === "win32" ? path.win32 : path;
|
|
447
|
-
for (const root of outputRoots) {
|
|
448
|
-
const rel = mod.relative(platform === "win32" ? mod.resolve(root).toLowerCase() : mod.resolve(root), platform === "win32" ? mod.resolve(dir).toLowerCase() : mod.resolve(dir));
|
|
449
|
-
const segments = rel.split(/[\\/]/);
|
|
450
|
-
if (segments.length >= 4 && segments[0] !== ".." && !mod.isAbsolute(rel) && /^[0-9a-f]{12}$/.test(segments[0]) && segments[1] === "g" && /^[0-9]{3,}$/.test(segments[2]) && isGenerationLeaf(segments[3])) return true;
|
|
451
|
-
}
|
|
452
|
-
return false;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* The filesystem-free identity of a signed `snapshotEvidence` (rightkit#1301 B9), shared by the gate's own verification of a receipt
|
|
458
|
-
* (verifySnapshotReceipt) and the hosted admission (qualification-verify.mjs): the commit is `commit` ({ sha, tree }), the ownership
|
|
459
|
-
* handle is `handle` when one is known, the request id is the job's, the snapshot path is `snapshotPath` when one is known (compared with
|
|
460
|
-
* `samePath`, which the gate gives a real-path comparison), and the snapshot held `tree` at START and at exit. Throws a
|
|
461
|
-
* SnapshotRequestError (`evidence`); returns the evidence's `snapshot`.
|
|
462
|
-
*/
|
|
463
|
-
export function verifySnapshotEvidenceIdentity(evidence, { commit, tree = commit?.tree, jobId, handle, snapshotPath, samePath = (a, b) => a === b }) {
|
|
464
|
-
if (!evidence || typeof evidence !== "object") fail("evidence", "the signed payload carries no snapshotEvidence: the broker did not build this as a snapshot request");
|
|
465
|
-
if (!same(evidence.commit, commit)) fail("evidence", "the signed commit is not the one this request carried");
|
|
466
|
-
if (handle !== undefined && evidence.ownership?.handle !== handle) fail("evidence", "the signed ownership handle is not this gate's");
|
|
467
|
-
if (typeof evidence.requestId !== "string" || evidence.requestId !== jobId) fail("evidence", "the signed request id is not this job");
|
|
468
|
-
const snap = evidence.snapshot ?? {};
|
|
469
|
-
if (snapshotPath !== undefined && !samePath(snap.path, snapshotPath)) fail("evidence", `the signed snapshot ${snap.path} is not ${snapshotPath}`);
|
|
470
|
-
if (snap.treeAtStart !== tree || snap.treeAtExit !== tree) {
|
|
471
|
-
fail("evidence", `the snapshot was tree ${snap.treeAtStart} at START and ${snap.treeAtExit} at exit, not ${tree} throughout: the build changed a tracked file (or added or removed one) in the commit's snapshot, so the result is discarded; that is the app owner's defect to fix (write generated output to an ignored path or an output directory, or generate before commit)`);
|
|
472
|
-
}
|
|
473
|
-
return snap;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
export const NESTED_CHILD_FIELDS = Object.freeze(["requestId", "parentRequestId", "shim", "argv", "cwd", "exitCode", "status", "outputDir"]);
|
|
477
|
-
/**
|
|
478
|
-
* Fields a nested child may also carry (rightkit#1418): `declaredInputDigests`, the digests of the snapshot's declared inputs the BROKER signs from
|
|
479
|
-
* the child's own admission and binds at its exit, as it does for a top-level compile. Optional until the broker signs them (rustright, nested compile
|
|
480
|
-
* children); when present it is well formed here and compared strictly by the gate (declaredInputDigestProblems, verifyBrokerLedger).
|
|
481
|
-
*/
|
|
482
|
-
export const NESTED_CHILD_OPTIONAL_FIELDS = Object.freeze(["declaredInputDigests"]);
|
|
483
|
-
const DIGEST_ENTRY_KEYS = (d) => { const k = Object.keys(d).sort().join(); return (k === "path,sha256" && typeof d.sha256 === "string" && /^[0-9a-f]{64}$/.test(d.sha256)) || (k === "absent,path" && d.absent === true); };
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* The problems of a nested child's signed `declaredInputDigests` against the gate's own truth, `[]` when they hold: `gateInputs` are the snapshot's
|
|
487
|
-
* declared input paths in declaration order, `policy` is `{ produced: Set, current: one digest per declared input }` as verifySnapshotReceipt takes it.
|
|
488
|
-
* Each entry must be the gate's digest of that input at the end of the stage unless the stage itself produced the input: an input swapped for the
|
|
489
|
-
* child and restored before the stage ended is seen as the child's differing digest (a child that read B while the stage ends with A).
|
|
490
|
-
*/
|
|
491
|
-
export function declaredInputDigestProblems(signed, { gateInputs, policy }) {
|
|
492
|
-
if (!Array.isArray(signed) || signed.length !== gateInputs.length || !signed.every((d, i) => isObject(d) && d.path === gateInputs[i] && DIGEST_ENTRY_KEYS(d))) return ["its signed declaredInputDigests are not the snapshot's declared inputs in declaration order, each exactly { path, sha256 } or { path, absent: true }"];
|
|
493
|
-
const { produced, current } = policy ?? {};
|
|
494
|
-
if (!(produced instanceof Set) || !Array.isArray(current) || current.length !== gateInputs.length) return ["the gate has no end-of-stage digest of the declared inputs to compare it with"];
|
|
495
|
-
const problems = [];
|
|
496
|
-
signed.forEach((d, i) => { if (!produced.has(gateInputs[i]) && !same(d, current[i])) problems.push(`its signed declaredInputDigests entry for ${gateInputs[i]} is not the gate's own digest of that input at the end of the stage, and the stage did not change it`); });
|
|
497
|
-
return problems;
|
|
498
|
-
}
|
|
499
|
-
/** The most children a root job's list may carry (rustright#190: the broker's cap; a refused child is never listed). */
|
|
500
|
-
export const NESTED_CHILDREN_CAP = 8192;
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* The nested children of a snapshot-bound adapter job (rustright#190, final): the list the broker signs at `payload.snapshotEvidence.nestedChildren`
|
|
504
|
-
* and mirrors at the receipt's `nestedChildren`; BOTH are required and must be equal. Entries are in admission order, each exactly
|
|
505
|
-
* `{ requestId, parentRequestId, shim, argv, cwd, exitCode, status, outputDir }`: `argv` is redacted (cargo only), `exitCode` is an integer or
|
|
506
|
-
* null, `status` is "UNFINISHED" for a child that had not ended when the root's receipt was built, `outputDir` is null for a child that does not
|
|
507
|
-
* compile (`rustc -vV`, `metadata`). A refused child is not listed. Returns the normalised list or throws a SnapshotRequestError (`nested`).
|
|
508
|
-
* Refused: a missing or differing list, more than the cap, a child whose `parentRequestId` is neither the root job nor an earlier listed child, a repeated request id, an
|
|
509
|
-
* UNFINISHED child, a null or non-zero exit code, a cwd outside the snapshot, and a non-null `outputDir` that is not absolute, is inside the
|
|
510
|
-
* snapshot or the checkout, or is not a managed generation target or inside one.
|
|
511
|
-
*/
|
|
512
|
-
export function verifyNestedChildren(evidence, receipt, { snapshotPath, checkout, outputRoots, platform = process.platform, canonicalPath = (p) => fs.realpathSync.native(p), jobId }) {
|
|
513
|
-
const list = evidence?.nestedChildren;
|
|
514
|
-
if (!Array.isArray(list)) fail("nested", "the signed snapshotEvidence carries no nestedChildren list: the broker did not sign what this adapter job's children ran");
|
|
515
|
-
if (!Array.isArray(receipt?.nestedChildren)) fail("nested", "the receipt carries no nestedChildren list (the mirror of the signed one)");
|
|
516
|
-
if (!same(receipt.nestedChildren, list)) fail("nested", "receipt nestedChildren differs from the signed list");
|
|
517
|
-
if (list.length > NESTED_CHILDREN_CAP) fail("nested", `the nestedChildren list holds ${list.length} entries, more than the cap ${NESTED_CHILDREN_CAP}`);
|
|
518
|
-
const canon = (p) => { try { return canonicalPath(p); } catch { return p; } };
|
|
519
|
-
const ids = new Set();
|
|
520
|
-
return list.map((child, index) => {
|
|
521
|
-
const where = `nestedChildren[${index}]`;
|
|
522
|
-
if (!isObject(child) || !NESTED_CHILD_FIELDS.every((k) => Object.hasOwn(child, k)) || !Object.keys(child).every((k) => NESTED_CHILD_FIELDS.includes(k) || NESTED_CHILD_OPTIONAL_FIELDS.includes(k))) fail("nested", `${where} is not exactly { ${NESTED_CHILD_FIELDS.join(", ")} } (plus optionally ${NESTED_CHILD_OPTIONAL_FIELDS.join(", ")})`);
|
|
523
|
-
if (child.declaredInputDigests !== undefined && (!Array.isArray(child.declaredInputDigests) || !child.declaredInputDigests.every((d) => isObject(d) && typeof d.path === "string" && DIGEST_ENTRY_KEYS(d)))) fail("nested", `${where} declaredInputDigests is not a list of { path, sha256 } or { path, absent: true }`);
|
|
524
|
-
if (typeof child.requestId !== "string" || !child.requestId || child.requestId === jobId || ids.has(child.requestId)) fail("nested", `${where} has no request id of its own`);
|
|
525
|
-
const name = `${where} (${child.requestId})`;
|
|
526
|
-
// The parent is the job the request named: this job, or a child listed before it (admission order; depth >= 2, rustright#190 ad9ecb37).
|
|
527
|
-
if (child.parentRequestId !== jobId && !ids.has(child.parentRequestId)) fail("nested", `${name} names parent ${JSON.stringify(child.parentRequestId)}, neither this job ${jobId} nor an earlier listed child`);
|
|
528
|
-
ids.add(child.requestId);
|
|
529
|
-
if (typeof child.shim !== "string" || !child.shim) fail("nested", `${name} names no shim`);
|
|
530
|
-
if (!Array.isArray(child.argv) || !child.argv.every((a) => typeof a === "string")) fail("nested", `${name} argv is not a list of strings`);
|
|
531
|
-
if (child.status === "UNFINISHED") fail("nested", `${name} (${child.argv.join(" ")}) had not finished when the job's receipt was built (UNFINISHED)`);
|
|
532
|
-
if (typeof child.status !== "string" || !child.status) fail("nested", `${name} has no status`);
|
|
533
|
-
if (!Number.isSafeInteger(child.exitCode) || child.exitCode !== 0) fail("nested", `${name} (${child.argv.join(" ")}) exited ${child.exitCode === null ? "with no exit code" : child.exitCode}, not 0: a child of this job failed or never finished`);
|
|
534
|
-
if (typeof child.cwd !== "string" || (!path.isAbsolute(child.cwd) && !path.win32.isAbsolute(child.cwd))) fail("nested", `${name} names no absolute working directory`);
|
|
535
|
-
if (!inside(child.cwd, snapshotPath, platform) && !inside(canon(child.cwd), canon(snapshotPath), platform)) fail("nested", `${name} ran in ${child.cwd}, outside the snapshot ${snapshotPath}`);
|
|
536
|
-
const out = child.outputDir;
|
|
537
|
-
if (out !== null) {
|
|
538
|
-
if (typeof out !== "string" || (!path.isAbsolute(out) && !path.win32.isAbsolute(out))) fail("nested", `${name} names an output directory that is neither null nor absolute`);
|
|
539
|
-
if (inside(out, snapshotPath, platform) || inside(out, canon(snapshotPath), platform)) fail("nested", `${name} output directory ${out} is inside the snapshot`);
|
|
540
|
-
if (inside(out, checkout, platform) || inside(out, canon(checkout), platform)) fail("nested", `${name} output directory ${out} is inside the checkout`);
|
|
541
|
-
if (!isInsideGenerationTarget(out, outputRoots, platform)) fail("nested", `${name} output directory ${out} is not inside a managed generation target under ${outputRoots.join(", ")}`);
|
|
542
|
-
}
|
|
543
|
-
return { requestId: child.requestId, parentRequestId: child.parentRequestId, shim: child.shim, argv: [...child.argv], cwd: child.cwd, exitCode: 0, status: child.status, outputDir: out, ...(child.declaredInputDigests !== undefined ? { declaredInputDigests: child.declaredInputDigests.map((d) => ({ ...d })) } : {}) };
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Verifies the receipt of one snapshot request (a cargo call, or with `adapter` an adapter job). `pins` come from this host's enrollment, never from the receipt.
|
|
549
|
-
* Returns `{ payload, evidence, attribution, toolchain, nestedChildren, requestDigest, causeEvidence }` (`causeEvidence` is null for a command that carries none); throws ProvenanceError (legacy, signature, pins, job, nonce, request, evidence, cause-unknown, cause-unexplained) or SnapshotRequestError (evidence).
|
|
550
|
-
*
|
|
551
|
-
* Beyond the signature, the job, the nonce and the request digest, the receipt must carry (item 7 row 7.22):
|
|
552
|
-
* - signed SUCCEEDED with exit 0, and signed snapshotEvidence equal to the receipt's copies (commit, ownership handle, request id,
|
|
553
|
-
* snapshot path, `treeAtStart` = `treeAtExit` = the expected tree);
|
|
554
|
-
* - `declaredInputDigests` well formed (the declaration's paths in order, each `{path, sha256}` or `{path, absent:true}`), and for a cargo request equal to the gate's own
|
|
555
|
-
* digest of the snapshot's declared inputs read now (absent included; an adapter request skips the comparison, it may produce an input); `inputPolicy` replaces that digest (see below);
|
|
556
|
-
* - `outputDir` absolute, outside the snapshot and the checkout, and a managed generation target under one of `outputRoots`;
|
|
557
|
-
* - signed stageEvidence (freshness, attribution, toolchain) equal to the receipt's;
|
|
558
|
-
* - for a compile, freshness.causeEvidence (rustright.cause-evidence.v1) coherent with its census and with a verdict of `explained`: refused as `evidence` when missing,
|
|
559
|
-
* of another schema or incoherent, `cause-unknown` when the broker could not say why units were rebuilt, `cause-unexplained` when a rebuilt unit has no explained cause (RA-03);
|
|
560
|
-
* - timingsMs, exit, diagnosticsPath, brokerVersion and executor present with their types; the retired `verdict` and `refreshed` are refused (GB-30: Class A and its verdict reuse are the gate's).
|
|
561
|
-
* `checkout` and `outputRoots` are required: without them nothing can be said about where the outputs went, so it refuses.
|
|
562
|
-
*/
|
|
563
|
-
export function verifySnapshotReceipt(receipt, { pins, jobId, carrier, argv, workspace, observedEnv = {}, adapter = null, adapterEnv = {}, checkout, outputRoots, platform = process.platform, canonicalPath = (p) => fs.realpathSync.native(p), digestInputs = declaredInputDigestsOf, readInputs = readDeclaredInputs, inputPolicy = null, allowFailedCompile = false }) {
|
|
564
|
-
const requestDigest = requestDigestOf(snapshotRequestCore({ argv, workspace, observedEnv, carrier, adapter, adapterEnv }));
|
|
565
|
-
const payload = verifyProvenance(receipt, pins, { jobId, nonce: carrier.nonce, requestDigest });
|
|
566
|
-
// The signed outcome, not the client's exit code: a passing row needs the broker to have signed SUCCEEDED with exit 0 and no
|
|
567
|
-
// signal (service.rs provenance_payload `result`). An authentic FAILED, or a payload without a result, is not a success.
|
|
568
|
-
const result = payload.result;
|
|
569
|
-
if (!result || typeof result !== "object") fail("result", "the signed payload carries no result: the broker did not sign this request's outcome");
|
|
570
|
-
const success = result.status === "SUCCEEDED" && result.exitCode === 0 && (result.signal === undefined || result.signal === null);
|
|
571
|
-
// Opt in only to an authenticated, non-signal Cargo compile failure. This is evidence of failure,
|
|
572
|
-
// not proof that its cause is a compiler diagnostic or that retry is appropriate.
|
|
573
|
-
const failedCompile = allowFailedCompile === true && adapter === null && isCompileClass(argv) && result.status === "FAILED" && result.failureClass === "compile" && Number.isSafeInteger(result.exitCode) && result.exitCode > 0 && result.exitCode <= 255 && (result.signal === undefined || result.signal === null);
|
|
574
|
-
if (!success && !failedCompile) {
|
|
575
|
-
// Any terminal status but SUCCEEDED fails the call, whatever the broker says about why (a tracked write is refused at exit with a
|
|
576
|
-
// `snapshot exit bind: ...` message; the field that carries it is pending RustRight's confirmation, so the usual spellings are read).
|
|
577
|
-
// The signed result of a broker verdict after a clean run (FAILED with exit 0: RR_UNEXPLAINED_COLD, ...) carries no reason; the receipt's own
|
|
578
|
-
// unsigned `error` names it. It is shown for diagnosis only and decides nothing: the verdict is the signed status.
|
|
579
|
-
// GB-66: a compile the broker refused to run because it could not name its toolchain fails with this code (and an UNKNOWN toolchain on its receipt).
|
|
580
|
-
if ([result.code, receipt?.code].includes(TOOLCHAIN_UNAVAILABLE_CODE)) fail(TOOLCHAIN_UNAVAILABLE, `the broker did not run this compile: it could not build the toolchain identity (${TOOLCHAIN_UNAVAILABLE_CODE}${isToolchainUnknown(receipt?.toolchain) ? `: ${receipt.toolchain.reason}` : ""}); register the toolchain's cargo and rustc and its name, then ask again`);
|
|
581
|
-
const why = [result.message, result.error, result.reason].find((v) => typeof v === "string" && v !== "");
|
|
582
|
-
const unsigned = why ? "" : [receipt?.error, receipt?.code].find((v) => typeof v === "string" && v !== "");
|
|
583
|
-
fail("result", `the broker signed ${result.status ?? "no status"} (exit ${result.exitCode ?? "none"}${result.signal ? `, signal ${result.signal}` : ""}${why ? `; ${why}` : ""}${unsigned ? `; the receipt's unsigned error: ${unsigned}` : ""}), not SUCCEEDED with exit 0`);
|
|
584
|
-
}
|
|
585
|
-
const evidence = payload.snapshotEvidence;
|
|
586
|
-
if (!evidence || typeof evidence !== "object") fail("evidence", "the signed payload carries no snapshotEvidence: the broker did not build this as a snapshot request");
|
|
587
|
-
for (const name of SNAPSHOT_EVIDENCE_FIELDS) {
|
|
588
|
-
if (evidence[name] === undefined || !same(receipt[name], evidence[name])) fail("evidence", `receipt ${name} differs from the signed snapshot evidence`);
|
|
589
|
-
}
|
|
590
|
-
verifySnapshotEvidenceIdentity(evidence, {
|
|
591
|
-
commit: carrier.commit, tree: carrier.snapshot.expectedTree, jobId, handle: carrier.ownership.handle, snapshotPath: carrier.snapshot.path,
|
|
592
|
-
samePath: (a, b) => { try { return canonicalPath(a) === canonicalPath(b); } catch { return false; } },
|
|
593
|
-
});
|
|
594
|
-
// Declared inputs. The broker admits every snapshot request with a declared input absent and records it as `{ path, absent: true }` in the signed
|
|
595
|
-
// snapshotEvidence.declaredInputDigests (declaration order); a compile is refused at exit if any declared input changed while it ran, an absent one
|
|
596
|
-
// appearing included (rustright d378d32). So an absent entry is evidence on any request, and the receipt is judged per class:
|
|
597
|
-
// - a cargo request (adapter === null): the receipt's digests equal the gate's current digest of the snapshot's inputs (the child copies the next
|
|
598
|
-
// file only after the call returns, and the broker refused a compile whose inputs changed during it);
|
|
599
|
-
// - an adapter request: the digest comparison is skipped (the job may be the producer of an input), but the receipt's entries must be well formed,
|
|
600
|
-
// the declaration's paths in declaration order, each exactly `{ path, sha256 }` or exactly `{ path, absent: true }`;
|
|
601
|
-
// - with `inputPolicy` ({ produced: Set<path>, current: digest array }) the gate's own digest is replaced: an input whose path is in `produced` accepts any
|
|
602
|
-
// well-formed entry (absent or any sha256); every other input must equal `current`'s entry for that path (the swap-around-admission refusal).
|
|
603
|
-
let gateInputs; let gateDigests = null;
|
|
604
|
-
try {
|
|
605
|
-
gateInputs = readInputs(carrier.snapshot.path);
|
|
606
|
-
if (!inputPolicy && adapter === null) gateDigests = digestInputs(carrier.snapshot.path, gateInputs, { platform, allowAbsent: true });
|
|
607
|
-
} catch (e) { fail("evidence", `the gate cannot digest the snapshot's declared inputs (${e.message})`); }
|
|
608
|
-
if (!same(gateInputs, carrier.declaredInputs?.inputs)) fail("evidence", "the snapshot's declared inputs are not the ones this request carried (declaredInputs differs from the snapshot declaration)");
|
|
609
|
-
const signedInputs = evidence.declaredInputDigests;
|
|
610
|
-
const wellFormed = Array.isArray(signedInputs) && signedInputs.length === gateInputs.length && signedInputs.every((d, i) => {
|
|
611
|
-
if (!isObject(d) || d.path !== gateInputs[i]) return false;
|
|
612
|
-
const keys = Object.keys(d).sort().join();
|
|
613
|
-
return (keys === "path,sha256" && typeof d.sha256 === "string" && /^[0-9a-f]{64}$/.test(d.sha256)) || (keys === "absent,path" && d.absent === true);
|
|
614
|
-
});
|
|
615
|
-
if (!wellFormed) fail("evidence", "the signed declaredInputDigests are not the snapshot's declared inputs in declaration order, each exactly { path, sha256 } or { path, absent: true }");
|
|
616
|
-
if (inputPolicy) {
|
|
617
|
-
const { produced, current } = inputPolicy;
|
|
618
|
-
if (!(produced instanceof Set) || !Array.isArray(current) || current.length !== gateInputs.length) fail("evidence", "the gate's input policy is not { produced: Set, current: one digest per declared input }");
|
|
619
|
-
signedInputs.forEach((d, i) => {
|
|
620
|
-
if (produced.has(gateInputs[i])) return;
|
|
621
|
-
if (!same(d, current[i])) fail("evidence", `the signed declaredInputDigests entry for ${gateInputs[i]} is not the gate's own digest of that input at the end of the stage, and the stage did not change it (an input the receipt records absent must be absent, and the reverse)`);
|
|
622
|
-
});
|
|
623
|
-
} else if (adapter === null && !same(signedInputs, gateDigests)) fail("evidence", "the signed declaredInputDigests are not the gate's own digest of the snapshot's declared inputs (an input the receipt records absent must be absent in the snapshot, and the reverse)");
|
|
624
|
-
// Output directory: where the outputs went must be the broker's managed generation target, never under the snapshot or the checkout.
|
|
625
|
-
const out = evidence.outputDir;
|
|
626
|
-
if (typeof out !== "string" || !path.isAbsolute(out) && !path.win32.isAbsolute(out)) fail("evidence", "the signed evidence names no absolute output directory");
|
|
627
|
-
if (!checkout || !path.isAbsolute(checkout) || !Array.isArray(outputRoots) || outputRoots.length === 0) fail("evidence", "the gate has no checkout or managed output root to judge the output directory against");
|
|
628
|
-
const canon = (p) => { try { return canonicalPath(p); } catch { return p; } };
|
|
629
|
-
if (inside(out, carrier.snapshot.path, platform) || inside(out, canon(carrier.snapshot.path), platform)) fail("evidence", `the output directory ${out} is inside the snapshot`);
|
|
630
|
-
if (inside(out, checkout, platform) || inside(out, canon(checkout), platform)) fail("evidence", `the output directory ${out} is inside the checkout`);
|
|
631
|
-
if (!isGenerationTarget(out, outputRoots, platform)) fail("evidence", `the output directory ${out} is not a managed generation target (<ws root>/<repo-key>/g/<generation>/{target|t}) under ${outputRoots.join(", ")}`);
|
|
632
|
-
// Stage evidence is signed with the rest and must equal the receipt's copy. `freshness`, `attribution` and `toolchain` are
|
|
633
|
-
// required only for a compile-class command (check, clippy, build, doc, rustc, test): the broker emits them for compiles only, so a
|
|
634
|
-
// read-only metadata, fetch --locked, fmt --check or tree --locked passes without them (rightkit#1311: a carried metadata job has
|
|
635
|
-
// no freshness census; the Mac witness, request ed37214e). When either side carries one
|
|
636
|
-
// anyway, both must carry the same value.
|
|
637
|
-
const stage = payload.stageEvidence;
|
|
638
|
-
if (!isObject(stage)) fail("evidence", "the signed payload carries no stageEvidence");
|
|
639
|
-
// An adapter job is not a cargo command: whether it signs attribution and toolchain is the adapter's; when either side carries one,
|
|
640
|
-
// both must carry the same value (below).
|
|
641
|
-
const compile = adapter === null && isCompileClass(argv);
|
|
642
|
-
for (const name of STAGE_EVIDENCE_FIELDS) {
|
|
643
|
-
const signed = stage[name] ?? null; const copy = receipt[name] ?? null;
|
|
644
|
-
const required = compile;
|
|
645
|
-
if (required && (signed === null || copy === null)) fail("evidence", `${name} is missing from the signed stage evidence or the receipt (a compile-class command, cargo ${cargoSubcommandOf(argv)}, carries it)`);
|
|
646
|
-
if (!same(copy, signed)) fail("evidence", `receipt ${name} differs from the signed stage evidence`);
|
|
647
|
-
}
|
|
648
|
-
// Shapes RustRight emits (item 4 row 4.18): attribution is `{available, ...}`, and an unavailable one names its reason
|
|
649
|
-
// (`cargo-json-message-format-not-requested` without a JSON message stream; a consumer that needs per-package attribution treats
|
|
650
|
-
// `available:false` as FAILED, not partial); toolchain is `<toolchain>|cargo:<sha256>|rustc:<sha256>`.
|
|
651
|
-
// GB-02 (BROKER-CONTRACT section 14): a compile's freshness is an object with a boolean `available`, and `available: false` always names a reason: absence is never an
|
|
652
|
-
// unavailable census, and an unavailable one on a SUCCEEDED compile is the broker's own failure (RR_FRESHNESS_UNAVAILABLE), never evidence.
|
|
653
|
-
if (compile) {
|
|
654
|
-
const freshness = receipt.freshness;
|
|
655
|
-
if (!isObject(freshness) || typeof freshness.available !== "boolean") fail("evidence", "receipt freshness is not {available, ...}");
|
|
656
|
-
if (freshness.available === false && !(typeof freshness.reason === "string" && freshness.reason !== "")) fail("evidence", "receipt freshness is unavailable and names no reason");
|
|
657
|
-
}
|
|
658
|
-
const attribution = receipt.attribution ?? null; const toolchain = receipt.toolchain ?? null;
|
|
659
|
-
if (attribution !== null) {
|
|
660
|
-
if (!isObject(attribution) || typeof attribution.available !== "boolean") fail("evidence", "receipt attribution is not {available, ...}");
|
|
661
|
-
if (attribution.available === false && !(typeof attribution.reason === "string" && attribution.reason !== "")) fail("evidence", "receipt attribution is unavailable and names no reason");
|
|
662
|
-
}
|
|
663
|
-
// GB-66: the broker signs `<name>|cargo:<sha256>|rustc:<sha256>` only when it could build that identity; when it could not (no configured name, an unregistered or
|
|
664
|
-
// changed cargo or rustc) the receipt's toolchain is exactly {"state":"UNKNOWN","reason":...}. That is a typed unavailable identity, never evidence and never a
|
|
665
|
-
// string with an empty component.
|
|
666
|
-
if (isToolchainUnknown(toolchain)) fail(TOOLCHAIN_UNAVAILABLE, `the broker could not name this compile's toolchain (${TOOLCHAIN_UNAVAILABLE_CODE}: UNKNOWN, ${toolchain.reason}); an unknown toolchain identity is not evidence, so the call is unverified and nothing is concluded from it`);
|
|
667
|
-
if (toolchain !== null && !(typeof toolchain === "string" && TOOLCHAIN_FORMAT.test(toolchain))) fail("evidence", "receipt toolchain is not <toolchain>|cargo:<sha256>|rustc:<sha256>");
|
|
668
|
-
// RA-03: a census that counts rebuilt units says nothing about why they were rebuilt. A compile's signed freshness must carry `causeEvidence`
|
|
669
|
-
// (rustright.cause-evidence.v1: provenance-verify.mjs requireExplainedCauses, the one implementation) whose verdict is `explained`: a missing or unrecognized
|
|
670
|
-
// schema or an incoherent one is `evidence`, an `unknown` verdict (a quiet, caller-logged or artifact-running root whose log was not read, dropped output, an
|
|
671
|
-
// uncovered unit) is `cause-unknown`, and a unit rebuilt with no explained cause is `cause-unexplained`; none is a success, and none is relaxed for an older
|
|
672
|
-
// broker that signs no cause evidence. The judged object is the SIGNED copy (the receipt's equals it, checked above). A command that is not a compile
|
|
673
|
-
// legitimately carries no census; when one carries cause evidence anyway it must still be well formed, but nothing is judged for it (nothing was rebuilt).
|
|
674
|
-
const signedFreshness = stage.freshness ?? null;
|
|
675
|
-
let causeEvidence = null;
|
|
676
|
-
// Adrian, 2026-11-02 (the broker owner's chat, checked with pulse `said`): "Refusal, remove but I want a daily job checking the warmth etc and
|
|
677
|
-
// reporting issues." An unexplained or unknown rebuild no longer fails a stage: the cause evidence is still read, checked well formed and
|
|
678
|
-
// recorded (the daily warmth check reports it), never judged here. The broker stopped refusing it too (rustright b00220f).
|
|
679
|
-
// A compile must still carry well-formed signed cause evidence (verifyCauseEvidence refuses a missing or incoherent one); its verdict is not judged.
|
|
680
|
-
if (compile || (isObject(signedFreshness) && signedFreshness.causeEvidence !== undefined)) causeEvidence = verifyCauseEvidence(signedFreshness);
|
|
681
|
-
// Fields the signature does not cover must still be present with their types (the consumer reads them). Every carried command:
|
|
682
|
-
// exit (an integer, or null with a signal) and signal, timingsMs{admission, queue, bind, cargo, afterExitBind, diagnostics} (each a
|
|
683
|
-
// number or null) and diagnosticsPath (a path, or null). Success needs exit 0 and no signal, as signed. `verdict` and `refreshed`
|
|
684
|
-
// are retired: the gate owns Class A, and RustRight refuses a receipt that carries either (rustright bc24d55, attestation.rs
|
|
685
|
-
// RETIRED_RESULT_FIELDS), so the gate refuses them too.
|
|
686
|
-
const timingsOk = isObject(receipt.timingsMs) && TIMING_KEYS.every((k) => Object.hasOwn(receipt.timingsMs, k) && (receipt.timingsMs[k] === null || Number.isFinite(receipt.timingsMs[k])));
|
|
687
|
-
const typed = [
|
|
688
|
-
["timingsMs", timingsOk], ["exit", receipt.exit === null || Number.isSafeInteger(receipt.exit)],
|
|
689
|
-
["signal", receipt.signal === null || typeof receipt.signal === "string" || Number.isSafeInteger(receipt.signal)],
|
|
690
|
-
["diagnosticsPath", receipt.diagnosticsPath === null || (typeof receipt.diagnosticsPath === "string" && receipt.diagnosticsPath !== "")], ["brokerVersion", typeof receipt.brokerVersion === "string" && receipt.brokerVersion !== ""],
|
|
691
|
-
["executor", typeof receipt.executor === "string" && receipt.executor !== ""],
|
|
692
|
-
];
|
|
693
|
-
for (const [name, ok] of typed) if (!ok) fail("evidence", `receipt ${name} is missing or has the wrong type`);
|
|
694
|
-
for (const name of ["verdict", "refreshed"]) if (Object.hasOwn(receipt, name)) fail("evidence", `receipt carries the retired field ${name}`);
|
|
695
|
-
if (receipt.exit !== result.exitCode || receipt.signal !== null) fail("evidence", `receipt exit ${receipt.exit} and signal ${receipt.signal} do not match the signed result (exit ${result.exitCode}, no signal)`);
|
|
696
|
-
// RustRight signs the result fields under payload.resultEvidence (service.rs provenance_payload; attestation.rs RESULT_EVIDENCE_FIELDS), never at
|
|
697
|
-
// the payload's top level. Every receipt copy must equal its signed counterpart, and a receipt with no signed resultEvidence is refused: the
|
|
698
|
-
// exit, signal, timings and diagnostics path it shows would otherwise be this receipt's own say-so.
|
|
699
|
-
const signedResult = payload.resultEvidence;
|
|
700
|
-
if (!isObject(signedResult)) fail("evidence", "the signed payload carries no resultEvidence: the receipt's exit, signal, timingsMs and diagnosticsPath are not covered by the signature");
|
|
701
|
-
for (const name of RESULT_EVIDENCE_FIELDS) {
|
|
702
|
-
if (!Object.hasOwn(signedResult, name) || !same(receipt[name], signedResult[name])) fail("evidence", `receipt ${name} differs from the signed result evidence`);
|
|
703
|
-
}
|
|
704
|
-
for (const name of ["verdict", "refreshed"]) if (Object.hasOwn(signedResult, name)) fail("evidence", `the signed result evidence carries the retired field ${name}`);
|
|
705
|
-
// Symmetric both ways: a field the broker signed that the protocol does not name is as unexplained as one the receipt lacks (an added field).
|
|
706
|
-
for (const name of Object.keys(signedResult)) if (!RESULT_EVIDENCE_FIELDS.includes(name)) fail("evidence", `the signed result evidence carries the unknown field ${name}`);
|
|
707
|
-
for (const name of Object.keys(isObject(receipt.timingsMs) ? receipt.timingsMs : {})) if (!TIMING_KEYS.includes(name)) fail("evidence", `receipt timingsMs carries the unknown key ${name}`);
|
|
708
|
-
// A snapshot-bound adapter job signs the compiles its own children made (rustright#190 D8).
|
|
709
|
-
const nestedChildren = adapter === null ? null : verifyNestedChildren(evidence, receipt, { snapshotPath: carrier.snapshot.path, checkout, outputRoots, platform, canonicalPath, jobId });
|
|
710
|
-
// GB-10 / GB-11: whatever the checks above did not already name, the production strict verifier (`verify_receipt_strict`, provenance-verify.mjs, judged
|
|
711
|
-
// against RustRight's receipt vector case for case) must also accept: no signed-only or receipt-only field anywhere, the signed result evidence with exactly
|
|
712
|
-
// its four fields and six phases, and the BR19 shape (profile, stage, resources, environment; a value or a typed UNKNOWN, never absent).
|
|
713
|
-
verifyReceiptCoverage(receipt, payload);
|
|
714
|
-
verifyFailureClass(receipt, payload);
|
|
715
|
-
const postChecks = verifyPostChecks(receipt, payload, { snapshotAttested: true });
|
|
716
|
-
if (success && Object.hasOwn(result, "failureClass") && result.failureClass !== null) fail("result", "a successful result has a non-null failureClass");
|
|
717
|
-
verifyResultEvidence(receipt, payload);
|
|
718
|
-
verifyBr19Evidence(receipt, payload);
|
|
719
|
-
return { payload, evidence, attribution, toolchain, nestedChildren, requestDigest, causeEvidence, signedResult: { status: result.status, exitCode: result.exitCode, signal: result.signal ?? null, ...(Object.hasOwn(result, "failureClass") ? { failureClass: result.failureClass } : {}), postChecks } };
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
export { CAUSE_EVIDENCE_SCHEMA, CAUSE_UNEXPLAINED, CAUSE_UNKNOWN, ProvenanceError };
|