@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/handle-revocation.mjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// GB-21/23/57 additive branch (rustright#228, rightkit#1511): a broker-signed revocation of ONE exact sub-handle whose lease the broker can no longer
|
|
2
|
-
// answer (UNKNOWN, no member row). It settles that sub-handle for a dead owner's reclaim only. It never stands in for REAPED or UNSENT, never
|
|
3
|
-
// overrides an ACTIVE lease or a listed member, and never releases a live owner: every other reclaim proof (owner pid, sibling sub-handles,
|
|
4
|
-
// detached groups, token holders, snapshot users) still runs unchanged.
|
|
5
|
-
//
|
|
6
|
-
// Trust: the host's ENROLLED broker pin only (broker-pins.mjs readEnrolledPins), never the revocation, the record, an environment variable or a
|
|
7
|
-
// checkout. The signature scheme is the broker's provenance scheme (ES256, P-256, canonical JSON) under its own domain string, so a receipt can
|
|
8
|
-
// never be replayed as a revocation, or the reverse.
|
|
9
|
-
//
|
|
10
|
-
// Location: exactly `<data root>/snapshot-leases/completed/<name>` (no suffix), where name is the lowercase SHA-256 of the canonical JSON array
|
|
11
|
-
// [snapshot, ownership]: the broker's own f227 completion key for that sub-handle, so the revocation also fences legacy exact-handle reuse (Terra,
|
|
12
|
-
// 2026-11-05). One file, read, authenticated and reread there; no sidecar. A file there with another schema (a legacy completion) is not a revocation
|
|
13
|
-
// and is ignored here; a link or a non-file refuses.
|
|
14
|
-
import { createHash, createPublicKey, verify } from "node:crypto";
|
|
15
|
-
import fs from "node:fs";
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
import { canonicalJson } from "./provenance-verify.mjs";
|
|
18
|
-
|
|
19
|
-
export const REVOCATION_SCHEMA = "rustright.snapshot-revocation.v1";
|
|
20
|
-
export const REVOCATION_DOMAIN = "rustright-snapshot-revocation-v1";
|
|
21
|
-
export const REVOCATION_DIR = path.join("snapshot-leases", "completed");
|
|
22
|
-
/** The signed payload's fields, exactly (Terra's proposal, 2026-11-05; not frozen until the shared golden fixture agrees). */
|
|
23
|
-
export const REVOCATION_FIELDS = Object.freeze(["dataRoot", "host", "keyId", "ownerFile", "ownerSha256", "ownership", "proofSha256", "runtime", "schema", "snapshot"]);
|
|
24
|
-
const SHA = /^[0-9a-f]{64}$/;
|
|
25
|
-
|
|
26
|
-
export class RevocationError extends Error {
|
|
27
|
-
constructor(code, message) { super(message); this.name = "RevocationError"; this.code = code; }
|
|
28
|
-
}
|
|
29
|
-
const refuse = (code, message) => { throw new RevocationError(code, message); };
|
|
30
|
-
const sha256Hex = (data) => createHash("sha256").update(data).digest("hex");
|
|
31
|
-
const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
32
|
-
const ID = /^[A-Za-z0-9._-]+$/;
|
|
33
|
-
|
|
34
|
-
/** The exact bytes the broker signs for a revocation payload. */
|
|
35
|
-
export const revocationSignedBytes = (payload) => Buffer.from(`${REVOCATION_DOMAIN}\n${canonicalJson(payload)}`, "utf8");
|
|
36
|
-
|
|
37
|
-
/** The f227 completion name of one sub-handle of one snapshot: lowercase SHA-256 of canonical JSON `[snapshot, ownership]`. */
|
|
38
|
-
export const revocationName = (snapshot, ownership) => sha256Hex(Buffer.from(canonicalJson([snapshot, ownership]), "utf8"));
|
|
39
|
-
|
|
40
|
-
/** The one path a revocation of `sub` (`<ownerHandle>#<id>`) of `snapshot` may live at under the managed data root `dataRoot`. */
|
|
41
|
-
export function revocationFile(dataRoot, ownerHandle, sub, snapshot) {
|
|
42
|
-
if (typeof ownerHandle !== "string" || !ID.test(ownerHandle)) refuse("handle", `${JSON.stringify(ownerHandle)} is not an owner handle`);
|
|
43
|
-
if (typeof sub !== "string" || !sub.startsWith(`${ownerHandle}#`) || !ID.test(sub.slice(ownerHandle.length + 1))) refuse("handle", `${JSON.stringify(sub)} is not a sub-handle of ${ownerHandle}`);
|
|
44
|
-
if (typeof snapshot !== "string" || !path.isAbsolute(snapshot)) refuse("root", "the owner record names no absolute snapshot");
|
|
45
|
-
if (typeof dataRoot !== "string" || !path.isAbsolute(dataRoot)) refuse("root", "the managed data root is not absolute");
|
|
46
|
-
return path.join(dataRoot, REVOCATION_DIR, revocationName(snapshot, sub));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** The revocation's bytes, or null when none exists. A link, a directory or an unreadable entry is a refusal, never null. */
|
|
50
|
-
export function readRevocation(file) {
|
|
51
|
-
let meta;
|
|
52
|
-
try { meta = fs.lstatSync(file); } catch (e) { if (e.code === "ENOENT") return null; return refuse("read", `${file} cannot be read (${e.code ?? e.message})`); }
|
|
53
|
-
if (!meta.isFile()) refuse("read", `${file} is not a plain file`);
|
|
54
|
-
return fs.readFileSync(file);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Whether `bytes` claim to be a snapshot revocation at all (its envelope schema); anything else at the completion key is the broker's own record. */
|
|
58
|
-
export function isRevocationEnvelope(bytes) {
|
|
59
|
-
try { return JSON.parse(Buffer.isBuffer(bytes) ? bytes.toString("utf8") : String(bytes))?.schema === REVOCATION_SCHEMA; } catch { return false; }
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const publicKeyOf = (hex) => {
|
|
63
|
-
const bytes = Buffer.from(hex, "hex");
|
|
64
|
-
if (bytes.length !== 65 || bytes[0] !== 0x04) refuse("pin", "the pinned public key is not an uncompressed SEC1 P-256 point");
|
|
65
|
-
return createPublicKey({ key: { kty: "EC", crv: "P-256", x: bytes.subarray(1, 33).toString("base64url"), y: bytes.subarray(33, 65).toString("base64url") }, format: "jwk" });
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Verifies `bytes` as the broker's revocation of exactly `sub` for exactly this owner record. Returns the signed payload; throws RevocationError
|
|
70
|
-
* (stable `code`) on any mismatch.
|
|
71
|
-
* pins: the host's enrolled `{ host, keyId, publicKey, brokerDigest }`
|
|
72
|
-
* expected: { ownerFile, dataRoot (both canonical, realpath), ownerBytes (the record bytes the reclaim judged), owner (parsed), sub }
|
|
73
|
-
*/
|
|
74
|
-
export function verifyRevocation(bytes, pins, { ownerFile, dataRoot, ownerBytes, owner, sub }) {
|
|
75
|
-
let envelope = null;
|
|
76
|
-
try { envelope = JSON.parse(Buffer.isBuffer(bytes) ? bytes.toString("utf8") : String(bytes)); } catch { envelope = null; }
|
|
77
|
-
if (!isRecord(envelope) || envelope.schema !== REVOCATION_SCHEMA) refuse("schema", "not a handle revocation");
|
|
78
|
-
const { payload, signature } = envelope;
|
|
79
|
-
if (!isRecord(payload) || !isRecord(signature)) refuse("malformed", "payload or signature is missing");
|
|
80
|
-
if (signature.alg !== "ES256") refuse("alg", "signature algorithm must be ES256");
|
|
81
|
-
if (!isRecord(pins) || typeof pins.publicKey !== "string" || sha256Hex(Buffer.from(pins.publicKey, "hex")) !== pins.keyId) refuse("pin", "the pinned key id does not match the pinned public key");
|
|
82
|
-
if (signature.keyId !== pins.keyId || payload.keyId !== pins.keyId) refuse("key", "not signed by the pinned broker key");
|
|
83
|
-
if (typeof signature.value !== "string" || !/^[0-9a-fA-F]{128}$/.test(signature.value)) refuse("signature", "signature is not 64 bytes r||s in hex");
|
|
84
|
-
let good = false;
|
|
85
|
-
try { good = verify("sha256", revocationSignedBytes(payload), { key: publicKeyOf(pins.publicKey), dsaEncoding: "ieee-p1363" }, Buffer.from(signature.value, "hex")); } catch (e) { if (e instanceof RevocationError) throw e; }
|
|
86
|
-
if (!good) refuse("signature", "signature does not verify");
|
|
87
|
-
// Everything below is signed: exactly these fields, bound to this host's broker runtime, this exact record's bytes, its snapshot and this exact sub-handle.
|
|
88
|
-
const fields = Object.keys(payload).sort();
|
|
89
|
-
if (JSON.stringify(fields) !== JSON.stringify(REVOCATION_FIELDS)) refuse("malformed", `the payload carries ${fields.join(", ")}, not exactly ${REVOCATION_FIELDS.join(", ")}`);
|
|
90
|
-
if (payload.schema !== REVOCATION_SCHEMA) refuse("schema", "the signed payload is not a snapshot revocation");
|
|
91
|
-
if (payload.host !== pins.host) refuse("host", "signed for another host");
|
|
92
|
-
if (!isRecord(payload.runtime) || JSON.stringify(Object.keys(payload.runtime)) !== '["brokerDigest"]' || payload.runtime.brokerDigest !== pins.brokerDigest) refuse("runtime", "signed by another broker runtime");
|
|
93
|
-
if (payload.dataRoot !== dataRoot) refuse("root", "revokes a sub-handle under another managed data root");
|
|
94
|
-
if (payload.ownerFile !== ownerFile) refuse("root", "revokes a sub-handle of another ownership record");
|
|
95
|
-
if (payload.snapshot !== owner.snapshot) refuse("root", "revokes a sub-handle of another snapshot");
|
|
96
|
-
if (payload.ownership !== sub) refuse("handle", `revokes ${payload.ownership}, not ${sub}`);
|
|
97
|
-
if (payload.ownerSha256 !== sha256Hex(ownerBytes)) refuse("owner", "signed over other owner record bytes (the record changed, or it is another record)");
|
|
98
|
-
if (typeof payload.proofSha256 !== "string" || !SHA.test(payload.proofSha256)) refuse("proof", "proofSha256 is not a lowercase SHA-256");
|
|
99
|
-
return payload;
|
|
100
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"envelope":{"payload":{"dataRoot":"/Volumes/D/.rightkit-managed","host":"fixture-host","keyId":"698bea63dc44a344663ff1429aea10842df27b6b991ef25866b2c6c02cdcc5be","ownerFile":"/Volumes/D/.rightkit-managed/build-ownership/770a65dcafd91981/owner.json","ownerSha256":"be6603d17ef691daaece03448790d3927c98d606a6576d105fbe6bfcc467a5a5","ownership":"26e12157-e275-4bfd-95a2-f1ff48f56e50#bf51a9c8-2f5d-4b80-9fa4-72a0be202da8","proofSha256":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd","runtime":{"brokerDigest":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"},"schema":"rustright.snapshot-revocation.v1","snapshot":"/Volumes/D/.rightkit-managed/snapshots/770a65dcafd91981"},"schema":"rustright.snapshot-revocation.v1","signature":{"alg":"ES256","keyId":"698bea63dc44a344663ff1429aea10842df27b6b991ef25866b2c6c02cdcc5be","value":"3f5fcdd39de47815032dcb4ba074b50a8e91d58cec8e0b89a234fc5a4e9fddf8a6769c4be9099afe62b87cf9e73464a0f3c532fcfab6cb23714f05d800ac8a9a"}},"pins":{"brokerDigest":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","host":"fixture-host","keyId":"698bea63dc44a344663ff1429aea10842df27b6b991ef25866b2c6c02cdcc5be","publicKey":"046b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c2964fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"}}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"schema": "rightkit.revocation-vectors/1",
|
|
3
|
-
"note": "rightkit#1511 / rustright#228 shared golden fixture. TEST KEY ONLY: never enrolled, never a broker key. Status: proposal, not frozen.",
|
|
4
|
-
"domain": "rustright-snapshot-revocation-v1",
|
|
5
|
-
"pins": {
|
|
6
|
-
"host": "fixture-host",
|
|
7
|
-
"keyId": "588caca3ea3415184feb9075c98ec15d92b0ed9aae918b27eff229f77cada0cc",
|
|
8
|
-
"publicKey": "04c51817454bc646c6b036d7c1ff156f4e2e2938173bbf5b00da7387f44f95e3f7f21c0fff3995ccd03c3c1985dcc12b483e85b37e3793e6da4e3529245f02b86a",
|
|
9
|
-
"brokerDigest": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
|
10
|
-
},
|
|
11
|
-
"ownerBytes": "{\"schema\":\"rightkit.build-ownership/1\",\"handle\":\"26e12157-e275-4bfd-95a2-f1ff48f56e50\",\"host\":\"fixture-host\",\"pid\":4242,\"snapshot\":\"/Volumes/D/.rightkit-managed/snapshots/770a65dcafd91981\"}",
|
|
12
|
-
"payload": {
|
|
13
|
-
"schema": "rustright.snapshot-revocation.v1",
|
|
14
|
-
"keyId": "588caca3ea3415184feb9075c98ec15d92b0ed9aae918b27eff229f77cada0cc",
|
|
15
|
-
"host": "fixture-host",
|
|
16
|
-
"runtime": {
|
|
17
|
-
"brokerDigest": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
|
18
|
-
},
|
|
19
|
-
"snapshot": "/Volumes/D/.rightkit-managed/snapshots/770a65dcafd91981",
|
|
20
|
-
"ownership": "26e12157-e275-4bfd-95a2-f1ff48f56e50#bf51a9c8-2f5d-4b80-9fa4-72a0be202da8",
|
|
21
|
-
"dataRoot": "/Volumes/D/.rightkit-managed",
|
|
22
|
-
"ownerFile": "/Volumes/D/.rightkit-managed/build-ownership/770a65dcafd91981/owner.json",
|
|
23
|
-
"ownerSha256": "be6603d17ef691daaece03448790d3927c98d606a6576d105fbe6bfcc467a5a5",
|
|
24
|
-
"proofSha256": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
|
|
25
|
-
},
|
|
26
|
-
"signedBytesUtf8": "rustright-snapshot-revocation-v1\n{\"dataRoot\":\"/Volumes/D/.rightkit-managed\",\"host\":\"fixture-host\",\"keyId\":\"588caca3ea3415184feb9075c98ec15d92b0ed9aae918b27eff229f77cada0cc\",\"ownerFile\":\"/Volumes/D/.rightkit-managed/build-ownership/770a65dcafd91981/owner.json\",\"ownerSha256\":\"be6603d17ef691daaece03448790d3927c98d606a6576d105fbe6bfcc467a5a5\",\"ownership\":\"26e12157-e275-4bfd-95a2-f1ff48f56e50#bf51a9c8-2f5d-4b80-9fa4-72a0be202da8\",\"proofSha256\":\"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\",\"runtime\":{\"brokerDigest\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"},\"schema\":\"rustright.snapshot-revocation.v1\",\"snapshot\":\"/Volumes/D/.rightkit-managed/snapshots/770a65dcafd91981\"}",
|
|
27
|
-
"signedBytesSha256": "61fd2ace1fa136a1e5dc77fb9c23fa0eca8d9079cc2288a21d7553c39d692623",
|
|
28
|
-
"fileNameInput": "[\"/Volumes/D/.rightkit-managed/snapshots/770a65dcafd91981\",\"26e12157-e275-4bfd-95a2-f1ff48f56e50#bf51a9c8-2f5d-4b80-9fa4-72a0be202da8\"]",
|
|
29
|
-
"fileName": "bf1857c7d0d283fdacc8d62dc941ef413ad234c1dbed42dcc55825e9e4d93cb4",
|
|
30
|
-
"expectedPath": "/Volumes/D/.rightkit-managed/snapshot-leases/completed/bf1857c7d0d283fdacc8d62dc941ef413ad234c1dbed42dcc55825e9e4d93cb4",
|
|
31
|
-
"envelope": {
|
|
32
|
-
"schema": "rustright.snapshot-revocation.v1",
|
|
33
|
-
"payload": {
|
|
34
|
-
"schema": "rustright.snapshot-revocation.v1",
|
|
35
|
-
"keyId": "588caca3ea3415184feb9075c98ec15d92b0ed9aae918b27eff229f77cada0cc",
|
|
36
|
-
"host": "fixture-host",
|
|
37
|
-
"runtime": {
|
|
38
|
-
"brokerDigest": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
|
39
|
-
},
|
|
40
|
-
"snapshot": "/Volumes/D/.rightkit-managed/snapshots/770a65dcafd91981",
|
|
41
|
-
"ownership": "26e12157-e275-4bfd-95a2-f1ff48f56e50#bf51a9c8-2f5d-4b80-9fa4-72a0be202da8",
|
|
42
|
-
"dataRoot": "/Volumes/D/.rightkit-managed",
|
|
43
|
-
"ownerFile": "/Volumes/D/.rightkit-managed/build-ownership/770a65dcafd91981/owner.json",
|
|
44
|
-
"ownerSha256": "be6603d17ef691daaece03448790d3927c98d606a6576d105fbe6bfcc467a5a5",
|
|
45
|
-
"proofSha256": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
|
|
46
|
-
},
|
|
47
|
-
"signature": {
|
|
48
|
-
"alg": "ES256",
|
|
49
|
-
"keyId": "588caca3ea3415184feb9075c98ec15d92b0ed9aae918b27eff229f77cada0cc",
|
|
50
|
-
"value": "dbd7e96246ce60b3393cd544bb3d1368bbdfe0b99083cf6fd235458ff4df6de21cad283712ec51769c0486c8af164cca72d20eb61a8377c5b40db28475c1face"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
// RightKit's half of the Legion frozen-scope broker (bogusyogi/rightkit#799; protocol: Orthic-Labs/legion
|
|
2
|
-
// docs/architecture/frozen-scope-broker.md "Shared consumers & coverage boundary", pinned at 2a6597a7c932b8a636462a08a28ee9a28e7d49c6,
|
|
3
|
-
// implementation engine/bins/legion/src/commands/freeze.rs and freeze_consumer.rs).
|
|
4
|
-
//
|
|
5
|
-
// What this module is: the pure parts a RightKit owner needs to use the broker, with no authority of its own.
|
|
6
|
-
// 1. Broker requests (`legion authority freeze broker`, one JSON request on stdin, one JSON answer): status, check, push, consume.
|
|
7
|
-
// `check` is diagnostic (`deliveryLease: false`) and is never a grant; `push` sends an explicit immutable source object and is
|
|
8
|
-
// the only managed delivery. Enrollment (`admin-enroll`) is root-only and is not reachable from here.
|
|
9
|
-
// 2. The `legion-native-consume-v1` frames a native owner adapter speaks on the broker's private pipes (prepare, prepared, commit,
|
|
10
|
-
// complete), the exact PreparedEffect serialization the broker digests, and a one-transaction state machine that refuses any
|
|
11
|
-
// deviation (an unknown key, a wrong nonce, a second prepare, a commit digest that is not the prepared one).
|
|
12
|
-
// 3. The publication binding: the typed effect for a `Publish` consume is built from the SEALED release that publication already
|
|
13
|
-
// verifies (verifyPublicationRelease: sealed manifest, signing and notarization receipts, ownership evidence) and from the
|
|
14
|
-
// artifact bytes read once, so the artifact digest the broker authorizes is the digest of the bytes that are uploaded.
|
|
15
|
-
//
|
|
16
|
-
// What it is not: no broker is installed, no adapter is enrolled and no native adapter executable exists here. The broker accepts only
|
|
17
|
-
// a native ELF or Mach-O executable pinned by a root-owned enrollment and refuses scripts, so this module cannot be the adapter; a native
|
|
18
|
-
// adapter links this protocol. Nothing in this module runs a build, a push or an upload. See docs/GATE-CONTRACT.md [GC-I23].
|
|
19
|
-
import { createHash } from "node:crypto";
|
|
20
|
-
import { spawnSync } from "./background-process.mjs";
|
|
21
|
-
|
|
22
|
-
export const CONSUME_PROTOCOL = "legion-native-consume-v1";
|
|
23
|
-
/** Every frame, in both directions, is at most this many bytes (the broker's CAP), newline included. */
|
|
24
|
-
export const FRAME_CAP_BYTES = 32 * 1024;
|
|
25
|
-
export const CONSUME_OPERATIONS = Object.freeze(["Build", "Dequeue", "Publish"]);
|
|
26
|
-
const MAX_BROKER_ANSWER_BYTES = 1024 * 1024;
|
|
27
|
-
const DIGEST = /^[0-9a-f]{64}$/;
|
|
28
|
-
const OID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
29
|
-
|
|
30
|
-
export class FreezeConsumerError extends Error {
|
|
31
|
-
constructor(code, message) { super(`[${code}] ${message}`); this.name = "FreezeConsumerError"; this.code = code; }
|
|
32
|
-
}
|
|
33
|
-
const refuse = (code, message) => { throw new FreezeConsumerError(code, message); };
|
|
34
|
-
const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
35
|
-
const sha256Hex = (data) => createHash("sha256").update(data).digest("hex");
|
|
36
|
-
|
|
37
|
-
/** The broker's text rule: 1 to 1024 bytes, no control character. */
|
|
38
|
-
export const isBrokerText = (value) => typeof value === "string" && value.length > 0 && Buffer.byteLength(value) <= 1024 && !/[\u0000-\u001f\u007f-\u009f]/.test(value);
|
|
39
|
-
export const isDigest = (value) => typeof value === "string" && DIGEST.test(value);
|
|
40
|
-
/** A full object id: 40 or 64 lower-case hex digits and not all zero (an absent object). */
|
|
41
|
-
export const isObjectId = (value) => typeof value === "string" && OID.test(value) && !/^0+$/.test(value);
|
|
42
|
-
|
|
43
|
-
function exactKeys(value, keys, where) {
|
|
44
|
-
if (!isRecord(value)) refuse("FREEZE_FRAME_INVALID", `${where} must be a JSON object`);
|
|
45
|
-
const extra = Object.keys(value).filter((key) => !keys.includes(key));
|
|
46
|
-
const missing = keys.filter((key) => !Object.hasOwn(value, key));
|
|
47
|
-
if (extra.length || missing.length) refuse("FREEZE_FRAME_INVALID", `${where}: unknown key(s) [${extra.join(", ")}] or missing key(s) [${missing.join(", ")}]`);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ---- 1. broker requests ---------------------------------------------------------------------------------------------------------
|
|
51
|
-
const requireId = (id) => { if (!isBrokerText(id)) refuse("FREEZE_REQUEST_INVALID", "the enrollment id must be non-empty text without control characters"); return id; };
|
|
52
|
-
const requireSource = (source) => { if (!isObjectId(source)) refuse("FREEZE_REQUEST_INVALID", "source must be an immutable full object id (40 or 64 lower-case hex digits), never a ref or a short id"); return source; };
|
|
53
|
-
const requireCandidate = (candidate) => { if (candidate !== undefined && candidate !== null && !isBrokerText(candidate)) refuse("FREEZE_REQUEST_INVALID", "candidate must be a prepared candidate key"); return candidate ?? null; };
|
|
54
|
-
|
|
55
|
-
/** The typed requests of `legion authority freeze broker`. Field names are the broker's (serde `op`, snake_case, unknown keys refused). */
|
|
56
|
-
export const brokerRequests = Object.freeze({
|
|
57
|
-
status: ({ id }) => ({ op: "status", id: requireId(id) }),
|
|
58
|
-
/** Diagnostic only: its answer carries `deliveryLease: false` and grants nothing a later upload may rely on. */
|
|
59
|
-
check: ({ id, source, candidate, operation }) => {
|
|
60
|
-
if (!["Build", "Dequeue", "Publish", "Push"].includes(operation)) refuse("FREEZE_REQUEST_INVALID", `operation must be one of Build, Dequeue, Publish, Push, not ${JSON.stringify(operation)}`);
|
|
61
|
-
return { op: "check", id: requireId(id), source: requireSource(source), candidate: requireCandidate(candidate), operation };
|
|
62
|
-
},
|
|
63
|
-
/** Managed delivery: the broker pushes this exact object to its enrolled URL and ref. The caller names no remote, ref or argv. */
|
|
64
|
-
push: ({ id, source, candidate }) => ({ op: "push", id: requireId(id), source: requireSource(source), candidate: requireCandidate(candidate) }),
|
|
65
|
-
/** A native owner transaction: the enrolled adapter, never a caller-chosen executable, prepares and performs the effect. */
|
|
66
|
-
consume: ({ id, operation, nativeRecordId }) => {
|
|
67
|
-
if (!CONSUME_OPERATIONS.includes(operation)) refuse("FREEZE_REQUEST_INVALID", `operation must be one of ${CONSUME_OPERATIONS.join(", ")}, not ${JSON.stringify(operation)}`);
|
|
68
|
-
if (!isBrokerText(nativeRecordId)) refuse("FREEZE_REQUEST_INVALID", "nativeRecordId must be non-empty text without control characters");
|
|
69
|
-
return { op: "consume", id: requireId(id), operation, native_record_id: nativeRecordId };
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
/** One broker answer: bounded JSON. A non-zero exit, a timeout, an unreadable answer or a failed spawn is a refusal; nothing is retried. */
|
|
74
|
-
export function callBroker(request, { launcher, timeoutMs = 120_000, run = spawnSync } = {}) {
|
|
75
|
-
if (!Array.isArray(launcher) || launcher.length === 0 || launcher.some((part) => typeof part !== "string" || part === "")) refuse("FREEZE_LAUNCHER_INVALID", "the restricted broker launcher must be a non-empty argv array (the restricted launcher or the authenticated SSH forced command; never admin-enroll)");
|
|
76
|
-
const body = JSON.stringify(request);
|
|
77
|
-
const result = run(launcher[0], launcher.slice(1), { input: body, encoding: "utf8", timeout: timeoutMs, maxBuffer: MAX_BROKER_ANSWER_BYTES, windowsHide: true });
|
|
78
|
-
if (result.error) refuse("FREEZE_BROKER_UNREACHABLE", `the broker could not be reached: ${result.error.message}; an unreachable broker denies`);
|
|
79
|
-
if (result.status !== 0) refuse("FREEZE_BROKER_DENIED", `the broker refused ${request.op}: ${String(result.stderr || result.stdout || `exit ${result.status}`).trim().slice(0, 500)}`);
|
|
80
|
-
let answer;
|
|
81
|
-
try { answer = JSON.parse(result.stdout); } catch { refuse("FREEZE_BROKER_ANSWER_INVALID", `the broker's ${request.op} answer is not JSON`); }
|
|
82
|
-
if (!isRecord(answer)) refuse("FREEZE_BROKER_ANSWER_INVALID", `the broker's ${request.op} answer is not an object`);
|
|
83
|
-
return answer;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* A `check` answer, read as what it is: a diagnostic. It is refused unless it says `allowed`, names the source that was asked about, and
|
|
88
|
-
* says `deliveryLease: false`; the returned value carries no field a later upload could present as permission.
|
|
89
|
-
*/
|
|
90
|
-
export function readCheckAnswer(answer, { source }) {
|
|
91
|
-
if (answer.status !== "allowed") refuse("FREEZE_CHECK_NOT_ALLOWED", `the broker did not allow ${source}: ${JSON.stringify(answer.status)}`);
|
|
92
|
-
if (answer.deliveryLease !== false) refuse("FREEZE_CHECK_LEASE", "a check answer must say deliveryLease false; an answer that does not is not the broker's check");
|
|
93
|
-
if (answer.source !== source) refuse("FREEZE_CHECK_SOURCE", `the broker checked ${answer.source}, not the requested ${source}`);
|
|
94
|
-
return { diagnostic: true, revision: answer.revision, sequence: answer.sequence, source: answer.source, closure: answer.closure };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** A `push` answer: delivered only when the broker says `pushed` for exactly the source that was sent. */
|
|
98
|
-
export function readPushAnswer(answer, { source }) {
|
|
99
|
-
if (answer.status !== "pushed") refuse("FREEZE_PUSH_NOT_DELIVERED", `the broker did not report a push of ${source}: ${JSON.stringify(answer.status)}`);
|
|
100
|
-
if (answer.source !== source) refuse("FREEZE_PUSH_SOURCE", `the broker pushed ${answer.source}, not the requested ${source}`);
|
|
101
|
-
return { source: answer.source, closure: answer.closure, revision: answer.revision, sequence: answer.sequence };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Broker-mediated push of one enrolled closure: the source is the immutable commit object, the destination is the enrollment's. */
|
|
105
|
-
export function pushThroughBroker({ id, source, candidate, launcher, timeoutMs, run }) {
|
|
106
|
-
const request = brokerRequests.push({ id, source, candidate });
|
|
107
|
-
return readPushAnswer(callBroker(request, { launcher, timeoutMs, run }), { source });
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ---- 2. the native consume protocol ---------------------------------------------------------------------------------------------
|
|
111
|
-
/** The PreparedEffect fields, in the order the broker serializes (and digests) them. */
|
|
112
|
-
export const PREPARED_EFFECT_KEYS = Object.freeze(["repository", "operation", "native_record_id", "source_oid", "candidate", "endpoint", "destination", "native_effect_sha256", "provenance_sha256", "artifact_sha256"]);
|
|
113
|
-
|
|
114
|
-
/** Validate a typed effect as the broker does and return it with its keys in the broker's order (optional fields as null). */
|
|
115
|
-
export function normalizeEffect(effect) {
|
|
116
|
-
if (!isRecord(effect)) refuse("FREEZE_EFFECT_INVALID", "the effect must be an object");
|
|
117
|
-
const unknown = Object.keys(effect).filter((key) => !PREPARED_EFFECT_KEYS.includes(key));
|
|
118
|
-
if (unknown.length) refuse("FREEZE_EFFECT_INVALID", `unknown effect key(s): ${unknown.join(", ")}`);
|
|
119
|
-
const out = {
|
|
120
|
-
repository: effect.repository, operation: effect.operation, native_record_id: effect.native_record_id, source_oid: effect.source_oid,
|
|
121
|
-
candidate: effect.candidate ?? null, endpoint: effect.endpoint, destination: effect.destination,
|
|
122
|
-
native_effect_sha256: effect.native_effect_sha256, provenance_sha256: effect.provenance_sha256, artifact_sha256: effect.artifact_sha256 ?? null,
|
|
123
|
-
};
|
|
124
|
-
const bad = (what) => refuse("FREEZE_EFFECT_INVALID", `effect ${what}`);
|
|
125
|
-
if (!isBrokerText(out.repository)) bad("repository must be text");
|
|
126
|
-
if (!CONSUME_OPERATIONS.includes(out.operation)) bad("operation must be Build, Dequeue or Publish");
|
|
127
|
-
if (!isBrokerText(out.native_record_id)) bad("native_record_id must be text");
|
|
128
|
-
if (!isObjectId(out.source_oid)) bad("source_oid must be a full immutable object id");
|
|
129
|
-
if (out.candidate !== null && !isDigest(out.candidate)) bad("candidate must be a sha256 hex digest when present");
|
|
130
|
-
if (!isBrokerText(out.endpoint) || !isBrokerText(out.destination)) bad("endpoint and destination must be text");
|
|
131
|
-
if (!isDigest(out.native_effect_sha256) || !isDigest(out.provenance_sha256)) bad("native_effect_sha256 and provenance_sha256 must be sha256 hex digests");
|
|
132
|
-
if (out.artifact_sha256 !== null && !isDigest(out.artifact_sha256)) bad("artifact_sha256 must be a sha256 hex digest when present");
|
|
133
|
-
if (out.operation === "Publish" && out.artifact_sha256 === null) bad("a Publish effect must carry artifact_sha256");
|
|
134
|
-
return out;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** The compact serialization the broker digests: the effect's fields in struct order, optional fields as null. */
|
|
138
|
-
export const serializeEffect = (effect) => JSON.stringify(normalizeEffect(effect));
|
|
139
|
-
/** The sha256 the broker computes over its own serialization and sends in `commit`; a mismatch means the adapter prepared something else. */
|
|
140
|
-
export const effectDigest = (effect) => sha256Hex(serializeEffect(effect));
|
|
141
|
-
|
|
142
|
-
/** One frame as a line: compact JSON and a newline, never over the cap. */
|
|
143
|
-
export function encodeFrame(frame) {
|
|
144
|
-
const text = `${JSON.stringify(frame)}\n`;
|
|
145
|
-
if (Buffer.byteLength(text) > FRAME_CAP_BYTES) refuse("FREEZE_FRAME_TOO_LARGE", `a frame is at most ${FRAME_CAP_BYTES} bytes`);
|
|
146
|
-
return text;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function decodeFrame(line) {
|
|
150
|
-
if (typeof line !== "string" || Buffer.byteLength(line) > FRAME_CAP_BYTES || !line.endsWith("\n")) refuse("FREEZE_FRAME_INVALID", `a frame is one newline-terminated line of at most ${FRAME_CAP_BYTES} bytes`);
|
|
151
|
-
let frame;
|
|
152
|
-
try { frame = JSON.parse(line); } catch { refuse("FREEZE_FRAME_INVALID", "a frame is not JSON"); }
|
|
153
|
-
if (!isRecord(frame)) refuse("FREEZE_FRAME_INVALID", "a frame is not an object");
|
|
154
|
-
if (frame.protocol !== CONSUME_PROTOCOL) refuse("FREEZE_FRAME_INVALID", `frame protocol must be ${CONSUME_PROTOCOL}`);
|
|
155
|
-
if (frame.phase === "prepare") exactKeys(frame, ["phase", "protocol", "preparation_nonce", "operation", "native_record_id"], "prepare frame");
|
|
156
|
-
else if (frame.phase === "commit") exactKeys(frame, ["phase", "protocol", "transaction_nonce", "prepared_sha256"], "commit frame");
|
|
157
|
-
else refuse("FREEZE_FRAME_INVALID", `unexpected frame phase ${JSON.stringify(frame.phase)}`);
|
|
158
|
-
return frame;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* One consume transaction, as the native owner sees the broker's pipe. The owner supplies:
|
|
163
|
-
* operation, endpoint, destination the adapter's enrolled values (the broker rejects an effect that differs);
|
|
164
|
-
* prepare({ nativeRecordId }) resolves the authoritative record, takes its lock and returns the typed effect, performing no effect;
|
|
165
|
-
* commit(effect) performs the actual effect of exactly the prepared effect, and returns when it has finished.
|
|
166
|
-
* `receive(line)` takes each broker frame in order and returns the line to write back. The order is prepare, then commit; anything else
|
|
167
|
-
* (a second prepare, a commit first, a wrong nonce, an unknown key, a digest that is not the prepared one) throws and ends the session,
|
|
168
|
-
* and a session never answers after it failed. `complete` is returned only after `commit(effect)` has returned.
|
|
169
|
-
*/
|
|
170
|
-
export function createConsumeSession({ operation, endpoint, destination, prepare, commit }) {
|
|
171
|
-
if (!CONSUME_OPERATIONS.includes(operation)) refuse("FREEZE_SESSION_INVALID", "operation must be Build, Dequeue or Publish");
|
|
172
|
-
if (!isBrokerText(endpoint) || !isBrokerText(destination)) refuse("FREEZE_SESSION_INVALID", "endpoint and destination must be the adapter's enrolled text");
|
|
173
|
-
let step = "prepare";
|
|
174
|
-
let preparationNonce = null;
|
|
175
|
-
let prepared = null;
|
|
176
|
-
let digest = null;
|
|
177
|
-
const fail = (code, message) => { step = "failed"; throw new FreezeConsumerError(code, message); };
|
|
178
|
-
return {
|
|
179
|
-
get step() { return step; },
|
|
180
|
-
async receive(line) {
|
|
181
|
-
if (step === "failed" || step === "done") fail("FREEZE_SESSION_CLOSED", `the transaction is ${step}; no further frame is answered`);
|
|
182
|
-
let frame;
|
|
183
|
-
try { frame = decodeFrame(line); } catch (error) { step = "failed"; throw error; }
|
|
184
|
-
if (step === "prepare") {
|
|
185
|
-
if (frame.phase !== "prepare") fail("FREEZE_SESSION_ORDER", "the first frame must be prepare");
|
|
186
|
-
if (frame.operation !== operation) fail("FREEZE_SESSION_OPERATION", `the broker asked for ${frame.operation}, this adapter is ${operation}`);
|
|
187
|
-
if (!isBrokerText(frame.preparation_nonce) || !isBrokerText(frame.native_record_id)) fail("FREEZE_FRAME_INVALID", "prepare carries no nonce or record id");
|
|
188
|
-
const effect = normalizeEffect(await prepare({ nativeRecordId: frame.native_record_id }));
|
|
189
|
-
if (effect.operation !== operation || effect.native_record_id !== frame.native_record_id || effect.endpoint !== endpoint || effect.destination !== destination) {
|
|
190
|
-
fail("FREEZE_SESSION_BINDING", "the prepared effect names another operation, record, endpoint or destination than the transaction");
|
|
191
|
-
}
|
|
192
|
-
preparationNonce = frame.preparation_nonce;
|
|
193
|
-
prepared = effect;
|
|
194
|
-
digest = effectDigest(effect);
|
|
195
|
-
step = "commit";
|
|
196
|
-
return encodeFrame({ phase: "prepared", protocol: CONSUME_PROTOCOL, preparation_nonce: preparationNonce, effect });
|
|
197
|
-
}
|
|
198
|
-
if (frame.phase !== "commit") fail("FREEZE_SESSION_ORDER", "the second frame must be commit");
|
|
199
|
-
if (frame.prepared_sha256 !== digest) fail("FREEZE_SESSION_DIGEST", "the broker's commit digest is not the digest of the prepared effect; nothing is committed");
|
|
200
|
-
if (!isBrokerText(frame.transaction_nonce)) fail("FREEZE_FRAME_INVALID", "commit carries no transaction nonce");
|
|
201
|
-
step = "committing";
|
|
202
|
-
try { await commit(prepared); } catch (error) { step = "failed"; throw error; }
|
|
203
|
-
step = "done";
|
|
204
|
-
return encodeFrame({ phase: "complete", protocol: CONSUME_PROTOCOL, transaction_nonce: frame.transaction_nonce, prepared_sha256: digest });
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ---- 3. the publication binding -------------------------------------------------------------------------------------------------
|
|
210
|
-
const stable = (value) => (Array.isArray(value) ? `[${value.map(stable).join(",")}]`
|
|
211
|
-
: isRecord(value) ? `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stable(value[key])}`).join(",")}}`
|
|
212
|
-
: JSON.stringify(value) ?? "null");
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* The typed effect for publishing one sealed artifact. `release` is what verifyPublicationRelease returned (the sealed manifest, already
|
|
216
|
-
* checked against its signing, notarization and ownership evidence, and `artifacts`, each read once and hash-checked against the seal);
|
|
217
|
-
* `fileName` names the artifact inside it. The source is the sealed manifest's commit, so the broker authorizes the source whose
|
|
218
|
-
* qualification produced these bytes, and artifact_sha256 is the digest of the bytes this process holds and will upload. Nothing here is
|
|
219
|
-
* taken from the caller except the transaction's names; a caller-supplied digest or commit cannot replace the sealed one.
|
|
220
|
-
*/
|
|
221
|
-
export function buildPublishEffect({ release, fileName, repository, nativeRecordId, endpoint, destination, candidate = null }) {
|
|
222
|
-
if (!isRecord(release?.manifest) || !(release.artifacts instanceof Map)) refuse("FREEZE_PUBLISH_UNVERIFIED", "the effect is built from a verified sealed release (verifyPublicationRelease), not from caller values");
|
|
223
|
-
const { manifest } = release;
|
|
224
|
-
const entry = (manifest.files ?? []).find((item) => item?.name === fileName);
|
|
225
|
-
const artifact = release.artifacts.get(fileName);
|
|
226
|
-
if (!entry || !artifact) refuse("FREEZE_PUBLISH_ARTIFACT", `${JSON.stringify(fileName)} is not an artifact of the sealed release`);
|
|
227
|
-
if (artifact.sha256 !== entry.sha256 || !isDigest(artifact.sha256)) refuse("FREEZE_PUBLISH_ARTIFACT", `the verified bytes of ${fileName} do not carry the sealed digest`);
|
|
228
|
-
if (!isObjectId(manifest.commit)) refuse("FREEZE_PUBLISH_SOURCE", "the sealed release names no full commit");
|
|
229
|
-
// The qualification provenance: the sealed manifest's source, ownership evidence, signing policy and every sealed file's identity.
|
|
230
|
-
const provenance = {
|
|
231
|
-
commit: manifest.commit, app: manifest.app ?? null, version: manifest.version ?? null, platform: manifest.platform ?? null, releaseId: manifest.releaseId ?? null,
|
|
232
|
-
ownershipEvidence: manifest.ownershipEvidence ?? null, configSha256: manifest.signing?.configSha256 ?? null,
|
|
233
|
-
signingReceipts: (manifest.signing?.receipts ?? []).map((r) => ({ file: r.file, sha256: r.sha256 })),
|
|
234
|
-
files: (manifest.files ?? []).map((f) => ({ name: f.name, sha256: f.sha256, sizeBytes: f.sizeBytes })),
|
|
235
|
-
};
|
|
236
|
-
const nativeEffect = { operation: "Publish", repository, nativeRecordId, source: manifest.commit, artifact: artifact.sha256, endpoint, destination };
|
|
237
|
-
return normalizeEffect({
|
|
238
|
-
repository, operation: "Publish", native_record_id: nativeRecordId, source_oid: manifest.commit, candidate, endpoint, destination,
|
|
239
|
-
native_effect_sha256: sha256Hex(stable(nativeEffect)), provenance_sha256: sha256Hex(stable(provenance)), artifact_sha256: artifact.sha256,
|
|
240
|
-
});
|
|
241
|
-
}
|
package/linux-qualifier.mjs
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// GB-29 (GATE-CONTRACT GC-L02; P-L, A-L; E4): the private Linux qualifier, only where a manifest DECLARES a Linux target, and the pending candidate that waits for it.
|
|
2
|
-
//
|
|
3
|
-
// A private app qualifies on Mac or Dell, never on a mandatory GitHub CI path. When its manifest declares a Linux deliverable (`targets.linux`), the exact sealed Linux bytes the Linux origin
|
|
4
|
-
// produced are qualified in a COMPATIBLE Linux runtime (OS, architecture, libc) hosted by the Mac or the Dell: they are not rebuilt there. With no compatible runtime the candidate WAITS:
|
|
5
|
-
// a pending record keeps the candidate identity, the exact sealed digest and the pinned policy, nothing is discarded, and a later qualification resumes it only when it binds the same
|
|
6
|
-
// candidate, the same bytes, the same policy digest and every expected check passed. Nothing declared, nothing created: an app that declares no Linux target has no Linux artifact or qualification.
|
|
7
|
-
import { createHash } from "node:crypto";
|
|
8
|
-
|
|
9
|
-
export const PENDING_SCHEMA = "rightkit.pending-linux-candidate/1";
|
|
10
|
-
export const LINUX_QUALIFIER_REFUSED = "RK_LINUX_QUALIFIER_REFUSED";
|
|
11
|
-
const SHA256 = /^[0-9a-f]{64}$/;
|
|
12
|
-
const ARCHES = new Set(["x86_64", "aarch64"]);
|
|
13
|
-
const HOSTS = ["dell", "mac"];
|
|
14
|
-
const refuse = (message) => { throw Object.assign(new Error(`${LINUX_QUALIFIER_REFUSED}: ${message}`), { code: LINUX_QUALIFIER_REFUSED }); };
|
|
15
|
-
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16
|
-
|
|
17
|
-
/** The Linux targets a product manifest declares (`targets.linux`: one object or a list, each `{ arch, libc? }`); none when it declares none. Never inferred from another target. */
|
|
18
|
-
export function declaredLinuxTargets(config) {
|
|
19
|
-
const declared = config?.targets?.linux;
|
|
20
|
-
if (declared === undefined || declared === null) return [];
|
|
21
|
-
const list = Array.isArray(declared) ? declared : [declared];
|
|
22
|
-
return list.map((target, i) => {
|
|
23
|
-
if (!isObject(target) || !ARCHES.has(target.arch) || (target.libc !== undefined && !["glibc", "musl"].includes(target.libc))) refuse(`targets.linux[${i}] must be { arch: x86_64|aarch64, libc?: glibc|musl }`);
|
|
24
|
-
return { os: "linux", arch: target.arch, ...(target.libc ? { libc: target.libc } : {}) };
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Whether one hosted runtime can qualify one declared target: Linux, the same architecture, the same libc when the target names one, and available now. */
|
|
29
|
-
export function runtimeCompatible(runtime, target) {
|
|
30
|
-
return isObject(runtime) && runtime.os === "linux" && runtime.available === true && runtime.arch === target.arch && (target.libc === undefined || runtime.libc === target.libc);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The qualifier for each declared target, or the reason it waits. `hosts` is the Mac and Dell's hosted Linux runtimes `[{ host: "dell"|"mac", runtime: { kind, os, arch, libc?, available } }]`.
|
|
35
|
-
* `{ state: "NOT_APPLICABLE" }` when nothing is declared; `{ state: "QUALIFIER", assignments }` when every declared target has a compatible hosted runtime (the Dell first, then the Mac, so the
|
|
36
|
-
* choice is stable); `{ state: "WAITING", assignments, missing }` otherwise. Never CI, never a rebuild.
|
|
37
|
-
*/
|
|
38
|
-
export function selectLinuxQualifier({ config, hosts }) {
|
|
39
|
-
const targets = declaredLinuxTargets(config);
|
|
40
|
-
if (targets.length === 0) return { state: "NOT_APPLICABLE", reason: "the manifest declares no Linux target: no Linux artifact or qualification is created" };
|
|
41
|
-
const ordered = [...(hosts ?? [])].filter((h) => HOSTS.includes(h?.host)).sort((a, b) => HOSTS.indexOf(a.host) - HOSTS.indexOf(b.host));
|
|
42
|
-
const assignments = []; const missing = [];
|
|
43
|
-
for (const target of targets) {
|
|
44
|
-
const hit = ordered.find((h) => runtimeCompatible(h.runtime, target));
|
|
45
|
-
if (hit) assignments.push({ target, host: hit.host, runtime: { kind: hit.runtime.kind, os: "linux", arch: hit.runtime.arch, ...(hit.runtime.libc ? { libc: hit.runtime.libc } : {}) } });
|
|
46
|
-
else missing.push({ target, reason: ordered.length ? `no hosted Linux runtime of ${ordered.map((h) => `${h.host}:${h.runtime?.arch ?? "?"}${h.runtime?.available === true ? "" : " (unavailable)"}`).join(", ")} is compatible with ${target.arch}${target.libc ? `/${target.libc}` : ""}` : "no Mac or Dell hosted Linux runtime is registered" });
|
|
47
|
-
}
|
|
48
|
-
return missing.length ? { state: "WAITING", assignments, missing } : { state: "QUALIFIER", assignments };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const digest = (text) => createHash("sha256").update(text).digest("hex");
|
|
52
|
-
|
|
53
|
-
/** The pending record of a Linux candidate that has no qualifier yet: it keeps everything a later qualification must bind to, and discards nothing. */
|
|
54
|
-
export function pendingCandidate({ candidate, artifactSha256, target, policyDigest, missing }) {
|
|
55
|
-
if (!SHA256.test(candidate ?? "") || !SHA256.test(artifactSha256 ?? "") || !SHA256.test(policyDigest ?? "")) refuse("a pending candidate names its candidate identity, sealed artifact digest and pinned policy digest");
|
|
56
|
-
return { schema: PENDING_SCHEMA, state: "WAITING", candidate, artifactSha256, target, policyDigest, missing: missing ?? [] };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Resume a pending candidate from a qualification run. Refuses (the pending record stays WAITING, unchanged) unless the evidence binds the same candidate and the exact sealed bytes, was
|
|
61
|
-
* produced by a runtime compatible with the declared target on a Mac or Dell host, ran under the policy digest pinned before the run, rebuilt nothing, and executed every expected check with a
|
|
62
|
-
* pass: a missing, skipped or failed check, an empty suite or a changed policy fails.
|
|
63
|
-
*/
|
|
64
|
-
export function resumeCandidate(pending, evidence) {
|
|
65
|
-
if (!isObject(pending) || pending.schema !== PENDING_SCHEMA || pending.state !== "WAITING") refuse("only a pending (WAITING) Linux candidate can be resumed");
|
|
66
|
-
if (!isObject(evidence)) refuse("the qualification evidence is not an object");
|
|
67
|
-
if (evidence.candidate !== pending.candidate) refuse("the evidence is for another candidate");
|
|
68
|
-
if (evidence.artifactSha256 !== pending.artifactSha256) refuse(`the evidence qualified ${String(evidence.artifactSha256).slice(0, 12)}, not the sealed ${pending.artifactSha256.slice(0, 12)}: the exact sealed bytes are qualified, never a rebuild`);
|
|
69
|
-
if (evidence.rebuilt === true) refuse("the qualifier rebuilt the bytes: sealed Linux bytes are qualified unchanged");
|
|
70
|
-
if (!HOSTS.includes(evidence.host)) refuse(`the qualifier host ${JSON.stringify(evidence.host)} is not the Mac or the Dell`);
|
|
71
|
-
if (!runtimeCompatible({ ...evidence.runtime, available: true }, pending.target)) refuse("the qualifier's runtime is not compatible with the declared target");
|
|
72
|
-
if (evidence.policyDigest !== pending.policyDigest) refuse("the qualification ran under another policy than the one pinned before the run");
|
|
73
|
-
const expected = evidence.expectedChecks; const executed = evidence.checks;
|
|
74
|
-
if (!Array.isArray(expected) || expected.length === 0) refuse("an empty mandatory suite is never a qualification");
|
|
75
|
-
if (!Array.isArray(executed)) refuse("the evidence carries no executed checks");
|
|
76
|
-
for (const id of expected) {
|
|
77
|
-
const run = executed.filter((c) => c?.id === id);
|
|
78
|
-
if (run.length !== 1) refuse(`expected check ${id} was ${run.length === 0 ? "not executed" : "executed more than once"}`);
|
|
79
|
-
if (run[0].result !== "pass") refuse(`check ${id} is ${run[0].result}`);
|
|
80
|
-
}
|
|
81
|
-
if (executed.some((c) => !expected.includes(c?.id))) refuse("the evidence carries a check the pinned policy does not expect");
|
|
82
|
-
return { state: "QUALIFIED", candidate: pending.candidate, artifactSha256: pending.artifactSha256, host: evidence.host, evidenceDigest: digest(JSON.stringify(evidence)) };
|
|
83
|
-
}
|
package/native-tool-planning.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// GB-51 (GATE Mac/Dell broker-only; commit output identity): the native build tools an app config declares (xcodegen and xcodebuild for iOS, Gradle for Android, CMake for a sidecar)
|
|
2
|
-
// each have a constrained broker adapter (native-adapters.mjs: capability `adapter:rightkit-xcodegen|xcodebuild|gradle|cmake`) and a launch route onto it (build-launch.mjs). This module decides at PLANNING, from the
|
|
3
|
-
// commit's own config, whether a stage that uses them can run, so the route (and `--route`) refuses before anything builds, naming the missing capability or the unsupported command:
|
|
4
|
-
// - a tool whose adapter capability the broker does not advertise (or whose capability query failed) is refused naming the missing capability (one of the four above);
|
|
5
|
-
// - a declared build step (a dev target's `build` list) whose argv the tool's registration would refuse (an output override, an unregistered flag, a release task, a signing identity) is
|
|
6
|
-
// refused naming the capability and the reason: an unsupported custom command never reaches the broker;
|
|
7
|
-
// - a Gradle step needs the committed wrapper's distribution pinned (`distributionSha256Sum`), the adapter's pinned executable identity.
|
|
8
|
-
// There is no direct-session exemption: a tool leaves the refusal only when its adapter is advertised.
|
|
9
|
-
import path from "node:path";
|
|
10
|
-
import { NATIVE_ADAPTERS, gradleWrapperPinProblem, nativeToolLaunch } from "./native-adapters.mjs";
|
|
11
|
-
import { validateAndroidNdk } from "./android-ndk.mjs";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* GB-62: `cargo ndk` is a pinned EXTERNAL tool: RustRight's `externalCommands` entry (shim cargo, command ndk, a toolId and the tool's digest; policy BUILD). The broker advertises it
|
|
15
|
-
* as this capability; a stage that builds JNI libraries is planned only when it is advertised.
|
|
16
|
-
*/
|
|
17
|
-
export const NDK_EXTERNAL_CAPABILITY = "external:cargo-ndk";
|
|
18
|
-
/** The ABIs RustRight's ndk grammar accepts (`parse_ndk_argv`: arm64-v8a, x86_64); the gate's own validator also knows armeabi-v7a and x86, which the broker would refuse. */
|
|
19
|
-
export const BROKER_NDK_ABIS = Object.freeze(["arm64-v8a", "x86_64"]);
|
|
20
|
-
|
|
21
|
-
/** The tools that run through a constrained adapter, by the capability name a refusal reports (xcodegen, xcodebuild, gradle and its wrapper, cmake). */
|
|
22
|
-
export const NATIVE_TOOLS_WITHOUT_ADAPTER = Object.freeze({ xcodegen: NATIVE_ADAPTERS.xcodegen.capability, xcodebuild: NATIVE_ADAPTERS.xcodebuild.capability, gradle: NATIVE_ADAPTERS.gradle.capability, gradlew: NATIVE_ADAPTERS.gradle.capability, cmake: NATIVE_ADAPTERS.cmake.capability });
|
|
23
|
-
|
|
24
|
-
const base = (command) => path.basename(String(command ?? "").replaceAll("\\", "/")).replace(/\.(exe|cmd|bat)$/i, "").toLowerCase();
|
|
25
|
-
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The native-tool uses of a stage, `[{ tool, capability, where }]`, from the commit's own config. `devPlatform` is the dev target's platform for a dev or
|
|
29
|
-
* test run (its declared build steps and, for iOS, the xcodegen/xcodebuild steps the gate itself generates are in play); a `cmake` sidecar is in play for
|
|
30
|
-
* every stage that stages sidecars.
|
|
31
|
-
*/
|
|
32
|
-
export function nativeToolUses({ config, to, devPlatform = null, platform = null }) {
|
|
33
|
-
const uses = [];
|
|
34
|
-
const add = (command, where, args = null, cwd = ".") => { const tool = base(command); if (Object.hasOwn(NATIVE_TOOLS_WITHOUT_ADAPTER, tool)) uses.push({ tool, capability: NATIVE_TOOLS_WITHOUT_ADAPTER[tool], where, ...(args ? { args, cwd } : {}) }); };
|
|
35
|
-
if (!isObject(config)) return uses;
|
|
36
|
-
const addNdk = (ndk, where, kind) => { if (ndk !== undefined) uses.push({ tool: "cargo-ndk", capability: NDK_EXTERNAL_CAPABILITY, where, ndk, kind }); };
|
|
37
|
-
if ((to === "dev" || to === "test") && (platform ?? devPlatform) === "android") addNdk(config.development?.targets?.android?.ndk, "development.targets.android.ndk", "dev");
|
|
38
|
-
if ((to === "package" || to === "release") && (platform ?? devPlatform) === "android") addNdk(config.targets?.android?.ndk, "targets.android.ndk", "release");
|
|
39
|
-
if (to === "dev" || to === "test") {
|
|
40
|
-
const target = config.development?.targets?.[devPlatform];
|
|
41
|
-
if (isObject(target)) {
|
|
42
|
-
for (const [i, step] of (Array.isArray(target.build) ? target.build : []).entries()) if (isObject(step)) add(step.cmd, `development.targets.${devPlatform}.build[${i}]`, Array.isArray(step.args) ? step.args.map(String) : [], typeof step.cwd === "string" ? step.cwd : ".");
|
|
43
|
-
if (devPlatform === "ios") {
|
|
44
|
-
if (target.projectSpec) add("xcodegen", `development.targets.ios.projectSpec ${target.projectSpec} (xcodegen generate)`);
|
|
45
|
-
add("xcodebuild", "development.targets.ios (xcodebuild build)");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
for (const [i, entry] of (Array.isArray(config.sidecars?.sidecars) ? config.sidecars.sidecars : Array.isArray(config.sidecars) ? config.sidecars : []).entries()) {
|
|
50
|
-
if (isObject(entry) && entry.kind === "cmake") add("cmake", `sidecars[${i}] ${entry.name ?? ""} (kind cmake)`);
|
|
51
|
-
}
|
|
52
|
-
return uses;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The refusal message for a stage's native-tool uses, or null. `capabilities` is the broker's advertised state (`{ ok, capabilities }` from `rustright doctor --json`, or null when it was not
|
|
57
|
-
* queried: every use is then unsupported). `readFile(relative)` reads the COMMIT's bytes (a Gradle wrapper's properties).
|
|
58
|
-
*/
|
|
59
|
-
export function nativeToolRefusal(uses, { capabilities = null, readFile = null, listFiles = null } = {}) {
|
|
60
|
-
if (!uses.length) return null;
|
|
61
|
-
const advertised = capabilities?.ok === true && Array.isArray(capabilities.capabilities) ? new Set(capabilities.capabilities) : new Set();
|
|
62
|
-
const problems = [];
|
|
63
|
-
for (const use of uses) {
|
|
64
|
-
if (!advertised.has(use.capability)) { problems.push(`${use.tool} at ${use.where}: the broker does not advertise ${use.capability}${capabilities?.ok === true ? "" : ` (${capabilities?.problem ?? "its capabilities were not queried"})`}`); continue; }
|
|
65
|
-
if (use.tool === "cargo-ndk") { const problem = ndkBlockProblem(use, listFiles); if (problem) problems.push(`${use.tool} at ${use.where}: ${problem}`); continue; }
|
|
66
|
-
if (use.args) {
|
|
67
|
-
const launch = nativeToolLaunch(use.tool === "gradlew" ? "gradle" : use.tool, use.args, { cwd: path.posix.resolve("/", use.cwd ?? ".") });
|
|
68
|
-
if (launch.refusal) { problems.push(`${use.tool} at ${use.where}: ${launch.refusal.message}`); continue; }
|
|
69
|
-
}
|
|
70
|
-
if ((use.tool === "gradle" || use.tool === "gradlew") && typeof readFile === "function") {
|
|
71
|
-
const pin = gradleWrapperPinProblem(readFile, use.cwd ?? ".");
|
|
72
|
-
if (pin) problems.push(`${use.tool} at ${use.where}: ${pin}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!problems.length) return null;
|
|
76
|
-
return `${problems.join("; ")} (a broker-managed host never runs a build tool around the broker, rightkit#1241; the capability names are in docs/GATE-CONTRACT.md "Native tool adapters"); nothing ran`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* GB-62: the reason a declared ndk block cannot run through the pinned cargo-ndk registration, or null. The gate's own validator names a malformed block; the ABIs must be ones RustRight's
|
|
81
|
-
* ndk grammar accepts; and `jniLibs`, the controlled generated output (emptied before every build and bound as the run's output ledger), must hold no committed file.
|
|
82
|
-
*/
|
|
83
|
-
function ndkBlockProblem(use, listFiles) {
|
|
84
|
-
let ndk;
|
|
85
|
-
try { ndk = validateAndroidNdk(use.ndk, { root: "/app", kind: use.kind }); } catch (error) { return error.message; }
|
|
86
|
-
const refused = ndk.abis.filter((abi) => !BROKER_NDK_ABIS.includes(abi));
|
|
87
|
-
if (refused.length) return `ndk.abis names ${refused.join(", ")}, which the registered cargo-ndk grammar refuses (only ${BROKER_NDK_ABIS.join(", ")}; ${NDK_EXTERNAL_CAPABILITY})`;
|
|
88
|
-
if (typeof listFiles === "function") {
|
|
89
|
-
let tracked = null;
|
|
90
|
-
try { tracked = listFiles(ndk.jniLibsRelative); } catch { tracked = null; }
|
|
91
|
-
if (Array.isArray(tracked) && tracked.length) return `ndk.jniLibs ${ndk.jniLibsRelative} commits ${tracked.length} file(s) (${tracked.slice(0, 3).join(", ")}): it is the generated output directory (emptied before every build) and must hold no committed file`;
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
package/owner-process-proof.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// rightkit#1511: prints the process-only proof of one dead owner record as JSON (build-ownership.mjs proveOwnerProcessesGone). Writes nothing.
|
|
3
|
-
// usage: node owner-process-proof.mjs <managed root>/build-ownership/<key>/owner.json
|
|
4
|
-
// exit 0 with the proof on stdout; exit 2 with the reason on stderr when a process is still live or unknown; exit 64 on bad usage.
|
|
5
|
-
import { proveOwnerProcessesGone } from "./build-ownership.mjs";
|
|
6
|
-
|
|
7
|
-
const file = process.argv[2];
|
|
8
|
-
if (!file || process.argv.length !== 3) { process.stderr.write("usage: owner-process-proof.mjs <owner.json>\n"); process.exit(64); }
|
|
9
|
-
try {
|
|
10
|
-
process.stdout.write(`${JSON.stringify(proveOwnerProcessesGone({ file }), null, 2)}\n`);
|
|
11
|
-
} catch (e) {
|
|
12
|
-
process.stderr.write(`${e.message}\n`);
|
|
13
|
-
process.exit(2);
|
|
14
|
-
}
|