@rightkit/release 0.6.52 → 0.6.54

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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/adapter-env.mjs +16 -105
  3. package/admission-host.mjs +14 -1
  4. package/bin/darwin/rightkit-swap +0 -0
  5. package/bin/rightkit-gate.mjs +585 -404
  6. package/broker-admission.mjs +122 -2
  7. package/build-launch.mjs +52 -58
  8. package/build-release.mjs +2 -2
  9. package/cargo-ledger.mjs +24 -5
  10. package/cargo-target-shim.mjs +54 -23
  11. package/cargo-target.mjs +2 -2
  12. package/carried-adapter-run.mjs +7 -8
  13. package/carried-cargo-run.mjs +1 -1
  14. package/ci-compile-admission.mjs +1 -1
  15. package/clippy-route.mjs +65 -18
  16. package/compile-inputs.mjs +91 -15
  17. package/cross-targets.mjs +5 -3
  18. package/deps-cargo-lock.mjs +1 -1
  19. package/deterministic-scans.mjs +789 -259
  20. package/development.mjs +33 -7
  21. package/direct-receipt.mjs +3 -5
  22. package/feature-coverage.mjs +45 -9
  23. package/feature-partition.mjs +204 -0
  24. package/feature-sets.mjs +113 -0
  25. package/gate-acceptance.mjs +187 -115
  26. package/gate-seam.mjs +352 -0
  27. package/gate-serve.mjs +34 -2
  28. package/gate-stages.mjs +6 -2
  29. package/ghsa-audit.mjs +19 -4
  30. package/heavy-command.mjs +5 -4
  31. package/install-tauri-authenticode.mjs +73 -4
  32. package/ios-dev.mjs +3 -3
  33. package/ios-package-recipe.mjs +6 -6
  34. package/linux-setup.mjs +3 -2
  35. package/local-publish.mjs +113 -17
  36. package/lock-identity.mjs +24 -100
  37. package/managed-cargo.mjs +3 -3
  38. package/managed-root-guard.mjs +2 -2
  39. package/managed-roots.mjs +3 -3
  40. package/native-adapters.mjs +41 -244
  41. package/native-helpers.mjs +1 -1
  42. package/pack-digest.mjs +1 -1
  43. package/package-recipe-targets.mjs +3 -3
  44. package/package.json +2 -2
  45. package/publication-gate.mjs +29 -6
  46. package/publish-cargo.mjs +4 -5
  47. package/publish-local-cargo.mjs +77 -1
  48. package/qualification-verify.mjs +76 -49
  49. package/receipt-signature.mjs +104 -0
  50. package/release-switch-registry.json +4 -0
  51. package/release-switch-scan.mjs +13 -10
  52. package/rightkit-versions.json +126 -113
  53. package/scan-digest.mjs +43 -14
  54. package/seam-broker.mjs +168 -0
  55. package/snapshot-check.mjs +4 -1
  56. package/snapshot-dependency-reuse.mjs +1 -1
  57. package/snapshot-metadata.mjs +24 -35
  58. package/snapshot.mjs +328 -49
  59. package/stage-commands.mjs +59 -5
  60. package/stage-ledger.mjs +2 -2
  61. package/{carried-cargo.mjs → stage-seam.mjs} +118 -70
  62. package/stage-sidecar.mjs +3 -3
  63. package/tauri-bundle-marker.mjs +5 -2
  64. package/tauri-locked.mjs +1 -1
  65. package/tool-build.mjs +8 -6
  66. package/unit-gate.mjs +40 -10
  67. package/broker-handshake.mjs +0 -160
  68. package/broker-wire.mjs +0 -278
  69. package/build-ownership.mjs +0 -1578
  70. package/cargo-shapes.mjs +0 -332
  71. package/cargo-width.mjs +0 -49
  72. package/carrier-census.mjs +0 -124
  73. package/clippy-equivalence.mjs +0 -202
  74. package/freshness-census.mjs +0 -405
  75. package/handle-revocation.mjs +0 -100
  76. package/handle-revocation.rust-vector.json +0 -1
  77. package/handle-revocation.vectors.json +0 -53
  78. package/legion-freeze-consumer.mjs +0 -241
  79. package/linux-qualifier.mjs +0 -83
  80. package/native-tool-planning.mjs +0 -94
  81. package/owner-process-proof.mjs +0 -14
  82. package/ownership-mark.mjs +0 -191
  83. package/ownership-recover.mjs +0 -78
  84. package/pnpm-adapter-grammar.mjs +0 -226
  85. package/provenance-verify.mjs +0 -413
  86. package/snapshot-broker.mjs +0 -808
  87. package/snapshot-request.mjs +0 -722
  88. package/unit-list-compile.mjs +0 -356
@@ -9,6 +9,9 @@
9
9
  // 2. a unit-gate report (`rightkit-gate --to compile --unit cargo:<name> --commit <sha> --receipt-out <file>`, schema
10
10
  // rightkit.unit-gate-report/1) from either broker host names this crate and version, this exact commit and its tree, with the
11
11
  // check and compile stages ok: the gate's Class A and its broker compile of that commit are the verification;
12
+ // or a unit-list receipt (`rightkit-gate --to compile --units-file <file> --receipt-dir <dir>`, schema
13
+ // rightkit.unit-list-compile/1, one per unit of one shared run) names this crate with status "passed", this exact commit, and
14
+ // binds every recorded command to this commit and tree with a passing broker seam receipt (rightkit#1560);
12
15
  // 3. the version is not on crates.io yet.
13
16
  // The commit's `crates/` folder is exported (git archive) to a temporary folder; `cargo package` and `cargo publish` run there with
14
17
  // `--no-verify --locked` and compile nothing, so they run with the broker's own cargo directly, as the gate's Class A cargo does
@@ -23,6 +26,47 @@ import { fileURLToPath } from "node:url";
23
26
  import { directCargoPath } from "./managed-cargo.mjs";
24
27
 
25
28
  export const UNIT_REPORT_SCHEMA = "rightkit.unit-gate-report/1";
