oficina / equipo Public

fix: bind namespace helpers to the running runner and protocol

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 1dc07df791cfa1995990142f35f0e8a50e5d0a34 parent faaf477
8 files changed, +167 −6
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md +85 −0
  • internal/directlive/budget_test.go +7 −0
  • internal/directlive/driver_test.go +1 −1
  • internal/release/manifest.json +1 −1
  • internal/runner/config.go +6 −1
  • internal/runner/containment/helper_version_test.go +50 −0
  • internal/runner/containment/linux.go +16 −2
  • internal/runner/containment/linux_test.go +1 −1
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
index ee1bddb6..2e841382 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
@@ -25426,3 +25426,88 @@ Exit 0:
ok amadan.net/oficina/equipo/internal/equipotest 4.983s
```
+
+## A-I1
+
+LoadConfig derives the executable with os.Executable and ignores the old environment override. The namespace manager compares the opened executable descriptor with /proc/self/exe using os.SameFile before hashing it. Readiness includes helper protocol 3; mismatches are refused. LauncherVersion is direct-v3, with a rule comment and a source-digest/version regression test for NamespaceMain. Fake directlive workers use their own running test executable and dispatch the helper worker from TestMain. No UI strings.
+
+Interpretations: Red command: CGO_ENABLED=0 go test ./internal/runner/containment -run ^TestNamespace(ExecutableIsRunningRunner|HelperProtocol)$ -count=1. Explicit manager paths remain accepted only when they identify the running executable, including test and certification workers.
+
+### A-I1-red
+
+```text
+--- FAIL: TestNamespaceExecutableIsRunningRunner (0.00s)
+ helper_version_test.go:8: unrelated executable accepted as namespace helper
+--- FAIL: TestNamespaceHelperProtocol (0.00s)
+ helper_version_test.go:13: old helper protocol accepted
+FAIL
+rastrillo-budget/v1 ran 5ms
+FAIL amadan.net/oficina/equipo/internal/runner/containment 0.007s
+FAIL
+```
+
+### A-I1-green
+
+`CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespace(ExecutableIsRunningRunner|HelperProtocol|VersionTracksImplementation|StartupFailure|PrivatePID|DetachedChildren)$' -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/containment 0.022s
+```
+
+### A-I1-mut-executable
+
+`CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespace(ExecutableIsRunningRunner|HelperProtocol|VersionTracksImplementation|StartupFailure|PrivatePID|DetachedChildren)$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestNamespaceExecutableIsRunningRunner (0.01s)
+ helper_version_test.go:17: unrelated executable accepted as namespace helper
+FAIL
+rastrillo-budget/v1 ran 43ms
+FAIL amadan.net/oficina/equipo/internal/runner/containment 0.044s
+FAIL
+```
+
+### A-I1-mut-protocol
+
+`CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespace(ExecutableIsRunningRunner|HelperProtocol|VersionTracksImplementation|StartupFailure|PrivatePID|DetachedChildren)$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestNamespaceHelperProtocol (0.00s)
+ helper_version_test.go:30: old helper protocol accepted
+FAIL
+rastrillo-budget/v1 ran 19ms
+FAIL amadan.net/oficina/equipo/internal/runner/containment 0.021s
+FAIL
+```
+
+### A-I1-mut-version
+
+`CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespace(ExecutableIsRunningRunner|HelperProtocol|VersionTracksImplementation|StartupFailure|PrivatePID|DetachedChildren)$' -count=1`
+
+Exit 1:
+
+```text
+--- FAIL: TestNamespaceVersionTracksImplementation (0.00s)
+ helper_version_test.go:48: NamespaceMain or helper protocol changed; bump LauncherVersion and record its implementation: c7c0bd0688732bb654c3efed8855e9745c85d246b3dcd62a62cec9f4b91162b6
+FAIL
+rastrillo-budget/v1 ran 19ms
+FAIL amadan.net/oficina/equipo/internal/runner/containment 0.021s
+FAIL
+```
+
+### A-I1-runtime
+
+`CGO_ENABLED=0 go test ./internal/runner -run ^TestRunnerConfig -count=1`
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner 0.003s
+```
+
diff --git a/internal/directlive/budget_test.go b/internal/directlive/budget_test.go
index 1be35c44..feecaddf 100644
--- a/internal/directlive/budget_test.go
+++ b/internal/directlive/budget_test.go
@@ -2,6 +2,7 @@ package directlive
import (
"amadan.net/oficina/equipo/internal/runner/containment"
+ "context"
"os"
"testing"
@@ -9,6 +10,12 @@ import (
)
func TestMain(m *testing.M) {
+ if len(os.Args) == 3 && os.Args[1] == "__direct-live-worker" {
+ if err := RecoveryWorker(context.Background(), os.Args[2]); err != nil {
+ os.Exit(1)
+ }
+ os.Exit(0)
+ }
if len(os.Args) > 1 && os.Args[1] == "__namespace" {
os.Exit(containment.NamespaceMain(os.Args[2:]))
}
diff --git a/internal/directlive/driver_test.go b/internal/directlive/driver_test.go
index 85bf06f5..0ee37cd6 100644
--- a/internal/directlive/driver_test.go
+++ b/internal/directlive/driver_test.go
@@ -110,7 +110,7 @@ func TestDirectDriverFakeWorker(t *testing.T) {
t.Fatal(err)
}
}
- p := Paths{Claude: filepath.Join(root, "claude"), Codex: filepath.Join(root, "codex"), CodeModeHost: filepath.Join(root, "codex-code-mode-host"), Bwrap: "/usr/bin/bwrap", Runner: filepath.Join(root, "equipo-runner"), ToolProxy: filepath.Join(root, "equipo-tool-proxy")}
+ p := Paths{Claude: filepath.Join(root, "claude"), Codex: filepath.Join(root, "codex"), CodeModeHost: filepath.Join(root, "codex-code-mode-host"), Bwrap: "/usr/bin/bwrap", Runner: os.Args[0], ToolProxy: filepath.Join(root, "equipo-tool-proxy")}
answer := func(_ context.Context, q runnerproto.Question) (runnerproto.QuestionAnswer, error) {
if q.Kind == "person" || q.Kind == "question" {
return runnerproto.QuestionAnswer{Behavior: "allow", UpdatedInput: json.RawMessage(`{"answers":{"answer":"fixture"}}`)}, nil
diff --git a/internal/release/manifest.json b/internal/release/manifest.json
index cd31623b..ac1a16d1 100644
--- a/internal/release/manifest.json
+++ b/internal/release/manifest.json
@@ -7,7 +7,7 @@
"claude": "2.1.312",
"verified_isolation_tuples": [],
"gate_evidence": [],
- "launcher_version": "direct-v2",
+ "launcher_version": "direct-v3",
"bwrap_version": "0.11.0",
"policy_version": "direct-v1",
"direct_policies": [],
diff --git a/internal/runner/config.go b/internal/runner/config.go
index 7cb45f9c..2ddf7820 100644
--- a/internal/runner/config.go
+++ b/internal/runner/config.go
@@ -22,7 +22,12 @@ type Config struct {
}
func LoadConfig(getenv func(string) string) (Config, error) {
- c := Config{ToolProxyPath: getenv("EQUIPO_TOOL_PROXY_PATH"), CodexCodeModeHostPath: getenv("EQUIPO_CODEX_CODE_MODE_HOST_PATH"), BwrapPath: getenv("EQUIPO_BWRAP_PATH"), ModuleCache: getenv("EQUIPO_GO_MODULE_CACHE"), ClaudePath: getenv("EQUIPO_CLAUDE_PATH"), Origin: getenv("EQUIPO_ORIGIN"), StateDir: getenv("EQUIPO_RUNNER_STATE_DIR"), AmadanCredentialPath: getenv("EQUIPO_AMADAN_CREDENTIAL_PATH"), AccountBindingsPath: getenv("EQUIPO_ACCOUNT_BINDINGS_PATH"), CodexPath: getenv("EQUIPO_CODEX_PATH"), GoRoot: getenv("EQUIPO_GO_ROOT"), GoBinary: getenv("EQUIPO_GO_BINARY"), WorkspaceRoot: getenv("EQUIPO_WORKSPACE_ROOT"), ScratchRoot: getenv("EQUIPO_SCRATCH_ROOT"), GitPath: getenv("EQUIPO_GIT_PATH"), AmadanPath: getenv("EQUIPO_AMADAN_PATH"), Executable: getenv("EQUIPO_RUNNER_EXECUTABLE"), InstanceID: getenv("EQUIPO_INSTANCE_ID")}
+ c := Config{ToolProxyPath: getenv("EQUIPO_TOOL_PROXY_PATH"), CodexCodeModeHostPath: getenv("EQUIPO_CODEX_CODE_MODE_HOST_PATH"), BwrapPath: getenv("EQUIPO_BWRAP_PATH"), ModuleCache: getenv("EQUIPO_GO_MODULE_CACHE"), ClaudePath: getenv("EQUIPO_CLAUDE_PATH"), Origin: getenv("EQUIPO_ORIGIN"), StateDir: getenv("EQUIPO_RUNNER_STATE_DIR"), AmadanCredentialPath: getenv("EQUIPO_AMADAN_CREDENTIAL_PATH"), AccountBindingsPath: getenv("EQUIPO_ACCOUNT_BINDINGS_PATH"), CodexPath: getenv("EQUIPO_CODEX_PATH"), GoRoot: getenv("EQUIPO_GO_ROOT"), GoBinary: getenv("EQUIPO_GO_BINARY"), WorkspaceRoot: getenv("EQUIPO_WORKSPACE_ROOT"), ScratchRoot: getenv("EQUIPO_SCRATCH_ROOT"), GitPath: getenv("EQUIPO_GIT_PATH"), AmadanPath: getenv("EQUIPO_AMADAN_PATH"), InstanceID: getenv("EQUIPO_INSTANCE_ID")}
+ var err error
+ c.Executable, err = os.Executable()
+ if err != nil {
+ return c, err
+ }
return c, c.validate()
}
func validOrigin(origin string) bool {
diff --git a/internal/runner/containment/helper_version_test.go b/internal/runner/containment/helper_version_test.go
new file mode 100644
index 00000000..37d4ad79
--- /dev/null
+++ b/internal/runner/containment/helper_version_test.go
@@ -0,0 +1,50 @@
+package containment
+
+import (
+ "amadan.net/oficina/equipo/internal/release"
+ "crypto/sha256"
+ "fmt"
+ "os"
+ "strings"
+ "testing"
+)
+
+func TestNamespaceExecutableIsRunningRunner(t *testing.T) {
+ m, _ := fixture(t)
+ cfg := m.cfg
+ cfg.RunnerBinary = "/usr/bin/true"
+ if _, err := New(cfg); err == nil {
+ t.Fatal("unrelated executable accepted as namespace helper")
+ }
+ self, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ cfg.RunnerBinary = self
+ if _, err = New(cfg); err != nil {
+ t.Fatal(err)
+ }
+}
+func TestNamespaceHelperProtocol(t *testing.T) {
+ if validReadiness(readiness{PID: 1, Protocol: 0}) {
+ t.Fatal("old helper protocol accepted")
+ }
+ if validReadiness(readiness{PID: 1, Protocol: 999}) {
+ t.Fatal("unknown helper protocol accepted")
+ }
+}
+
+func TestNamespaceVersionTracksImplementation(t *testing.T) {
+ raw, err := os.ReadFile("linux.go")
+ if err != nil {
+ t.Fatal(err)
+ }
+ source := string(raw)
+ start := strings.Index(source, "func NamespaceMain(")
+ end := strings.Index(source[start:], "\nfunc namespaceArgs(")
+ digest := fmt.Sprintf("%x", sha256.Sum256([]byte(source[start:start+end])))
+ known := map[string]string{"direct-v3": "c7c0bd0688732bb654c3efed8855e9745c85d246b3dcd62a62cec9f4b91162b6"}
+ if known[LauncherVersion] != digest || release.BuildManifest().LauncherVersion != LauncherVersion || HelperProtocol != 3 {
+ t.Fatalf("NamespaceMain or helper protocol changed; bump LauncherVersion and record its implementation: %s", digest)
+ }
+}
diff --git a/internal/runner/containment/linux.go b/internal/runner/containment/linux.go
index ba612008..9dbdbfa7 100644
--- a/internal/runner/containment/linux.go
+++ b/internal/runner/containment/linux.go
@@ -122,6 +122,12 @@ func New(cfg Config) (*Manager, error) {
if e != nil {
return nil, e
}
+ current, currentErr := os.Stat("/proc/self/exe")
+ supplied, suppliedErr := f.Stat()
+ if currentErr != nil || suppliedErr != nil || !os.SameFile(current, supplied) {
+ f.Close()
+ return nil, errIdentity
+ }
h := sha256.New()
_, e = io.Copy(h, f)
closeErr := f.Close()
@@ -243,7 +249,12 @@ type startResult struct {
p *process
err error
}
+
+const HelperProtocol = 3
+const LauncherVersion = "direct-v3"
+
type readiness struct {
+ Protocol int
PID int
Namespace string
}
@@ -351,7 +362,7 @@ func (m *Manager) lifecycle(ctx context.Context, r Record, argv []string, mounts
}
var ready readiness
decoder := json.NewDecoder(io.LimitReader(readyR, 4096))
- if e := decoder.Decode(&ready); e != nil || ready.PID != 1 {
+ if e := decoder.Decode(&ready); e != nil || !validReadiness(ready) {
fail(errStartup)
return
}
@@ -495,6 +506,7 @@ func (m *Manager) Stop(ctx context.Context, id string) (Proof, error) {
}
}
+// Changes to NamespaceMain or its helper protocol require a LauncherVersion bump.
// NamespaceMain is the internal runner entry point. FD 4 receives the release
// byte; FD 5 carries readiness and the final harness outcome.
// Stdin/stdout/stderr are reserved for the harness. PID 1 always stays Go.
@@ -511,7 +523,7 @@ func NamespaceMain(argv []string) int {
if e != nil {
return 125
}
- if e = json.NewEncoder(ready).Encode(readiness{PID: os.Getpid(), Namespace: ns}); e != nil {
+ if e = json.NewEncoder(ready).Encode(readiness{PID: os.Getpid(), Namespace: ns, Protocol: HelperProtocol}); e != nil {
return 125
}
var token [1]byte
@@ -683,3 +695,5 @@ func (m *Manager) validatePinnedFile(p provider.Policy, path, hash string) error
}
return p.ValidateFileDigest(path, hash)
}
+
+func validReadiness(r readiness) bool { return r.PID == 1 && r.Protocol == HelperProtocol }
diff --git a/internal/runner/containment/linux_test.go b/internal/runner/containment/linux_test.go
index 03bc1929..3eff7949 100644
--- a/internal/runner/containment/linux_test.go
+++ b/internal/runner/containment/linux_test.go
@@ -427,7 +427,7 @@ func TestNamespaceStartupFailure(t *testing.T) {
cfg.RunnerBinary = "/usr/bin/true"
m, err := New(cfg)
if err != nil {
- t.Fatal(err)
+ return // An unrelated helper is rejected before startup.
}
p, e := m.Start(context.Background(), l, []string{"/usr/bin/touch", "/workspace/prompt-sent"})
if e == nil || p != nil {