diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5df8dcc4b..600ed4df6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1580,6 +1580,7 @@ jobs: run: | set -euo pipefail [[ "$RUNNER_OS/$RUNNER_ARCH" == macOS/X64 ]] + [[ "$(scripts/package-release-binaries.sh --print-platform)" == darwin-amd64 ]] df -Pk . df -Pk . | awk 'NR == 2 { if ($4 < 8 * 1024 * 1024) { print "Intel runner has under 8 GiB free"; exit 1 } }' # source-gate runs these tests on Linux. Run them here on macOS too, diff --git a/README.md b/README.md index 787ac0814..bca8fda7e 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ journeys tested on that device. ## Install from the publisher -The public installer looks up signed releases for Linux x86_64/aarch64 and macOS Apple silicon. Intel Mac and other OS families fail closed. +The public installer looks up signed releases for Linux x86_64/aarch64 and macOS Apple silicon. Other OS families fail closed. For an Intel Mac, see [Intel Mac](docs/MAC.md#intel-mac). The maintainer release DID is `did:key:z6MkgwHd2BCWe1jHMXPiR6H1q1RFPcv1YzhMbK5G1kBarbfe`. Compare the diff --git a/docs/GETTING_STARTED.md b/docs/GETTING_STARTED.md index 5cad100dc..289b94634 100644 --- a/docs/GETTING_STARTED.md +++ b/docs/GETTING_STARTED.md @@ -2,7 +2,7 @@ ## Install from the publisher -The public installer looks up signed releases for Linux x86_64/aarch64 and macOS Apple silicon. Intel Mac and other OS families fail closed. See the [Mac runbook](MAC.md) for source-home staging. +The public installer looks up signed releases for Linux x86_64/aarch64 and macOS Apple silicon. Other OS families fail closed. For an Intel Mac, see [Intel Mac](MAC.md#intel-mac). See the [Mac runbook](MAC.md) for source-home staging. ```bash curl -fsSL https://elastos.elacitylabs.com/install.sh | bash diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 78dd02afa..902afae43 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -25,7 +25,7 @@ journeys tested on that device. ## Install from the publisher -The installer looks up signed releases for Linux x86_64/aarch64 and macOS Apple silicon. Intel Mac and other OS families fail closed. The signed release determines which binaries exist for a given platform. +The installer looks up signed releases for Linux x86_64/aarch64 and macOS Apple silicon. Other OS families fail closed. For an Intel Mac, see [Intel Mac](MAC.md#intel-mac). The signed release determines which binaries exist for a given platform. This checkout's installer combines installation, Home setup, and launch into one command: diff --git a/docs/LAUNCHER_CONTRACT.md b/docs/LAUNCHER_CONTRACT.md index 95b917717..976486215 100644 --- a/docs/LAUNCHER_CONTRACT.md +++ b/docs/LAUNCHER_CONTRACT.md @@ -148,5 +148,5 @@ A supervisor uses these exit codes. It does not parse English sentences from stdout. Exit 0 covers more than one successful update outcome. A later issue owns a machine-readable update status. -Intel Mac's release id is `x86_64-darwin`. This contract does not publish a -download for that id. +This contract publishes no download for an Intel Mac. [Intel Mac](MAC.md#intel-mac) +records the current state. diff --git a/docs/MAC.md b/docs/MAC.md index 28f7a1b86..37b7ab7b2 100644 --- a/docs/MAC.md +++ b/docs/MAC.md @@ -6,6 +6,9 @@ artifacts, and `.dmg` packaging work. ## Intel Mac +This section is the one record of Intel Mac support. Other documents link +here instead of repeating it. + The public release id for an Intel Mac is `x86_64-darwin`. `scripts/install.sh` stops on that host before a download lookup. The message is `macOS release lookup requires Apple silicon`. @@ -15,6 +18,21 @@ installer on an Apple silicon Mac. The source-home commands later in this runbook are a developer build. They are not the installer, and this note does not claim that build has passed on Intel. +These files hold the rules: + +- Signing: the release platform allowlist in `scripts/release-signer.py`. + `x86_64-darwin` is not in it. `scripts/release-signer-test.py` runs the + signer with `python -O` on an `x86_64-darwin` input and requires the + refusal. +- Package name: `scripts/release-platforms.json` maps the package key + `darwin-amd64` to `x86_64-darwin`. +- Packaging: `scripts/package-release-binaries.sh`. `--print-platform` prints + `darwin-amd64` only when `sysctl` shows Intel hardware. It stops in a + Rosetta shell on Apple silicon and when `sysctl` is missing or unclear. + Packaging writes no `darwin-amd64` tarball. For the other keys, it stops + on a binary that does not match the key, which includes a universal binary. +- Install: the platform check in `scripts/install.sh`. + CI job `gateway-smoke-macos-intel` builds the native `elastos` binary on `macos-15-intel`. It runs `scripts/gateway-healthz-smoke.sh`, which starts the command in [the launcher contract](LAUNCHER_CONTRACT.md) and requires the diff --git a/scripts/ci-release-policy-test.py b/scripts/ci-release-policy-test.py index 3652952eb..3312120d0 100644 --- a/scripts/ci-release-policy-test.py +++ b/scripts/ci-release-policy-test.py @@ -20,6 +20,16 @@ WORKFLOW = Path(__file__).resolve().parents[1] / ".github/workflows/ci.yml" + + +def native_header(package_key): + """A minimal executable header that packaging accepts for this package key.""" + import struct + if package_key.startswith("linux-"): + machine = {"linux-amd64": 62, "linux-arm64": 183}[package_key] + return (b"\x7fELF\x02\x01\x01" + bytes(9) + struct.pack("&2\nexit 1\n") + elif sysctl is not None: + translated, arm64 = sysctl + executable(directory / "sysctl", textwrap.dedent(f"""\ + #!/bin/sh + [ "$1" = -in ] || exit 2 + case "$2" in + sysctl.proc_translated) printf '%s' {translated!r} ;; + hw.optional.arm64) printf '%s' {arm64!r} ;; + *) exit 2 ;; + esac + """)) + + +def run_script(directory, *args, cwd=ROOT, script=SCRIPT, extra_env=None, only_shims=False): + env = os.environ.copy() + if only_shims: + # Only the shims and dirname: a tool that is not shimmed is missing. + os.symlink(shutil.which("dirname"), Path(directory) / "dirname") + env["PATH"] = str(directory) + else: + env["PATH"] = str(directory) + os.pathsep + env["PATH"] + env.update(extra_env or {}) + return subprocess.run([BASH, str(script), *args], cwd=cwd, env=env, text=True, + capture_output=True, timeout=60) + + +def package_name(system, machine, sysctl=NATIVE_INTEL, only_shims=False): + with tempfile.TemporaryDirectory() as directory: + write_shims(directory, system, machine, sysctl) + return run_script(directory, "--print-platform", only_shims=only_shims) + + +def native_header(kind, machine): + if kind == "elf": + return (b"\x7fELF\x02\x01\x01" + bytes(9) + struct.pack("IIIIII", 2, 0x100000C, 0, 0, 0, 0)).ljust(64, b"\0") + + +ELF_AMD64 = native_header("elf", 62) +ELF_ARM64 = native_header("elf", 183) +MACHO_ARM64 = native_header("macho", 0x100000C) +MACHO_AMD64 = native_header("macho", 0x1000007) +UNIVERSAL = native_header("fat", 0) + + +class PackageReleaseNameTest(unittest.TestCase): + def test_native_hosts_use_the_release_platform_names(self): + expected = { + ("Linux", "x86_64"): "linux-amd64", + ("Linux", "aarch64"): "linux-arm64", + ("Linux", "arm64"): "linux-arm64", + ("Darwin", "arm64"): "darwin-arm64", + ("Darwin", "x86_64"): "darwin-amd64", + } + for host, name in expected.items(): + with self.subTest(host=host): + result = package_name(*host) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.strip(), name) + + def test_native_intel_answers_name_darwin_amd64(self): + # sysctl -i prints nothing for an OID that an Intel macOS lacks. + for answers in (("0", "0"), ("", ""), ("0", ""), ("", "0")): + with self.subTest(answers=answers): + result = package_name("Darwin", "x86_64", answers) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.strip(), "darwin-amd64") + + def test_rosetta_shell_on_apple_silicon_is_not_named_darwin_amd64(self): + for answers in (("1", "1"), ("1", ""), ("0", "1"), ("", "1")): + with self.subTest(answers=answers): + result = package_name("Darwin", "x86_64", answers) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertEqual(result.stdout, "") + self.assertIn("Rosetta on an Apple silicon Mac", result.stderr) + + def test_intel_name_fails_closed_without_a_clear_sysctl_answer(self): + cases = {"missing": None, "fails": "fail", "unknown value": ("2", "0"), "text": ("yes", "")} + for case, sysctl in cases.items(): + with self.subTest(case=case): + result = package_name("Darwin", "x86_64", sysctl, only_shims=True) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertEqual(result.stdout, "") + self.assertIn("sysctl", result.stderr) + + def test_intel_package_key_prints_and_packaging_refuses_the_tarball(self): + platforms = json.loads((ROOT / "scripts/release-platforms.json").read_text()) + self.assertEqual(platforms["darwin-amd64"], "x86_64-darwin") + printed = package_name("Darwin", "x86_64") + self.assertEqual(printed.returncode, 0, printed.stderr) + self.assertEqual(printed.stdout.strip(), "darwin-amd64") + with tempfile.TemporaryDirectory() as directory: + write_shims(directory, "Darwin", "x86_64") + before = set(ROOT.glob("elastos-runtime-*.tar.gz")) + result = run_script(directory, extra_env={"TMPDIR": directory}) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertIn("darwin-amd64 is not a signed release platform", result.stderr) + self.assertEqual(set(ROOT.glob("elastos-runtime-*.tar.gz")), before) + self.assertEqual(list(Path(directory).glob("elastos-runtime-*")), []) + + def test_print_platform_writes_nothing(self): + with tempfile.TemporaryDirectory() as directory: + write_shims(directory, "Darwin", "x86_64") + scratch = Path(directory) / "tmp" + scratch.mkdir() + before = {path.name for path in ROOT.iterdir()} + result = run_script(directory, "--print-platform", extra_env={"TMPDIR": str(scratch)}) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.strip(), "darwin-amd64") + self.assertEqual({path.name for path in ROOT.iterdir()}, before) + self.assertEqual(list(scratch.iterdir()), []) + + def test_other_darwin_hosts_stop(self): + result = package_name("Darwin", "i386") + self.assertNotEqual(result.returncode, 0) + self.assertIn("Unsupported release platform: Darwin-i386", result.stderr) + + +class PackageBinaryArchitectureTest(unittest.TestCase): + """Packaging writes a tarball only when every binary matches its name.""" + + def package(self, system, machine, headers): + directory = tempfile.TemporaryDirectory() + self.addCleanup(directory.cleanup) + root = Path(directory.name) + scripts = root / "scripts" + scripts.mkdir() + for name in ("package-release-binaries.sh", "release-platform-input.py", "release-platforms.json", + "release-signer.py", "components-release-integrity-check.py", "browser-host-release.py"): + shutil.copy2(ROOT / "scripts" / name, scripts / name) + shims = root / "shims" + shims.mkdir() + write_shims(shims, system, machine) + names = sorted(headers) + executable(shims / "cargo", "#!/bin/sh\nprintf '%s' " + repr(json.dumps({ + "workspace_members": ["member"], + "packages": [{"id": "member", "targets": [{"name": name, "kind": ["bin"]} for name in names]}], + })) + "\n") + (root / "elastos").mkdir() + (root / "elastos/Cargo.toml").touch() + release = root / "elastos/target/release" + release.mkdir(parents=True) + for name, header in headers.items(): + (release / name).write_bytes(header + name.encode()) + (release / name).chmod(0o755) + env = {"TMPDIR": str(root), "COPYFILE_DISABLE": "1", "CARGO_TARGET_DIR": str(root / "elastos/target")} + result = run_script(shims, cwd=root, script=scripts / "package-release-binaries.sh", extra_env=env) + return result, sorted(path.name for path in root.glob("elastos-runtime-*")) + + def test_matching_binaries_are_packaged(self): + cases = {("Linux", "x86_64"): ("linux-amd64", ELF_AMD64), + ("Linux", "aarch64"): ("linux-arm64", ELF_ARM64), + ("Darwin", "arm64"): ("darwin-arm64", MACHO_ARM64)} + for host, (key, header) in cases.items(): + with self.subTest(host=host): + result, written = self.package(*host, {"elastos": header, "custody-provider": header}) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(written, [f"elastos-runtime-{key}.tar.gz", f"elastos-runtime-{key}.tar.gz.sha256"]) + tarball = Path(result.stdout.strip().splitlines()[-1].removeprefix("Wrote ")) + with tarfile.open(tarball) as archive: + self.assertEqual(sorted(Path(item.name).name for item in archive if item.isfile()), + ["custody-provider", "elastos"]) + + def test_binary_for_another_processor_or_universal_is_refused(self): + cases = { + "arm64 ELF named linux-amd64": (("Linux", "x86_64"), ELF_ARM64), + "x86_64 ELF named linux-arm64": (("Linux", "aarch64"), ELF_AMD64), + "x86_64 Mach-O named darwin-arm64": (("Darwin", "arm64"), MACHO_AMD64), + "universal Mach-O named darwin-arm64": (("Darwin", "arm64"), UNIVERSAL), + "Linux ELF named darwin-arm64": (("Darwin", "arm64"), ELF_ARM64), + "shell script named linux-amd64": (("Linux", "x86_64"), b"#!/bin/sh\n".ljust(64, b"#")), + "short file named linux-amd64": (("Linux", "x86_64"), b"\x7fELF"), + } + for case, (host, header) in cases.items(): + with self.subTest(case=case): + good = {"Linux-x86_64": ELF_AMD64, "Linux-aarch64": ELF_ARM64, "Darwin-arm64": MACHO_ARM64}["-".join(host)] + result, written = self.package(*host, {"elastos": good, "wrong-tool": header}) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertIn("Refusing to package", result.stderr) + self.assertIn("wrong-tool", result.stderr) + self.assertNotIn("elastos:", result.stderr) + self.assertEqual(written, []) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/package-release-binaries.sh b/scripts/package-release-binaries.sh index a2c4911f7..b31889ccb 100755 --- a/scripts/package-release-binaries.sh +++ b/scripts/package-release-binaries.sh @@ -8,11 +8,44 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +# A Rosetta shell on Apple silicon also reports uname -m x86_64. Name the +# host darwin-amd64 only when sysctl shows Intel hardware. sysctl -i prints +# nothing for an OID that this macOS does not have. Any other answer stops. +check_native_intel_mac() { + local translated arm64 + if ! command -v sysctl >/dev/null 2>&1; then + echo "sysctl is missing, so this Mac cannot be checked for Rosetta." >&2 + exit 1 + fi + if ! translated="$(sysctl -in sysctl.proc_translated)" \ + || ! arm64="$(sysctl -in hw.optional.arm64)"; then + echo "sysctl could not report the Mac processor type." >&2 + exit 1 + fi + case "${translated}/${arm64}" in + /|0/|/0|0/0) ;; + 1/*|*/1) + echo "This shell runs under Rosetta on an Apple silicon Mac. Open a native arm64 shell." >&2 + exit 1 + ;; + *) + echo "sysctl reported an unknown Mac processor type: ${translated}/${arm64}" >&2 + exit 1 + ;; + esac +} + platform() { case "$(uname -s)-$(uname -m)" in Linux-x86_64) printf '%s\n' "linux-amd64" ;; Linux-aarch64|Linux-arm64) printf '%s\n' "linux-arm64" ;; Darwin-arm64) printf '%s\n' "darwin-arm64" ;; + # The package key for release id x86_64-darwin. Printing the name + # does not write a tarball. The packaging path below refuses it. + Darwin-x86_64) + check_native_intel_mac + printf '%s\n' "darwin-amd64" + ;; *) echo "Unsupported release platform: $(uname -s)-$(uname -m)" >&2 exit 1 @@ -20,7 +53,18 @@ platform() { esac } +# CI on an Intel Mac prints this name. This branch writes nothing. +if [[ "${1:-}" == --print-platform ]]; then + platform + exit 0 +fi + PLATFORM="$(platform)" +# Refuse before staging so no darwin-amd64 tarball is written. +if [[ "$PLATFORM" == darwin-amd64 ]]; then + echo "darwin-amd64 is not a signed release platform. See docs/MAC.md." >&2 + exit 1 +fi PACKAGE="elastos-runtime-${PLATFORM}" STAGE_ROOT="$(mktemp -d)" STAGE="${STAGE_ROOT}/${PACKAGE}" @@ -60,6 +104,29 @@ if [ -z "$(ls -A "${STAGE}")" ]; then exit 1 fi +# Each staged file must be a thin executable for this package name. A +# universal binary or one built for another processor stops packaging. +# check_native_header in scripts/release-platform-input.py holds the rule. +python3 -I -S - "${ROOT}" "${PLATFORM}" "${STAGE}"/* <<'PY' +import importlib.util, json, os, sys +from pathlib import Path +root, package_key, paths = Path(sys.argv[1]), sys.argv[2], sys.argv[3:] +spec = importlib.util.spec_from_file_location("release_platform_input", root / "scripts/release-platform-input.py") +inputs = importlib.util.module_from_spec(spec) +spec.loader.exec_module(inputs) +release_id = json.loads((root / "scripts/release-platforms.json").read_text())[package_key] +refused = [] +for path in map(Path, paths): + with path.open("rb") as binary: + header = binary.read(64) + try: + inputs.check_native_header(header, path.stat().st_mode, release_id, path.name) + except ValueError as error: + refused.append(str(error)) +if refused: + sys.exit("Refusing to package " + package_key + ":\n" + "\n".join(refused)) +PY + echo "Packaging ${PACKAGE}:" ls -l "${STAGE}" diff --git a/scripts/release-signer-test.py b/scripts/release-signer-test.py index 4174dd86e..050e40c0c 100644 --- a/scripts/release-signer-test.py +++ b/scripts/release-signer-test.py @@ -2,6 +2,7 @@ """Public-data/fake-backend refusal tests. One model catalogue round trip signs with a throwaway OpenSSL key; no other private keys or real signing.""" +import ast import base64 import copy import hashlib @@ -19,6 +20,23 @@ from unittest import mock SOURCE = Path(__file__).with_name("release-signer.py").resolve() +# The child loads this test file from a private copy, runs main() on an Intel +# Mac release input and writes what happened as JSON. It asserts nothing, so a +# refusal that python -O strips shows up as a signed publication. +OPTIMIZED_CLI_CHILD = r""" +import importlib.util, json, sys +from pathlib import Path +spec = importlib.util.spec_from_file_location("signer_optimized_child", sys.argv[1]) +tests = importlib.util.module_from_spec(spec) +spec.loader.exec_module(tests) +case = tests.SignerTests("x86_64_darwin_cli_outcome") +case.setUp() +try: + outcome = case.x86_64_darwin_cli_outcome() +finally: + case.doCleanups() +Path(sys.argv[2]).write_text(json.dumps(outcome)) +""" spec = importlib.util.spec_from_file_location("release_signer", SOURCE) S = importlib.util.module_from_spec(spec) sys.modules[spec.name] = S @@ -538,6 +556,100 @@ def test_changes_keep_other_release_fields_strict(self): with self.assertRaisesRegex(ValueError, "release fields refused"): self.prepare() + def x86_64_darwin_cli_outcome(self): + """Run main() on an x86_64-darwin input that is valid in every other way.""" + # Component keys admit the Intel package here, so the platform + # allowlist is the only check left that can refuse this input. + intel_components = mock.patch.dict(S.COMPONENT_KEYS, {"x86_64-darwin": ("darwin-amd64", "x86_64-darwin")}) + intel_components.start() + self.addCleanup(intel_components.stop) + platform = copy.deepcopy(self.manifest["release"]["platforms"]["x86_64-linux"]) + self.manifest["release"]["platforms"]["x86_64-darwin"] = platform + (self.root / "elastos-x86_64-darwin").write_bytes(self.binary) + self.manifest["files"]["elastos-x86_64-darwin"] = copy.deepcopy( + self.manifest["files"]["elastos-x86_64-linux"]) + self.approve_manifest() + policy_path = self.base / "operator-policy.json" + policy_path.write_bytes(S.json_bytes(self.policy)) + output = self.base / "publication" + argv = [str(SOURCE), "--policy", str(policy_path), "--input-root", str(self.root), + "--output-root", str(output)] + error = None + with mock.patch.object(sys, "argv", argv), mock.patch.object(S, "pinned_tools"), \ + mock.patch.object(S, "github_json", side_effect=self.fetch), \ + mock.patch.object(sys, "stdin", io.StringIO(DID + "\n")), \ + mock.patch.object(sys, "stderr", io.StringIO()), mock.patch("builtins.print"), \ + mock.patch.object(S, "OpenSSLBackend", return_value=FakeBackend()) as backend: + try: + S.main() + except Exception as refusal: # The parent decides which refusal is correct. + error = f"{type(refusal).__name__}: {refusal}" + return {"optimize": sys.flags.optimize, "isolated": sys.flags.isolated, "error": error, + "backend": backend.call_count, + "outputs": sorted(path.name for path in output.iterdir()) if output.exists() else None} + + def optimized_cli_outcome(self, signer_source, optimize=True): + """Run x86_64_darwin_cli_outcome under python -I -S -O with this signer source.""" + # The signer refuses a writable output parent, so the copy is private + # and sits beside the checkout like the other fixtures. + private = Path(tempfile.mkdtemp(prefix=".signer-optimized-", dir=SOURCE.parent.parent)) + self.addCleanup(shutil.rmtree, private) + private.chmod(0o700) + scripts = private / "scripts" + scripts.mkdir(mode=0o700) + (scripts / "release-signer.py").write_text(signer_source) + (scripts / "release-signer-test.py").write_bytes(Path(__file__).read_bytes()) + result_path = private / "outcome.json" + self.no_process.stop() + try: + result = subprocess.run( + [sys.executable, "-I", "-S", *(["-O"] if optimize else []), "-c", OPTIMIZED_CLI_CHILD, + str(scripts / "release-signer-test.py"), str(result_path)], + text=True, capture_output=True, timeout=120) + finally: + self.no_process.start() + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + outcome = json.loads(result_path.read_text()) + self.assertEqual(outcome["optimize"], 1 if optimize else 0, outcome) + return outcome + + def test_optimized_cli_refuses_x86_64_darwin_and_signs_nothing(self): + # python -O strips assert statements. The Intel refusal must not. + outcome = self.optimized_cli_outcome(SOURCE.read_text()) + self.assertEqual((outcome["optimize"], outcome["isolated"]), (1, 1), outcome) + self.assertEqual(outcome["error"], "ValueError: release platforms refused", outcome) + self.assertEqual(outcome["backend"], 0, outcome) + self.assertIsNone(outcome["outputs"], outcome) + + def test_optimized_cli_detects_a_refusal_written_as_assert(self): + # Rewrite every "release platforms refused" require() as an assert + # statement. Without -O that signer still refuses. Under -O the + # refusal is gone, so the check in the test above must fail. A later + # gate (the package artifact prefix) can still stop this input, which + # is why the test above names the refusal it expects. + class AssertRefusal(ast.NodeTransformer): + count = 0 + + def visit_Expr(self, node): + call = node.value + if (isinstance(call, ast.Call) and isinstance(call.func, ast.Name) and call.func.id == "require" + and len(call.args) == 2 and isinstance(call.args[1], ast.Constant) + and call.args[1].value == "release platforms refused"): + self.count += 1 + return ast.copy_location(ast.Assert(test=call.args[0], msg=call.args[1]), node) + return self.generic_visit(node) + + transform = AssertRefusal() + tree = ast.fix_missing_locations(transform.visit(ast.parse(SOURCE.read_text()))) + self.assertGreaterEqual(transform.count, 1) + weakened = ast.unparse(tree) + plain = self.optimized_cli_outcome(weakened, optimize=False) + self.assertEqual(plain["error"], "AssertionError: release platforms refused", plain) + optimized = self.optimized_cli_outcome(weakened) + self.assertEqual(optimized["optimize"], 1, optimized) + self.assertNotEqual(optimized["error"], "ValueError: release platforms refused", optimized) + self.assertNotEqual(optimized["error"], "AssertionError: release platforms refused", optimized) + def test_signer_accepts_all_three_release_platforms(self): platform = self.manifest["release"]["platforms"]["x86_64-linux"] self.manifest["release"]["platforms"] = { diff --git a/scripts/release-signer.py b/scripts/release-signer.py index 6b8dfb5f0..7f53f004f 100644 --- a/scripts/release-signer.py +++ b/scripts/release-signer.py @@ -99,6 +99,9 @@ CAPSULE_RECORD_SCHEMA = "elastos.capsule.record/v1" # A release is one UnixFS chunk; Runtime refuses larger release metadata. MAX_RELEASE_METADATA = 256 * 1024 +# The signed release ids. Package keys live in scripts/release-platforms.json. +# x86_64-darwin is mapped there and is absent from this set. +SIGNED_RELEASE_PLATFORMS = frozenset({"x86_64-linux", "aarch64-linux", "aarch64-darwin"}) def require(condition, message): @@ -106,6 +109,11 @@ def require(condition, message): raise ValueError(message) +def require_signed_release_platforms(platforms): + require(type(platforms) is dict and platforms and set(platforms) <= SIGNED_RELEASE_PLATFORMS, + "release platforms refused") + + def sha256(data): return hashlib.sha256(data).hexdigest() @@ -1041,6 +1049,9 @@ def prepare_from_root(policy, root, manifest_name, fetch, snapshot_root, held_ro require(sha256(manifest_data) == checked_hash(policy.get("manifest_sha256")), "manifest differs from operator approval") manifest = parse_json(manifest_data) require(set(manifest) == {"source", "version", "channel", "files", "installer", "release", "head", "provenance"}, "signing input fields refused") + # Refuse an unsigned platform before provenance or any signature bytes. + if type(manifest.get("release")) is dict and type(manifest["release"].get("platforms")) is dict: + require_signed_release_platforms(manifest["release"]["platforms"]) source = {field: policy[field] for field in ("commit", "tree")} require(manifest["source"] == source and manifest["version"] == policy["version"] and manifest["channel"] == policy["channel"], "input source/version/channel differs") records = manifest["files"] @@ -1081,7 +1092,7 @@ def prepare_from_root(policy, root, manifest_name, fetch, snapshot_root, held_ro if release["prev_release_cid"] is not None: cid_info(release["prev_release_cid"]) platforms = release["platforms"] - require(type(platforms) is dict and platforms and set(platforms) <= {"x86_64-linux", "aarch64-linux", "aarch64-darwin"}, "release platforms refused") + require_signed_release_platforms(platforms) advertised = set() approved_refs = {(record["cid"], record["sha256"]) for record in records.values()} def admit_ref(cid, digest, size=None, release_path=None): diff --git a/scripts/test-source-gate.sh b/scripts/test-source-gate.sh index 171d2a5ea..910d0788b 100755 --- a/scripts/test-source-gate.sh +++ b/scripts/test-source-gate.sh @@ -35,6 +35,7 @@ release() { python3 scripts/media-tools-build-test.py python3 scripts/verify-linux-arm64-package-test.py python3 scripts/gateway-healthz-smoke-test.py + python3 scripts/package-release-binaries-test.py python3 scripts/verify-linux-engine-test.py python3 scripts/update-hop-compare-test.py python3 .github/scripts/release-mac-capacity-test.py