ci, runner: install the pinned Pi and hold it to its pins
The CI box installs the pinned Pi as a runner has it (Node by its archive and program digests, npm ci --ignore-scripts from the committed lockfile, sealed, the tree digest checked in Python exactly as provider.TreeSHA256 computes it) and mounts it at /opt/equipo-pi with EQUIPO_PI_ROOT; testci fingerprints it. equipo-runner install-pi <root> does the same on a Linux runner through the Mac installer's pinned-archive fetch; install and verify-installed check pi.Verify when EQUIPO_PI_ROOT is set. The release check also refuses the test build's leave to spend.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+431
−1
cmd/equipo-runner/install.go+7 −0cmd/equipo-runner/install_config.go+4 −0cmd/equipo-runner/install_pi.go+136 −0cmd/equipo-runner/main.go+3 −0cmd/equipo-runner/release_guard_test.go+8 −1internal/runner/provider/pi/home.go+26 −0internal/runner/provider/pi/pins_test.go+69 −0internal/testci/box_test.go+34 −0scripts/ci-box.json+20 −0scripts/ci-box.py+120 −0scripts/no-fake-worker.sh+4 −0
diff --git a/cmd/equipo-runner/install.go b/cmd/equipo-runner/install.go| index cdf83990..8b03fd60 100644 |
| --- a/cmd/equipo-runner/install.go |
| +++ b/cmd/equipo-runner/install.go |
| @@ -1,6 +1,7 @@ |
| package main |
| import ( |
| + "amadan.net/oficina/equipo/internal/runner/provider/pi" |
| "bufio" |
| "context" |
| "encoding/json" |
| @@ -91,6 +92,12 @@ func installRunner(ctx context.Context, args []string, input io.Reader, out, err |
| // The installer runs it before enrolling, and staging and the production |
| // cutover run it (equipo-runner verify-installed) before starting a unit. |
| func verifyInstalled(m release.Manifest, cfg runner.Config) error { |
| + // The pinned Pi, where this runner has one, is held to its pins too. |
| + if cfg.PiRoot != "" { |
| + if err := pi.Verify(cfg.PiRoot); err != nil { |
| + return err |
| + } |
| + } |
| return m.VerifyInstalled(map[string]string{"bwrap": cfg.Bwrap(), "claude": cfg.ClaudePath, "codex": cfg.CodexPath, "codex-code-mode-host": cfg.CodexCodeModeHostPath, "equipo-tool-proxy": cfg.ToolProxy()}) |
| } |
| func installManifest(args []string, out io.Writer) int { |
diff --git a/cmd/equipo-runner/install_config.go b/cmd/equipo-runner/install_config.go| index e46bf312..a54cccdf 100644 |
| --- a/cmd/equipo-runner/install_config.go |
| +++ b/cmd/equipo-runner/install_config.go |
| @@ -34,6 +34,10 @@ func installConfig(root, origin, instance, version string, getenv func(string) s |
| values["EQUIPO_GO_ROOT"] = strings.TrimSpace(string(b)) |
| } |
| values["EQUIPO_GO_MODULE_CACHE"] = getenv("EQUIPO_GO_MODULE_CACHE") |
| + // The pinned Pi (equipo-runner install-pi), if this runner has one. |
| + if root := getenv("EQUIPO_PI_ROOT"); root != "" { |
| + values["EQUIPO_PI_ROOT"] = root |
| + } |
| cfg, e := runner.LoadConfig(func(k string) string { return values[k] }) |
| if e != nil { |
| return cfg, e |
diff --git a/cmd/equipo-runner/install_pi.go b/cmd/equipo-runner/install_pi.go| new file mode 100644 |
| index 00000000..2ab419b9 |
| --- /dev/null |
| +++ b/cmd/equipo-runner/install_pi.go |
| @@ -0,0 +1,136 @@ |
| +package main |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "io" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "runtime" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/mac" |
| + "amadan.net/oficina/equipo/internal/runner/provider/pi" |
| +) |
| + |
| +// installPi installs the pinned Pi under root, for a Linux runner's |
| +// metered connections (connectors spec §3, "Pinning"): Node from its |
| +// official archive, checked against its digest before anything is |
| +// unpacked; the npm tree from the committed lockfile with `npm ci |
| +// --ignore-scripts`; the tree sealed read-only; then the Node program |
| +// and the whole tree held to the committed digests (pi.Verify). It |
| +// prints the line for the runner's environment file. An install that |
| +// does not verify is removed. |
| +func installPi(ctx context.Context, args []string, output, errout io.Writer) int { |
| + if len(args) != 1 || !filepath.IsAbs(args[0]) || filepath.Clean(args[0]) != args[0] { |
| + fmt.Fprintln(errout, "usage: equipo-runner install-pi <absolute root>") |
| + return 2 |
| + } |
| + root := args[0] |
| + if err := installPiAt(ctx, root, runtime.GOARCH, fetchTool, npmCIPi); err != nil { |
| + fmt.Fprintln(errout, "equipo-runner: the pinned Pi could not be installed:", err) |
| + return 1 |
| + } |
| + fmt.Fprintf(output, "EQUIPO_PI_ROOT=%q\n", root) |
| + return 0 |
| +} |
| + |
| +func npmCIPi(ctx context.Context, node, npmCLI, prefix, cache string) error { |
| + cmd := exec.CommandContext(ctx, node, npmCLI, "ci", "--ignore-scripts", "--no-audit", "--no-fund") |
| + cmd.Dir = prefix |
| + cmd.Env = []string{"PATH=" + filepath.Dir(node) + ":/usr/bin:/bin", "HOME=" + cache, "npm_config_cache=" + cache, "npm_config_update_notifier=false"} |
| + // The host's own way out to the registry, if it has one. |
| + for _, k := range []string{"HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY", "https_proxy", "http_proxy", "no_proxy"} { |
| + if v := os.Getenv(k); v != "" { |
| + cmd.Env = append(cmd.Env, k+"="+v) |
| + } |
| + } |
| + cmd.Stderr = os.Stderr |
| + return cmd.Run() |
| +} |
| + |
| +func installPiAt(ctx context.Context, root, goarch string, fetch func(context.Context, string, int64) ([]byte, error), npmCI func(ctx context.Context, node, npmCLI, prefix, cache string) error) error { |
| + if pi.Verify(root) == nil { |
| + return nil |
| + } |
| + _, archive, ok := pi.Pins(goarch) |
| + if !ok { |
| + return pi.ErrUnpinned |
| + } |
| + if err := os.MkdirAll(root, 0700); err != nil { |
| + return err |
| + } |
| + scratch, err := os.MkdirTemp(root, ".install-") |
| + if err != nil { |
| + return err |
| + } |
| + defer removeTree(scratch) |
| + tool := mac.Tool{Name: "node", Version: archive.Version, URL: archive.URL, SHA256: archive.SHA256, Root: archive.Root, Binary: "bin/node", |
| + Links: map[string]string{"bin/npm": "../lib/node_modules/npm/bin/npm-cli.js", "bin/npx": "../lib/node_modules/npm/bin/npx-cli.js"}, |
| + SkipLinks: []string{"bin/corepack"}} |
| + node, err := mac.Fetch(ctx, tool, filepath.Join(scratch, "tools"), fetch) |
| + if err != nil { |
| + return err |
| + } |
| + prefix := filepath.Join(scratch, "pi") |
| + if err := os.MkdirAll(prefix, 0700); err != nil { |
| + return err |
| + } |
| + pkg, lock := pi.Package() |
| + if os.WriteFile(filepath.Join(prefix, "package.json"), pkg, 0600) != nil || os.WriteFile(filepath.Join(prefix, "package-lock.json"), lock, 0600) != nil { |
| + return pi.ErrUnpinned |
| + } |
| + cache := filepath.Join(scratch, "npm") |
| + if err := os.MkdirAll(cache, 0700); err != nil { |
| + return err |
| + } |
| + if err := npmCI(ctx, node, filepath.Join(filepath.Dir(filepath.Dir(node)), "lib", "node_modules", "npm", "bin", "npm-cli.js"), prefix, cache); err != nil { |
| + return err |
| + } |
| + tree := filepath.Join(prefix, "node_modules") |
| + if err := pi.Seal(tree); err != nil { |
| + return err |
| + } |
| + // Into place: the old install (if any) goes first. |
| + nodeDst, treeDst := pi.Paths(root) |
| + for _, old := range []string{filepath.Dir(filepath.Dir(nodeDst)), filepath.Dir(treeDst)} { |
| + removeTree(old) |
| + } |
| + if err := os.MkdirAll(filepath.Dir(nodeDst), 0700); err != nil { |
| + return err |
| + } |
| + raw, err := os.ReadFile(node) |
| + if err != nil || os.WriteFile(nodeDst, raw, 0555) != nil { |
| + return pi.ErrUnpinned |
| + } |
| + if err := os.MkdirAll(filepath.Dir(treeDst), 0700); err != nil { |
| + return err |
| + } |
| + // A directory moves to another parent only while it is writable. |
| + if err := os.Chmod(tree, 0755); err != nil { |
| + return err |
| + } |
| + if err := os.Rename(tree, treeDst); err != nil { |
| + return err |
| + } |
| + if err := os.Chmod(treeDst, 0555); err != nil { |
| + return err |
| + } |
| + if err := pi.Verify(root); err != nil { |
| + removeTree(filepath.Dir(treeDst)) |
| + removeTree(filepath.Dir(filepath.Dir(nodeDst))) |
| + return err |
| + } |
| + return nil |
| +} |
| + |
| +// removeTree removes a tree a seal made read-only. |
| +func removeTree(dir string) { |
| + filepath.Walk(dir, func(p string, info os.FileInfo, err error) error { |
| + if err == nil && info.IsDir() { |
| + os.Chmod(p, 0700) |
| + } |
| + return nil |
| + }) |
| + os.RemoveAll(dir) |
| +} |
diff --git a/cmd/equipo-runner/main.go b/cmd/equipo-runner/main.go| index fc06f911..2129d97d 100644 |
| --- a/cmd/equipo-runner/main.go |
| +++ b/cmd/equipo-runner/main.go |
| @@ -69,6 +69,9 @@ func run(ctx context.Context, args []string, input io.Reader, output, errorOutpu |
| if len(args) > 0 && args[0] == "verify-install-manifest" { |
| return installManifest(args[1:], output) |
| } |
| + if len(args) > 0 && args[0] == "install-pi" { |
| + return installPi(ctx, args[1:], output, errorOutput) |
| + } |
| if len(args) != 1 { |
| return fail(nil) |
| } |
diff --git a/cmd/equipo-runner/release_guard_test.go b/cmd/equipo-runner/release_guard_test.go| index bff7dbc7..4a67fafa 100644 |
| --- a/cmd/equipo-runner/release_guard_test.go |
| +++ b/cmd/equipo-runner/release_guard_test.go |
| @@ -52,6 +52,9 @@ func TestReleaseRunnerHasNoFakeWorker(t *testing.T) { |
| if bytes.Contains(raw, []byte(egressMarker)) { |
| t.Fatal("the release runner contains the test build's egress route") |
| } |
| + if bytes.Contains(raw, []byte(spendMarker)) { |
| + t.Fatal("the release runner contains the test build's leave to spend") |
| + } |
| if out, err := exec.Command("../../scripts/no-fake-worker.sh", bin).CombinedOutput(); err != nil { |
| t.Fatalf("the release check refused a clean binary: %s", out) |
| } |
| @@ -62,7 +65,7 @@ func TestReleaseRunnerHasNoFakeWorker(t *testing.T) { |
| if out, err := test.CombinedOutput(); err != nil { |
| t.Fatalf("test build: %v %s", err, out) |
| } |
| - if raw, _ := os.ReadFile(archive); !bytes.Contains(raw, []byte(marker)) { |
| + if raw, _ := os.ReadFile(archive); !bytes.Contains(raw, []byte(marker)) || !bytes.Contains(raw, []byte(spendMarker)) { |
| t.Fatal("the test build has no marker: this guard sees nothing") |
| } |
| if out, err := exec.Command("../../scripts/no-fake-worker.sh", archive).CombinedOutput(); err == nil { |
| @@ -85,6 +88,10 @@ func TestReleaseRunnerHasNoFakeWorker(t *testing.T) { |
| } |
| } |
| +// spendMarker names the test build's leave to spend (internal/runner/thin |
| +// spend_testbuild.go): metered steps before S3, in tests only. |
| +const spendMarker = "EQUIPO_TEST_LEAVE_TO_SPEND" |
| + |
| // egressMarker names the test build's egress route (internal/runner/egress |
| // proxy_testbuild.go). |
| const egressMarker = "EQUIPO_TEST_EGRESS_UPSTREAM" |
diff --git a/internal/runner/provider/pi/home.go b/internal/runner/provider/pi/home.go| index 8e9efb3e..eb0b9328 100644 |
| --- a/internal/runner/provider/pi/home.go |
| +++ b/internal/runner/provider/pi/home.go |
| @@ -2,6 +2,7 @@ package pi |
| import ( |
| "crypto/rand" |
| + "crypto/sha256" |
| "encoding/hex" |
| "errors" |
| "io" |
| @@ -178,3 +179,28 @@ func NewSessionID() string { |
| h := hex.EncodeToString(b[:]) |
| return h[0:8] + "-" + h[8:12] + "-" + h[12:16] + "-" + h[16:20] + "-" + h[20:] |
| } |
| + |
| +// Verify holds an install root to this platform's pins: the Node |
| +// program's digest and the whole tree's (sealed, every file, mode and |
| +// link). A runner checks it at install and before it starts; every |
| +// launch checks both again (provider.BuildPiPolicy and its attestation). |
| +func Verify(root string) error { |
| + treePin, nodePin, ok := Pins(runtime.GOARCH) |
| + if !ok { |
| + return ErrUnpinned |
| + } |
| + node, tree := Paths(root) |
| + raw, err := os.ReadFile(node) |
| + if err != nil { |
| + return ErrUnpinned |
| + } |
| + sum := sha256.Sum256(raw) |
| + if hex.EncodeToString(sum[:]) != nodePin.BinarySHA256 { |
| + return ErrUnpinned |
| + } |
| + got, err := TreeSHA256(tree) |
| + if err != nil || got != treePin { |
| + return ErrUnpinned |
| + } |
| + return nil |
| +} |
diff --git a/internal/runner/provider/pi/pins_test.go b/internal/runner/provider/pi/pins_test.go| index b77abfc6..accdad6c 100644 |
| --- a/internal/runner/provider/pi/pins_test.go |
| +++ b/internal/runner/provider/pi/pins_test.go |
| @@ -163,3 +163,72 @@ func must(t *testing.T, err error) { |
| t.Fatal(err) |
| } |
| } |
| + |
| +// The pinned Pi this machine has (CI's box installs it) is exactly the |
| +// pinned one; a changed file in it is not. |
| +func TestPinnedInstallVerifies(t *testing.T) { |
| + inst := realInstall(t) |
| + root := filepath.Dir(filepath.Dir(inst.Tree)) |
| + if err := Verify(root); err != nil { |
| + t.Fatalf("the pinned install does not verify: %v", err) |
| + } |
| + if err := Verify(t.TempDir()); err == nil { |
| + t.Fatal("an empty root verified") |
| + } |
| + // The right Node beside another tree. |
| + other := t.TempDir() |
| + node, tree := Paths(other) |
| + must(t, os.MkdirAll(filepath.Dir(node), 0755)) |
| + must(t, os.Symlink(inst.Node, node)) |
| + must(t, os.MkdirAll(tree, 0755)) |
| + must(t, os.WriteFile(filepath.Join(tree, "index.js"), []byte("x"), 0444)) |
| + must(t, Seal(tree)) |
| + sealed := tree |
| + t.Cleanup(func() { unseal(sealed) }) |
| + if err := Verify(other); err == nil { |
| + t.Fatal("another tree verified") |
| + } |
| + // The right tree beside another Node. |
| + third := t.TempDir() |
| + node, tree = Paths(third) |
| + must(t, os.MkdirAll(filepath.Dir(node), 0755)) |
| + must(t, os.WriteFile(node, []byte("#!/bin/sh\n"), 0555)) |
| + copyTree(t, inst.Tree, tree) |
| + copied := tree |
| + t.Cleanup(func() { unseal(copied) }) |
| + if sum, err := TreeSHA256(tree); err != nil || sum != inst.TreeSHA256 { |
| + t.Fatalf("the copy is not the pinned tree: %v", err) |
| + } |
| + if err := Verify(third); err == nil { |
| + t.Fatal("another Node verified") |
| + } |
| +} |
| + |
| +// copyTree copies a sealed tree, links and modes as they are. |
| +func copyTree(t *testing.T, from, to string) { |
| + t.Helper() |
| + err := filepath.Walk(from, func(p string, info os.FileInfo, err error) error { |
| + if err != nil { |
| + return err |
| + } |
| + rel, _ := filepath.Rel(from, p) |
| + dst := filepath.Join(to, rel) |
| + switch { |
| + case info.Mode()&os.ModeSymlink != 0: |
| + target, err := os.Readlink(p) |
| + if err != nil { |
| + return err |
| + } |
| + return os.Symlink(target, dst) |
| + case info.IsDir(): |
| + return os.MkdirAll(dst, 0755) |
| + } |
| + raw, err := os.ReadFile(p) |
| + if err != nil { |
| + return err |
| + } |
| + return os.WriteFile(dst, raw, info.Mode().Perm()) |
| + }) |
| + must(t, err) |
| + must(t, Seal(to)) |
| +} |
diff --git a/internal/testci/box_test.go b/internal/testci/box_test.go| index 0aa7958e..60bf12c2 100644 |
| --- a/internal/testci/box_test.go |
| +++ b/internal/testci/box_test.go |
| @@ -9,6 +9,7 @@ import ( |
| "amadan.net/oficina/equipo/internal/runner/provider/claude" |
| "amadan.net/oficina/equipo/internal/runner/provider/codex" |
| + "amadan.net/oficina/equipo/internal/runner/provider/pi" |
| ) |
| // The CI box fetches the pinned programs by the digests in |
| @@ -97,3 +98,36 @@ func TestBoxChromiumPinned(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// The CI box installs the pinned Pi for the real-Pi tests: Node by the |
| +// archive and program digests the code pins, and the tree the lockfile |
| +// makes, checked against the committed tree digest. They are the code's. |
| +func TestBoxPiMatchesTheCode(t *testing.T) { |
| + raw, err := os.ReadFile("../../scripts/ci-box.json") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var box struct { |
| + Pi struct { |
| + Version, Lockfile, Box string |
| + TreeSHA256 string `json:"tree_sha256"` |
| + Node map[string]struct { |
| + URL, Root, SHA256 string |
| + ArchiveSHA256 string `json:"archive_sha256"` |
| + } |
| + } |
| + } |
| + if err = json.Unmarshal(raw, &box); err != nil { |
| + t.Fatal(err) |
| + } |
| + if box.Pi.Version != pi.Version || box.Pi.Lockfile != "internal/runner/provider/pi/npm" || box.Pi.Box != "/opt/equipo-pi" { |
| + t.Fatalf("pi %+v", box.Pi) |
| + } |
| + for _, arch := range []string{"amd64", "arm64"} { |
| + tree, node, ok := pi.Pins(arch) |
| + got := box.Pi.Node[arch] |
| + if !ok || box.Pi.TreeSHA256 != tree || got.URL != node.URL || got.ArchiveSHA256 != node.SHA256 || got.SHA256 != node.BinarySHA256 || got.Root != node.Root { |
| + t.Errorf("%s: the box installs %+v and tree %s, the code pins %+v and tree %s", arch, got, box.Pi.TreeSHA256, node, tree) |
| + } |
| + } |
| +} |
diff --git a/scripts/ci-box.json b/scripts/ci-box.json| index 7ebf2afa..e91bb94c 100644 |
| --- a/scripts/ci-box.json |
| +++ b/scripts/ci-box.json |
| @@ -106,5 +106,25 @@ |
| "box": "/usr/lib/aarch64-linux-gnu/libwrap.so.0" |
| } |
| } |
| + }, |
| + "pi": { |
| + "version": "1.5.2", |
| + "lockfile": "internal/runner/provider/pi/npm", |
| + "tree_sha256": "d0ce14faa1c7442ee2cc5289b350f7a56b2bddbdf7d7c1675331de37c6cbc534", |
| + "box": "/opt/equipo-pi", |
| + "node": { |
| + "amd64": { |
| + "url": "https://nodejs.org/dist/v22.23.4/node-v22.23.4-linux-x64.tar.gz", |
| + "archive_sha256": "b8492284c76a54baf58d61668dd0e41ee0fc98adabf9503d30f05d08f55b4406", |
| + "root": "node-v22.23.4-linux-x64", |
| + "sha256": "94efd062ed066c1a0b332e18249859c905e920eeada5df55d24c99b919629a90" |
| + }, |
| + "arm64": { |
| + "url": "https://nodejs.org/dist/v22.23.4/node-v22.23.4-linux-arm64.tar.gz", |
| + "archive_sha256": "f7a1e486dbc8b286847815b477d4fb5e9fb963ed4489c3e1588853d685f589f9", |
| + "root": "node-v22.23.4-linux-arm64", |
| + "sha256": "7e48183361053f039294fbbc3ba586722fe756bf296d6cb8195356d10819cd16" |
| + } |
| + } |
| } |
| } |
diff --git a/scripts/ci-box.py b/scripts/ci-box.py| index 0fe488a8..62020fb7 100755 |
| --- a/scripts/ci-box.py |
| +++ b/scripts/ci-box.py |
| @@ -19,6 +19,12 @@ pinned programs mounted where a runner host has them: |
| ~/.local/share/equipo/try/bin codex, its code mode host, claude |
| /usr/bin/socat Claude's own sandbox needs it |
| /opt/chromium-<version>/chrome the browser tests' Chromium |
| + /opt/equipo-pi the pinned Pi and its Node |
| + |
| +The Pi install is what a runner's is: Node from the official archive by |
| +its digest, and the npm tree `npm ci --ignore-scripts` makes from the |
| +committed lockfile, made read-only and checked against the committed |
| +tree digest (scripts/ci-box.json "pi", the same as the code's pins). |
| Every pinned program is fetched by URL and checked against the SHA-256 in |
| scripts/ci-box.json, for this machine's architecture. Chromium is Debian's |
| @@ -233,6 +239,115 @@ def fetch_tools(): |
| return tools_dir() |
| +# Pi: Node and an npm tree, not one program. |
| + |
| +def pi_root(): |
| + return os.path.join(tools_dir(), "pi-" + pins()["pi"]["tree_sha256"][:16]) |
| + |
| + |
| +def seal(top): |
| + """The tree read-only, as provider.SealTree makes it: directories |
| + 0555, files 0555 when npm made them executable for their owner, |
| + else 0444.""" |
| + dirs = [] |
| + for root, _, files in os.walk(top): |
| + dirs.append(root) |
| + for f in files: |
| + path = os.path.join(root, f) |
| + if not os.path.islink(path): |
| + os.chmod(path, 0o555 if os.stat(path).st_mode & 0o100 else 0o444) |
| + for d in reversed(dirs): |
| + os.chmod(d, 0o555) |
| + |
| + |
| +def tree_sha256(top): |
| + """provider.TreeSHA256: every entry in Go's WalkDir order (lexical, |
| + each directory's entries right after it), refusing anything writable |
| + and any link that is absolute or leaves the tree.""" |
| + h = hashlib.sha256() |
| + |
| + def mode(st): |
| + return format(st.st_mode & 0o777, "o") |
| + |
| + def visit(path, rel): |
| + st = os.lstat(path) |
| + if os.path.islink(path): |
| + target = os.readlink(path) |
| + resolved = os.path.normpath(os.path.join(os.path.dirname(path), target)) |
| + if os.path.isabs(target) or not resolved.startswith(top + os.sep): |
| + raise RuntimeError("pi tree: link %s leaves the tree" % rel) |
| + h.update(("l\0%s\0%s\n" % (rel, target)).encode()) |
| + return |
| + if st.st_mode & 0o222: |
| + raise RuntimeError("pi tree: %s is writable" % rel) |
| + if os.path.isdir(path): |
| + h.update(("d\0%s\0%s\n" % (rel, mode(st))).encode()) |
| + for name in sorted(os.listdir(path)): |
| + visit(os.path.join(path, name), name if rel == "." else rel + "/" + name) |
| + return |
| + if not os.path.isfile(path): |
| + raise RuntimeError("pi tree: %s is not a file" % rel) |
| + h.update(("f\0%s\0%s\0%s\n" % (rel, mode(st), sha256_file(path))).encode()) |
| + |
| + visit(top, ".") |
| + return h.hexdigest() |
| + |
| + |
| +def install_pi(): |
| + """Install the pinned Pi once per tree digest: Node's archive checked |
| + by its digest and unpacked, `npm ci --ignore-scripts` from the |
| + committed lockfile, the tree sealed and checked against its pin, the |
| + node program checked against its own.""" |
| + pin = pins()["pi"] |
| + node_pin = pin["node"][arch()] |
| + root = pi_root() |
| + stamp = os.path.join(root, "pinned-" + pin["tree_sha256"]) |
| + if os.path.isfile(stamp): |
| + return "pi: present" |
| + started = time.time() |
| + if os.path.isdir(root): |
| + for d, _, _ in os.walk(root): |
| + os.chmod(d, 0o755) |
| + shutil.rmtree(root) |
| + with tempfile.TemporaryDirectory(dir=tools_dir()) as scratch: |
| + archive = os.path.join(scratch, "node.tar.gz") |
| + got = download(node_pin["url"], archive) |
| + if got != node_pin["archive_sha256"]: |
| + raise RuntimeError("pi: %s has SHA-256 %s, pinned %s" % (node_pin["url"], got, node_pin["archive_sha256"])) |
| + with tarfile.open(archive, "r:gz") as tar: |
| + for member in tar.getmembers(): |
| + if not (member.name == node_pin["root"] or member.name.startswith(node_pin["root"] + "/")) or ".." in member.name.split("/"): |
| + raise RuntimeError("pi: %s is outside the archive's root" % member.name) |
| + tar.extractall(scratch) |
| + node_dir = os.path.join(scratch, node_pin["root"]) |
| + node = os.path.join(node_dir, "bin", "node") |
| + if sha256_file(node) != node_pin["sha256"]: |
| + raise RuntimeError("pi: the node program is not the pinned one") |
| + prefix = os.path.join(scratch, "pi") |
| + os.makedirs(prefix) |
| + for name in ("package.json", "package-lock.json"): |
| + shutil.copyfile(os.path.join(ROOT, pin["lockfile"], name), os.path.join(prefix, name)) |
| + env = dict(os.environ, PATH=os.path.join(node_dir, "bin") + ":/usr/bin:/bin", npm_config_cache=os.path.join(scratch, "npm-cache"), npm_config_update_notifier="false") |
| + subprocess.run([node, os.path.join(node_dir, "lib", "node_modules", "npm", "bin", "npm-cli.js"), "ci", "--ignore-scripts", "--no-audit", "--no-fund"], cwd=prefix, env=env, check=True, stdout=subprocess.DEVNULL) |
| + tree = os.path.join(prefix, "node_modules") |
| + seal(tree) |
| + got = tree_sha256(tree) |
| + if got != pin["tree_sha256"]: |
| + raise RuntimeError("pi: the installed tree has digest %s, pinned %s" % (got, pin["tree_sha256"])) |
| + os.makedirs(os.path.join(root, "node", "bin")) |
| + shutil.copyfile(node, os.path.join(root, "node", "bin", "node")) |
| + os.chmod(os.path.join(root, "node", "bin", "node"), 0o555) |
| + # A directory moves to another parent only while it is writable. |
| + os.makedirs(os.path.join(root, "pi")) |
| + os.chmod(tree, 0o755) |
| + os.rename(tree, os.path.join(root, "pi", "node_modules")) |
| + os.chmod(os.path.join(root, "pi", "node_modules"), 0o555) |
| + with open(stamp, "w") as f: |
| + f.write(pin["tree_sha256"] + "\n") |
| + os.utime(stamp, (TOOL_TIME, TOOL_TIME)) |
| + return "pi: installed and verified in %.1fs" % (time.time() - started) |
| + |
| + |
| # Chromium: a tree of Debian packages, not one program. |
| def chromium_pins(): |
| @@ -476,6 +591,8 @@ def run(command): |
| missing = [name for name, tool in tools.items() if not os.path.isfile(tool_path(name, tool))] |
| if not os.path.isfile(os.path.join(chromium_dir(), "chrome")): |
| missing.append("chromium") |
| + if not os.path.isfile(os.path.join(pi_root(), "pinned-" + pins()["pi"]["tree_sha256"])): |
| + missing.append("pi") |
| 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") |
| @@ -494,6 +611,7 @@ def run(command): |
| if inside: |
| args += ["-v", tool_path(name, entry) + ":" + inside + ":ro"] |
| args += ["-v", chromium_dir() + ":" + chromium_box() + ":ro"] |
| + args += ["-v", pi_root() + ":" + pins()["pi"]["box"] + ":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 |
| @@ -509,6 +627,7 @@ def run(command): |
| "GOCACHE": GOCACHE, "GOMODCACHE": GOMODCACHE, |
| "EQUIPO_TEST_TOOLS_REQUIRED": "1", |
| "RASTRILLO_CHROME": chromium_box() + "/chrome", |
| + "EQUIPO_PI_ROOT": pins()["pi"]["box"], |
| "EQUIPO_BOX_UID": str(os.getuid()), "EQUIPO_BOX_GID": str(os.getgid()), |
| } |
| if tool == "podman" and os.getuid() != 0: |
| @@ -620,6 +739,7 @@ def prepare(): |
| image = pool.submit(pull_image) |
| chromium = pool.submit(fetch_chromium) |
| fetch_tools() |
| + say(install_pi()) |
| say(chromium.result()) |
| image.result() |
| if os.environ.get("AMADAN_CI") == "1": |
diff --git a/scripts/no-fake-worker.sh b/scripts/no-fake-worker.sh| index 620e5ca3..fc075e17 100755 |
| --- a/scripts/no-fake-worker.sh |
| +++ b/scripts/no-fake-worker.sh |
| @@ -13,3 +13,7 @@ if grep -q 'EQUIPO_TEST_EGRESS_UPSTREAM' "$1"; then |
| echo "refusing $1: it contains the test build's egress route" >&2 |
| exit 1 |
| fi |
| +if grep -q 'EQUIPO_TEST_LEAVE_TO_SPEND' "$1"; then |
| + echo "refusing $1: it contains the test build's leave to spend" >&2 |
| + exit 1 |
| +fi |