29
+ /** The per-unit receipt a unit-list run writes (`rightkit-gate --to compile --units-file <file> --receipt-dir <dir>`): one shared run, one receipt per unit (rightkit#1560). */
30
+ export const UNIT_LIST_COMPILE_SCHEMA = "rightkit.unit-list-compile/1";
31
+
32
+ /**
33
+ * Why a unit-list receipt does not prove this crate at this commit; empty when it does. The gate writes status "passed" only when its
34
+ * shared run exited 0, its union was verified and every requirement of the unit passed (rightkit-gate.mjs, the unit-list report). This
35
+ * re-checks what the file itself carries: the unit, the exact commit, every recorded command bound to that commit and tree with a
36
+ * passing broker seam receipt as its last attempt, every requirement and every scan passed (a scan with evidence of its own must show a
37
+ * broker seam receipt; one answered from the gate's cache has none). The receipt names no version: the caller
38
+ * reads the version from the commit's own Cargo.toml, and the commit and tree are bound here.
39
+ */
40
+ export function unitListCompileProblems(report, { name, commit, tree }) {
41
+ const problems = [];
42
+ const unit = `cargo:${name}`;
43
+ const passed = (status) => status === "pass" || status === "passed";
44
+ const seamReceipt = (e) => e?.seam === true && typeof e.requestId === "string" && e.requestId !== "" && /^[0-9a-f]{64}$/.test(e.receiptSha256 ?? "");
45
+ if (report?.unit !== unit) problems.push(`unit is ${JSON.stringify(report?.unit)}, not ${unit}`);
46
+ if (report?.status !== "passed") problems.push(`unit status is ${JSON.stringify(report?.status)}, not "passed"`);
47
+ if (report?.commit !== commit) problems.push(`commit ${report?.commit} != ${commit}`);
48
+ const commands = Array.isArray(report?.commands) ? report.commands : [];
49
+ if (!commands.length) problems.push("no broker command is recorded for the unit");
50
+ for (const c of commands) {
51
+ if (c?.selector !== unit) problems.push(`command ${c?.id} belongs to ${JSON.stringify(c?.selector)}`);
52
+ if (c?.commit !== commit) problems.push(`command ${c?.id} ran on commit ${c?.commit}`);
53
+ if (c?.tree !== tree) problems.push(`command ${c?.id} ran on tree ${c?.tree}, not ${tree}`);
54
+ const last = Array.isArray(c?.attempts) ? c.attempts.at(-1) : undefined;
55
+ if (!last || !passed(last.status) || !seamReceipt(last.snapshotEvidence)) problems.push(`command ${c?.id} has no passing broker seam receipt as its last attempt`);
56
+ }
57
+ const requirements = Array.isArray(report?.requirements) ? report.requirements : [];
58
+ if (!requirements.length) problems.push("no requirement is recorded for the unit");
59
+ for (const r of requirements) if (r?.selector !== unit || !passed(r?.status)) problems.push(`requirement ${r?.id} (${JSON.stringify(r?.selector)}) is ${JSON.stringify(r?.status)}`);
60
+ const scans = Array.isArray(report?.scans) ? report.scans : [];
61
+ if (!scans.length) problems.push("no scan is recorded for the unit");
62
+ // A scan the run answered from the gate's cache carries no evidence of its own (the pass was stored by the run that executed it); a scan
63
+ // that carries evidence must carry a broker seam receipt. The unit's own commands above are never answered without one.
64
+ for (const sc of scans) {
65
+ if (!passed(sc?.status)) problems.push(`scan ${sc?.id} is ${JSON.stringify(sc?.status)}`);
66
+ else if (sc.snapshotEvidence !== undefined && !seamReceipt(sc.snapshotEvidence)) problems.push(`scan ${sc?.id} carries evidence that is not a broker seam receipt`);
67
+ }
68
+ return problems;
69
+ }
26
70
 
27
71
  /** The Keychain item cargo's macOS provider stores the crates.io token under. */
28
72
  export const CARGO_KEYCHAIN_SERVICE = "cargo-registry:https://github.com/rust-lang/crates.io-index";
@@ -46,8 +90,40 @@ export function parseArgs(argv) {
46
90
  return out;
47
91
  }
48
92
 
93
+ /** The per-unit result of a together compile (gate/compile.mjs unitResult): each crate carries its own result and the broker job that proves each call. */
94
+ export const UNIT_RESULT_SCHEMA = "rightkit.unit-result/1";
95
+
96
+ /**
97
+ * Why a unit result does not prove this crate at this commit; empty when it does. It must name the unit, the exact commit and tree, say
98
+ * "passed", show lint, test build and tests passed (docs too when the crate has a library call), and every call that named the crate must have
99
+ * passed with a broker job as evidence (a request id and the sha256 of its signed receipt). A call skipped because it had already passed for this
100
+ * commit carries the job that proved it then.
101
+ */
102
+ export function unitResultProblems(report, { name, commit, tree }) {
103
+ const problems = [];
104
+ const unit = `cargo:${name}`;
105
+ const job = (e) => typeof e?.requestId === "string" && e.requestId !== "" && /^[0-9a-f]{64}$/.test(e.receiptSha256 ?? "");
106
+ if (report?.unit !== unit) problems.push(`unit is ${JSON.stringify(report?.unit)}, not ${unit}`);
107
+ if (report?.result !== "passed") problems.push(`unit result is ${JSON.stringify(report?.result)}, not "passed"`);
108
+ if (report?.commit !== commit) problems.push(`commit ${report?.commit} != ${commit}`);
109
+ if (report?.tree !== tree) problems.push(`tree ${report?.tree} != ${tree}`);
110
+ if (report?.stage !== "compile") problems.push(`stage is ${JSON.stringify(report?.stage)}, not "compile"`);
111
+ for (const stage of ["lint", "test-build", "tests"]) if (report?.stages?.[stage]?.result !== "passed") problems.push(`stage ${stage} is ${JSON.stringify(report?.stages?.[stage]?.result)}, not "passed"`);
112
+ if (report?.stages?.docs !== undefined && report.stages.docs.result !== "passed") problems.push(`stage docs is ${JSON.stringify(report.stages.docs.result)}, not "passed"`);
113
+ const calls = Array.isArray(report?.calls) ? report.calls : [];
114
+ if (!calls.length) problems.push("no call is recorded for the unit");
115
+ for (const c of calls) {
116
+ if (c?.result !== "passed") problems.push(`call ${c?.id} is ${JSON.stringify(c?.result)}`);
117
+ else if (!job(c.evidence)) problems.push(`call ${c?.id} carries no broker job as evidence`);
118
+ }
119
+ for (const stage of ["lint", "test-build"]) if (!calls.some((c) => c?.stage === stage)) problems.push(`no ${stage} call is recorded for the unit`);
120
+ return problems;
121
+ }
122
+
49
123
  /** The reasons a unit-gate report does not prove this crate, version and commit compiled; empty when it does. */
