ci-box: socat, a machine id, a git identity and /tmp on disk
From the first full hosted run (arm64, 32 CPUs, cold: 351 s): - Claude's own sandbox needs socat; fetch Debian's pinned build and its libwrap, like the other programs. - The image has no /etc/machine-id and no git identity; tests need both. - /tmp is now a directory on disk: the installer tests set user extended attributes, which a tmpfs refuses before Linux 6.6 (hosted is 6.1). - The release fixture rewrites the arm64 Codex pin too, since the prerequisites check reads it on an arm64 machine.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
5 files changed,
+113
−27
internal/runner/provider/providertest/release.go+7 −0internal/testci/box_test.go+8 −2scripts/ci-box-enter.sh+7 −1scripts/ci-box.json+45 −3scripts/ci-box.py+46 −21
Intent
diff --git a/internal/runner/provider/providertest/release.go b/internal/runner/provider/providertest/release.go| index cdc523f6..3c03ed8a 100644 |
| --- a/internal/runner/provider/providertest/release.go |
| +++ b/internal/runner/provider/providertest/release.go |
| @@ -9,6 +9,7 @@ import ( |
| "fmt" |
| "os" |
| "path/filepath" |
| + "regexp" |
| "strings" |
| "testing" |
| ) |
| @@ -50,6 +51,12 @@ func installCertificationFixture(t *testing.T, root string, m *release.Manifest, |
| } |
| releaseMust(t, os.WriteFile(path, []byte(strings.Join(lines, "\n")), 0600)) |
| } |
| + // On an arm64 machine the prerequisites check reads the arm64 pin. |
| + path := filepath.Join(root, "internal/runner/provider/codex/pins.go") |
| + data, err := os.ReadFile(path) |
| + releaseMust(t, err) |
| + arm := regexp.MustCompile(`(ExecutableSHA256Arm64\s+= )"[a-f0-9]{64}"`) |
| + releaseMust(t, os.WriteFile(path, arm.ReplaceAll(data, []byte(`${1}"`+binaryHashes["codex"]+`"`)), 0600)) |
| } |
| for i, c := range m.DirectPolicies { |
| dir := filepath.Join(root, "internal/release/evidence", c.Provider) |
diff --git a/internal/testci/box_test.go b/internal/testci/box_test.go| index b1d1c38e..fd8de184 100644 |
| --- a/internal/testci/box_test.go |
| +++ b/internal/testci/box_test.go |
| @@ -51,7 +51,13 @@ func TestBoxPinsMatchTheCode(t *testing.T) { |
| } |
| } |
| } |
| - if len(box.Tools) != 4 { |
| - t.Errorf("the box fetches %d programs; this test knows 4", len(box.Tools)) |
| + // Every other program the box fetches is pinned for both architectures too. |
| + for name, tool := range box.Tools { |
| + for _, arch := range []string{"amd64", "arm64"} { |
| + var entry struct{ URL, SHA256 string } |
| + if err = json.Unmarshal(tool[arch], &entry); err != nil || !strings.HasPrefix(entry.URL, "https://") || !digest.MatchString(entry.SHA256) { |
| + t.Errorf("%s %s: want an https URL and a SHA-256, got %q %q (%v)", name, arch, entry.URL, entry.SHA256, err) |
| + } |
| + } |
| } |
| } |
diff --git a/scripts/ci-box-enter.sh b/scripts/ci-box-enter.sh| index de40ce48..79ddb356 100755 |
| --- a/scripts/ci-box-enter.sh |
| +++ b/scripts/ci-box-enter.sh |
| @@ -6,7 +6,9 @@ |
| # - /etc on a filesystem of its own. Containment lays an overlay over |
| # /etc, and the kernel refuses one whose lower layer is the |
| # container's own overlay root; |
| -# - a home directory, with the pinned programs where tests look for them; |
| +# - a machine id, which a real host has and the image does not; |
| +# - a home directory, with the pinned programs where tests look for them, |
| +# and a git identity, without which git refuses to commit; |
| # - a cgroup v2 subtree the user may write, at the path systemd gives a |
| # user session. The cgroup move test moves a contained process between |
| # two cgroups there, as a person on a runner host can. |
| @@ -28,6 +30,7 @@ mkdir -p /run/equipo-etc |
| mount -t tmpfs -o mode=0755 tmpfs /run/equipo-etc |
| cp -a /etc/. /run/equipo-etc/ |
| mount --bind /run/equipo-etc /etc |
| +[ -s /etc/machine-id ] || echo 0ec1b0c1e9015c1b0c5e9015c1b0c1e9 >/etc/machine-id |
| grep -q '^ci:' /etc/passwd || [ "$uid" = 0 ] || echo "ci:x:$uid:$gid:Equipo CI:$home:/bin/sh" >>/etc/passwd |
| grep -q '^ci:' /etc/group || [ "$gid" = 0 ] || echo "ci:x:$gid:" >>/etc/group |
| @@ -44,6 +47,9 @@ else |
| echo "ci-box: no writable cgroup v2 tree here; the cgroup move test will fail" >&2 |
| fi |
| +printf '[user]\n\tname = Equipo CI\n\temail = ci@equipo.invalid\n' >"$home/.gitconfig" |
| +[ "$uid" != 0 ] || printf '[safe]\n\tdirectory = *\n' >>"$home/.gitconfig" |
| +chown "$uid:$gid" "$home/.gitconfig" |
| export HOME="$home" |
| if [ "$uid" = 0 ]; then |
| exec "$@" |
diff --git a/scripts/ci-box.json b/scripts/ci-box.json| index 6125e6a9..097a38e9 100644 |
| --- a/scripts/ci-box.json |
| +++ b/scripts/ci-box.json |
| @@ -16,7 +16,8 @@ |
| "format": "deb", |
| "member": "./usr/bin/bwrap", |
| "sha256": "ef2316fc741885e6d7b422661ea60c20cbe07ec7eb592a4c2370cbcb90843b59" |
| - } |
| + }, |
| + "box": "/usr/bin/bwrap" |
| }, |
| "codex": { |
| "version": "codex-cli 0.165.0", |
| @@ -33,7 +34,9 @@ |
| "format": "tar.gz", |
| "member": "codex-aarch64-unknown-linux-musl", |
| "sha256": "b32ece31af06440da980b733fb8fefdd1f193439595fda84096f1caaceec543f" |
| - } |
| + }, |
| + "box": "/usr/local/bin/codex", |
| + "try_bin": true |
| }, |
| "codex-code-mode-host": { |
| "amd64": { |
| @@ -49,7 +52,8 @@ |
| "format": "tar.gz", |
| "member": "codex-code-mode-host-aarch64-unknown-linux-musl", |
| "sha256": "fd7a4a1f29871fb0015c19ad2f885ef6a878244643260703e17663418695aa14" |
| - } |
| + }, |
| + "try_bin": true |
| }, |
| "claude": { |
| "version": "2.1.312 (Claude Code)", |
| @@ -62,6 +66,44 @@ |
| "url": "https://downloads.claude.ai/claude-code-releases/2.1.312/linux-arm64/claude", |
| "format": "raw", |
| "sha256": "dc4af28917455e009d26704b82a438353a06149e825b6cdf782908b2d28661f5" |
| + }, |
| + "try_bin": true |
| + }, |
| + "socat": { |
| + "version": "socat 1.8.0.3", |
| + "box": "/usr/bin/socat", |
| + "amd64": { |
| + "url": "https://snapshot.debian.org/file/37c6de3f1d589800dcaf20979c2e209ab65975ef", |
| + "archive_sha256": "6ad18d699071c1e0e3b1e9acd020368544369d339607e80b7eca97bcf4f97017", |
| + "format": "deb", |
| + "member": "./usr/bin/socat1", |
| + "sha256": "7053ab3b63bb5f1bde806e8b32c13607fc65a6c76efa9cd440b7427ada51300a" |
| + }, |
| + "arm64": { |
| + "url": "https://snapshot.debian.org/file/493b336ad97e9592797bd9cdd3aa5365ec5c5ab6", |
| + "archive_sha256": "935b5ea942807ed82507bf585ae4e666937ebf5c910c5bbe6887ea2b22f19a44", |
| + "format": "deb", |
| + "member": "./usr/bin/socat1", |
| + "sha256": "0b8d4c71219df55dfdcfd96de153ec1452cffe0c756f8b9fc87d66a6931a7e02" |
| + } |
| + }, |
| + "libwrap": { |
| + "version": "libwrap0 7.6.q-36", |
| + "amd64": { |
| + "url": "https://snapshot.debian.org/file/f68950b258f62f06af58295d7ae6c141a9a0e47d", |
| + "archive_sha256": "cde12afa15d6b1556c5e0564d22edf3b99e6b8fa94c59ccd8b8eebbb62dc19ec", |
| + "format": "deb", |
| + "member": "./usr/lib/x86_64-linux-gnu/libwrap.so.0.7.6", |
| + "sha256": "a1679facc8b1b3e16b1d910b7557c1e33461f981add05d3fcb71d2b1aa2df894", |
| + "box": "/usr/lib/x86_64-linux-gnu/libwrap.so.0" |
| + }, |
| + "arm64": { |
| + "url": "https://snapshot.debian.org/file/2147a199f0eb525d8f88e6dfe925e10f7a627849", |
| + "archive_sha256": "fd2e54582a07fba9c8a6f78c68dcc6d3c8cf1c70632a68124394bde4dccf52ea", |
| + "format": "deb", |
| + "member": "./usr/lib/aarch64-linux-gnu/libwrap.so.0.7.6", |
| + "sha256": "961f48b0d807ffdbdf8971b7e13f04409a4bc639cff3ea42defbd850b6ca739d", |
| + "box": "/usr/lib/aarch64-linux-gnu/libwrap.so.0" |
| } |
| } |
| } |
diff --git a/scripts/ci-box.py b/scripts/ci-box.py| index 5192fc89..4125c171 100755 |
| --- a/scripts/ci-box.py |
| +++ b/scripts/ci-box.py |
| @@ -17,6 +17,7 @@ pinned programs mounted where a runner host has them: |
| /usr/bin/bwrap Debian's 0.11.0-2+deb13u1 build |
| /usr/local/bin/codex codex 0.165.0 |
| ~/.local/share/equipo/try/bin codex, its code mode host, claude |
| + /usr/bin/socat Claude's own sandbox needs it |
| Every pinned program is fetched by URL and checked against the SHA-256 in |
| scripts/ci-box.json, for this machine's architecture. The job's checkout |
| @@ -34,6 +35,7 @@ import lzma |
| import os |
| import platform |
| import shutil |
| +import signal |
| import subprocess |
| import sys |
| import tarfile |
| @@ -98,7 +100,13 @@ def box_dir(): |
| def tools_dir(): |
| - return os.path.join(box_dir(), "tools", arch(), "bin") |
| + return os.path.join(box_dir(), "tools", arch()) |
| + |
| + |
| +def tool_path(name, tool): |
| + """Where a fetched program is kept: the ones tests find in the try |
| + directory together in bin, mounted as that directory; the rest in sys.""" |
| + return os.path.join(tools_dir(), "bin" if tool.get("try_bin") else "sys", name) |
| def boxed(): |
| @@ -183,12 +191,12 @@ def extract(archive, fmt, member, dest): |
| shutil.copyfileobj(source, out) |
| -def fetch_tool(name, pin, directory): |
| - target = os.path.join(directory, name) |
| +def fetch_tool(name, pin, target): |
| if os.path.isfile(target) and sha256_file(target) == pin["sha256"]: |
| return "%s: present" % name |
| started = time.time() |
| - with tempfile.TemporaryDirectory(dir=directory) as scratch: |
| + os.makedirs(os.path.dirname(target), exist_ok=True) |
| + with tempfile.TemporaryDirectory(dir=tools_dir()) as scratch: |
| archive = os.path.join(scratch, "archive") |
| got = download(pin["url"], archive) |
| want = pin.get("archive_sha256", pin["sha256"]) |
| @@ -205,18 +213,17 @@ def fetch_tool(name, pin, directory): |
| def fetch_tools(): |
| - directory = tools_dir() |
| - os.makedirs(directory, exist_ok=True) |
| + os.makedirs(os.path.join(tools_dir(), "bin"), exist_ok=True) |
| machine = arch() |
| jobs = [] |
| for name, tool in sorted(pins()["tools"].items()): |
| if machine not in tool: |
| sys.exit("ci-box: %s has no pin for %s" % (name, machine)) |
| - jobs.append((name, tool[machine])) |
| + jobs.append((name, tool[machine], tool_path(name, tool))) |
| with ThreadPoolExecutor(max_workers=len(jobs)) as pool: |
| - for line in pool.map(lambda job: fetch_tool(job[0], job[1], directory), jobs): |
| + for line in pool.map(lambda job: fetch_tool(*job), jobs): |
| say(line) |
| - return directory |
| + return tools_dir() |
| # The container engine and the image. |
| @@ -312,21 +319,29 @@ def run(command): |
| if not boxed(): |
| os.chdir(ROOT) |
| os.execvp(command[0], command) |
| - tools = tools_dir() |
| - missing = [name for name in pins()["tools"] if not os.path.isfile(os.path.join(tools, name))] |
| + machine = arch() |
| + tools = pins()["tools"] |
| + missing = [name for name, tool in tools.items() if not os.path.isfile(tool_path(name, tool))] |
| if missing: |
| sys.exit("ci-box: %s not fetched; run scripts/ci-box.py prepare first" % ", ".join(sorted(missing))) |
| gocache, gomodcache = go_env("GOCACHE"), go_env("GOMODCACHE") |
| for path in (gocache, gomodcache): |
| os.makedirs(path, exist_ok=True) |
| tool = engine() |
| + # /tmp on disk, not a tmpfs: the installer tests set user extended |
| + # attributes, which a tmpfs refuses before Linux 6.6. |
| + os.makedirs(os.path.join(box_dir(), "tmp"), exist_ok=True) |
| + scratch = tempfile.mkdtemp(dir=os.path.join(box_dir(), "tmp")) |
| + os.chmod(scratch, 0o1777) |
| args = [tool, "run", "--rm", "--privileged", "--cgroupns=private", |
| - "--tmpfs", "/tmp:exec,mode=1777", |
| + "-v", scratch + ":/tmp", |
| "-v", ROOT + ":" + WORK, "-w", WORK, |
| "-v", gocache + ":" + GOCACHE, "-v", gomodcache + ":" + GOMODCACHE, |
| - "-v", os.path.join(tools, "bwrap") + ":/usr/bin/bwrap:ro", |
| - "-v", os.path.join(tools, "codex") + ":/usr/local/bin/codex:ro", |
| - "-v", tools + ":" + TRY_BIN + ":ro"] |
| + "-v", os.path.join(tools_dir(), "bin") + ":" + TRY_BIN + ":ro"] |
| + for name, entry in sorted(tools.items()): |
| + inside = entry[machine].get("box") or entry.get("box") |
| + if inside: |
| + args += ["-v", tool_path(name, entry) + ":" + inside + ":ro"] |
| if tool == "docker": |
| args.append("--init") # reaps the orphans the containment tests leave on purpose |
| # A CI runner checks a branch out as a git worktree: .git is a file |
| @@ -336,7 +351,7 @@ def run(command): |
| common = git("rev-parse", "--path-format=absolute", "--git-common-dir").stdout.decode().strip() |
| if common: |
| args += ["-v", common + ":" + common] |
| - for mount in filter(None, os.environ.get("EQUIPO_CI_BOX_MOUNTS", "").split(os.pathsep)): |
| + for mount in filter(None, os.environ.get("EQUIPO_CI_BOX_MOUNTS", "").split(",")): |
| args += ["-v", mount] |
| env = { |
| "GOCACHE": GOCACHE, "GOMODCACHE": GOMODCACHE, |
| @@ -354,7 +369,20 @@ def run(command): |
| for name in sorted(env): |
| args += ["-e", name + "=" + env[name]] |
| args += [pins()["image"], WORK + "/scripts/ci-box-enter.sh"] + command |
| - os.execvp(args[0], args) |
| + child = subprocess.Popen(args) |
| + for number in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP): |
| + signal.signal(number, lambda n, _frame: child.send_signal(n)) |
| + status = child.wait() |
| + # The job's scratch goes with the command. Inside, files may belong to |
| + # the engine's other users, so the box removes them. |
| + subprocess.call([tool, "run", "--rm", "-v", scratch + ":/scratch", pins()["image"], |
| + "find", "/scratch", "-mindepth", "1", "-delete"], |
| + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| + try: |
| + os.rmdir(scratch) |
| + except OSError: |
| + pass |
| + return status if status >= 0 else 128 - status |
| # The Go caches. |
| @@ -421,7 +449,7 @@ def facts(): |
| say("python %s; %s" % (platform.python_version(), out(engine(), "--version"))) |
| say("user namespaces allowed: " + out("cat", "/proc/sys/user/max_user_namespaces")) |
| say("cgroup: " + out("stat", "-fc", "%T", "/sys/fs/cgroup")) |
| - for path in ("/tmp", ROOT, box_dir()): |
| + for path in (ROOT, box_dir()): |
| say("disk %s: %s" % (path, out("df", "-h", "--output=fstype,size,avail", path).replace("\n", " | "))) |
| @@ -451,9 +479,6 @@ def main(argv): |
| return cache() |
| if argv == ["facts"]: |
| return facts() |
| - if argv == ["tools"]: |
| - print(fetch_tools()) |
| - return 0 |
| print(__doc__, file=sys.stderr) |
| return 2 |