From 634fb42b5c93d7812bfe1537575c40960d432a77 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:00:34 +0400 Subject: [PATCH 1/6] Test that the UK Modal launcher's image installs the emitter The launcher's image installs only uv, so run_uk_cut.py's pre-flight, which starts the separately installed microcosm-emitter to check write access, refuses every Modal run. These tests ask the image to install microcosm-emitter at or above the release minimum_emitter_version.json names, as the US Modal image does, to point the build at it, to refuse a minimum file it cannot read, and to say in the plan what it installs. They fail on this commit. Co-Authored-By: Claude Opus 5.5 --- .../tests/engine_free/uk/test_modal_uk_cut.py | 92 ++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py b/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py index 3277591051..304034e0fd 100644 --- a/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py +++ b/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py @@ -3,6 +3,7 @@ from __future__ import annotations import importlib.util +import re import shutil import sys from pathlib import Path @@ -74,16 +75,105 @@ def test_planning_contacts_no_modal_service(monkeypatch, capsys): assert "missing credentials" in capsys.readouterr().out +def _image_steps(stub, step): + """The calls named ``step`` the module made on the stub, in order.""" + + return [entry for entry in stub.mock_calls if entry[0].split(".")[-1] == step] + + def test_the_image_carries_the_registry_for_the_container(monkeypatch): module, stub = _load_app(monkeypatch) built = stub.Image.debian_slim.return_value.apt_install.return_value - added = built.pip_install.return_value.env.return_value.add_local_file + # The registry's copy comes after the emitter's install: Modal refuses + # build steps after a local file. + installed = built.pip_install.return_value.env.return_value.run_commands + added = installed.return_value.add_local_file added.assert_called_once_with(str(module.REGISTRY_SOURCE), module.REGISTRY_REMOTE) assert module.REGISTRY_SOURCE.is_file() # Modal places the app module in /root, beside the registry's copy. assert Path(module.REGISTRY_REMOTE).parent == Path("/root") +def test_the_image_installs_the_emitter_at_the_builds_minimum_release(monkeypatch): + """The pre-flight starts the separately installed emitter (#1410, #1460).""" + + from microcosm.build.telemetry_emitter import MINIMUM_EMITTER_VERSION + + _, stub = _load_app(monkeypatch) + assert [step.args for step in _image_steps(stub, "run_commands")] == [ + ( + "UV_TOOL_BIN_DIR=/usr/local/bin uv tool install " + f"'microcosm-emitter>={MINIMUM_EMITTER_VERSION}'", + "/usr/local/bin/microcosm-emitter version", + ) + ] + + +def test_the_build_is_pointed_at_the_installed_emitter(monkeypatch): + _, stub = _load_app(monkeypatch) + (environment,) = _image_steps(stub, "env") + assert environment.args[0].get("MICROCOSM_EMITTER_COMMAND") == ( + "/usr/local/bin/microcosm-emitter" + ) + + +@pytest.mark.parametrize( + "content", + [ + None, + "not json", + "[]", + '{"minimum_emitter_version": 17}', + '{"minimum_emitter_version": "0.17"}', + '{"minimum_emitter_version": "0.17.0 "}', + ], +) +def test_an_unreadable_minimum_release_stops_the_image_definition( + monkeypatch, tmp_path, content +): + module, _ = _load_app(monkeypatch) + version_file = tmp_path / "minimum_emitter_version.json" + if content is not None: + version_file.write_text(content, encoding="utf-8") + monkeypatch.setattr( + module, "MINIMUM_EMITTER_VERSION_FILE", version_file, raising=False + ) + with pytest.raises(SystemExit, match=re.escape(str(version_file))): + module._image() + + +def test_the_container_defines_the_image_without_the_checkout(monkeypatch, tmp_path): + """The container imports the module at /root, with no checkout around it.""" + + module, stub = _load_app(monkeypatch) + monkeypatch.setattr( + module, + "MINIMUM_EMITTER_VERSION_FILE", + tmp_path / "missing" / "minimum_emitter_version.json", + raising=False, + ) + stub.is_local.return_value = False + stub.reset_mock() + module._image() + assert _image_steps(stub, "run_commands") == [] + assert _image_steps(stub, "add_local_file") == [] + + +def test_the_plan_names_the_emitter_the_image_installs(monkeypatch, capsys): + from microcosm.build.telemetry_emitter import MINIMUM_EMITTER_VERSION + + module, _ = _load_app(monkeypatch) + monkeypatch.setattr( + module.subprocess, + "run", + lambda argv, **kw: module.subprocess.CompletedProcess(argv, 0), + ) + module.plan("a" * 40, "t") + assert f"emitter microcosm-emitter>={MINIMUM_EMITTER_VERSION}" in ( + capsys.readouterr().out + ) + + def test_the_registry_loads_from_a_bare_copy(monkeypatch, tmp_path): """In the container only the copied file exists, with no microcosm.""" From e376b4e5c221f39c454090712fe36c77e9305feb Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:06:45 +0400 Subject: [PATCH 2/6] Install the emitter in the UK Modal launcher's image run_uk_cut.py's preflight starts the separately installed microcosm-emitter to check write access (#1460), and the workspace lock pins only its interface (#1410), so the launcher's image, which installed only uv, stopped every Modal run there. As the US Modal image does, the image now installs microcosm-emitter at or above the release minimum_emitter_version.json names in the launching checkout, into /usr/local/bin outside the environment the container syncs, runs its version so a command that cannot run fails the image build, and sets MICROCOSM_EMITTER_COMMAND to it. The launcher refuses a minimum file it cannot read, and its plan names the requirement. The container defines the image without reading the checkout, as before. Closes #1757. Co-Authored-By: Claude Opus 5.5 --- README.md | 3 +- .../1757-uk-modal-launcher-emitter.fixed.md | 1 + docs/orrery-publication.md | 3 +- docs/uk-cut-anyone.md | 5 ++ tools/modal_uk_cut.py | 66 ++++++++++++++++++- 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 changelog.d/1757-uk-modal-launcher-emitter.fixed.md diff --git a/README.md b/README.md index 1cf8eb3756..65bdbaf6af 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,8 @@ added `microcosm-emitter status`, which the US Modal stage runner runs after each stage to record how many telemetry events the stage's emitter left undelivered. The release is written once, in `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json`, -which builds read as package data and the Modal image's install step reads +which builds read as package data and the install steps of the Modal images +(the US stage runner's and the UK launcher's, `tools/modal_uk_cut.py`) read from the launching checkout. Releases before 0.10.0 send telemetry to the collector's Cloud Run address, which changes when the collector moves to another Google Cloud project; from 0.10.0 on, releases send to the diff --git a/changelog.d/1757-uk-modal-launcher-emitter.fixed.md b/changelog.d/1757-uk-modal-launcher-emitter.fixed.md new file mode 100644 index 0000000000..8e36249223 --- /dev/null +++ b/changelog.d/1757-uk-modal-launcher-emitter.fixed.md @@ -0,0 +1 @@ +`tools/modal_uk_cut.py`'s image installs the separately installed `microcosm-emitter` (microcosm#1757), so a UK build run on Modal no longer stops at `run_uk_cut.py`'s preflight, which starts the emitter to check write access (#1460). As in the US Modal image, the install step asks for `microcosm-emitter>=` the release `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json` names in the launching checkout, installs it into `/usr/local/bin` outside the environment the container syncs, and runs its `version` so a command that cannot run fails the image build; `MICROCOSM_EMITTER_COMMAND` points the build at it. The launcher refuses a minimum file it cannot read, and its plan names the emitter requirement. The build enforces the minimum of the commit it clones, so launch from a checkout at or after that commit. The emitter's event queue files stay in the container's cache directory, as in the US runner, so hand-overs still queued when the container exits are lost with it. The launcher has still never run on Modal. diff --git a/docs/orrery-publication.md b/docs/orrery-publication.md index 721e9a05aa..0768bb1449 100644 --- a/docs/orrery-publication.md +++ b/docs/orrery-publication.md @@ -157,7 +157,8 @@ asks for starts without it. A build does not start an emitter older than `MINIMUM_EMITTER_VERSION` in `microcosm.build.telemetry_emitter`, now 0.17.0, and the Modal image installs at least the same release (`image_emitter_requirement()` in -`tools/modal_us_stage_plan.py`, `microcosm-emitter>=0.17.0`). The release is +`tools/modal_us_stage_plan.py`, `microcosm-emitter>=0.17.0`), as does the UK +launcher's image (`emitter_requirement()` in `tools/modal_uk_cut.py`). The release is written once, in microcosm-build's package data, `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json`: the adapter reads it as package data, and the runner, which imports nothing diff --git a/docs/uk-cut-anyone.md b/docs/uk-cut-anyone.md index ce82d62e4e..9e6ed51b4c 100644 --- a/docs/uk-cut-anyone.md +++ b/docs/uk-cut-anyone.md @@ -127,6 +127,11 @@ the Mac is busy, short of disk or asleep. The container: - clones a pushed commit on main; - syncs that commit's own lock with the `uk` extra; +- runs the `microcosm-emitter` its image installs, at or above the release + `minimum_emitter_version.json` names in the checkout you launch from, as + the US Modal image does. The build checks the minimum of the commit it + clones, so launch from a checkout at or after that commit, or preflight + refuses an older emitter in a cached image; - keeps the work directory, with its inputs and every step's outputs, on the `microcosm-uk-cuts` volume, so a rerun resumes. diff --git a/tools/modal_uk_cut.py b/tools/modal_uk_cut.py index 5018101c10..2cc75f990d 100644 --- a/tools/modal_uk_cut.py +++ b/tools/modal_uk_cut.py @@ -6,6 +6,15 @@ directory on the ``microcosm-uk-cuts`` Modal volume, so fetched inputs and every step's outputs survive the container and a rerun resumes. +The build hands its uploads to the separately installed ``microcosm-emitter`` +(microcosm#1410, #1460), which the runner's preflight starts to check write +access, and the workspace lock pins only its interface. So the image installs +the emitter on its own, at or above the release +``minimum_emitter_version.json`` names in the checkout that launches the app, +as the US Modal image does. The build enforces the minimum of the commit it +clones, so a commit that needs a newer emitter than a cached image holds stops +at preflight; launch from a checkout at or after the commit. + Processing UK Data Service microdata on Modal needs the data owners' OK before first use (``docs/uk-cut-anyone.md``). The volume keeps UKDS inputs and outputs, and anyone in the Modal workspace can read it. @@ -35,8 +44,10 @@ import argparse import importlib.util +import json import os import re +import shlex import subprocess import sys from pathlib import Path @@ -60,6 +71,20 @@ "packages/microcosm-data/src/microcosm/data/gate_signing_keys.py" ) REGISTRY_REMOTE = "/root/gate_signing_keys.py" +#: The oldest emitter release a build starts, written once in microcosm-build's +#: package data (``MINIMUM_EMITTER_VERSION`` in +#: ``microcosm.build.telemetry_emitter``); read by its path, since the launcher +#: cannot import microcosm. +MINIMUM_EMITTER_VERSION_FILE = Path(__file__).resolve().parents[1] / ( + "packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json" +) +EMITTER_RELEASE = re.compile(r"\d+\.\d+\.\d+") +#: Where the image installs the emitter command, outside the environment the +#: container syncs, and the variable through which the build's interface +#: finds it (the interface also searches PATH). +EMITTER_BIN_DIR = "/usr/local/bin" +EMITTER_COMMAND = f"{EMITTER_BIN_DIR}/microcosm-emitter" +EMITTER_COMMAND_ENV = "MICROCOSM_EMITTER_COMMAND" def load_gate_signing_keys(path: Path | None = None) -> ModuleType: @@ -87,6 +112,28 @@ def load_gate_signing_keys(path: Path | None = None) -> ModuleType: registry = load_gate_signing_keys() +def emitter_requirement() -> str: + """What the image installs: at least the oldest emitter release a build starts. + + Read from ``MINIMUM_EMITTER_VERSION_FILE`` in the launching checkout. + Refuses a file that is missing or does not hold + ``{"minimum_emitter_version": "X.Y.Z"}``. + """ + + path = MINIMUM_EMITTER_VERSION_FILE + try: + data = json.loads(path.read_text(encoding="utf-8")) + except (OSError, ValueError) as error: + raise SystemExit( + f"cannot read the emitter's minimum release from {path} " + f"({type(error).__name__})." + ) from None + version = data.get("minimum_emitter_version") if isinstance(data, dict) else None + if not isinstance(version, str) or EMITTER_RELEASE.fullmatch(version) is None: + raise SystemExit(f'{path} must hold {{"minimum_emitter_version": "X.Y.Z"}}.') + return f"microcosm-emitter>={version}" + + def _secrets() -> list[modal.Secret]: # The launcher attaches the credentials only to a deliberate run: modal # run sends the app's secrets before the entrypoint can refuse. In the @@ -107,9 +154,23 @@ def _image() -> modal.Image: modal.Image.debian_slim(python_version=PYTHON_VERSION) .apt_install("git", "build-essential", "libhdf5-dev") .pip_install(f"uv=={UV_VERSION}") - .env({"UV_LINK_MODE": "copy", "PYTHONDONTWRITEBYTECODE": "1"}) + .env( + { + "UV_LINK_MODE": "copy", + "PYTHONDONTWRITEBYTECODE": "1", + EMITTER_COMMAND_ENV: EMITTER_COMMAND, + } + ) ) if modal.is_local(): + # The newest release at or above the minimum when Modal first builds + # this step; Modal reuses the layer while the minimum is unchanged. + # Running its version fails the image build if the command cannot run. + image = image.run_commands( + f"UV_TOOL_BIN_DIR={EMITTER_BIN_DIR} uv tool install " + f"{shlex.quote(emitter_requirement())}", + f"{EMITTER_COMMAND} version", + ) # Last, because Modal refuses build steps after a local file. image = image.add_local_file(str(REGISTRY_SOURCE), REGISTRY_REMOTE) return image @@ -196,7 +257,8 @@ def plan(commit: str, label: str, *, publish: bool = False) -> list[str]: ] print( f"cut {label} at {commit[:9]} on Modal; publish={publish}; " - f"work dir {VOLUME_NAME}:{WORK}; missing credentials: {missing or 'none'}" + f"work dir {VOLUME_NAME}:{WORK}; emitter {emitter_requirement()}; " + f"missing credentials: {missing or 'none'}" ) return missing From bb2823ad1d3b6cee690c3e699581c78ca3972432 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:35:51 +0400 Subject: [PATCH 3/6] Test that the UK Modal image distrusts the eMudhra roots before downloading Review round 1 of #1758 found that the new emitter install step, which resolves the emitter's dependencies without hashes, runs with uv 0.11.7 and the cached base's pip 25.3 and CA store, all of which trust the compromised eMudhra (emSign) roots; the US Modal image left them for that reason. These tests ask the UK image for the US image's measures in the same order (ca-certificates upgrade, the hash-pinned pip bootstrap, uv at the US image's version), for UV_PYTHON_DOWNLOADS=never, and for the plan to refuse a commit whose minimum emitter release is above the launching checkout's or cannot be read. Two more check that the two launchers agree on the emitter requirement and command. The image-chain, ordering, download, and both refusal tests fail on this commit. Co-Authored-By: Claude Opus 5.5 --- .../tests/engine_free/uk/test_modal_uk_cut.py | 180 +++++++++++++++--- 1 file changed, 157 insertions(+), 23 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py b/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py index 304034e0fd..731f731a0c 100644 --- a/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py +++ b/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py @@ -3,6 +3,7 @@ from __future__ import annotations import importlib.util +import json import re import shutil import sys @@ -60,14 +61,40 @@ def test_without_the_opt_in_no_credential_is_attached(monkeypatch): module.main("a" * 40, "t", run=True) +def _git_answering(module, commit_minimum): + """``subprocess.run`` for ``plan``: the commit is on main, and its + ``minimum_emitter_version.json`` names ``commit_minimum`` (``None``: the + commit has no such file, as before microcosm#1522).""" + + def run(argv, **kwargs): + if argv[:2] == ["git", "show"]: + if commit_minimum is None: + return module.subprocess.CompletedProcess( + argv, 128, stdout="", stderr="fatal: path does not exist" + ) + return module.subprocess.CompletedProcess( + argv, + 0, + stdout=json.dumps({"minimum_emitter_version": commit_minimum}), + stderr="", + ) + return module.subprocess.CompletedProcess(argv, 0) + + return run + + +def _launching_minimum(): + from microcosm.build.telemetry_emitter import MINIMUM_EMITTER_VERSION + + return MINIMUM_EMITTER_VERSION + + def test_planning_contacts_no_modal_service(monkeypatch, capsys): monkeypatch.setenv("HF_TOKEN", "hf-test") monkeypatch.delenv(UK_GATE_SIGNING_KEY_ENV, raising=False) module, stub = _load_app(monkeypatch) monkeypatch.setattr( - module.subprocess, - "run", - lambda argv, **kw: module.subprocess.CompletedProcess(argv, 0), + module.subprocess, "run", _git_answering(module, _launching_minimum()) ) stub.reset_mock() assert module.plan("a" * 40, "t") == [UK_GATE_SIGNING_KEY_ENV] @@ -81,29 +108,94 @@ def _image_steps(stub, step): return [entry for entry in stub.mock_calls if entry[0].split(".")[-1] == step] +def _image_chain(stub): + """Each image-definition call as (step name, arguments), in order.""" + + return [ + (name.rsplit(".", 1)[-1], args) + for name, args, _ in stub.mock_calls + if name.startswith("Image.debian_slim") + ] + + +def _emitter_installs(stub): + return [ + step.args + for step in _image_steps(stub, "run_commands") + if any("microcosm-emitter" in command for command in step.args) + ] + + +def _load_us_plan(monkeypatch): + """The US Modal stage runner's plan module, loaded by path like the tools.""" + + spec = importlib.util.spec_from_file_location( + "modal_us_stage_plan_beside_uk_launcher", + ROOT / "tools" / "modal_us_stage_plan.py", + ) + module = importlib.util.module_from_spec(spec) + assert spec.loader is not None + # dataclasses resolve string annotations through sys.modules. + monkeypatch.setitem(sys.modules, spec.name, module) + spec.loader.exec_module(module) + return module + + def test_the_image_carries_the_registry_for_the_container(monkeypatch): module, stub = _load_app(monkeypatch) - built = stub.Image.debian_slim.return_value.apt_install.return_value - # The registry's copy comes after the emitter's install: Modal refuses - # build steps after a local file. - installed = built.pip_install.return_value.env.return_value.run_commands - added = installed.return_value.add_local_file - added.assert_called_once_with(str(module.REGISTRY_SOURCE), module.REGISTRY_REMOTE) + # The registry's copy is the last step, called on the image the emitter's + # install returns: Modal refuses build steps after a local file. + added = [ + entry + for entry in stub.mock_calls + if entry[0] + == ( + "Image.debian_slim().apt_install().run_commands().pip_install()" + ".env().run_commands().add_local_file" + ) + ] + assert [entry.args for entry in added] == [ + (str(module.REGISTRY_SOURCE), module.REGISTRY_REMOTE) + ] + assert _image_chain(stub)[-1][0] == "add_local_file" assert module.REGISTRY_SOURCE.is_file() # Modal places the app module in /root, beside the registry's copy. assert Path(module.REGISTRY_REMOTE).parent == Path("/root") +def test_the_image_trusts_no_compromised_certificate_authority(monkeypatch): + """As the US Modal image does, before anything is downloaded. + + The compromised eMudhra (emSign) roots: uv before 0.13.4 compiles them in, + the cached base's pip 25.3 bundles them, and the base's CA store, which + git and the standard library read, holds them until it is upgraded. + """ + + us_plan = _load_us_plan(monkeypatch) + _, stub = _load_app(monkeypatch) + chain = _image_chain(stub) + assert [name for name, _ in chain] == [ + "debian_slim", + "apt_install", + "run_commands", + "pip_install", + "env", + "run_commands", + "add_local_file", + ] + assert "ca-certificates" in chain[1][1] + assert chain[2][1] == (us_plan.image_pip_bootstrap_command(),) + assert chain[3][1] == (f"uv=={us_plan.IMAGE_UV_VERSION}",) + + def test_the_image_installs_the_emitter_at_the_builds_minimum_release(monkeypatch): """The pre-flight starts the separately installed emitter (#1410, #1460).""" - from microcosm.build.telemetry_emitter import MINIMUM_EMITTER_VERSION - _, stub = _load_app(monkeypatch) - assert [step.args for step in _image_steps(stub, "run_commands")] == [ + assert _emitter_installs(stub) == [ ( "UV_TOOL_BIN_DIR=/usr/local/bin uv tool install " - f"'microcosm-emitter>={MINIMUM_EMITTER_VERSION}'", + f"'microcosm-emitter>={_launching_minimum()}'", "/usr/local/bin/microcosm-emitter version", ) ] @@ -117,6 +209,22 @@ def test_the_build_is_pointed_at_the_installed_emitter(monkeypatch): ) +def test_uv_never_downloads_a_python_in_the_image(monkeypatch): + """The image's 3.13 meets the lock and the emitter, as CI tests the lock.""" + + _, stub = _load_app(monkeypatch) + (environment,) = _image_steps(stub, "env") + assert environment.args[0].get("UV_PYTHON_DOWNLOADS") == "never" + + +def test_the_launchers_agree_on_the_emitter(monkeypatch): + us_plan = _load_us_plan(monkeypatch) + module, _ = _load_app(monkeypatch) + assert module.emitter_requirement() == us_plan.image_emitter_requirement() + assert module.EMITTER_COMMAND == us_plan.IMAGE_EMITTER_COMMAND + assert module.EMITTER_COMMAND_ENV == us_plan.EMITTER_COMMAND_ENV + + @pytest.mark.parametrize( "content", [ @@ -155,25 +263,53 @@ def test_the_container_defines_the_image_without_the_checkout(monkeypatch, tmp_p stub.is_local.return_value = False stub.reset_mock() module._image() - assert _image_steps(stub, "run_commands") == [] + assert _emitter_installs(stub) == [] assert _image_steps(stub, "add_local_file") == [] def test_the_plan_names_the_emitter_the_image_installs(monkeypatch, capsys): - from microcosm.build.telemetry_emitter import MINIMUM_EMITTER_VERSION - module, _ = _load_app(monkeypatch) monkeypatch.setattr( - module.subprocess, - "run", - lambda argv, **kw: module.subprocess.CompletedProcess(argv, 0), + module.subprocess, "run", _git_answering(module, _launching_minimum()) ) module.plan("a" * 40, "t") - assert f"emitter microcosm-emitter>={MINIMUM_EMITTER_VERSION}" in ( + assert f"emitter microcosm-emitter>={_launching_minimum()}" in ( capsys.readouterr().out ) +def test_the_plan_refuses_a_commit_that_needs_a_newer_emitter(monkeypatch): + """Preflight in the paid container would refuse the image's emitter.""" + + module, _ = _load_app(monkeypatch) + monkeypatch.setattr(module.subprocess, "run", _git_answering(module, "99.0.0")) + with pytest.raises(SystemExit, match=r"99\.0\.0.*checkout at or after"): + module.plan("a" * 40, "t") + + +def test_the_plan_refuses_a_commit_whose_minimum_it_cannot_read(monkeypatch): + module, _ = _load_app(monkeypatch) + monkeypatch.setattr(module.subprocess, "run", _git_answering(module, "0.17")) + with pytest.raises(SystemExit, match="aaaaaaaaa"): + module.plan("a" * 40, "t") + + +@pytest.mark.parametrize("commit_minimum", ["launching", "0.13.0", None]) +def test_the_plan_accepts_a_commit_the_image_emitter_satisfies( + monkeypatch, commit_minimum +): + """The same minimum, an older one, or none: commits before microcosm#1522 + kept an older minimum in code.""" + + module, _ = _load_app(monkeypatch) + if commit_minimum == "launching": + commit_minimum = _launching_minimum() + monkeypatch.setattr( + module.subprocess, "run", _git_answering(module, commit_minimum) + ) + module.plan("a" * 40, "t") + + def test_the_registry_loads_from_a_bare_copy(monkeypatch, tmp_path): """In the container only the copied file exists, with no microcosm.""" @@ -199,9 +335,7 @@ def test_missing_credentials_are_asked_for_one_command(monkeypatch): monkeypatch.delenv(UK_GATE_SIGNING_KEY_ENV, raising=False) module, _ = _load_app(monkeypatch) monkeypatch.setattr( - module.subprocess, - "run", - lambda argv, **kw: module.subprocess.CompletedProcess(argv, 0), + module.subprocess, "run", _git_answering(module, _launching_minimum()) ) with pytest.raises(SystemExit, match="to this command") as refusal: module.main("a" * 40, "t", run=True) From 9b09e7f38addfc5466238dc6d0339f9b56e0dcd9 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:38:18 +0400 Subject: [PATCH 4/6] Drop the eMudhra roots from the UK Modal image before it downloads Review round 1 of #1758: the new emitter install resolves the emitter's dependencies without hashes, and the image downloaded with uv 0.11.7, the base's pip 25.3 and the base's CA store, which all trust the compromised eMudhra (emSign) roots; code swapped in there would run with HF_TOKEN and the signing key. As in the US Modal image, the image now upgrades ca-certificates, replaces pip with the hash-pinned 26.2.2 before any other download, installs uv 0.13.4, and sets UV_PYTHON_DOWNLOADS=never. The plan also reads the cloned commit's minimum_emitter_version.json with git show and refuses a commit whose minimum is above the launching checkout's, which preflight would otherwise refuse in the paid container with upgrade advice that cannot apply to an image. docs/orrery-publication.md now says which of the two Modal images each sentence describes. Co-Authored-By: Claude Opus 5.5 --- .../1757-uk-modal-launcher-emitter.fixed.md | 2 +- docs/orrery-publication.md | 32 +++-- docs/uk-cut-anyone.md | 6 +- tools/modal_uk_cut.py | 133 +++++++++++++++--- 4 files changed, 140 insertions(+), 33 deletions(-) diff --git a/changelog.d/1757-uk-modal-launcher-emitter.fixed.md b/changelog.d/1757-uk-modal-launcher-emitter.fixed.md index 8e36249223..e8affd0cf1 100644 --- a/changelog.d/1757-uk-modal-launcher-emitter.fixed.md +++ b/changelog.d/1757-uk-modal-launcher-emitter.fixed.md @@ -1 +1 @@ -`tools/modal_uk_cut.py`'s image installs the separately installed `microcosm-emitter` (microcosm#1757), so a UK build run on Modal no longer stops at `run_uk_cut.py`'s preflight, which starts the emitter to check write access (#1460). As in the US Modal image, the install step asks for `microcosm-emitter>=` the release `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json` names in the launching checkout, installs it into `/usr/local/bin` outside the environment the container syncs, and runs its `version` so a command that cannot run fails the image build; `MICROCOSM_EMITTER_COMMAND` points the build at it. The launcher refuses a minimum file it cannot read, and its plan names the emitter requirement. The build enforces the minimum of the commit it clones, so launch from a checkout at or after that commit. The emitter's event queue files stay in the container's cache directory, as in the US runner, so hand-overs still queued when the container exits are lost with it. The launcher has still never run on Modal. +`tools/modal_uk_cut.py`'s image installs the separately installed `microcosm-emitter` (microcosm#1757), so a UK build run on Modal no longer stops at `run_uk_cut.py`'s preflight, which starts the emitter to check write access (#1460). As in the US Modal image, the install step asks for `microcosm-emitter>=` the release `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json` names in the launching checkout, installs it into `/usr/local/bin` outside the environment the container syncs, and runs its `version` so a command that cannot run fails the image build; `MICROCOSM_EMITTER_COMMAND` points the build at it. Before it downloads anything, the image now also drops the compromised eMudhra (emSign) certificate authorities as the US image does (`emudhra-ca-trust`): it upgrades `ca-certificates`, replaces the base's pip 25.3 with the hash-pinned pip 26.2.2, and installs uv 0.13.4 instead of 0.11.7; it also sets `UV_PYTHON_DOWNLOADS=never`. The launcher refuses a minimum file it cannot read, its plan names the emitter requirement, and the plan refuses a commit whose `minimum_emitter_version.json` names a higher release than the launching checkout's, which the build's preflight would otherwise refuse in the paid container. The emitter's event queue files stay in the container's cache directory, as in the US runner, so hand-overs still queued when the container exits are lost with it. The launcher has still never run on Modal. diff --git a/docs/orrery-publication.md b/docs/orrery-publication.md index 0768bb1449..8aa32bdff5 100644 --- a/docs/orrery-publication.md +++ b/docs/orrery-publication.md @@ -146,8 +146,11 @@ Hugging Face. (`>=0.16.0,<1`), the dependency-free package of typed calls, which `uv.lock` records with its hashes. The emitter itself, `microcosm-emitter`, is not a workspace dependency: each machine installs it on its own with -`uv tool install microcosm-emitter`, and the Modal image installs the newest -release when it is built for a plan commit. A running build keeps the +`uv tool install microcosm-emitter`. The US Modal stage runner's image +installs the newest release when it is built for a plan commit; the UK +launcher's image (`tools/modal_uk_cut.py`), which clones its commit only at +run time, installs the newest release when Modal first builds that step and +keeps it until the minimum below rises. A running build keeps the emitter it started; the next build uses whichever release is installed then. So an emitter release needs no Microcosm change. The socket protocol carries its own version (`PROTOCOL_VERSION`), every emitter release accepts the @@ -155,19 +158,22 @@ versions interfaces still send, and an emitter that lacks a module the build asks for starts without it. A build does not start an emitter older than `MINIMUM_EMITTER_VERSION` in -`microcosm.build.telemetry_emitter`, now 0.17.0, and the Modal image installs -at least the same release (`image_emitter_requirement()` in -`tools/modal_us_stage_plan.py`, `microcosm-emitter>=0.17.0`), as does the UK -launcher's image (`emitter_requirement()` in `tools/modal_uk_cut.py`). The release is +`microcosm.build.telemetry_emitter`, now 0.17.0, and both Modal images install +at least the same release (`microcosm-emitter>=0.17.0`): the US stage +runner's through `image_emitter_requirement()` in +`tools/modal_us_stage_plan.py`, the UK launcher's through +`emitter_requirement()` in `tools/modal_uk_cut.py`. The release is written once, in microcosm-build's package data, `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json`: -the adapter reads it as package data, and the runner, which imports nothing -from the workspace, reads it by its path in the checkout that launches the -app. The image adds that checkout's file beside the runner's copy of the -plan module, so the check, which runs in the container, reads the same -file. At a Modal launch the install step therefore comes from the launching -checkout and the minimum from the commit the plan pins (see the -[US Modal stage runbook](us-modal-stage-runbook.md)). Releases +the adapter reads it as package data, and both launchers, which import +nothing from the workspace, read it by its path in the checkout that +launches the app. At a Modal launch the install step therefore comes from +the launching checkout and the minimum from the commit the build runs. The +US runner's image adds the launching checkout's file beside its copy of the +plan module, so its check, which runs in the container, reads the same file +(see the [US Modal stage runbook](us-modal-stage-runbook.md)). The UK +launcher's plan reads the commit's file with `git show` and refuses a +commit whose minimum is higher than the launching checkout's. Releases before 0.10.0 send telemetry to the collector's Cloud Run address, which changes when the collector moves to another Google Cloud project. From 0.10.0 on, the emitter's default collector address is the collector's hostname, diff --git a/docs/uk-cut-anyone.md b/docs/uk-cut-anyone.md index 9e6ed51b4c..9589047326 100644 --- a/docs/uk-cut-anyone.md +++ b/docs/uk-cut-anyone.md @@ -130,8 +130,10 @@ the Mac is busy, short of disk or asleep. The container: - runs the `microcosm-emitter` its image installs, at or above the release `minimum_emitter_version.json` names in the checkout you launch from, as the US Modal image does. The build checks the minimum of the commit it - clones, so launch from a checkout at or after that commit, or preflight - refuses an older emitter in a cached image; + clones, so the plan refuses a commit whose minimum is higher: launch from + a checkout at or after that commit. Like the US image, the image first + drops the compromised eMudhra certificate authorities (an upgraded CA + store, a hash-pinned pip and uv 0.13.4) before it downloads anything; - keeps the work directory, with its inputs and every step's outputs, on the `microcosm-uk-cuts` volume, so a rerun resumes. diff --git a/tools/modal_uk_cut.py b/tools/modal_uk_cut.py index 2cc75f990d..5e5ffd4360 100644 --- a/tools/modal_uk_cut.py +++ b/tools/modal_uk_cut.py @@ -12,8 +12,11 @@ the emitter on its own, at or above the release ``minimum_emitter_version.json`` names in the checkout that launches the app, as the US Modal image does. The build enforces the minimum of the commit it -clones, so a commit that needs a newer emitter than a cached image holds stops -at preflight; launch from a checkout at or after the commit. +clones, so the plan refuses a commit whose minimum is higher than the +launching checkout's; launch from a checkout at or after the commit. As in the +US image, the image first drops the compromised eMudhra certificate +authorities (an upgraded CA store, a hash-pinned pip, uv 0.13.4) before it +downloads anything else. Processing UK Data Service microdata on Modal needs the data owners' OK before first use (``docs/uk-cut-anyone.md``). The volume keeps UKDS inputs @@ -61,7 +64,19 @@ REPO_URL = "https://github.com/PolicyEngine/microcosm.git" CHECKOUT = "/microcosm" PYTHON_VERSION = "3.13" # the version PR CI tests the lock with -UV_VERSION = "0.11.7" +# The compromised eMudhra (emSign) roots, whose intermediate keys were +# disclosed on 2026-10-20, are dropped as in the US Modal image +# (tools/modal_us_stage_plan.py, whose values the tests compare with these). +# uv verifies HTTPS against a CA list compiled into it, and 0.13.4 is the +# first release whose list drops them. +UV_VERSION = "0.13.4" +# Modal's cached debian_slim base carries pip 25.3, whose bundled certifi +# still contains emSign ECC Root CA - G3, so the image replaces it with this +# pip before downloading anything else. The wheel's sha256, as PyPI publishes +# it, not the connection, makes that one download authentic. +PIP_VERSION = "26.2.2" +PIP_WHEEL_SHA256 = "fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70" +PIP_BOOTSTRAP_REQUIREMENTS = "/tmp/pip-bootstrap.txt" SHA = re.compile(r"^[0-9a-f]{40}$") #: The launcher's opt-in for attaching credentials to a ``modal run``. RUN_OPT_IN = "MICROCOSM_UK_CUT_MODAL_RUN" @@ -74,10 +89,13 @@ #: The oldest emitter release a build starts, written once in microcosm-build's #: package data (``MINIMUM_EMITTER_VERSION`` in #: ``microcosm.build.telemetry_emitter``); read by its path, since the launcher -#: cannot import microcosm. -MINIMUM_EMITTER_VERSION_FILE = Path(__file__).resolve().parents[1] / ( +#: cannot import microcosm. ``plan`` also reads the cloned commit's copy. +MINIMUM_EMITTER_VERSION_PATH = ( "packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json" ) +MINIMUM_EMITTER_VERSION_FILE = ( + Path(__file__).resolve().parents[1] / MINIMUM_EMITTER_VERSION_PATH +) EMITTER_RELEASE = re.compile(r"\d+\.\d+\.\d+") #: Where the image installs the emitter command, outside the environment the #: container syncs, and the variable through which the build's interface @@ -112,26 +130,86 @@ def load_gate_signing_keys(path: Path | None = None) -> ModuleType: registry = load_gate_signing_keys() -def emitter_requirement() -> str: - """What the image installs: at least the oldest emitter release a build starts. +def pip_bootstrap_command() -> str: + """The shell step that replaces the base's pip before any package download. + + ``--require-hashes`` refuses any file whose sha256 is not + ``PIP_WHEEL_SHA256``, whatever index or certificate answers the request. + """ + + requirement = f"pip=={PIP_VERSION} --hash=sha256:{PIP_WHEEL_SHA256}" + path = shlex.quote(PIP_BOOTSTRAP_REQUIREMENTS) + return ( + f"printf '%s\\n' {shlex.quote(requirement)} > {path}" + f" && python -m pip install --require-hashes --no-deps -r {path}" + f" && rm {path}" + ) + + +def _minimum_release(text: str, source: str) -> str: + """The release a ``minimum_emitter_version.json`` text names; ``source`` names it.""" + + try: + data = json.loads(text) + except ValueError as error: + raise SystemExit( + f"cannot read the emitter's minimum release from {source} " + f"({type(error).__name__})." + ) from None + version = data.get("minimum_emitter_version") if isinstance(data, dict) else None + if not isinstance(version, str) or EMITTER_RELEASE.fullmatch(version) is None: + raise SystemExit(f'{source} must hold {{"minimum_emitter_version": "X.Y.Z"}}.') + return version + - Read from ``MINIMUM_EMITTER_VERSION_FILE`` in the launching checkout. - Refuses a file that is missing or does not hold - ``{"minimum_emitter_version": "X.Y.Z"}``. +def minimum_emitter_version() -> str: + """The oldest emitter release a build starts, as the launching checkout says. + + Refuses a ``MINIMUM_EMITTER_VERSION_FILE`` that is missing or does not + hold ``{"minimum_emitter_version": "X.Y.Z"}``. """ path = MINIMUM_EMITTER_VERSION_FILE try: - data = json.loads(path.read_text(encoding="utf-8")) + text = path.read_text(encoding="utf-8") except (OSError, ValueError) as error: raise SystemExit( f"cannot read the emitter's minimum release from {path} " f"({type(error).__name__})." ) from None - version = data.get("minimum_emitter_version") if isinstance(data, dict) else None - if not isinstance(version, str) or EMITTER_RELEASE.fullmatch(version) is None: - raise SystemExit(f'{path} must hold {{"minimum_emitter_version": "X.Y.Z"}}.') - return f"microcosm-emitter>={version}" + return _minimum_release(text, str(path)) + + +def emitter_requirement() -> str: + """What the image installs: at least the oldest emitter release a build starts.""" + + return f"microcosm-emitter>={minimum_emitter_version()}" + + +def commit_minimum_emitter_version(commit: str) -> str | None: + """The oldest emitter release the build at ``commit`` starts. + + ``None`` when the commit has no ``minimum_emitter_version.json``: commits + before microcosm#1522 kept an older minimum in code. ``commit`` must be + in the launching checkout, as ``plan`` has checked. + """ + + shown = subprocess.run( + ["git", "show", f"{commit}:{MINIMUM_EMITTER_VERSION_PATH}"], + cwd=Path(__file__).resolve().parents[1], + capture_output=True, + text=True, + check=False, + ) + if shown.returncode != 0: + return None + return _minimum_release( + shown.stdout, f"{MINIMUM_EMITTER_VERSION_PATH} at {commit[:9]}" + ) + + +def _release_order(version: str) -> tuple[int, ...]: + return tuple(int(part) for part in version.split(".")) def _secrets() -> list[modal.Secret]: @@ -152,12 +230,19 @@ def _secrets() -> list[modal.Secret]: def _image() -> modal.Image: image = ( modal.Image.debian_slim(python_version=PYTHON_VERSION) - .apt_install("git", "build-essential", "libhdf5-dev") + # Naming ca-certificates upgrades the base's CA store, which git and + # the standard library's ssl module read, to the distribution's + # current release, without the eMudhra roots. + .apt_install("git", "build-essential", "libhdf5-dev", "ca-certificates") + # Before the base's pip downloads anything else. + .run_commands(pip_bootstrap_command()) .pip_install(f"uv=={UV_VERSION}") .env( { "UV_LINK_MODE": "copy", "PYTHONDONTWRITEBYTECODE": "1", + # The image's Python meets the lock and the emitter. + "UV_PYTHON_DOWNLOADS": "never", EMITTER_COMMAND_ENV: EMITTER_COMMAND, } ) @@ -250,6 +335,20 @@ def plan(commit: str, label: str, *, publish: bool = False) -> list[str]: f"{commit} is not on origin/main here (git fetch first); Modal cuts " "build only from main." ) + # The image installs this checkout's minimum and the build enforces the + # commit's, so a higher one at the commit would stop preflight in the + # paid container, where the emitter's upgrade advice cannot be followed. + image_minimum = minimum_emitter_version() + commit_minimum = commit_minimum_emitter_version(commit) + if commit_minimum is not None and ( + _release_order(commit_minimum) > _release_order(image_minimum) + ): + raise SystemExit( + f"{commit[:9]} needs microcosm-emitter>={commit_minimum}, but this " + f"checkout's image installs microcosm-emitter>={image_minimum}, which " + "the build's preflight would refuse; launch from a checkout at or " + f"after {commit[:9]}." + ) missing = [ name for name in ("HF_TOKEN", registry.UK_GATE_SIGNING_KEY_ENV) @@ -257,7 +356,7 @@ def plan(commit: str, label: str, *, publish: bool = False) -> list[str]: ] print( f"cut {label} at {commit[:9]} on Modal; publish={publish}; " - f"work dir {VOLUME_NAME}:{WORK}; emitter {emitter_requirement()}; " + f"work dir {VOLUME_NAME}:{WORK}; emitter microcosm-emitter>={image_minimum}; " f"missing credentials: {missing or 'none'}" ) return missing From f24ebf91975e15f91dbf9e13e686263416d6653b Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:04:29 +0400 Subject: [PATCH 5/6] Test that the UK Modal plan refuses a commit it cannot read Review round 2 of #1758: git show exits 128 alike for a path the commit lacks and for a commit git cannot read, and the plan took either as "no minimum file", so it could let through a commit it should refuse. The stand-in git now answers ls-tree too, and a new test expects the plan to refuse an unreadable commit. The certificate-authority test also asks for the US image's certifi floor on the image's own Python. Both fail on this commit. Co-Authored-By: Claude Opus 5.5 --- .../tests/engine_free/uk/test_modal_uk_cut.py | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py b/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py index 731f731a0c..3b59e02b7e 100644 --- a/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py +++ b/packages/microcosm-build/tests/engine_free/uk/test_modal_uk_cut.py @@ -61,17 +61,25 @@ def test_without_the_opt_in_no_credential_is_attached(monkeypatch): module.main("a" * 40, "t", run=True) -def _git_answering(module, commit_minimum): +def _git_answering(module, commit_minimum, *, commit_readable=True): """``subprocess.run`` for ``plan``: the commit is on main, and its ``minimum_emitter_version.json`` names ``commit_minimum`` (``None``: the - commit has no such file, as before microcosm#1522).""" + commit has no such file, as before microcosm#1522). Without + ``commit_readable``, git cannot read the commit's tree, and answers + ``ls-tree`` and ``show`` as it does then.""" def run(argv, **kwargs): + unreadable = module.subprocess.CompletedProcess( + argv, 128, stdout="", stderr="fatal: not a tree object" + ) + if argv[:2] == ["git", "ls-tree"]: + if not commit_readable: + return unreadable + listed = "" if commit_minimum is None else f"{argv[-1]}\n" + return module.subprocess.CompletedProcess(argv, 0, stdout=listed, stderr="") if argv[:2] == ["git", "show"]: - if commit_minimum is None: - return module.subprocess.CompletedProcess( - argv, 128, stdout="", stderr="fatal: path does not exist" - ) + if not commit_readable or commit_minimum is None: + return unreadable return module.subprocess.CompletedProcess( argv, 0, @@ -185,7 +193,11 @@ def test_the_image_trusts_no_compromised_certificate_authority(monkeypatch): ] assert "ca-certificates" in chain[1][1] assert chain[2][1] == (us_plan.image_pip_bootstrap_command(),) - assert chain[3][1] == (f"uv=={us_plan.IMAGE_UV_VERSION}",) + # certifi for the image's own Python, which Modal's client uses. + assert chain[3][1] == ( + f"uv=={us_plan.IMAGE_UV_VERSION}", + f"certifi>={us_plan.RUNNER_CERTIFI_MINIMUM_VERSION}", + ) def test_the_image_installs_the_emitter_at_the_builds_minimum_release(monkeypatch): @@ -287,6 +299,19 @@ def test_the_plan_refuses_a_commit_that_needs_a_newer_emitter(monkeypatch): module.plan("a" * 40, "t") +def test_the_plan_refuses_a_commit_whose_tree_it_cannot_read(monkeypatch): + """git answers a missing commit and a missing path alike (exit 128).""" + + module, _ = _load_app(monkeypatch) + monkeypatch.setattr( + module.subprocess, + "run", + _git_answering(module, _launching_minimum(), commit_readable=False), + ) + with pytest.raises(SystemExit, match="aaaaaaaaa"): + module.plan("a" * 40, "t") + + def test_the_plan_refuses_a_commit_whose_minimum_it_cannot_read(monkeypatch): module, _ = _load_app(monkeypatch) monkeypatch.setattr(module.subprocess, "run", _git_answering(module, "0.17")) From bd1a22381025a22be5d9f31241fa0d9aa4180ae7 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:05:15 +0400 Subject: [PATCH 6/6] Refuse a commit the UK Modal plan cannot read, and floor certifi Review round 2 of #1758: git show exits 128 alike for a path the commit lacks and for a commit git cannot read, so the plan took an unreadable commit as one without a minimum file and let it through. It now asks git ls-tree first, which lists nothing for a missing path, and refuses when either command fails. The image's pip install also asks for certifi 2026.10.19 or later, as the US image does, so the image's own Python, which Modal's client runs on, drops the eMudhra roots too and the docs' "as the US image does" holds. The build adapter's comment and docs/orrery-publication.md now name both launchers and say when Modal rebuilds the emitter's layer. Co-Authored-By: Claude Opus 5.5 --- .../1757-uk-modal-launcher-emitter.fixed.md | 2 +- docs/orrery-publication.md | 4 +- docs/uk-cut-anyone.md | 3 +- .../src/microcosm/build/telemetry_emitter.py | 7 ++-- tools/modal_uk_cut.py | 38 +++++++++++++++---- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/changelog.d/1757-uk-modal-launcher-emitter.fixed.md b/changelog.d/1757-uk-modal-launcher-emitter.fixed.md index e8affd0cf1..37968a605a 100644 --- a/changelog.d/1757-uk-modal-launcher-emitter.fixed.md +++ b/changelog.d/1757-uk-modal-launcher-emitter.fixed.md @@ -1 +1 @@ -`tools/modal_uk_cut.py`'s image installs the separately installed `microcosm-emitter` (microcosm#1757), so a UK build run on Modal no longer stops at `run_uk_cut.py`'s preflight, which starts the emitter to check write access (#1460). As in the US Modal image, the install step asks for `microcosm-emitter>=` the release `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json` names in the launching checkout, installs it into `/usr/local/bin` outside the environment the container syncs, and runs its `version` so a command that cannot run fails the image build; `MICROCOSM_EMITTER_COMMAND` points the build at it. Before it downloads anything, the image now also drops the compromised eMudhra (emSign) certificate authorities as the US image does (`emudhra-ca-trust`): it upgrades `ca-certificates`, replaces the base's pip 25.3 with the hash-pinned pip 26.2.2, and installs uv 0.13.4 instead of 0.11.7; it also sets `UV_PYTHON_DOWNLOADS=never`. The launcher refuses a minimum file it cannot read, its plan names the emitter requirement, and the plan refuses a commit whose `minimum_emitter_version.json` names a higher release than the launching checkout's, which the build's preflight would otherwise refuse in the paid container. The emitter's event queue files stay in the container's cache directory, as in the US runner, so hand-overs still queued when the container exits are lost with it. The launcher has still never run on Modal. +`tools/modal_uk_cut.py`'s image installs the separately installed `microcosm-emitter` (microcosm#1757), so a UK build run on Modal no longer stops at `run_uk_cut.py`'s preflight, which starts the emitter to check write access (#1460). As in the US Modal image, the install step asks for `microcosm-emitter>=` the release `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json` names in the launching checkout, installs it into `/usr/local/bin` outside the environment the container syncs, and runs its `version` so a command that cannot run fails the image build; `MICROCOSM_EMITTER_COMMAND` points the build at it. Before it downloads anything, the image now also drops the compromised eMudhra (emSign) certificate authorities as the US image does (`emudhra-ca-trust`): it upgrades `ca-certificates`, replaces the base's pip 25.3 with the hash-pinned pip 26.2.2, and installs uv 0.13.4 instead of 0.11.7 and certifi 2026.10.19 or later for the image's own Python; it also sets `UV_PYTHON_DOWNLOADS=never`. The launcher refuses a minimum file it cannot read, its plan names the emitter requirement, and the plan refuses a commit whose tree it cannot read, or whose `minimum_emitter_version.json` names a higher release than the launching checkout's, which the build's preflight would otherwise refuse in the paid container. The emitter's event queue files stay in the container's cache directory, as in the US runner, so hand-overs still queued when the container exits are lost with it. The launcher has still never run on Modal. diff --git a/docs/orrery-publication.md b/docs/orrery-publication.md index 8aa32bdff5..60feea124e 100644 --- a/docs/orrery-publication.md +++ b/docs/orrery-publication.md @@ -150,7 +150,9 @@ workspace dependency: each machine installs it on its own with installs the newest release when it is built for a plan commit; the UK launcher's image (`tools/modal_uk_cut.py`), which clones its commit only at run time, installs the newest release when Modal first builds that step and -keeps it until the minimum below rises. A running build keeps the +keeps it until the minimum below rises or Modal rebuilds the layer, as it +does when an earlier step of the image or Modal's image builder version +changes. A running build keeps the emitter it started; the next build uses whichever release is installed then. So an emitter release needs no Microcosm change. The socket protocol carries its own version (`PROTOCOL_VERSION`), every emitter release accepts the diff --git a/docs/uk-cut-anyone.md b/docs/uk-cut-anyone.md index 9589047326..c189738d48 100644 --- a/docs/uk-cut-anyone.md +++ b/docs/uk-cut-anyone.md @@ -133,7 +133,8 @@ the Mac is busy, short of disk or asleep. The container: clones, so the plan refuses a commit whose minimum is higher: launch from a checkout at or after that commit. Like the US image, the image first drops the compromised eMudhra certificate authorities (an upgraded CA - store, a hash-pinned pip and uv 0.13.4) before it downloads anything; + store, a hash-pinned pip, uv 0.13.4 and a certifi floor) before it + downloads anything; - keeps the work directory, with its inputs and every step's outputs, on the `microcosm-uk-cuts` volume, so a rerun resumes. diff --git a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py index 871633d966..be159157db 100644 --- a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py +++ b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py @@ -112,9 +112,10 @@ STARTUP_TIMEOUT_SECONDS = 15.0 #: The package data file that holds the oldest emitter release a build #: starts, ``MINIMUM_EMITTER_VERSION``. It is the one place the release is -#: written: the Modal stage runner (``tools/modal_us_stage_plan.py``), which -#: imports nothing from the workspace, reads the same file by its path in the -#: checkout that launches it, and installs at least that release in its image. +#: written: the US Modal stage runner (``tools/modal_us_stage_plan.py``) and +#: the UK Modal launcher (``tools/modal_uk_cut.py``), which import nothing +#: from the workspace, read the same file by its path in the checkout that +#: launches them, and install at least that release in their images. MINIMUM_EMITTER_VERSION_RESOURCE = "minimum_emitter_version.json" _RELEASE_NUMBER = re.compile(r"(\d+)\.(\d+)\.(\d+)") diff --git a/tools/modal_uk_cut.py b/tools/modal_uk_cut.py index 5e5ffd4360..3e71707725 100644 --- a/tools/modal_uk_cut.py +++ b/tools/modal_uk_cut.py @@ -15,8 +15,8 @@ clones, so the plan refuses a commit whose minimum is higher than the launching checkout's; launch from a checkout at or after the commit. As in the US image, the image first drops the compromised eMudhra certificate -authorities (an upgraded CA store, a hash-pinned pip, uv 0.13.4) before it -downloads anything else. +authorities (an upgraded CA store, a hash-pinned pip, uv 0.13.4 and a certifi +floor) before it downloads anything else. Processing UK Data Service microdata on Modal needs the data owners' OK before first use (``docs/uk-cut-anyone.md``). The volume keeps UKDS inputs @@ -77,6 +77,10 @@ PIP_VERSION = "26.2.2" PIP_WHEEL_SHA256 = "fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70" PIP_BOOTSTRAP_REQUIREMENTS = "/tmp/pip-bootstrap.txt" +# The first certifi release without emSign ECC Root CA - G3, for the image's +# own Python, which Modal's client in the container runs on. Stated, since +# Modal reuses a cached layer while its definition is unchanged. +CERTIFI_MINIMUM_VERSION = "2026.10.19" SHA = re.compile(r"^[0-9a-f]{40}$") #: The launcher's opt-in for attaching credentials to a ``modal run``. RUN_OPT_IN = "MICROCOSM_UK_CUT_MODAL_RUN" @@ -190,19 +194,39 @@ def commit_minimum_emitter_version(commit: str) -> str | None: """The oldest emitter release the build at ``commit`` starts. ``None`` when the commit has no ``minimum_emitter_version.json``: commits - before microcosm#1522 kept an older minimum in code. ``commit`` must be - in the launching checkout, as ``plan`` has checked. + before microcosm#1522 kept an older minimum in code. Refuses a commit + whose tree or file git cannot read here: ``git show`` exits 128 alike + for a missing path and an unreadable commit, so ``git ls-tree``, which + lists nothing for a missing path, tells them apart first. """ + checkout = Path(__file__).resolve().parents[1] + listed = subprocess.run( + ["git", "ls-tree", "--name-only", commit, "--", MINIMUM_EMITTER_VERSION_PATH], + cwd=checkout, + capture_output=True, + text=True, + check=False, + ) + if listed.returncode != 0: + raise SystemExit( + f"cannot read {commit[:9]}'s tree here (git ls-tree exited " + f"{listed.returncode}); fetch it, then plan again." + ) + if not listed.stdout.strip(): + return None shown = subprocess.run( ["git", "show", f"{commit}:{MINIMUM_EMITTER_VERSION_PATH}"], - cwd=Path(__file__).resolve().parents[1], + cwd=checkout, capture_output=True, text=True, check=False, ) if shown.returncode != 0: - return None + raise SystemExit( + f"cannot read {MINIMUM_EMITTER_VERSION_PATH} at {commit[:9]} here " + f"(git show exited {shown.returncode}); fetch it, then plan again." + ) return _minimum_release( shown.stdout, f"{MINIMUM_EMITTER_VERSION_PATH} at {commit[:9]}" ) @@ -236,7 +260,7 @@ def _image() -> modal.Image: .apt_install("git", "build-essential", "libhdf5-dev", "ca-certificates") # Before the base's pip downloads anything else. .run_commands(pip_bootstrap_command()) - .pip_install(f"uv=={UV_VERSION}") + .pip_install(f"uv=={UV_VERSION}", f"certifi>={CERTIFI_MINIMUM_VERSION}") .env( { "UV_LINK_MODE": "copy",