Runner builds for darwin/arm64; make build checks it
The runner and tool proxy did not compile for a Mac: openat2, O_PATH, pidfds, prctl, close_range, SO_PEERCRED, the Linux pty ioctls and the boot-time clock. Each now sits behind a _linux.go/_darwin.go pair; on macOS the bubblewrap-only calls refuse (ENOSYS) and Mac sign-in waits for P3. The containment launcher reaches unix through a sysunix shim so NamespaceMain's text, and so the certified launcher digest, is unchanged. make build (CI 05-build) now cross-compiles both binaries.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 files changed,
+322
−80
Makefile+4 −1internal/runner/clock_darwin.go+23 −0internal/runner/clock_linux.go+23 −0internal/runner/connect/login.go+0 −27internal/runner/connect/pty_darwin.go+12 −0internal/runner/connect/pty_linux.go+35 −0internal/runner/containment/linux.go+2 −3internal/runner/containment/mounts.go+1 −2internal/runner/containment/recovery.go+4 −4internal/runner/containment/sys_darwin.go+18 −0internal/runner/containment/sys_linux.go+23 −0internal/runner/containment/sysunix/sysunix_darwin.go+30 −0internal/runner/containment/sysunix/sysunix_linux.go+26 −0internal/runner/containment/tool.go+1 −1internal/runner/egress/open_darwin.go+10 −0internal/runner/egress/open_linux.go+8 −0internal/runner/egress/proxy.go+1 −1internal/runner/{lease_linux.go => lease.go}+0 −17internal/runner/peer_darwin.go+13 −0internal/runner/peer_linux.go+13 −0internal/runner/provider/accounts.go+1 −1internal/runner/provider/check_policy.go+1 −1internal/runner/provider/open_darwin.go+9 −0internal/runner/provider/open_linux.go+9 −0internal/runner/provider/policy.go+1 −1internal/runner/provider/runtime_claude.go+1 −1internal/runner/setup/pidfd_darwin.go+5 −0internal/runner/setup/pidfd_linux.go+13 −0internal/runner/setup/preflight.go+1 −8internal/runner/supervisor.go+1 −1internal/runner/supervisor_test.go+1 −1internal/runner/thin/mcp.go+4 −4internal/runner/thin_exports.go+3 −0internal/runner/tool_socket.go+4 −4internal/toolproxy/stdio.go+2 −2internal/toolproxy/walk_darwin.go+6 −0internal/toolproxy/walk_linux.go+6 −0scripts/runner-reference-allowlist.json+7 −0
Intent
diff --git a/Makefile b/Makefile| index 528dab19..68e99f0e 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -33,9 +33,12 @@ RASTRILLO := go run amadan.net/rastrillo/rastrillo/cmd/rastrillo |
| # build is the compile check: with more than one package matched, go |
| # build discards the output, so this catches a broken package without |
| -# producing an artifact. |
| +# producing an artifact. The runner also builds for a Mac worker |
| +# (darwin/arm64), so a Linux-only call outside a _linux.go file fails here. |
| build: |
| CGO_ENABLED=0 go build ./... |
| + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o /dev/null ./cmd/equipo-runner |
| + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o /dev/null ./cmd/equipo-tool-proxy |
| # Stamp the clean commit so /api/version identifies the running release. |
| # Strip debug data to reduce the upload size; keep module build metadata. |
diff --git a/internal/runner/clock_darwin.go b/internal/runner/clock_darwin.go| new file mode 100644 |
| index 00000000..47745209 |
| --- /dev/null |
| +++ b/internal/runner/clock_darwin.go |
| @@ -0,0 +1,23 @@ |
| +package runner |
| + |
| +import ( |
| + "time" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +// hostClock on macOS: the monotonic clock that keeps counting in sleep |
| +// and the boot session's UUID. |
| +type hostClock struct{} |
| + |
| +func (hostClock) Read() (ClockReading, error) { |
| + var ts unix.Timespec |
| + if err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err != nil { |
| + return ClockReading{}, err |
| + } |
| + boot, err := unix.Sysctl("kern.bootsessionuuid") |
| + if err != nil { |
| + return ClockReading{}, err |
| + } |
| + return ClockReading{Wall: time.Now(), Elapsed: time.Duration(ts.Nano()), BootID: boot}, nil |
| +} |
diff --git a/internal/runner/clock_linux.go b/internal/runner/clock_linux.go| new file mode 100644 |
| index 00000000..3bac34ce |
| --- /dev/null |
| +++ b/internal/runner/clock_linux.go |
| @@ -0,0 +1,23 @@ |
| +package runner |
| + |
| +import ( |
| + "os" |
| + "strings" |
| + "time" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +type hostClock struct{} |
| + |
| +func (hostClock) Read() (ClockReading, error) { |
| + var ts unix.Timespec |
| + if err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil { |
| + return ClockReading{}, err |
| + } |
| + b, err := os.ReadFile("/proc/sys/kernel/random/boot_id") |
| + if err != nil { |
| + return ClockReading{}, err |
| + } |
| + return ClockReading{Wall: time.Now(), Elapsed: time.Duration(ts.Nano()), BootID: strings.TrimSpace(string(b))}, nil |
| +} |
diff --git a/internal/runner/connect/login.go b/internal/runner/connect/login.go| index 8a9db0f2..83a40cbc 100644 |
| --- a/internal/runner/connect/login.go |
| +++ b/internal/runner/connect/login.go |
| @@ -235,30 +235,3 @@ func ClaudeLoopbackLogin(ctx context.Context, binary, home, scratch string, env |
| } |
| } |
| } |
| - |
| -// openPTY opens a pseudo-terminal pair, wide enough that the CLI never |
| -// wraps a line. |
| -func openPTY() (*os.File, *os.File, error) { |
| - master, err := os.OpenFile("/dev/ptmx", os.O_RDWR|unix.O_NOCTTY|unix.O_CLOEXEC, 0) |
| - if err != nil { |
| - return nil, nil, err |
| - } |
| - fd := int(master.Fd()) |
| - if err = unix.IoctlSetPointerInt(fd, unix.TIOCSPTLCK, 0); err != nil { |
| - master.Close() |
| - return nil, nil, err |
| - } |
| - n, err := unix.IoctlGetInt(fd, unix.TIOCGPTN) |
| - if err != nil { |
| - master.Close() |
| - return nil, nil, err |
| - } |
| - tty, err := os.OpenFile(fmt.Sprintf("/dev/pts/%d", n), os.O_RDWR|unix.O_NOCTTY, 0) |
| - if err != nil { |
| - master.Close() |
| - return nil, nil, err |
| - } |
| - ws := unix.Winsize{Row: 50, Col: 1000} |
| - _ = unix.IoctlSetWinsize(int(tty.Fd()), unix.TIOCSWINSZ, &ws) |
| - return master, tty, nil |
| -} |
diff --git a/internal/runner/connect/pty_darwin.go b/internal/runner/connect/pty_darwin.go| new file mode 100644 |
| index 00000000..8fd82439 |
| --- /dev/null |
| +++ b/internal/runner/connect/pty_darwin.go |
| @@ -0,0 +1,12 @@ |
| +package connect |
| + |
| +import ( |
| + "errors" |
| + "os" |
| +) |
| + |
| +// openPTY: signing in on a Mac waits for probe P3 (Mac runners spec |
| +// §3.4); a Mac worker runs checks, which need no account. |
| +func openPTY() (*os.File, *os.File, error) { |
| + return nil, nil, errors.New("signing in on a Mac runner is not available yet") |
| +} |
diff --git a/internal/runner/connect/pty_linux.go b/internal/runner/connect/pty_linux.go| new file mode 100644 |
| index 00000000..b241bc16 |
| --- /dev/null |
| +++ b/internal/runner/connect/pty_linux.go |
| @@ -0,0 +1,35 @@ |
| +package connect |
| + |
| +import ( |
| + "fmt" |
| + "os" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +// openPTY opens a pseudo-terminal pair, wide enough that the CLI never |
| +// wraps a line. |
| +func openPTY() (*os.File, *os.File, error) { |
| + master, err := os.OpenFile("/dev/ptmx", os.O_RDWR|unix.O_NOCTTY|unix.O_CLOEXEC, 0) |
| + if err != nil { |
| + return nil, nil, err |
| + } |
| + fd := int(master.Fd()) |
| + if err = unix.IoctlSetPointerInt(fd, unix.TIOCSPTLCK, 0); err != nil { |
| + master.Close() |
| + return nil, nil, err |
| + } |
| + n, err := unix.IoctlGetInt(fd, unix.TIOCGPTN) |
| + if err != nil { |
| + master.Close() |
| + return nil, nil, err |
| + } |
| + tty, err := os.OpenFile(fmt.Sprintf("/dev/pts/%d", n), os.O_RDWR|unix.O_NOCTTY, 0) |
| + if err != nil { |
| + master.Close() |
| + return nil, nil, err |
| + } |
| + ws := unix.Winsize{Row: 50, Col: 1000} |
| + _ = unix.IoctlSetWinsize(int(tty.Fd()), unix.TIOCSWINSZ, &ws) |
| + return master, tty, nil |
| +} |
diff --git a/internal/runner/containment/linux.go b/internal/runner/containment/linux.go| index 9d0f9ef0..6922acac 100644 |
| --- a/internal/runner/containment/linux.go |
| +++ b/internal/runner/containment/linux.go |
| @@ -15,12 +15,11 @@ import ( |
| "path/filepath" |
| "runtime" |
| "sync" |
| - "syscall" |
| "time" |
| + unix "amadan.net/oficina/equipo/internal/runner/containment/sysunix" |
| "amadan.net/oficina/equipo/internal/runner/egress" |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| - "golang.org/x/sys/unix" |
| ) |
| type Config struct { |
| @@ -348,7 +347,7 @@ func (m *Manager) lifecycle(ctx context.Context, r Record, argv []string, mounts |
| cmd.Stdin = inputR |
| cmd.Stdout = outputW |
| cmd.Stderr = errorW |
| - cmd.SysProcAttr = &syscall.SysProcAttr{Pdeathsig: syscall.SIGKILL} |
| + cmd.SysProcAttr = parentDeathKill() |
| if e = cmd.Start(); e != nil { |
| result <- startResult{err: e} |
| return |
diff --git a/internal/runner/containment/mounts.go b/internal/runner/containment/mounts.go| index 51d9fa85..a0c8cc59 100644 |
| --- a/internal/runner/containment/mounts.go |
| +++ b/internal/runner/containment/mounts.go |
| @@ -12,7 +12,6 @@ import ( |
| "amadan.net/oficina/equipo/internal/runner/egress" |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| - "golang.org/x/sys/unix" |
| ) |
| var errMount = errors.New("namespace_mount_rejected") |
| @@ -41,7 +40,7 @@ func pin(path string) (*os.File, error) { |
| if !cleanAbsolute(path) { |
| return nil, errMount |
| } |
| - fd, err := unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: unix.O_PATH | unix.O_CLOEXEC, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + fd, err := pathNoLinks(path) |
| if err != nil { |
| return nil, fmt.Errorf("%w: %v", errMount, err) |
| } |
diff --git a/internal/runner/containment/recovery.go b/internal/runner/containment/recovery.go| index d925cb0f..fc03b80e 100644 |
| --- a/internal/runner/containment/recovery.go |
| +++ b/internal/runner/containment/recovery.go |
| @@ -58,7 +58,7 @@ func identity(pid int) (uint64, string, error) { |
| return ticks, ns, e |
| } |
| func exactPID(r Record) (int, error) { |
| - fd, e := unix.PidfdOpen(r.HostPID, 0) |
| + fd, e := pidfdOpen(r.HostPID) |
| if e == unix.ESRCH { |
| return -1, errNamespaceExited |
| } |
| @@ -191,7 +191,7 @@ func (m *Manager) Recover(ctx context.Context, r Record) (Proof, error) { |
| // intent-only namespace cannot have launched the harness. Old records |
| // lack parent identity; their release pipe is already closed at restart. |
| if r.ParentPID > 0 { |
| - fd, err := unix.PidfdOpen(r.ParentPID, 0) |
| + fd, err := pidfdOpen(r.ParentPID) |
| if err == nil { |
| defer unix.Close(fd) |
| ticks, _, identityErr := identity(r.ParentPID) |
| @@ -247,7 +247,7 @@ func (m *Manager) Recover(ctx context.Context, r Record) (Proof, error) { |
| return proof, errIdentity |
| } |
| defer unix.Close(fd) |
| - if e = unix.PidfdSendSignal(fd, unix.SIGKILL, nil, 0); e != nil && e != unix.ESRCH { |
| + if e = pidfdSignal(fd, unix.SIGKILL); e != nil && e != unix.ESRCH { |
| return proof, e |
| } |
| if e = waitPID(ctx, fd); e != nil { |
| @@ -370,7 +370,7 @@ func ControllerAlive(r Record) (bool, error) { |
| if r.ParentPID <= 0 || r.ParentTicks == 0 { |
| return false, errIdentity |
| } |
| - fd, err := unix.PidfdOpen(r.ParentPID, 0) |
| + fd, err := pidfdOpen(r.ParentPID) |
| if err == unix.ESRCH { |
| return false, nil |
| } |
diff --git a/internal/runner/containment/sys_darwin.go b/internal/runner/containment/sys_darwin.go| new file mode 100644 |
| index 00000000..8f14973b |
| --- /dev/null |
| +++ b/internal/runner/containment/sys_darwin.go |
| @@ -0,0 +1,18 @@ |
| +package containment |
| + |
| +import ( |
| + "syscall" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +// A Mac worker never starts a bubblewrap namespace (Mac runners spec |
| +// §4): these stand-ins refuse, so anything that reaches them fails |
| +// closed rather than running unconfined. |
| + |
| +const oPath = unix.O_RDONLY |
| + |
| +func pidfdOpen(int) (int, error) { return -1, unix.ENOSYS } |
| +func pidfdSignal(int, unix.Signal) error { return unix.ENOSYS } |
| +func parentDeathKill() *syscall.SysProcAttr { return &syscall.SysProcAttr{} } |
| +func pathNoLinks(string) (int, error) { return -1, unix.ENOSYS } |
diff --git a/internal/runner/containment/sys_linux.go b/internal/runner/containment/sys_linux.go| new file mode 100644 |
| index 00000000..912de26b |
| --- /dev/null |
| +++ b/internal/runner/containment/sys_linux.go |
| @@ -0,0 +1,23 @@ |
| +package containment |
| + |
| +import ( |
| + "syscall" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +// The Linux system calls the containment needs; sys_darwin.go stands in |
| +// so the runner builds for a Mac, where bubblewrap never runs. |
| + |
| +const oPath = unix.O_PATH |
| + |
| +func pidfdOpen(pid int) (int, error) { return unix.PidfdOpen(pid, 0) } |
| +func pidfdSignal(fd int, sig unix.Signal) error { |
| + return unix.PidfdSendSignal(fd, sig, nil, 0) |
| +} |
| +func parentDeathKill() *syscall.SysProcAttr { |
| + return &syscall.SysProcAttr{Pdeathsig: syscall.SIGKILL} |
| +} |
| +func pathNoLinks(path string) (int, error) { |
| + return unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: unix.O_PATH | unix.O_CLOEXEC, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| +} |
diff --git a/internal/runner/containment/sysunix/sysunix_darwin.go b/internal/runner/containment/sysunix/sysunix_darwin.go| new file mode 100644 |
| index 00000000..773ca215 |
| --- /dev/null |
| +++ b/internal/runner/containment/sysunix/sysunix_darwin.go |
| @@ -0,0 +1,30 @@ |
| +// Package sysunix is the slice of golang.org/x/sys/unix that the |
| +// containment's launcher (linux.go) uses. On macOS the Linux-only calls |
| +// refuse (ENOSYS): a Mac worker never starts a bubblewrap namespace. |
| +package sysunix |
| + |
| +import ( |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +type WaitStatus = unix.WaitStatus |
| + |
| +const ( |
| + EINTR = unix.EINTR |
| + ESRCH = unix.ESRCH |
| + SIGKILL = unix.SIGKILL |
| + PR_SET_DUMPABLE = 4 |
| + CLOSE_RANGE_CLOEXEC = 4 |
| +) |
| + |
| +var ( |
| + Close = unix.Close |
| + Wait4 = unix.Wait4 |
| +) |
| + |
| +func CloseRange(uint, uint, uint) error { return unix.ENOSYS } |
| +func PidfdSendSignal(int, unix.Signal, *Siginfo, int) error { return unix.ENOSYS } |
| +func Prctl(int, uintptr, uintptr, uintptr, uintptr) error { return unix.ENOSYS } |
| + |
| +// Siginfo stands in for Linux's siginfo_t; only nil is ever passed. |
| +type Siginfo struct{} |
diff --git a/internal/runner/containment/sysunix/sysunix_linux.go b/internal/runner/containment/sysunix/sysunix_linux.go| new file mode 100644 |
| index 00000000..600d85d8 |
| --- /dev/null |
| +++ b/internal/runner/containment/sysunix/sysunix_linux.go |
| @@ -0,0 +1,26 @@ |
| +// Package sysunix is the slice of golang.org/x/sys/unix that the |
| +// containment's launcher (linux.go) uses. On Linux every name is the |
| +// unix package's own; on macOS (sysunix_darwin.go) the Linux-only calls |
| +// refuse, so the runner builds for a Mac worker, which never starts a |
| +// bubblewrap namespace. |
| +package sysunix |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +type WaitStatus = unix.WaitStatus |
| + |
| +const ( |
| + EINTR = unix.EINTR |
| + ESRCH = unix.ESRCH |
| + SIGKILL = unix.SIGKILL |
| + PR_SET_DUMPABLE = unix.PR_SET_DUMPABLE |
| + CLOSE_RANGE_CLOEXEC = unix.CLOSE_RANGE_CLOEXEC |
| +) |
| + |
| +var ( |
| + Close = unix.Close |
| + CloseRange = unix.CloseRange |
| + PidfdSendSignal = unix.PidfdSendSignal |
| + Prctl = unix.Prctl |
| + Wait4 = unix.Wait4 |
| +) |
diff --git a/internal/runner/containment/tool.go b/internal/runner/containment/tool.go| index 162fdb57..e1302733 100644 |
| --- a/internal/runner/containment/tool.go |
| +++ b/internal/runner/containment/tool.go |
| @@ -23,7 +23,7 @@ func (p *mounts) bindTool(path string) error { |
| if unix.Fstat(int(parent.Fd()), &stat) != nil || stat.Mode&0777 != 0700 || stat.Uid != uint32(os.Getuid()) { |
| return errMount |
| } |
| - fd, e := unix.Openat(int(parent.Fd()), "equipo.sock", unix.O_PATH|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0) |
| + fd, e := unix.Openat(int(parent.Fd()), "equipo.sock", oPath|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0) |
| if e != nil { |
| return e |
| } |
diff --git a/internal/runner/egress/open_darwin.go b/internal/runner/egress/open_darwin.go| new file mode 100644 |
| index 00000000..4ec20d1c |
| --- /dev/null |
| +++ b/internal/runner/egress/open_darwin.go |
| @@ -0,0 +1,10 @@ |
| +package egress |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +// openDirNoLinks opens a directory refusing a symbolic link anywhere |
| +// (O_NOFOLLOW_ANY). The egress proxy serves the Linux containment; a Mac |
| +// worker never starts it, but the package builds there. |
| +func openDirNoLinks(dir string) (int, error) { |
| + return unix.Open(dir, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC|unix.O_NOFOLLOW_ANY, 0) |
| +} |
diff --git a/internal/runner/egress/open_linux.go b/internal/runner/egress/open_linux.go| new file mode 100644 |
| index 00000000..fa42346a |
| --- /dev/null |
| +++ b/internal/runner/egress/open_linux.go |
| @@ -0,0 +1,8 @@ |
| +package egress |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +// openDirNoLinks opens a directory refusing a symbolic link anywhere. |
| +func openDirNoLinks(dir string) (int, error) { |
| + return unix.Openat2(unix.AT_FDCWD, dir, &unix.OpenHow{Flags: unix.O_PATH | unix.O_DIRECTORY | unix.O_CLOEXEC, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| +} |
diff --git a/internal/runner/egress/proxy.go b/internal/runner/egress/proxy.go| index 61c1d8a3..1e683120 100644 |
| --- a/internal/runner/egress/proxy.go |
| +++ b/internal/runner/egress/proxy.go |
| @@ -78,7 +78,7 @@ func open(ctx context.Context, dir string, policy Policy, d dependencies) (*Prox |
| if !filepath.IsAbs(dir) || filepath.Clean(dir) != dir { |
| return nil, errPolicy |
| } |
| - fd, e := unix.Openat2(unix.AT_FDCWD, dir, &unix.OpenHow{Flags: unix.O_PATH | unix.O_DIRECTORY | unix.O_CLOEXEC, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + fd, e := openDirNoLinks(dir) |
| if e != nil { |
| return nil, e |
| } |
diff --git a/internal/runner/lease_linux.go b/internal/runner/lease.go| similarity index 86% |
| rename from internal/runner/lease_linux.go |
| rename to internal/runner/lease.go |
| index 04c6d18a..10c22295 100644 |
| --- a/internal/runner/lease_linux.go |
| +++ b/internal/runner/lease.go |
| @@ -1,13 +1,10 @@ |
| package runner |
| import ( |
| - "os" |
| - "strings" |
| "sync" |
| "time" |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| - "golang.org/x/sys/unix" |
| ) |
| type ClockReading struct { |
| @@ -16,20 +13,6 @@ type ClockReading struct { |
| BootID string |
| } |
| type ElapsedClock interface{ Read() (ClockReading, error) } |
| -type linuxClock struct{} |
| - |
| -func (linuxClock) Read() (ClockReading, error) { |
| - var ts unix.Timespec |
| - if err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil { |
| - return ClockReading{}, err |
| - } |
| - b, err := os.ReadFile("/proc/sys/kernel/random/boot_id") |
| - if err != nil { |
| - return ClockReading{}, err |
| - } |
| - return ClockReading{Wall: time.Now(), Elapsed: time.Duration(ts.Nano()), BootID: strings.TrimSpace(string(b))}, nil |
| -} |
| - |
| type leaseGuard struct { |
| mu sync.Mutex |
| last ClockReading |
diff --git a/internal/runner/peer_darwin.go b/internal/runner/peer_darwin.go| new file mode 100644 |
| index 00000000..75001cf0 |
| --- /dev/null |
| +++ b/internal/runner/peer_darwin.go |
| @@ -0,0 +1,13 @@ |
| +package runner |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +const walkFlags = unix.O_RDONLY |
| + |
| +func peerUID(fd int) (uint32, error) { |
| + cred, err := unix.GetsockoptXucred(fd, unix.SOL_LOCAL, unix.LOCAL_PEERCRED) |
| + if err != nil { |
| + return 0, err |
| + } |
| + return cred.Uid, nil |
| +} |
diff --git a/internal/runner/peer_linux.go b/internal/runner/peer_linux.go| new file mode 100644 |
| index 00000000..a0b86269 |
| --- /dev/null |
| +++ b/internal/runner/peer_linux.go |
| @@ -0,0 +1,13 @@ |
| +package runner |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +const walkFlags = unix.O_PATH |
| + |
| +func peerUID(fd int) (uint32, error) { |
| + cred, err := unix.GetsockoptUcred(fd, unix.SOL_SOCKET, unix.SO_PEERCRED) |
| + if err != nil { |
| + return 0, err |
| + } |
| + return cred.Uid, nil |
| +} |
diff --git a/internal/runner/provider/accounts.go b/internal/runner/provider/accounts.go| index ee79b917..13261f20 100644 |
| --- a/internal/runner/provider/accounts.go |
| +++ b/internal/runner/provider/accounts.go |
| @@ -91,7 +91,7 @@ func pinDirectory(path string) (*os.File, error) { |
| if !cleanPath(path) { |
| return nil, ErrPolicy |
| } |
| - fd, e := unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_DIRECTORY | unix.O_CLOEXEC, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + fd, e := openNoLinks(path, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC) |
| if e != nil { |
| return nil, ErrPolicy |
| } |
diff --git a/internal/runner/provider/check_policy.go b/internal/runner/provider/check_policy.go| index 2d08f2a8..ce0654ee 100644 |
| --- a/internal/runner/provider/check_policy.go |
| +++ b/internal/runner/provider/check_policy.go |
| @@ -54,7 +54,7 @@ func BuildCheckPolicy(in CheckPolicyInputs) (Policy, error) { |
| m.OuterMounts = append(m.OuterMounts, Mount{Source: in.ModuleCache, Target: "/opt/go-mod", ReadOnly: true}) |
| } |
| for _, mount := range files { |
| - fd, err := unix.Openat2(unix.AT_FDCWD, mount.Source, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_CLOEXEC | unix.O_NONBLOCK, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + fd, err := openNoLinks(mount.Source, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NONBLOCK) |
| if err != nil { |
| return Policy{}, ErrPolicy |
| } |
diff --git a/internal/runner/provider/open_darwin.go b/internal/runner/provider/open_darwin.go| new file mode 100644 |
| index 00000000..62265165 |
| --- /dev/null |
| +++ b/internal/runner/provider/open_darwin.go |
| @@ -0,0 +1,9 @@ |
| +package provider |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +// openNoLinks opens path refusing a symbolic link in any component |
| +// (O_NOFOLLOW_ANY, macOS 11 and later). |
| +func openNoLinks(path string, flags int) (int, error) { |
| + return unix.Open(path, flags|unix.O_NOFOLLOW_ANY, 0) |
| +} |
diff --git a/internal/runner/provider/open_linux.go b/internal/runner/provider/open_linux.go| new file mode 100644 |
| index 00000000..1774fff5 |
| --- /dev/null |
| +++ b/internal/runner/provider/open_linux.go |
| @@ -0,0 +1,9 @@ |
| +package provider |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +// openNoLinks opens path refusing a symbolic link in any component |
| +// (openat2 RESOLVE_NO_SYMLINKS and RESOLVE_NO_MAGICLINKS). |
| +func openNoLinks(path string, flags int) (int, error) { |
| + return unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: uint64(flags), Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| +} |
diff --git a/internal/runner/provider/policy.go b/internal/runner/provider/policy.go| index 0b89a81b..9c49a77b 100644 |
| --- a/internal/runner/provider/policy.go |
| +++ b/internal/runner/provider/policy.go |
| @@ -199,7 +199,7 @@ func hashFiles(mounts []Mount, b Binding) ([]fileDigest, error) { |
| if !(strings.HasPrefix(m.Target, "/opt/") || strings.HasPrefix(m.Target, "/config/") || strings.HasPrefix(m.Target, "/etc/claude-code/") || strings.HasPrefix(m.Target, "/etc/codex/")) { |
| return nil, ErrPolicy |
| } |
| - fd, e := unix.Openat2(unix.AT_FDCWD, m.Source, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_CLOEXEC | unix.O_NONBLOCK, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + fd, e := openNoLinks(m.Source, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NONBLOCK) |
| if e != nil { |
| return nil, ErrPolicy |
| } |
diff --git a/internal/runner/provider/runtime_claude.go b/internal/runner/provider/runtime_claude.go| index f44abd0a..1ef23a67 100644 |
| --- a/internal/runner/provider/runtime_claude.go |
| +++ b/internal/runner/provider/runtime_claude.go |
| @@ -99,7 +99,7 @@ func (l *AccountLease) claudeGitIgnore(info os.FileInfo) bool { |
| return false |
| } |
| path := filepath.Join(l.runtime, ".config/git/ignore") |
| - fd, err := unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_CLOEXEC | unix.O_NONBLOCK, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + fd, err := openNoLinks(path, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NONBLOCK) |
| if err != nil { |
| return false |
| } |
diff --git a/internal/runner/setup/pidfd_darwin.go b/internal/runner/setup/pidfd_darwin.go| new file mode 100644 |
| index 00000000..8e4cf582 |
| --- /dev/null |
| +++ b/internal/runner/setup/pidfd_darwin.go |
| @@ -0,0 +1,5 @@ |
| +package runnersetup |
| + |
| +// pidfdAlive: macOS has no process handles. The namespace preflight is |
| +// Linux only; a Mac installs through the Mac path. |
| +func pidfdAlive(int) error { return errPIDFD } |
diff --git a/internal/runner/setup/pidfd_linux.go b/internal/runner/setup/pidfd_linux.go| new file mode 100644 |
| index 00000000..c4e8bbcc |
| --- /dev/null |
| +++ b/internal/runner/setup/pidfd_linux.go |
| @@ -0,0 +1,13 @@ |
| +package runnersetup |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +// pidfdAlive opens a process handle and signals it with 0. |
| +func pidfdAlive(pid int) error { |
| + fd, e := unix.PidfdOpen(pid, 0) |
| + if e != nil { |
| + return e |
| + } |
| + defer unix.Close(fd) |
| + return unix.PidfdSendSignal(fd, 0, nil, 0) |
| +} |
diff --git a/internal/runner/setup/preflight.go b/internal/runner/setup/preflight.go| index cc72476a..c06e56c4 100644 |
| --- a/internal/runner/setup/preflight.go |
| +++ b/internal/runner/setup/preflight.go |
| @@ -13,7 +13,6 @@ import ( |
| "time" |
| "amadan.net/oficina/equipo/internal/release" |
| - "golang.org/x/sys/unix" |
| ) |
| type probeHost struct { |
| @@ -134,13 +133,7 @@ func namespaceProbe(ctx context.Context, binary string, policy []string) error { |
| return |
| } |
| } |
| - fd, e := unix.PidfdOpen(status.PID, 0) |
| - if e != nil { |
| - done <- errPIDFD |
| - return |
| - } |
| - defer unix.Close(fd) |
| - if unix.PidfdSendSignal(fd, 0, nil, 0) != nil { |
| + if pidfdAlive(status.PID) != nil { |
| done <- errPIDFD |
| return |
| } |
diff --git a/internal/runner/supervisor.go b/internal/runner/supervisor.go| index d1a45451..b5860889 100644 |
| --- a/internal/runner/supervisor.go |
| +++ b/internal/runner/supervisor.go |
| @@ -80,7 +80,7 @@ func NewSupervisor(c SupervisorConfig) (*Supervisor, error) { |
| if c.Workflow.cfg.Witness == nil || c.Workflow.cfg.Workspaces == nil || (c.Workflow.cfg.Namespaces != c.Namespaces || len(c.Workflow.cfg.Launchers) != 2 || c.Workflow.cfg.Launch == nil) || c.Workflow.cfg.Witness.journal != c.Journal { |
| return nil, provider.ErrContract |
| } |
| - return &Supervisor{namespaces: c.Namespaces, journal: c.Journal, api: c.API, workflow: c.Workflow, clock: linuxClock{}, credentialsPath: c.CredentialsPath, installCredentials: c.InstallCredentials, states: map[string]*attemptState{}}, nil |
| + return &Supervisor{namespaces: c.Namespaces, journal: c.Journal, api: c.API, workflow: c.Workflow, clock: hostClock{}, credentialsPath: c.CredentialsPath, installCredentials: c.InstallCredentials, states: map[string]*attemptState{}}, nil |
| } |
| func attemptKey(scope team.Scope, h team.Handle) string { |
| return runnerproto.EventHash([]any{scope, h.Attempt, h.Fence, h.Runner}) |
diff --git a/internal/runner/supervisor_test.go b/internal/runner/supervisor_test.go| index 30d184e3..05be269b 100644 |
| --- a/internal/runner/supervisor_test.go |
| +++ b/internal/runner/supervisor_test.go |
| @@ -34,7 +34,7 @@ func cleanupFixture(t *testing.T) (*Supervisor, *attemptState, any, *[]string) { |
| t.Cleanup(func() { j.Close() }) |
| order := []string{} |
| api := &supervisorAPI{order: &order} |
| - s := &Supervisor{journal: j, api: api, clock: linuxClock{}, states: map[string]*attemptState{}} |
| + s := &Supervisor{journal: j, api: api, clock: hostClock{}, states: map[string]*attemptState{}} |
| r := &attemptState{Claim: RunClaim{Assignment: runnerproto.Assignment{ID: "assignment", Kind: "step", StepKey: "reproduce"}, ClaimResponse: runnerproto.ClaimResponse{Scope: team.Scope{Account: "team", Job: 1}, Handle: team.Handle{Attempt: 1, Fence: 1, Runner: "runner"}}}, Owner: ProcessOwner{Attempt: 1, Fence: 1, Marker: "marker", AgentID: "agent", Workspace: provider.Workspace{ServerID: "server", WorkspaceID: "workspace", Path: t.TempDir()}}, Agent: provider.Agent{ServerID: "server", AgentID: "agent"}, Phase: "completed"} |
| s.states[attemptKey(r.Claim.Scope, r.Claim.Handle)] = r |
| if err := s.save(context.Background(), r); err != nil { |
diff --git a/internal/runner/thin/mcp.go b/internal/runner/thin/mcp.go| index 2fb0b68e..7ee3e664 100644 |
| --- a/internal/runner/thin/mcp.go |
| +++ b/internal/runner/thin/mcp.go |
| @@ -14,7 +14,7 @@ import ( |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| - "golang.org/x/sys/unix" |
| + "amadan.net/oficina/equipo/internal/runner" |
| ) |
| const maxToolFrame = 64 << 10 |
| @@ -108,11 +108,11 @@ func (s *toolSocket) accept(ctx context.Context) { |
| } |
| // Only this user's processes may talk to the broker. |
| raw, err := c.SyscallConn() |
| - var cred *unix.Ucred |
| + uid, known := uint32(0), false |
| if err == nil { |
| - _ = raw.Control(func(fd uintptr) { cred, err = unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED) }) |
| + _ = raw.Control(func(fd uintptr) { uid, err = runner.PeerUID(int(fd)); known = err == nil }) |
| } |
| - if err != nil || cred == nil || cred.Uid != uint32(os.Getuid()) { |
| + if err != nil || !known || uid != uint32(os.Getuid()) { |
| c.Close() |
| continue |
| } |
diff --git a/internal/runner/thin_exports.go b/internal/runner/thin_exports.go| index 2e27c162..ad21225a 100644 |
| --- a/internal/runner/thin_exports.go |
| +++ b/internal/runner/thin_exports.go |
| @@ -25,3 +25,6 @@ func (c Config) ToolProxy() string { return c.toolProxy() } |
| // Validate checks the configuration as LoadConfig does. |
| func (c Config) Validate() error { return c.validate() } |
| + |
| +// PeerUID is the user id of a Unix socket's peer. |
| +func PeerUID(fd int) (uint32, error) { return peerUID(fd) } |
diff --git a/internal/runner/tool_socket.go b/internal/runner/tool_socket.go| index 9ca8b666..bf6312b0 100644 |
| --- a/internal/runner/tool_socket.go |
| +++ b/internal/runner/tool_socket.go |
| @@ -324,8 +324,8 @@ func toolPeer(c *net.UnixConn) bool { |
| } |
| ok := false |
| if raw.Control(func(fd uintptr) { |
| - cred, err := unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED) |
| - ok = err == nil && toolOwner(cred.Uid) |
| + uid, err := peerUID(int(fd)) |
| + ok = err == nil && toolOwner(uid) |
| }) != nil { |
| return false |
| } |
| @@ -407,13 +407,13 @@ func openNoLinks(path string, flags int) (*os.File, error) { |
| if !filepath.IsAbs(path) || filepath.Clean(path) != path { |
| return nil, runnerproto.ErrInvalid |
| } |
| - fd, err := unix.Open("/", unix.O_PATH|unix.O_DIRECTORY|unix.O_CLOEXEC, 0) |
| + fd, err := unix.Open("/", walkFlags|unix.O_DIRECTORY|unix.O_CLOEXEC, 0) |
| if err != nil { |
| return nil, runnerproto.ErrInvalid |
| } |
| parts := strings.Split(strings.TrimPrefix(path, "/"), "/") |
| for i, p := range parts { |
| - f := unix.O_PATH | unix.O_DIRECTORY |
| + f := walkFlags | unix.O_DIRECTORY |
| if i == len(parts)-1 { |
| f = flags |
| } |
diff --git a/internal/toolproxy/stdio.go b/internal/toolproxy/stdio.go| index fe44c2c5..e0021e56 100644 |
| --- a/internal/toolproxy/stdio.go |
| +++ b/internal/toolproxy/stdio.go |
| @@ -109,13 +109,13 @@ func openNoLinks(path string, flags int) (*os.File, error) { |
| if !filepath.IsAbs(path) || filepath.Clean(path) != path { |
| return nil, errInvalid |
| } |
| - fd, err := unix.Open("/", unix.O_PATH|unix.O_DIRECTORY|unix.O_CLOEXEC, 0) |
| + fd, err := unix.Open("/", walkFlags|unix.O_DIRECTORY|unix.O_CLOEXEC, 0) |
| if err != nil { |
| return nil, errInvalid |
| } |
| parts := strings.Split(strings.TrimPrefix(path, "/"), "/") |
| for i, p := range parts { |
| - f := unix.O_PATH | unix.O_DIRECTORY |
| + f := walkFlags | unix.O_DIRECTORY |
| if i == len(parts)-1 { |
| f = flags |
| } |
diff --git a/internal/toolproxy/walk_darwin.go b/internal/toolproxy/walk_darwin.go| new file mode 100644 |
| index 00000000..e5a8f9ef |
| --- /dev/null |
| +++ b/internal/toolproxy/walk_darwin.go |
| @@ -0,0 +1,6 @@ |
| +package toolproxy |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +// walkFlags: macOS has no O_PATH; a directory opened for search will do. |
| +const walkFlags = unix.O_RDONLY |
diff --git a/internal/toolproxy/walk_linux.go b/internal/toolproxy/walk_linux.go| new file mode 100644 |
| index 00000000..ef2d873d |
| --- /dev/null |
| +++ b/internal/toolproxy/walk_linux.go |
| @@ -0,0 +1,6 @@ |
| +package toolproxy |
| + |
| +import "golang.org/x/sys/unix" |
| + |
| +// walkFlags opens the directories of a no-follow walk without reading them. |
| +const walkFlags = unix.O_PATH |
diff --git a/scripts/runner-reference-allowlist.json b/scripts/runner-reference-allowlist.json| index 8bef6d35..581bab59 100644 |
| --- a/scripts/runner-reference-allowlist.json |
| +++ b/scripts/runner-reference-allowlist.json |
| @@ -10925,5 +10925,12 @@ |
| "match": "node", |
| "count": 1, |
| "reason": "Recorded Mac hello fixture: the node toolchain version in its capability report." |
| + }, |
| + { |
| + "path": "Makefile", |
| + "line_sha256": "5a6830c98b8313cc0b6d7f76d210bbde44cb833c9be69570244d0263081f49de", |
| + "match": "equipo-runner", |
| + "count": 1, |
| + "reason": "Mac runner (darwin worker): the runner executable, its launchd agent, install paths, the pinned srt package and Node it needs, and their tests and docs." |
| } |
| ] |