50
124
  export function compileReportProblems(report, { name, version, commit, tree }) {
125
+ if (report?.schema === UNIT_RESULT_SCHEMA) return unitResultProblems(report, { name, commit, tree });
126
+ if (report?.schema === UNIT_LIST_COMPILE_SCHEMA) return unitListCompileProblems(report, { name, commit, tree });
51
127
  const problems = [];
52
128
  if (report?.schema !== UNIT_REPORT_SCHEMA) problems.push(`schema is ${JSON.stringify(report?.schema)}, not ${UNIT_REPORT_SCHEMA}`);
53
129
  if (report?.unit?.kind !== "cargo" || report?.unit?.name !== name) problems.push(`unit is ${JSON.stringify(report?.unit)}, not cargo:${name}`);
@@ -101,7 +177,7 @@ export async function publishLocalCargo(argv, { run = spawnSync, log = console.l
101
177
  try { report = JSON.parse(fs.readFileSync(o.report, "utf8")); } catch (e) { fail(`cannot read the compile report ${o.report}: ${e.message}`); }
102
178
  const problems = compileReportProblems(report, { name, version, commit, tree });
103
179
  if (problems.length) fail(`the compile report does not prove cargo:${name} ${version} at ${commit}: ${problems.join("; ")}`);
104
- log(`publish-local: compile report ok for cargo:${name} ${version} at ${commit.slice(0, 12)} (executor ${report.executor ?? "unknown"})`);
180
+ log(`publish-local: compile report ok for cargo:${name} ${version} at ${commit.slice(0, 12)} (executor ${report.executor ?? (report.schema === UNIT_LIST_COMPILE_SCHEMA ? `broker seam, unit-list run ${report.runId}` : report.schema === UNIT_RESULT_SCHEMA ? "broker seam, together compile" : "unknown")})`);
105
181
  // The broker's cargo, run directly: package and publish --no-verify compile nothing (GC-A11).
106
182
  const pathKey = platform === "win32" ? (Object.keys(env).find((k) => k.toUpperCase() === "PATH") ?? "Path") : "PATH";
107
183
  const direct = directCargoPath({ env: { ...env, PATH: env[pathKey] }, platform, gateWrappers: true });
@@ -2,15 +2,28 @@
2
2
  // (scripts/ci/publish-admission.mjs, inside publish.yml) and the gate's own self-check before it dispatches anything (unit-gate.mjs).
3
3
  // It lives in this package, not under scripts/, because unit-gate ships in the package and may import nothing outside it.
4
4
  // Pure over the dispatched commit: `git(...args)` reads that commit's objects; nothing here touches the filesystem or the broker.
5
- import { ProvenanceError, carriedCallNonce, qualificationNonce, verifyProvenance } from "./provenance-verify.mjs";
6
- import { SnapshotRequestError, ownershipOfHandle, verifySnapshotEvidenceIdentity } from "./snapshot-request.mjs";
5
+ import path from "node:path";
6
+ import { ProvenanceError, verifyProvenanceSignature } from "./receipt-signature.mjs";
7
7
  import { assignJobs, describeCommand, expectedStageCommands, rootOfWorkspace } from "./stage-commands.mjs";
8
8
 
9
9
  export const ATTESTED_STAGES = ["compile", "package"];
10
10
  export const MAX_VERIFIED_RECEIPTS = 64;
11
11
  const SHA256_HEX = /^[0-9a-f]{64}$/;
12
12
  const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
13
- const sameJson = (a, b) => JSON.stringify(a) === JSON.stringify(b);
13
+ const GIT_ID = /^[0-9a-f]{40}$/;
14
+ const isAbsolutePath = (p) => typeof p === "string" && p !== "" && (path.posix.isAbsolute(p.replaceAll("\\", "/")) || /^[A-Za-z]:[\\/]/.test(p));
15
+ const posixOf = (p) => String(p ?? "").replaceAll("\\", "/").replace(/\/+$/, "");
16
+ /**
17
+ * A path as the enrolled host's file system compares it, for the seam receipt's fields: the broker signs `request.workspace` as the client submitted it and `gate.snapshot`
18
+ * canonicalized (rustright normalize_impl.rs submitted_workspace; gate_admission.rs real_path), so on Windows one may carry the extended `\\?\` (or `\\?\UNC\`) prefix and
19
+ * another case than the other. win32: prefix dropped, separators unified, case folded (NTFS compares case-insensitively); darwin and others: the posix spelling, case kept.
20
+ */
21
+ export function hostPathKey(p, platform) {
22
+ let s = posixOf(p);
23
+ if (platform !== "win32") return s;
24
+ s = s.replace(/^\/\/\?\/UNC\//i, "//").replace(/^\/\/\?\//, "");
25
+ return s.toLowerCase();
26
+ }
14
27
 
15
28
  const refuse = (message) => { throw new Error(`publication admission refused: ${message}`); };
16
29
  const requireThat = (condition, message) => { if (!condition) refuse(message); };
@@ -29,27 +42,41 @@ export function enrolledPins(sha, git) {
29
42
  /**
30
43
  * The qualification's broker receipts, verified. For each of the compile and package stages: at least one receipt whose signature
31
44
  * verifies against the pins enrolled at the dispatched commit for the receipt's host, whose job id is its own, and whose signed result is
32
- * SUCCEEDED with exit code 0. The nonce binds the dispatched commit, its real git tree, the unit and the stage: a carried call (a cargo call, or a pnpm
33
- * adapter job) carries the per-call nonce derived from it, the directory it ran in and its argv (carriedCallNonce, rightkit#1301 B8),
34
- * checked against the stage row the job is assigned to. A receipt of another commit, tree, unit or stage, or of another
35
- * command or directory, cannot carry the nonce. Every receipt also carries signed snapshotEvidence (B9): the commit and tree equal the
36
- * dispatched commit's, the snapshot held that tree at start and at exit, and its request id is the job's; all receipts share one snapshot
37
- * path and one ownership handle, and, with the stage row's directory removed, one primary root. A job id is used once across stages.
38
- * The qualification's tree must equal the dispatched commit's tree. Returns the verified summary the admission receipt records.
45
+ * SUCCEEDED with exit code 0, and whose signed `gate` object names the dispatched commit and its real git tree (below). The qualification's
46
+ * tree must equal the dispatched commit's tree. A job id is used once across stages. Returns the verified summary the admission receipt records.
47
+ *
48
+ * THE RECEIPT SHAPE (reset plan section 3; the carrier-era shape, with its caller nonce and signed snapshotEvidence, was deleted at plan step 5 and is refused: a receipt
49
+ * with no signed `gate` object admits nothing):
50
+ * - SEAM receipt (the payload carries `gate`): signature against the pin enrolled at the dispatched commit for the receipt's host; payload.jobId === receipt.id; SUCCEEDED with
51
+ * exit 0; signed gate.commit and gate.tree are the dispatched commit's and its real git tree; gate.snapshotUnchanged is true; one gate.snapshot and one directory of Class A
52
+ * verdicts (every verdict named for this commit) across all receipts; one host; a job id used once; each signed request is one of the stage's own commands (exact argv and
53
+ * directory, stage-commands.mjs assignJobs) and EVERY command of the stage is covered; the request's checkout (workspace without the row's directory) is gate.snapshot itself.
54
+ * WHAT THE REMOVED CALLER NONCE BOUND, AND WHAT BINDS IT NOW:
55
+ * commit and tree nonce (derived from them) -> signed gate.commit, gate.tree (broker-written from the admitted request and the snapshot state; stronger: not a value the caller chose)
56
+ * the command and its dir carriedCallNonce (cwd + argv) -> signed request.requestedArgv/workspace matched to the stage row (assignJobs) and the root rule
57
+ * one run, one snapshot snapshotEvidence snapshot path -> signed gate.snapshot equal across receipts and equal to the request's own checkout
58
+ * the snapshot held the tree snapshotEvidence start/exit -> signed gate.snapshotUnchanged (the broker's post-job tree check)
59
+ * Class A ran first (not bound by CI before) -> signed gate.classA names a verdict of this commit (only the file name is checked here; the broker admitted the job on its content)
60
+ * NOT BOUND ANY MORE (a weakening, reported, not hidden):
61
+ * - the UNIT and the STAGE label: the nonce hashed `unit` and `stage` in. A seam receipt carries neither; it is tied to the unit and stage only through its argv and directory
62
+ * matching one command of that stage. A receipt of an identical command (same argv and directory) of another unit or of the other stage would satisfy this one.
63
+ * - ONE DOOR RUN: no per-run handle (the build ownership is gone; the snapshot lock is the only exclusion). `gate.snapshot` is `<data root>/snapshots/<repo-key>`, the same path for every run of the repository on a host,
64
+ * so receipts of two separate runs of this commit on one host are indistinguishable. Both are genuine broker runs of the dispatched commit and tree.
65
+ * - the caller's freshness: the old nonce was derived from public values, so it never proved recency either; nothing here does (terminalAt is signed but not judged).
39
66
  */
40
67
  export function verifyQualificationReceipts(text, { sha, git }) {
41
68
  let q;
42
69
  try { q = JSON.parse(text); } catch { refuse("the qualification input is not JSON"); }
43
- return verifyReceiptStages(q, { sha, git, stages: ATTESTED_STAGES, nonceOf: ({ commit, tree, unit, stage }) => qualificationNonce({ commit, tree, unit, stage }) });
70
+ return verifyReceiptStages(q, { sha, git, stages: ATTESTED_STAGES });
44
71
  }
45
72
 
46
- // CI supplies its independently bound nonce; publication always uses the fixed wrapper above.
73
+ // CI supplies its identity-derived stage nonce (ci-compile-admission.mjs); a seam receipt carries no caller nonce (the client mints its own), so the value is only validated here.
47
74
  export function verifyCiCompileReceipts(q, { sha, git, stageNonce }) {
48
75
  requireThat(typeof stageNonce === "string" && SHA256_HEX.test(stageNonce), "the CI compile nonce is invalid");
49
- return verifyReceiptStages(q, { sha, git, stages: ["compile"], nonceOf: () => stageNonce });
76
+ return verifyReceiptStages(q, { sha, git, stages: ["compile"] });
50
77
  }
51
78
 
52
- function verifyReceiptStages(q, { sha, git, stages, nonceOf }) {
79
+ function verifyReceiptStages(q, { sha, git, stages }) {
53
80
  const tree = String(git("rev-parse", `${sha}^{tree}`)).trim();
54
81
  requireThat(/^[0-9a-f]{40}$/.test(tree), `cannot read the tree of ${sha.slice(0, 12)}`);
55
82
  requireThat(q?.tree === tree, `the qualification receipt is for tree ${String(q?.tree).slice(0, 12)}, the dispatched commit's tree is ${tree.slice(0, 12)}`);
@@ -71,26 +98,14 @@ function verifyReceiptStages(q, { sha, git, stages, nonceOf }) {
71
98
  return expectedByPlatform.get(platform);
72
99
  };
73
100
  let platform = null;
74
- let primaryRoot = null, snapshotPath = null, handle = null;
101
+ let primaryRoot = null, primaryCheckout = null;
102
+ let seamSnapshot = null, seamVerdictDir = null;
75
103
  const seen = new Set();
76
104
  const verified = {};
77
105
  for (const stage of stages) {
78
106
  const list = q.stages?.[stage]?.receipts;
79
107
  requireThat(Array.isArray(list) && list.length >= 1, `the qualification receipt's ${stage} stage carries no signed broker receipts; an unauthenticated qualification admits nothing`);
80
108
  requireThat(list.length <= MAX_VERIFIED_RECEIPTS, `the qualification receipt's ${stage} stage carries ${list.length} receipts (at most ${MAX_VERIFIED_RECEIPTS})`);
81
- const stageNonce = nonceOf({ commit: sha, tree, unit, stage });
82
- // The nonces a receipt may carry, before its row is known: every carried call (a Cargo call, and a pnpm adapter job, rightkit#1301 B8) the
83
- // nonce derived for the directory of each of the stage's rows it could be and the argv it signed. The row it is assigned to (below) must
84
- // then be the one that fits.
85
- const nonceFor = (row, argv) => carriedCallNonce({ stageNonce, cwd: row.cwd ?? ".", argv });
86
- // The stage nonce is always tried as well, so a job that is none of the stage's commands is refused for that (below), not for its nonce.
87
- const candidateNonces = (host, request) => {
88
- if ((request?.kind !== "cargo" && request?.kind !== "adapter") || !Array.isArray(request.requestedArgv)) return [stageNonce];
89
- // A cargo row is told apart by its exact argv; an adapter row's argv can hold a scratch path (pack), so every adapter row is tried (a job
90
- // of another adapter then reaches the command check below and is refused for that, not for its nonce).
91
- const rows = expectedFor(host.platform)[stage].filter((row) => row.kind === request.kind && (row.kind === "adapter" || row.argvs.some((argv) => sameJson(argv, request.requestedArgv))));
92
- return [...new Set([...rows.map((row) => nonceFor(row, request.requestedArgv)), stageNonce])];
93
- };
94
109
  const jobs = [];
95
110
  const summaries = new Map();
96
111
  list.forEach((receipt, index) => {
@@ -100,11 +115,10 @@ function verifyReceiptStages(q, { sha, git, stages, nonceOf }) {
100
115
  seen.add(receipt.id);
101
116
  const candidates = pins.filter((p) => p.host === receipt.provenance?.payload?.host);
102
117
  requireThat(candidates.length > 0, `${where}: signed for host ${JSON.stringify(receipt.provenance?.payload?.host)}, which ci/rk-pipeline.json does not enroll`);
118
+ // No caller nonce exists for a seam receipt (the client mints it internally): the signature, the pinned host and broker, and the job id are checked, nothing else here.
103
119
  let payload, failure, pin;
104
120
  for (const candidate of candidates) {
105
- for (const nonce of candidateNonces(candidate, receipt.provenance?.payload?.request)) {
106
- try { payload = verifyProvenance(receipt, candidate, { jobId: receipt.id, nonce }); pin = candidate; break; } catch (error) { if (!(error instanceof ProvenanceError)) throw error; failure = error; }
107
- }
121
+ try { payload = verifyProvenanceSignature(receipt, candidate, receipt.id); pin = candidate; } catch (error) { if (!(error instanceof ProvenanceError)) throw error; failure = error; }
108
122
  if (payload) break;
109
123
  }
110
124
  requireThat(payload, `${where} (job ${receipt.id}) does not verify against the enrolled pins at ${sha.slice(0, 12)}: ${failure?.code}: ${failure?.message}`);
@@ -115,18 +129,22 @@ function verifyReceiptStages(q, { sha, git, stages, nonceOf }) {
115
129
  // run on the enrolled host: the same one for every receipt of the qualification.
116
130
  platform ??= pin.platform;
117
131
  requireThat(pin.platform === platform, `${where} (job ${receipt.id}) was signed by the ${pin.platform} host, another host than the qualification's other jobs (${platform})`);
118
- // The signed snapshot evidence names the commit, tree and job and shows the snapshot held the tree throughout (the same pure
119
- // function the gate applies to its own receipts), and one snapshot and one ownership handle carry every job of the qualification.
120
- const evidence = payload.snapshotEvidence;
121
- requireThat(isRecord(evidence), `${where} (job ${receipt.id}) carries no signed snapshotEvidence: it was not built as a snapshot request of the dispatched commit`);
122
- try { verifySnapshotEvidenceIdentity(evidence, { commit: { sha, tree }, tree, jobId: receipt.id }); }
123
- catch (error) { if (!(error instanceof SnapshotRequestError)) throw error; refuse(`${where} (job ${receipt.id}): ${error.message}`); }
124
- // Each carried request signs its own sub-handle `<ownership-handle>#<n>`; the qualification's one ownership is the part before the `#`.
125
- const path = evidence.snapshot?.path, owner = ownershipOfHandle(evidence.ownership?.handle);
126
- requireThat(typeof path === "string" && path !== "" && typeof owner === "string" && owner !== "", `${where} (job ${receipt.id}) names no snapshot path or ownership handle`);
127
- requireThat(snapshotPath === null || snapshotPath === path, `${where} (job ${receipt.id}) ran in the snapshot ${path}, another snapshot than the qualification's other jobs (${snapshotPath})`);
128
- requireThat(handle === null || handle === owner, `${where} (job ${receipt.id}) was signed under ownership handle ${owner}, another than the qualification's other jobs (${handle})`);
129
- snapshotPath = path; handle = owner;
132
+ // The seam receipt's signed `gate` object (the broker writes it from the admitted request, the snapshot state and its own post-job tree check): this commit, this tree,
133
+ // the snapshot unchanged. See the binding comment above verifyQualificationReceipts for what this does and does not bind.
134
+ const gate = payload.gate;
135
+ requireThat(isRecord(gate), `${where} (job ${receipt.id}) carries no signed gate object`);
136
+ requireThat(gate.commit === sha, `${where} (job ${receipt.id}) was built from commit ${String(gate.commit).slice(0, 12)}, not the dispatched ${sha.slice(0, 12)}`);
137
+ requireThat(gate.tree === tree, `${where} (job ${receipt.id}) was built from tree ${String(gate.tree).slice(0, 12)}, the dispatched commit's tree is ${tree.slice(0, 12)}`);
138
+ requireThat(gate.snapshotUnchanged === true, `${where} (job ${receipt.id}) did not leave the snapshot unchanged (gate.snapshotUnchanged is ${JSON.stringify(gate.snapshotUnchanged)})`);
139
+ requireThat(isAbsolutePath(gate.snapshot) && isAbsolutePath(gate.classA), `${where} (job ${receipt.id}) names no absolute snapshot or Class A verdict path`);
140
+ // The verdict file's name carries its commit (gate-seam.mjs verdictFileName: class-a-<commit12>-<scope>-<workspace>.json); every call of a door run names a verdict of
141
+ // that commit, derived from the one root verdict, so all of them sit in one directory.
142
+ const verdict = hostPathKey(gate.classA, platform);
143
+ requireThat(path.posix.basename(verdict).startsWith(`class-a-${sha.slice(0, 12)}-`), `${where} (job ${receipt.id}) names the Class A verdict ${path.posix.basename(verdict)}, not one of commit ${sha.slice(0, 12)}`);
144
+ const verdictDir = path.posix.dirname(verdict);
145
+ requireThat(seamSnapshot === null || seamSnapshot === hostPathKey(gate.snapshot, platform), `${where} (job ${receipt.id}) ran in the snapshot ${gate.snapshot}, another snapshot than the qualification's other jobs (${seamSnapshot})`);
146
+ requireThat(seamVerdictDir === null || seamVerdictDir === verdictDir, `${where} (job ${receipt.id}) names a Class A verdict in ${verdictDir}, another directory than the qualification's other jobs (${seamVerdictDir})`);
147
+ seamSnapshot = hostPathKey(gate.snapshot, platform); seamVerdictDir = verdictDir;
130
148
  jobs.push({ id: receipt.id, payload });
131
149
  summaries.set(receipt.id, { jobId: receipt.id, host: payload.host, keyId: payload.keyId, requestDigest: payload.requestDigest, requestedArgv: payload.request.requestedArgv });
132
150
  });
@@ -137,15 +155,24 @@ function verifyReceiptStages(q, { sha, git, stages, nonceOf }) {
137
155
  if (missing.length) requireThat(false, `the qualification carries no signed receipt of the ${stage} stage's ${missing.length ? describeCommand(missing[0]) : ""} (${missing.length} of ${assigned.size + missing.length} required command(s) missing)`);
138
156
  for (const job of jobs) {
139
157
  const row = assigned.get(job.id);
140
- const { workspace, workspaceRoot, requestedArgv } = job.payload.request;
141
- // The nonce is the one this row's command owes: derived from the directory its row runs in and the argv it signed (a Cargo call or a pnpm job).
142
- requireThat(job.payload.nonce === nonceFor(row, requestedArgv), `${stage} job ${job.id} carries a nonce that is not the one its command (${describeCommand(row)}) owes`);
158
+ const { workspace, workspaceRoot } = job.payload.request;
159
+ // A seam receipt has no caller nonce: its command binding is the argv/cwd assignment above plus the signed gate commit and tree.
143
160
  // The primary root: the signed workspace without the directory of the row's command (a carried cargo call runs from its manifest's
144
- // directory, a pnpm job at the root). Every job of the qualification must show the same one, and so must its workspaceRoot.
145
- const root = rootOfWorkspace(workspace, row.cwd);
161
+ // directory, a pnpm job at the root). Every job of the qualification must show the same one.
162
+ // A seam receipt's paths are compared as the enrolled host compares them (hostPathKey).
163
+ const keyOf = (p) => hostPathKey(p, platform);
164
+ const cwdKey = platform === "win32" && typeof row.cwd === "string" ? row.cwd.toLowerCase() : row.cwd;
165
+ const root = rootOfWorkspace(keyOf(workspace), cwdKey);
146
166
  requireThat(root !== null, `${stage} job ${job.id} ran in ${workspace}, which is not the directory ${row.cwd} of a checkout`);
147
- requireThat(workspaceRoot === undefined || rootOfWorkspace(workspaceRoot, row.cwd) === root, `${stage} job ${job.id} ran in ${workspace} with workspace root ${workspaceRoot}, not in one checkout`);
167
+ // The signed workspaceRoot of a gate-bound job is the app's target identity, the primary checkout the snapshot was taken from (rustright normalize_impl.rs:
168
+ // workspace_root = binding.primary; finish_impl.rs signs it), never a directory of the snapshot. Every job of the qualification must name the same one.
169
+ requireThat(isAbsolutePath(workspaceRoot), `${stage} job ${job.id} ran in ${workspace} and names no absolute workspace root (primary checkout): ${JSON.stringify(workspaceRoot)}`);
170
+ requireThat(primaryCheckout === null || primaryCheckout === keyOf(workspaceRoot), `${stage} job ${job.id} names the primary checkout ${workspaceRoot}, another one than the qualification's other jobs (${primaryCheckout})`);
171
+ primaryCheckout = keyOf(workspaceRoot);
148
172
  requireThat(primaryRoot === null || primaryRoot === root, `${stage} job ${job.id} ran in ${workspace}, another workspace than the qualification's other jobs (${primaryRoot})`);
173
+ // A seam job's primary root is the snapshot its signed gate object names: the directory the request ran in lies in that very snapshot, so the request
174
+ // and the gate evidence describe one checkout.
175
+ requireThat(root === seamSnapshot, `${stage} job ${job.id} ran in ${workspace}, whose checkout ${root} is not the snapshot ${seamSnapshot} its gate evidence names`);
149
176
  primaryRoot = root;
150
177
  }
151
178
  verified[stage] = list.map((receipt) => summaries.get(receipt.id));
@@ -0,0 +1,104 @@
1
+ // The signature half of a RustRight broker job receipt, in pure JS (node:crypto only), exactly as rustright-protocol's attestation.rs
2
+ // `verify_receipt` does: canonical JSON, the signed bytes, the pinned ES256 key and the checks that need no caller-side nonce. It is the part of
3
+ // CI's publication admission that outlived the carrier: qualification-verify.mjs imports it for a seam receipt (the reset plan section 2, Trust); the carrier-era
4
+ // verifier that wrapped it (provenance-verify.mjs) was deleted at plan step 5.
5
+ // Never trusts a value from the receipt that the caller can pin instead.
6
+ import { createHash, createPublicKey, verify } from "node:crypto";
7
+
8
+ export const PROVENANCE_SCHEMA = "rustright.provenance.v1";
9
+ export const PROVENANCE_DOMAIN = "rustright-provenance-v1";
10
+
11
+ export class ProvenanceError extends Error {
12
+ constructor(code, message) { super(message); this.name = "ProvenanceError"; this.code = code; }
13
+ }
14
+ const refuse = (code, message) => { throw new ProvenanceError(code, message); };
15
+
16
+ const sha256Hex = (data) => createHash("sha256").update(data).digest("hex");
17
+ const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
18
+
19
+ function writeString(text, out) {
20
+ let s = '"';
21
+ for (const ch of text) {
22
+ const code = ch.codePointAt(0);
23
+ if (ch === '"') s += '\\"';
24
+ else if (ch === "\\") s += "\\\\";
25
+ else if (code < 0x20) s += `\\u${code.toString(16).padStart(4, "0")}`;
26
+ else s += ch;
27
+ }
28
+ out.push(`${s}"`);
29
+ }
30
+
31
+ function writeCanonical(value, out) {
32
+ if (value === null) out.push("null");
33
+ else if (typeof value === "boolean") out.push(value ? "true" : "false");
34
+ else if (typeof value === "number") {
35
+ // Integers only: serde_json prints floats with its own algorithm, and an integer beyond 2^53 was already corrupted by JSON.parse.
36
+ // Either would make a signature fail for the wrong reason, so refuse loudly instead.
37
+ if (!Number.isSafeInteger(value)) refuse("canonical", "canonical JSON takes only safe integers");
38
+ out.push(String(value));
39
+ } else if (typeof value === "string") writeString(value, out);
40
+ else if (Array.isArray(value)) {
41
+ out.push("[");
42
+ value.forEach((item, index) => { if (index > 0) out.push(","); writeCanonical(item, out); });
43
+ out.push("]");
44
+ } else if (isRecord(value)) {
45
+ // Rust sorts by the UTF-8 bytes of the key; JavaScript's default sort is by UTF-16 code unit and differs above U+FFFF.
46
+ const keys = Object.keys(value).sort((a, b) => Buffer.compare(Buffer.from(a, "utf8"), Buffer.from(b, "utf8")));
47
+ out.push("{");
48
+ keys.forEach((key, index) => { if (index > 0) out.push(","); writeString(key, out); out.push(":"); writeCanonical(value[key], out); });
49
+ out.push("}");
50
+ } else refuse("canonical", `canonical JSON cannot carry a ${typeof value}`);
51
+ }
52
+
53
+ /** Canonical JSON: keys sorted by byte order, no whitespace, strings escape only `"`, `\` and control characters < 0x20 (\u00xx lower-case). */
54
+ export function canonicalJson(value) {
55
+ const out = [];
56
+ writeCanonical(value, out);
57
+ return out.join("");
58
+ }
59
+
60
+ /** The exact bytes the broker signs for a payload. */
61
+ export function signedBytes(payload) {
62
+ return Buffer.from(`${PROVENANCE_DOMAIN}\n${canonicalJson(payload)}`, "utf8");
63
+ }
64
+
65
+ const HEX = /^(?:[0-9a-fA-F]{2})+$/;
66
+ const keyFromSec1 = (publicKeyHex) => {
67
+ if (typeof publicKeyHex !== "string" || !HEX.test(publicKeyHex)) refuse("pin", "pinned public key is not hex");
68
+ const bytes = Buffer.from(publicKeyHex, "hex");
69
+ if (bytes.length !== 65 || bytes[0] !== 0x04) refuse("pin", "pinned public key is not an uncompressed SEC1 P-256 point");
70
+ try {
71
+ return createPublicKey({ key: { kty: "EC", crv: "P-256", x: bytes.subarray(1, 33).toString("base64url"), y: bytes.subarray(33, 65).toString("base64url") }, format: "jwk" });
72
+ } catch { return refuse("pin", "pinned public key is not a P-256 point"); }
73
+ };
74
+
75
+ /**
76
+ * Verifies receipt.provenance's signature against the pins the caller holds (never from the receipt) and the job the caller expects. Every
77
+ * check fails closed (throws ProvenanceError with a stable `code`) and returns the signed payload on success. It checks no nonce and no
78
+ * request digest: a seam receipt has none.
79
+ * pins: { publicKey (SEC1 uncompressed hex), keyId, host, brokerDigest }
80
+ * jobId: the receipt's job id; the signed payload's `jobId` and the receipt's own `id` must both equal it.
81
+ */
82
+ export function verifyProvenanceSignature(receipt, pins, jobId) {
83
+ const envelope = receipt?.provenance;
84
+ if (!isRecord(envelope)) refuse("legacy", "the receipt has no provenance envelope");
85
+ if (envelope.schema !== PROVENANCE_SCHEMA) refuse("schema", "unknown provenance schema");
86
+ const payload = envelope.payload;
87
+ if (!isRecord(payload)) refuse("malformed", "payload is missing");
88
+ const signature = envelope.signature;
89
+ if (!isRecord(signature)) refuse("malformed", "signature is missing");
90
+ if (signature.alg !== "ES256") refuse("alg", "signature algorithm must be ES256");
91
+ if (!isRecord(pins) || typeof pins.publicKey !== "string" || !HEX.test(pins.publicKey)) refuse("pin", "pinned public key is not hex");
92
+ if (sha256Hex(Buffer.from(pins.publicKey, "hex")) !== pins.keyId) refuse("pin", "pinned key id does not match the pinned public key");
93
+ if (signature.keyId !== pins.keyId || payload.keyId !== pins.keyId) refuse("key", "the receipt was not signed by the pinned key");
94
+ const key = keyFromSec1(pins.publicKey);
95
+ if (typeof signature.value !== "string" || !/^[0-9a-fA-F]+$/.test(signature.value)) refuse("signature", "signature is not hex");
96
+ if (signature.value.length !== 128) refuse("signature", "signature is not 64 bytes r||s");
97
+ let good = false;
98
+ try { good = verify("sha256", signedBytes(payload), { key, dsaEncoding: "ieee-p1363" }, Buffer.from(signature.value, "hex")); } catch (error) { if (error instanceof ProvenanceError) throw error; }
99
+ if (!good) refuse("signature", "signature does not verify");
100
+ if (payload.host !== pins.host) refuse("host", "signed for another host");
101
+ if (payload.broker?.brokerDigest !== pins.brokerDigest) refuse("runtime", "signed by another broker runtime");
102
+ if (typeof jobId !== "string" || payload.jobId !== jobId || receipt.id !== jobId) refuse("job", "the receipt is for another job");
103
+ return payload;
104
+ }
@@ -122,6 +122,10 @@
122
122
  "name": "--qa",
123
123
  "class": "S1"
124
124
  },
125
+ {
126
+ "name": "--rightkit-qa-credentials",
127
+ "class": "S1"
128
+ },
125
129
  {
126
130
  "name": "--demo",
127
131
  "class": "S1"
@@ -103,14 +103,17 @@ export function featureClosureFindings(treeText, { forbidden = [...REGISTRY.forb
103
103
  return findings;
104
104
  }
105
105
 
106
- // M7 lane E: rightkit-daemon `remote` (the HTTPS host with tokio, axum and hyper) may enter a release graph only for an app
107
- // that declares `releaseSwitches.remoteHost: true` (the Hetzner Pulse and PostRight server builds). `testing` implies `remote`,
108
- // so it is caught by the same line. Fail-closed: a value other than a boolean throws, and `false` or an absent key refuses.
109
- // PK17-2: a `remote` that appears ONLY beneath the daemon `remote-loopback` feature (the loopback feature enables the shared
110
- // router and auth internals) is not a host declaration; that case is judged by `remoteLoopbackFindings`, not here. Any other
111
- // path to `remote` (a direct request, `testing`, another crate's feature) is still refused exactly as before.
112
- export const REMOTE_SERVICE_CRATE = "rightkit-daemon";
106
+ // M7 lane E: the `remote` feature of rightkit-daemon-remote (the HTTPS host with tokio, axum and hyper; rightkit-daemon's own
107
+ // `remote` feature until rightkit-daemon 0.7.0) may enter a release graph only for an app that declares
108
+ // `releaseSwitches.remoteHost: true` (the Hetzner Pulse and PostRight server builds). Its `link` and `relay` features (the device
109
+ // client and the relay protocol, no listener) are not a host. Fail-closed: a value other than a boolean throws, and `false` or an
110
+ // absent key refuses. PK17-2: a `remote` that appears ONLY beneath the daemon `remote-loopback` feature is not a host
111
+ // declaration; that case is judged by `remoteLoopbackFindings`, not here (since rightkit-daemon 0.7.0 the loopback feature
112
+ // enables nothing in rightkit-daemon-remote, so the exception can no longer apply). Any other path to `remote` is refused.
113
+ export const REMOTE_SERVICE_CRATE = "rightkit-daemon-remote";
113
114
  export const REMOTE_SERVICE_FEATURE = "remote";
115
+ // The loopback host stays in rightkit-daemon with the local service (2026-11-11 shape review).
116
+ export const REMOTE_LOOPBACK_CRATE = "rightkit-daemon";
114
117
  export const REMOTE_LOOPBACK_FEATURE = "remote-loopback";
115
118
 
116
119
  // Feature lines of a `cargo tree -e features` text with their parent. Default `--prefix indent` output indents each level by
@@ -130,7 +133,7 @@ function featureTreeEntries(treeText) {
130
133
  }
131
134
  return entries;
132
135
  }
133
- const impliedByLoopback = (entry) => entry.parent?.crate === REMOTE_SERVICE_CRATE && entry.parent?.feature === REMOTE_LOOPBACK_FEATURE;
136
+ const impliedByLoopback = (entry) => entry.parent?.crate === REMOTE_LOOPBACK_CRATE && entry.parent?.feature === REMOTE_LOOPBACK_FEATURE;
134
137
 
135
138
  export function remoteServiceFindings(treeText, { remoteHost = false } = {}) {
136
139
  if (typeof remoteHost !== "boolean") throw new Error(`releaseSwitches.remoteHost must be true or false, got ${JSON.stringify(remoteHost)}`);
@@ -153,9 +156,9 @@ export function remoteLoopbackFindings(treeText, { remoteLoopback = false } = {}
153
156
  if (typeof remoteLoopback !== "boolean") throw new Error(`releaseSwitches.remoteLoopback must be true or false, got ${JSON.stringify(remoteLoopback)}`);
154
157
  if (remoteLoopback) return [];
155
158
  for (const entry of featureTreeEntries(treeText)) {
156
- if (entry.crate !== REMOTE_SERVICE_CRATE || entry.feature !== REMOTE_LOOPBACK_FEATURE) continue;
159
+ if (entry.crate !== REMOTE_LOOPBACK_CRATE || entry.feature !== REMOTE_LOOPBACK_FEATURE) continue;
157
160
  const id = "remote-loopback-undeclared";
158
- return [{ layer: "feature-closure", rule: id, file: "<cargo tree>", reason: `${id}: crate \`${REMOTE_SERVICE_CRATE}\` has feature \`${REMOTE_LOOPBACK_FEATURE}\` enabled in the resolved graph, but the app does not declare releaseSwitches.remoteLoopback: true (only a headless engine build that serves its own loopback API may enable it; releaseSwitches.remoteHost does not cover it)` }];
161
+ return [{ layer: "feature-closure", rule: id, file: "<cargo tree>", reason: `${id}: crate \`${REMOTE_LOOPBACK_CRATE}\` has feature \`${REMOTE_LOOPBACK_FEATURE}\` enabled in the resolved graph, but the app does not declare releaseSwitches.remoteLoopback: true (only a headless engine build that serves its own loopback API may enable it; releaseSwitches.remoteHost does not cover it)` }];
159
162
  }
160
163
  return [];
161
164
  }