carlos / platform Public

host: the claim-launch egress witness removes its target namespace before the generation census (#328)

Run 20261025T163313-7a7e8c: TestPlan14EgressClaimLaunchRootRunner's
retirement child failed with "/proc/1/task/1: mounts: permission denied".
`ip netns add` bind-mounts the target namespace at /run/netns, and the
generation census (generationMounts) refuses any nsfs mount on purpose: a
bind-mounted namespace can keep staged mounts alive. Production is right;
the fixture now tears the namespace down (egressTargetNetnsClosable) once
the egress checks are done, before the harness reaches the census.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 07000bd9eb92989602f6bab460818b6de8c61a88 parent 4e7bbc4
2 files changed, +42 −11
  • internal/host/egress_startpaths_rootrunner_linux_test.go +39 −9
  • internal/host/plan14_installed_launch_root_linux_test.go +3 −2
diff --git a/internal/host/egress_startpaths_rootrunner_linux_test.go b/internal/host/egress_startpaths_rootrunner_linux_test.go
index 0b3a07a88..e27b6a680 100644
--- a/internal/host/egress_startpaths_rootrunner_linux_test.go
+++ b/internal/host/egress_startpaths_rootrunner_linux_test.go
@@ -175,6 +175,28 @@ func egressTemplateDeny(t *testing.T) string {
// pair and the namespace.
func egressTargetNetns(t *testing.T) map[string]string {
t.Helper()
+ addrs, _ := egressTargetNetnsClosable(t)
+ return addrs
+}
+
+// egressTargetNetnsClosable is egressTargetNetns with its teardown, for a
+// test that must have the fixture gone before it goes on: `ip netns add`
+// bind-mounts the namespace at /run/netns, and the root generation census
+// (generationMounts) refuses any nsfs mount on purpose. Calling close, or
+// the test's end, tears it down once, last-made first.
+func egressTargetNetnsClosable(t *testing.T) (map[string]string, func()) {
+ t.Helper()
+ var steps []func()
+ var once sync.Once
+ closeAll := func() {
+ once.Do(func() {
+ for i := len(steps) - 1; i >= 0; i-- {
+ steps[i]()
+ }
+ })
+ }
+ t.Cleanup(closeAll)
+ cleanup := func(f func()) { steps = append(steps, f) }
if os.Geteuid() != 0 {
t.Fatal("needs real root")
}
@@ -190,7 +212,7 @@ func egressTargetNetns(t *testing.T) map[string]string {
}
egressIP(t, "netns", "add", egressNetns)
- t.Cleanup(func() {
+ cleanup(func() {
if out, err := exec.Command("ip", "netns", "del", egressNetns).CombinedOutput(); err != nil {
t.Errorf("ip netns del %s: %v: %s", egressNetns, err, out)
}
@@ -199,7 +221,7 @@ func egressTargetNetns(t *testing.T) map[string]string {
}
})
egressIP(t, "link", "add", egressHostLink, "type", "veth", "peer", "name", egressNsLink, "netns", egressNetns)
- t.Cleanup(func() {
+ cleanup(func() {
// Deleting one end removes the pair. The namespace's own deletion
// would too, but only once nothing holds the namespace, so the
// pair goes first and explicitly.
@@ -240,7 +262,7 @@ func egressTargetNetns(t *testing.T) map[string]string {
if err != nil {
t.Fatalf("listen on %s in %s: %v", a, egressNetns, err)
}
- t.Cleanup(func() { ln.Close() })
+ cleanup(func() { ln.Close() })
go func() {
for {
c, err := ln.Accept()
@@ -279,7 +301,7 @@ func egressTargetNetns(t *testing.T) map[string]string {
}
}
}
- return addrs
+ return addrs, closeAll
}
// egressListenIn opens a TCP listener inside the network namespace at
@@ -1140,9 +1162,9 @@ func TestPlan14EgressClaimLaunchRootRunner(t *testing.T) {
// dir) whose row carries 10.0.5.20 with an unexpired expiry. The registry
// is the one the claims asserter is built over (instanceControlClaimResources);
// under claims it only names slices.
-func plan14EgressClaimSetup(t *testing.T, host, dir string, uid, gid int) (targets map[string]string, reg *registry.Registry, data string) {
+func plan14EgressClaimSetup(t *testing.T, host, dir string, uid, gid int) (targets map[string]string, reg *registry.Registry, data string, closeTargets func()) {
t.Helper()
- targets = egressTargetNetns(t)
+ targets, closeTargets = egressTargetNetnsClosable(t)
slice := instancectl.SliceName(host)
egressSliceProperties(t, slice)
data = filepath.Join(dir, "egress-data")
@@ -1167,7 +1189,7 @@ func plan14EgressClaimSetup(t *testing.T, host, dir string, uid, gid int) (targe
if got := egressShow(t, slice, "IPAddressAllow"); got != "10.0.5.20/32" {
t.Fatalf("hand grant: slice holds %q", got)
}
- return targets, reg, data
+ return targets, reg, data, closeTargets
}
// plan14EgressClaimPolicy puts, in the harness's store, a policy for the
@@ -1190,9 +1212,17 @@ func plan14EgressClaimPolicy(t *testing.T, store release.Store, priv ed25519.Pri
// control service's handler over the same asserter) reports under_claims
// with claimsEgressDetail, the agent's status probe publishes it for the
// row that carries the allow (REASON "egress: not yet supported under
-// claims"), and root wrote no policy of its own.
-func plan14EgressClaimChecks(t *testing.T, host string, tenant *http.Client, targets map[string]string, egress *instancectl.EgressAsserter, reg *registry.Registry, optDir string) {
+// claims"), and root wrote no policy of its own. Then it removes the
+// target fixture: the harness goes on to the generation census, which
+// refuses the namespace's nsfs mount (generationMounts), on purpose.
+func plan14EgressClaimChecks(t *testing.T, host string, tenant *http.Client, targets map[string]string, closeTargets func(), egress *instancectl.EgressAsserter, reg *registry.Registry, optDir string) {
t.Helper()
+ defer func() {
+ closeTargets()
+ if _, err := os.Lstat(filepath.Join("/run/netns", egressNetns)); !errors.Is(err, fs.ErrNotExist) {
+ t.Errorf("the target namespace is still mounted before the generation census: %v", err)
+ }
+ }()
slice := instancectl.SliceName(host)
if got := egressShow(t, slice, "IPAddressAllow"); got != "" {
t.Fatalf("under claims: slice holds %q after the claim launch, want nothing", got)
diff --git a/internal/host/plan14_installed_launch_root_linux_test.go b/internal/host/plan14_installed_launch_root_linux_test.go
index 539001ef9..d18b755eb 100644
--- a/internal/host/plan14_installed_launch_root_linux_test.go
+++ b/internal/host/plan14_installed_launch_root_linux_test.go
@@ -230,8 +230,9 @@ func plan14InstalledClaimLaunch(t *testing.T, boundUnit string, runtimeUpdate ..
var egressReg *registry.Registry
var egressData string
var egressAsserter *instancectl.EgressAsserter
+ var closeEgressTargets func()
if egress {
- egressTargets, egressReg, egressData = plan14EgressClaimSetup(t, host, dir, uid, gid)
+ egressTargets, egressReg, egressData, closeEgressTargets = plan14EgressClaimSetup(t, host, dir, uid, gid)
}
var endpoint string
if tcpMode {
@@ -777,7 +778,7 @@ func plan14InstalledClaimLaunch(t *testing.T, boundUnit string, runtimeUpdate ..
checkService(client)
}
if egress {
- plan14EgressClaimChecks(t, host, client, egressTargets, egressAsserter, egressReg, "/opt/carlos")
+ plan14EgressClaimChecks(t, host, client, egressTargets, closeEgressTargets, egressAsserter, egressReg, "/opt/carlos")
}
if isolation || realConsole || woodstar {
if tcpMode {