From a22e1facb7a91420bbe9976e60a173270f542903 Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Sun, 29 Nov 2026 04:12:39 +0100 Subject: [PATCH 1/6] Add offline exact-subject gate receipt consistency verifier (no promotion) --- scripts/hardware_review.py | 139 +++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 scripts/hardware_review.py diff --git a/scripts/hardware_review.py b/scripts/hardware_review.py new file mode 100644 index 00000000..c5db878a --- /dev/null +++ b/scripts/hardware_review.py @@ -0,0 +1,139 @@ +"""Offline hardware gate receipt consistency check; never authorizes publication. + +The review ledger digest must come from an independent trusted authority. +A digest supplied by the submitter is NOT a trust anchor. This tool checks +consistency only: it neither verifies CI via GitHub nor establishes reviewer +identity, security clearance, or authority to release. Publication stays closed. +""" +import argparse +import hashlib +import hmac +import json +import re +from pathlib import Path + +GATES = frozenset({ + "immutable_images", "wine_recovery_soak", "layer_state_restore", + "real_app_game", "installer_replay", "control_accessibility", + "security_supply_chain", "hardware_test_manifest", +}) +LIMIT = 65536 + + +class InvalidReview(ValueError): + """A fixed, public-safe error category.""" + + +def require(condition, reason): + if not condition: + raise InvalidReview(reason) + + +def unique_object(pairs): + result = {} + for key, value in pairs: + require(key not in result, "duplicate_json_key") + result[key] = value + return result + + +def read_json(path): + with Path(path).open("rb") as stream: + data = stream.read(LIMIT + 1) + require(len(data) <= LIMIT, "oversize") + return data + + +def decode(data): + require(len(data) <= LIMIT, "oversize") + return json.loads(data, object_pairs_hook=unique_object) + + +def digest(data): + return "sha256:" + hashlib.sha256(data).hexdigest() + + +def is_digest(value): + return isinstance(value, str) and re.fullmatch(r"sha256:[0-9a-f]{64}", value) + + +def exact_keys(value, keys): + return isinstance(value, dict) and set(value) == set(keys) + + +def positive_int(value): + return type(value) is int and value > 0 + + +def validate(ledger_bytes, receipts_bytes, trusted_ledger_digest, source, + runtime, instrumented, app_manifest): + require(is_digest(trusted_ledger_digest), "missing_review_anchor") + require(hmac.compare_digest(digest(ledger_bytes), trusted_ledger_digest), + "untrusted_review_ledger") + require(isinstance(source, str) and re.fullmatch(r"[0-9a-f]{40}", source), + "invalid_source") + require(all(is_digest(item) for item in (runtime, instrumented, app_manifest)) + and runtime != instrumented, "invalid_subject") + subjects = {"runtime_image_id": runtime, "instrumented_image_id": instrumented, + "app_manifest_sha256": app_manifest} + ledger = decode(ledger_bytes) + require(exact_keys(ledger, {"schema", "source", "subjects", "gate_receipts", + "security_review"}), "invalid_ledger") + require(ledger["schema"] == "winebot.hardware-review-ledger/1", "schema") + require(ledger["source"] == source and ledger["subjects"] == subjects, + "stale_review") + require(ledger["security_review"] == "approved", "security_hold") + approved = ledger["gate_receipts"] + require(exact_keys(approved, GATES) and all(is_digest(v) for v in approved.values()), + "incomplete_review") + require(len(set(approved.values())) == len(GATES), "duplicate_review_receipt") + receipts = decode(receipts_bytes) + require(isinstance(receipts, list) and len(receipts) == len(GATES), + "incomplete_receipts") + seen = set() + for record in receipts: + require(exact_keys(record, {"schema", "gate", "source", "subjects", "result", + "evidence_class", "run_id", "job_id", + "evidence_sha256"}), "invalid_receipt") + gate = record["gate"] + require(isinstance(gate, str) and gate in GATES and gate not in seen, + "unknown_or_duplicate_gate") + seen.add(gate) + require(record["schema"] == "winebot.hardware-gate-receipt/1", "schema") + require(record["source"] == source and record["subjects"] == subjects, + "stale_receipt") + require(record["result"] == "pass", "gate_not_passed") + require(record["evidence_class"] in ("PRODUCT_QUALIFICATION", + "RELEASE_QUALIFICATION"), + "insufficient_evidence_class") + require(positive_int(record["run_id"]) and positive_int(record["job_id"]) + and is_digest(record["evidence_sha256"]), "invalid_evidence_identity") + canonical = json.dumps(record, sort_keys=True, separators=(",", ":"), + ensure_ascii=True).encode("ascii") + require(hmac.compare_digest(digest(canonical), approved[gate]), + "unreviewed_receipt") + require(seen == GATES, "incomplete_receipts") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + for name in ("ledger", "receipts", "trusted-ledger-digest", "source", + "runtime", "instrumented", "app-manifest"): + parser.add_argument("--" + name, required=True) + args = parser.parse_args() + try: + validate(read_json(args.ledger), read_json(args.receipts), + args.trusted_ledger_digest, args.source, args.runtime, + args.instrumented, args.app_manifest) + except InvalidReview as exc: + print("HARDWARE_REVIEW_CONSISTENCY result=fail reason=" + str(exc)) + return 1 + except (OSError, ValueError, TypeError, RecursionError): + print("HARDWARE_REVIEW_CONSISTENCY result=fail reason=invalid_input") + return 1 + print("HARDWARE_REVIEW_CONSISTENCY result=pass publication=blocked") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From eed79a82c6fbc7c7c4c45fe07b25164b62d94bbd Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Sun, 29 Nov 2026 04:12:56 +0100 Subject: [PATCH 2/6] Exercise missing, stale, duplicate, untrusted and security-held review fixtures --- scripts/test_hardware_review.py | 105 ++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 scripts/test_hardware_review.py diff --git a/scripts/test_hardware_review.py b/scripts/test_hardware_review.py new file mode 100644 index 00000000..0756348c --- /dev/null +++ b/scripts/test_hardware_review.py @@ -0,0 +1,105 @@ +"""Synthetic negative and positive consistency fixtures, not product proof.""" +import copy +import json +import unittest + +import hardware_review as review + + +def encode(value): + return json.dumps(value, sort_keys=True, separators=(",", ":")).encode("ascii") + + +class ReviewTest(unittest.TestCase): + def setUp(self): + self.source = "a" * 40 + self.runtime = "sha256:" + "b" * 64 + self.instrumented = "sha256:" + "c" * 64 + self.app = "sha256:" + "d" * 64 + self.subjects = {"runtime_image_id": self.runtime, + "instrumented_image_id": self.instrumented, + "app_manifest_sha256": self.app} + self.receipts = [ + {"schema": "winebot.hardware-gate-receipt/1", "gate": gate, + "source": self.source, "subjects": copy.deepcopy(self.subjects), + "result": "pass", "evidence_class": "PRODUCT_QUALIFICATION", + "run_id": i + 1, "job_id": i + 101, "evidence_sha256": self.app} + for i, gate in enumerate(sorted(review.GATES)) + ] + self.ledger = {"schema": "winebot.hardware-review-ledger/1", + "source": self.source, "subjects": self.subjects, + "security_review": "approved", + "gate_receipts": {r["gate"]: review.digest(encode(r)) + for r in self.receipts}} + self.anchor = review.digest(encode(self.ledger)) + + def check(self): + review.validate(encode(self.ledger), encode(self.receipts), self.anchor, + self.source, self.runtime, self.instrumented, self.app) + + def reanchor(self): + self.anchor = review.digest(encode(self.ledger)) + + def reject(self, reason): + with self.assertRaisesRegex(review.InvalidReview, "^" + reason + "$"): + self.check() + + def test_complete_synthetic_review_consistency(self): + self.check() + + def test_missing_anchor(self): + self.anchor = "" + self.reject("missing_review_anchor") + + def test_untrusted_ledger(self): + self.ledger["security_review"] = "pending" + self.reject("untrusted_review_ledger") + + def test_security_hold_even_with_matching_anchor(self): + self.ledger["security_review"] = "pending" + self.reanchor() + self.reject("security_hold") + + def test_stale_source(self): + self.source = "e" * 40 + self.reject("stale_review") + + def test_other_image(self): + self.runtime = "sha256:" + "f" * 64 + self.reject("stale_review") + + def test_missing_gate(self): + self.receipts.pop() + self.reject("incomplete_receipts") + + def test_duplicate_gate(self): + self.receipts[-1] = self.receipts[0] + self.reject("unknown_or_duplicate_gate") + + def test_synthetic_evidence_not_admissible(self): + self.receipts[0]["evidence_class"] = "MOCKED_BEHAVIOR" + self.reject("insufficient_evidence_class") + + def test_failed_receipt(self): + self.receipts[0]["result"] = "fail" + self.reject("gate_not_passed") + + def test_mismatched_receipt_subject(self): + self.receipts[0]["subjects"]["runtime_image_id"] = self.app + self.reject("stale_receipt") + + def test_unreviewed_receipt(self): + self.receipts[0]["job_id"] = 9999 + self.reject("unreviewed_receipt") + + def test_duplicate_json_keys(self): + with self.assertRaisesRegex(review.InvalidReview, "duplicate_json_key"): + review.decode(b'{"schema":1,"schema":2}') + + def test_bool_not_job_id(self): + self.receipts[0]["job_id"] = True + self.reject("invalid_evidence_identity") + + +if __name__ == "__main__": + unittest.main() From 080418f2237999dbeac603121114d018cd7c997a Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Sun, 29 Nov 2026 04:13:09 +0100 Subject: [PATCH 3/6] Qualify offline review consistency on read-only public runner --- .../workflows/hardware-review-consistency.yml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/hardware-review-consistency.yml diff --git a/.github/workflows/hardware-review-consistency.yml b/.github/workflows/hardware-review-consistency.yml new file mode 100644 index 00000000..1158a377 --- /dev/null +++ b/.github/workflows/hardware-review-consistency.yml @@ -0,0 +1,34 @@ +name: Hardware Review Consistency RDTE + +on: + pull_request: + paths: + - 'scripts/hardware_review.py' + - 'scripts/test_hardware_review.py' + - '.github/workflows/hardware-review-consistency.yml' + +permissions: + contents: read + +jobs: + synthetic-consistency: + if: github.repository == 'SemperSupra/WineBot' && github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + with: + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + - name: Check exact source and offline synthetic consistency + env: + SOURCE_SHA: ${{ github.event.pull_request.head.sha }} + run: | + test "$(git rev-parse HEAD)" = "$SOURCE_SHA" + python3 scripts/test_hardware_review.py + - name: Assert publication remains closed + run: | + if output="$(env GITHUB_EVENT_NAME=push GITHUB_REF=refs/heads/rdte/r066-installer-integrated-20261127 bash scripts/ci/publish-candidate-images.sh 2>&1)"; then + exit 1 + fi + test "$output" = 'WINE11_CANDIDATE stage=pre_hardware_admission_required result=fail' From c929dd7c2eef561848b0faa003fc0f9d03a39981 Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Sun, 29 Nov 2026 10:21:44 +0100 Subject: [PATCH 4/6] R077 audit exact historical public candidate receipt custody without promotion --- .../historical-candidate-custody.yml | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 .github/workflows/historical-candidate-custody.yml diff --git a/.github/workflows/historical-candidate-custody.yml b/.github/workflows/historical-candidate-custody.yml new file mode 100644 index 00000000..b29d3af6 --- /dev/null +++ b/.github/workflows/historical-candidate-custody.yml @@ -0,0 +1,218 @@ +name: Historical candidate receipt custody RDTE + +# Bounded audit of the public R075/R076 receipt, not a permanent release gate. +# The fixture expires 2026-12-12; remove this audit workflow after reconciliation. +on: + pull_request: + paths: + - '.github/workflows/historical-candidate-custody.yml' + +permissions: {} + +jobs: + audit: + if: github.repository == 'SemperSupra/WineBot' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.number == 253 + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + actions: read + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + with: + ref: {{ github.event.pull_request.head.sha }} + persist-credentials: false + - name: Retrieve bounded public evidence by fixed IDs + env: + GH_TOKEN: {{ github.token }} + shell: bash + run: | + set -euo pipefail + umask 077 + ulimit -f 1024 + dir="$RUNNER_TEMP/winebot-receipt-audit" + mkdir -m 700 "$dir" + repo=repos/SemperSupra/WineBot/actions + gh api "$repo/runs/46193146510" > "$dir/run.json" + gh api "$repo/jobs/141128297070" > "$dir/job.json" + gh api "$repo/artifacts/15282598696" > "$dir/artifact.json" + gh api "$repo/artifacts/15282598696/zip" > "$dir/receipt.zip" + - name: Verify exact run, job, artifact and bounded receipt + env: + SOURCE_SHA: {{ github.event.pull_request.head.sha }} + shell: bash + run: | + set -euo pipefail + test "$(git rev-parse HEAD)" = "$SOURCE_SHA" + python3 - "$RUNNER_TEMP/winebot-receipt-audit" <<'PY' + import copy + import hashlib + import io + import json + import re + import sys + import zipfile + from pathlib import Path + + SOURCE = "8efcc5133dd773af9bae0d9b9555bbab0c011a65" + REPO = 1141013461 + RUN = 46193146510 + JOB = 141128297070 + ARTIFACT = 15282598696 + ARCHIVE = "sha256:d7ad24184f77cbb4daf10312fda5d6e449a214c4a8635e085be36ca38034c2cd" + STEPS = ( + "Checkout exact public candidate source", + "Assert closed publication boundary before building", + "Run the complete required unit suite before image qualification", + "Build and qualify both final image objects", + "Scan tested objects and generate package inventories", + "Preserve bounded qualification receipt only", + ) + CHECKS = { + "wine11-version", "read-only-uid1000", "mode-capabilities", + "internal-workload-network", "host-published-api-viewer", + "read-only-token-denial", "actual-windows-notepad-save", + "brokered-ahk-input", "independent-windows-input-sensor", + "windows-tracer-stop-restart", "post-stop-input-denial", + "synthetic-desktop-screenshot", "live-dashboard-rfb-pixels", + "human-cv-viewer-geometry", "sigkill-recreate-state-replay", + } + + class Rejected(ValueError): + pass + + def require(condition, reason): + if not condition: + raise Rejected(reason) + + def unique(pairs): + result = {} + for key, value in pairs: + require(key not in result, "duplicate_key") + result[key] = value + return result + + def decode(data): + return json.loads(data, object_pairs_hook=unique) + + def hash_bytes(data): + return "sha256:" + hashlib.sha256(data).hexdigest() + + def validate_metadata(run, job, artifact): + require(run["id"] == RUN and run["head_sha"] == SOURCE + and run["repository"]["id"] == REPO + and run["head_repository"]["id"] == REPO + and run["event"] == "pull_request" + and run["workflow_id"] == 433829357 + and run["path"].split("@", 1)[0] == ".github/workflows/wine11-candidate-images.yml", + "run_identity") + require(run["status"] == "completed" and run["conclusion"] == "success" + and type(run["run_attempt"]) is int and run["run_attempt"] > 0, + "run_status") + require(job["id"] == JOB and job["run_id"] == RUN + and job["run_attempt"] == run["run_attempt"] + and job["name"] == "qualify", "job_identity") + require(job["status"] == "completed" and job["conclusion"] == "success" + and "ubuntu-24.04" in job["labels"], "job_status") + for name in STEPS: + matches = [s for s in job["steps"] if s["name"] == name] + require(len(matches) == 1 and matches[0]["status"] == "completed" + and matches[0]["conclusion"] == "success", "required_step") + origin = artifact["workflow_run"] + require(artifact["id"] == ARTIFACT and origin["id"] == RUN + and origin["repository_id"] == REPO + and origin["head_repository_id"] == REPO + and origin["head_sha"] == SOURCE + and artifact["name"] == f"wine11-candidate-qualification-{RUN}", + "artifact_identity") + require(artifact["expired"] is False and artifact["digest"] == ARCHIVE + and type(artifact["size_in_bytes"]) is int + and 0 < artifact["size_in_bytes"] <= 65536, "artifact_status") + + def validate_archive(data, artifact, attempt): + require(len(data) == artifact["size_in_bytes"] and len(data) <= 65536 + and hash_bytes(data) == ARCHIVE, "archive_digest") + with zipfile.ZipFile(io.BytesIO(data)) as archive: + entries = archive.infolist() + require(len(entries) == 1 and entries[0].filename == "qualification.json" + and not entries[0].is_dir() and 0 < entries[0].file_size <= 8192 + and not entries[0].flag_bits & 1, "archive_members") + with archive.open(entries[0]) as stream: + receipt_bytes = stream.read(8193) + require(len(receipt_bytes) <= 8192, "receipt_size") + receipt = decode(receipt_bytes) + require(set(receipt) == {"schema", "source_revision", "qualification", + "envelope", "hosted_runner", "run_id", "run_attempt", "images", + "checks", "wininspect_provider_bundled", + "hostile_actor_containment_qualified", "physical_hardware_qualified"}, + "receipt_schema") + require(receipt["schema"] == "winebot.candidate-images/1" + and receipt["source_revision"] == SOURCE + and receipt["run_id"] == str(RUN) + and receipt["run_attempt"] == str(attempt) + and receipt["qualification"] == "pass" + and receipt["envelope"] == "single-operator-disposable-linux-oci" + and receipt["hosted_runner"] == "ubuntu-24.04", "receipt_identity") + require(all(receipt[k] is False for k in ( + "wininspect_provider_bundled", "hostile_actor_containment_qualified", + "physical_hardware_qualified")), "receipt_scope") + require(len(receipt["checks"]) == len(CHECKS) + and set(receipt["checks"]) == CHECKS, "receipt_checks") + images = receipt["images"] + require(isinstance(images, list) and len(images) == 2, "image_count") + for image in images: + require(set(image) == {"mode", "local_image_id", "bytes"} + and isinstance(image["local_image_id"], str) + and re.fullmatch(r"sha256:[0-9a-f]{64}", image["local_image_id"]) + and type(image["bytes"]) is int and image["bytes"] > 0, "image_schema") + by_mode = {image["mode"]: image for image in images} + require(set(by_mode) == {"runtime", "instrumented"}, "image_modes") + runtime, instrumented = by_mode["runtime"], by_mode["instrumented"] + require(runtime["local_image_id"] != instrumented["local_image_id"] + and runtime["bytes"] < instrumented["bytes"] + and runtime["bytes"] <= 3500000000 + and instrumented["bytes"] <= 4000000000, "image_identity") + return hash_bytes(receipt_bytes) + + def reject(call, expected): + try: + call() + except Rejected as exc: + require(str(exc) == expected, "negative_wrong_reason") + else: + raise Rejected("negative_accepted") + + try: + root = Path(sys.argv[1]) + run, job, artifact = (decode((root / name).read_bytes()) for name in + ("run.json", "job.json", "artifact.json")) + validate_metadata(run, job, artifact) + data = (root / "receipt.zip").read_bytes() + receipt_hash = validate_archive(data, artifact, run["run_attempt"]) + stale = copy.deepcopy(run) + stale["head_sha"] = "0" * 40 + reject(lambda: validate_metadata(stale, job, artifact), "run_identity") + other = copy.deepcopy(job) + other["run_id"] = 1 + reject(lambda: validate_metadata(run, other, artifact), "job_identity") + failed = copy.deepcopy(job) + next(s for s in failed["steps"] if s["name"] == STEPS[2])["conclusion"] = "failure" + reject(lambda: validate_metadata(run, failed, artifact), "required_step") + expired = copy.deepcopy(artifact) + expired["expired"] = True + reject(lambda: validate_metadata(run, job, expired), "artifact_status") + reject(lambda: validate_archive(data[:-1] + bytes([data[-1] ^ 1]), + artifact, run["run_attempt"]), "archive_digest") + print("HISTORICAL_CUSTODY result=pass receipt_sha256=" + receipt_hash + + " negatives=5 scope=single_operator publication=blocked") + except Rejected as exc: + print("HISTORICAL_CUSTODY result=fail reason=" + str(exc)) + sys.exit(1) + except (OSError, ValueError, KeyError, TypeError, IndexError, AttributeError, + RuntimeError, zipfile.BadZipFile): + print("HISTORICAL_CUSTODY result=fail reason=invalid_evidence") + sys.exit(1) + PY + - name: Clean up bounded local evidence + if: always() + run: rm -rf "$RUNNER_TEMP/winebot-receipt-audit" From bd5bd50ce1603006d4cbdbf699771dc517117bcb Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Sun, 29 Nov 2026 10:21:58 +0100 Subject: [PATCH 5/6] Correct GitHub expression delimiters in R077 historical audit workflow --- .github/workflows/historical-candidate-custody.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/historical-candidate-custody.yml b/.github/workflows/historical-candidate-custody.yml index b29d3af6..c2df2bc2 100644 --- a/.github/workflows/historical-candidate-custody.yml +++ b/.github/workflows/historical-candidate-custody.yml @@ -20,11 +20,11 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with: - ref: {{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false - name: Retrieve bounded public evidence by fixed IDs env: - GH_TOKEN: {{ github.token }} + GH_TOKEN: ${{ github.token }} shell: bash run: | set -euo pipefail @@ -39,7 +39,7 @@ jobs: gh api "$repo/artifacts/15282598696/zip" > "$dir/receipt.zip" - name: Verify exact run, job, artifact and bounded receipt env: - SOURCE_SHA: {{ github.event.pull_request.head.sha }} + SOURCE_SHA: ${{ github.event.pull_request.head.sha }} shell: bash run: | set -euo pipefail From bc529db4a6d5773c84d96c4f211415c2c4404eee Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:47:17 +0100 Subject: [PATCH 6/6] R078 retire expiring historical receipt audit after verified custody --- .../historical-candidate-custody.yml | 218 ------------------ 1 file changed, 218 deletions(-) delete mode 100644 .github/workflows/historical-candidate-custody.yml diff --git a/.github/workflows/historical-candidate-custody.yml b/.github/workflows/historical-candidate-custody.yml deleted file mode 100644 index c2df2bc2..00000000 --- a/.github/workflows/historical-candidate-custody.yml +++ /dev/null @@ -1,218 +0,0 @@ -name: Historical candidate receipt custody RDTE - -# Bounded audit of the public R075/R076 receipt, not a permanent release gate. -# The fixture expires 2026-12-12; remove this audit workflow after reconciliation. -on: - pull_request: - paths: - - '.github/workflows/historical-candidate-custody.yml' - -permissions: {} - -jobs: - audit: - if: github.repository == 'SemperSupra/WineBot' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.number == 253 - runs-on: ubuntu-24.04 - timeout-minutes: 5 - permissions: - contents: read - actions: read - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd - with: - ref: ${{ github.event.pull_request.head.sha }} - persist-credentials: false - - name: Retrieve bounded public evidence by fixed IDs - env: - GH_TOKEN: ${{ github.token }} - shell: bash - run: | - set -euo pipefail - umask 077 - ulimit -f 1024 - dir="$RUNNER_TEMP/winebot-receipt-audit" - mkdir -m 700 "$dir" - repo=repos/SemperSupra/WineBot/actions - gh api "$repo/runs/46193146510" > "$dir/run.json" - gh api "$repo/jobs/141128297070" > "$dir/job.json" - gh api "$repo/artifacts/15282598696" > "$dir/artifact.json" - gh api "$repo/artifacts/15282598696/zip" > "$dir/receipt.zip" - - name: Verify exact run, job, artifact and bounded receipt - env: - SOURCE_SHA: ${{ github.event.pull_request.head.sha }} - shell: bash - run: | - set -euo pipefail - test "$(git rev-parse HEAD)" = "$SOURCE_SHA" - python3 - "$RUNNER_TEMP/winebot-receipt-audit" <<'PY' - import copy - import hashlib - import io - import json - import re - import sys - import zipfile - from pathlib import Path - - SOURCE = "8efcc5133dd773af9bae0d9b9555bbab0c011a65" - REPO = 1141013461 - RUN = 46193146510 - JOB = 141128297070 - ARTIFACT = 15282598696 - ARCHIVE = "sha256:d7ad24184f77cbb4daf10312fda5d6e449a214c4a8635e085be36ca38034c2cd" - STEPS = ( - "Checkout exact public candidate source", - "Assert closed publication boundary before building", - "Run the complete required unit suite before image qualification", - "Build and qualify both final image objects", - "Scan tested objects and generate package inventories", - "Preserve bounded qualification receipt only", - ) - CHECKS = { - "wine11-version", "read-only-uid1000", "mode-capabilities", - "internal-workload-network", "host-published-api-viewer", - "read-only-token-denial", "actual-windows-notepad-save", - "brokered-ahk-input", "independent-windows-input-sensor", - "windows-tracer-stop-restart", "post-stop-input-denial", - "synthetic-desktop-screenshot", "live-dashboard-rfb-pixels", - "human-cv-viewer-geometry", "sigkill-recreate-state-replay", - } - - class Rejected(ValueError): - pass - - def require(condition, reason): - if not condition: - raise Rejected(reason) - - def unique(pairs): - result = {} - for key, value in pairs: - require(key not in result, "duplicate_key") - result[key] = value - return result - - def decode(data): - return json.loads(data, object_pairs_hook=unique) - - def hash_bytes(data): - return "sha256:" + hashlib.sha256(data).hexdigest() - - def validate_metadata(run, job, artifact): - require(run["id"] == RUN and run["head_sha"] == SOURCE - and run["repository"]["id"] == REPO - and run["head_repository"]["id"] == REPO - and run["event"] == "pull_request" - and run["workflow_id"] == 433829357 - and run["path"].split("@", 1)[0] == ".github/workflows/wine11-candidate-images.yml", - "run_identity") - require(run["status"] == "completed" and run["conclusion"] == "success" - and type(run["run_attempt"]) is int and run["run_attempt"] > 0, - "run_status") - require(job["id"] == JOB and job["run_id"] == RUN - and job["run_attempt"] == run["run_attempt"] - and job["name"] == "qualify", "job_identity") - require(job["status"] == "completed" and job["conclusion"] == "success" - and "ubuntu-24.04" in job["labels"], "job_status") - for name in STEPS: - matches = [s for s in job["steps"] if s["name"] == name] - require(len(matches) == 1 and matches[0]["status"] == "completed" - and matches[0]["conclusion"] == "success", "required_step") - origin = artifact["workflow_run"] - require(artifact["id"] == ARTIFACT and origin["id"] == RUN - and origin["repository_id"] == REPO - and origin["head_repository_id"] == REPO - and origin["head_sha"] == SOURCE - and artifact["name"] == f"wine11-candidate-qualification-{RUN}", - "artifact_identity") - require(artifact["expired"] is False and artifact["digest"] == ARCHIVE - and type(artifact["size_in_bytes"]) is int - and 0 < artifact["size_in_bytes"] <= 65536, "artifact_status") - - def validate_archive(data, artifact, attempt): - require(len(data) == artifact["size_in_bytes"] and len(data) <= 65536 - and hash_bytes(data) == ARCHIVE, "archive_digest") - with zipfile.ZipFile(io.BytesIO(data)) as archive: - entries = archive.infolist() - require(len(entries) == 1 and entries[0].filename == "qualification.json" - and not entries[0].is_dir() and 0 < entries[0].file_size <= 8192 - and not entries[0].flag_bits & 1, "archive_members") - with archive.open(entries[0]) as stream: - receipt_bytes = stream.read(8193) - require(len(receipt_bytes) <= 8192, "receipt_size") - receipt = decode(receipt_bytes) - require(set(receipt) == {"schema", "source_revision", "qualification", - "envelope", "hosted_runner", "run_id", "run_attempt", "images", - "checks", "wininspect_provider_bundled", - "hostile_actor_containment_qualified", "physical_hardware_qualified"}, - "receipt_schema") - require(receipt["schema"] == "winebot.candidate-images/1" - and receipt["source_revision"] == SOURCE - and receipt["run_id"] == str(RUN) - and receipt["run_attempt"] == str(attempt) - and receipt["qualification"] == "pass" - and receipt["envelope"] == "single-operator-disposable-linux-oci" - and receipt["hosted_runner"] == "ubuntu-24.04", "receipt_identity") - require(all(receipt[k] is False for k in ( - "wininspect_provider_bundled", "hostile_actor_containment_qualified", - "physical_hardware_qualified")), "receipt_scope") - require(len(receipt["checks"]) == len(CHECKS) - and set(receipt["checks"]) == CHECKS, "receipt_checks") - images = receipt["images"] - require(isinstance(images, list) and len(images) == 2, "image_count") - for image in images: - require(set(image) == {"mode", "local_image_id", "bytes"} - and isinstance(image["local_image_id"], str) - and re.fullmatch(r"sha256:[0-9a-f]{64}", image["local_image_id"]) - and type(image["bytes"]) is int and image["bytes"] > 0, "image_schema") - by_mode = {image["mode"]: image for image in images} - require(set(by_mode) == {"runtime", "instrumented"}, "image_modes") - runtime, instrumented = by_mode["runtime"], by_mode["instrumented"] - require(runtime["local_image_id"] != instrumented["local_image_id"] - and runtime["bytes"] < instrumented["bytes"] - and runtime["bytes"] <= 3500000000 - and instrumented["bytes"] <= 4000000000, "image_identity") - return hash_bytes(receipt_bytes) - - def reject(call, expected): - try: - call() - except Rejected as exc: - require(str(exc) == expected, "negative_wrong_reason") - else: - raise Rejected("negative_accepted") - - try: - root = Path(sys.argv[1]) - run, job, artifact = (decode((root / name).read_bytes()) for name in - ("run.json", "job.json", "artifact.json")) - validate_metadata(run, job, artifact) - data = (root / "receipt.zip").read_bytes() - receipt_hash = validate_archive(data, artifact, run["run_attempt"]) - stale = copy.deepcopy(run) - stale["head_sha"] = "0" * 40 - reject(lambda: validate_metadata(stale, job, artifact), "run_identity") - other = copy.deepcopy(job) - other["run_id"] = 1 - reject(lambda: validate_metadata(run, other, artifact), "job_identity") - failed = copy.deepcopy(job) - next(s for s in failed["steps"] if s["name"] == STEPS[2])["conclusion"] = "failure" - reject(lambda: validate_metadata(run, failed, artifact), "required_step") - expired = copy.deepcopy(artifact) - expired["expired"] = True - reject(lambda: validate_metadata(run, job, expired), "artifact_status") - reject(lambda: validate_archive(data[:-1] + bytes([data[-1] ^ 1]), - artifact, run["run_attempt"]), "archive_digest") - print("HISTORICAL_CUSTODY result=pass receipt_sha256=" + receipt_hash - + " negatives=5 scope=single_operator publication=blocked") - except Rejected as exc: - print("HISTORICAL_CUSTODY result=fail reason=" + str(exc)) - sys.exit(1) - except (OSError, ValueError, KeyError, TypeError, IndexError, AttributeError, - RuntimeError, zipfile.BadZipFile): - print("HISTORICAL_CUSTODY result=fail reason=invalid_evidence") - sys.exit(1) - PY - - name: Clean up bounded local evidence - if: always() - run: rm -rf "$RUNNER_TEMP/winebot-receipt-audit"