carlos / platform Public

host: share the egress target netns fixture with the prefix witness

egressTargetNetnsAt now takes the address layout (egressNetnsAddrs: box
IPv4/IPv6 end and targets) besides the names; Task 13/14 pass
egressNetnsTask13Addrs, which issues the same ip commands in the same
order as before. TestRootEgressPrefixKernelProof uses it with its own
names and addresses instead of a copied namespace and listener fixture.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d121ceca9f50306c4b4dada7fbeb15dbb16b6c7e parent dd845e4
2 files changed, +65 −120
  • internal/host/egress_fixtures_rootrunner_linux_test.go +48 −16
  • internal/host/egress_prefix_rootrunner_linux_test.go +17 −104

Intent

Human

<task-notification> <task-id>a081f1af5f0f781d5</task-id> <tool-use-id>toolu_01372em5AjAmsWKFMfqS1yKs</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22311489-9a69-4708-aa90-e32c2ae39ed2/tasks/a081f1af5f0f781d5.output</output-file> <status>completed</status> <summary>Agent "Apply Luna copy changes" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: done. Commit `dd845e4a` ("egress ranges: copy pass (Luna, delegated)") on `egress-allow-cidr`. Rows 1-12, 14 and 15 are applied verbatim, and row 13 is skipped. - **Tests:** these pass with the sandbox off and the default GOCACHE. - `./internal/egressaddr/` and `./internal/instancectl/` with your `-run` filter. - `./internal/console/ -run Egress`. - Root `-run 'AppsSet|Policy|Copy|Approved'`, which includes the copy gate `TestInstancePolicyCopyIsApplied`. - `TestPlan14RootReadCensus`, after the census step below. - **Builds:** `gofmt -l` is clean, and the darwin and windows builds pass. - **Tests edited:** `apps_policy_test.go`, `egressaddr_test.go`, `instancectl/egress_test.go` and `console/egressfleet_test.go`. - **Copy record:** I updated IP1-06, 08, 10, 11, 14, 50, 53, IP2-30 and IP2-60. The entries have no note field, so I added a top-level `amended_by` key naming the delegation and those IDs. IP2-60 changed only for row 6 (the verb set shrinks from two to one). - **Census:** the test failed on the three re-pinned envelopes (`.`, `egressaddr`, `instancectl`) with no changed units. I ran `census-propose NAME=egress-allow-cidr-console` with an empty claims file. That rewrote the existing overlay tsv and approval card, the test then passed, and both are in the commit. - **Concerns:** - I did not edit fixtures that only pass old refused strings through, or older plan, spec and notes docs that quote the old text as history. - Row 6 now reads "10.0.5.20: this box has an address in 10.0.5.20/32" for single IPs. - The commit printed a `packed-refs.lock` error afterward, but the commit landed and the tree is clean. - The report file is `.superpowers/sdd/2026-11-22-egress-allow-cidr/copy-apply-report.md`. It is not in the commit, so it may be gitignored.</result> <usage><subagent_tokens>61401</subagent_tokens><tool_uses>12</tool_uses><duration_ms>219869</duration_ms></usage> </task-notification>

diff --git a/internal/host/egress_fixtures_rootrunner_linux_test.go b/internal/host/egress_fixtures_rootrunner_linux_test.go
index 6cfa25609..cd85608d2 100644
--- a/internal/host/egress_fixtures_rootrunner_linux_test.go
+++ b/internal/host/egress_fixtures_rootrunner_linux_test.go
@@ -197,7 +197,7 @@ func egressTargetNetns(t *testing.T) map[string]string {
// the test's end, tears it down once, last-made first.
func egressTargetNetnsClosable(t *testing.T) (map[string]string, func()) {
t.Helper()
- return egressTargetNetnsAt(t, egressNetnsTask13)
+ return egressTargetNetnsAt(t, egressNetnsTask13, egressNetnsTask13Addrs)
}
// egressNetnsNames names a target fixture's namespace and veth pair, so
@@ -210,9 +210,24 @@ type egressNetnsNames struct {
// egressNetnsTask13 is Task 13's fixture (carlos-egr, carlos-egr1/1n).
var egressNetnsTask13 = egressNetnsNames{ns: egressNetns, hostLink: egressHostLink, nsLink: egressNsLink}
+// egressNetnsAddrs lays out a target fixture's addresses: the box end's
+// IPv4 and IPv6 address (each a host address; box6 "" for none) and the
+// targets inside the namespace, each IPv4 or IPv6.
+type egressNetnsAddrs struct {
+ box4, box6 string
+ targets []string
+}
+
+// egressNetnsTask13Addrs is the layout Task 13's and Task 14's witnesses
+// use: 10.0.5.1 and fd00:5::1 on the box end, egressTargets inside.
+var egressNetnsTask13Addrs = egressNetnsAddrs{box4: "10.0.5.1", box6: "fd00:5::1", targets: egressTargets}
+
// egressTargetNetnsAt is egressTargetNetnsClosable with the fixture's
-// names given.
-func egressTargetNetnsAt(t *testing.T, n egressNetnsNames) (map[string]string, func()) {
+// names and addresses given: the box end holds lay.box4 (and lay.box6), with a
+// host route to each target through the veth from the box address of its
+// family; the namespace end holds the targets, with host routes back to
+// the box addresses.
+func egressTargetNetnsAt(t *testing.T, n egressNetnsNames, lay egressNetnsAddrs) (map[string]string, func()) {
t.Helper()
var steps []func()
var once sync.Once
@@ -268,24 +283,41 @@ func egressTargetNetnsAt(t *testing.T, n egressNetnsNames) (map[string]string, f
}
}
})
- egressIP(t, "addr", "add", "10.0.5.1/32", "dev", n.hostLink)
- egressIP(t, "-6", "addr", "add", "fd00:5::1/128", "dev", n.hostLink, "nodad")
+ for _, target := range lay.targets {
+ if netip.MustParseAddr(target).Is6() && lay.box6 == "" {
+ t.Fatalf("target %s is IPv6, but the fixture's box end has no IPv6 address", target)
+ }
+ }
+ egressIP(t, "addr", "add", lay.box4+"/32", "dev", n.hostLink)
+ if lay.box6 != "" {
+ egressIP(t, "-6", "addr", "add", lay.box6+"/128", "dev", n.hostLink, "nodad")
+ }
egressIP(t, "link", "set", n.hostLink, "up")
- egressIP(t, "route", "add", "10.0.5.20/32", "dev", n.hostLink, "src", "10.0.5.1")
- egressIP(t, "route", "add", "10.0.5.21/32", "dev", n.hostLink, "src", "10.0.5.1")
- egressIP(t, "-6", "route", "add", "fd00:5::20/128", "dev", n.hostLink, "src", "fd00:5::1")
+ for _, target := range lay.targets {
+ if netip.MustParseAddr(target).Is6() {
+ egressIP(t, "-6", "route", "add", target+"/128", "dev", n.hostLink, "src", lay.box6)
+ } else {
+ egressIP(t, "route", "add", target+"/32", "dev", n.hostLink, "src", lay.box4)
+ }
+ }
in := func(args ...string) { t.Helper(); egressIP(t, append([]string{"-n", n.ns}, args...)...) }
in("link", "set", "lo", "up")
- in("addr", "add", "10.0.5.20/32", "dev", n.nsLink)
- in("addr", "add", "10.0.5.21/32", "dev", n.nsLink)
- in("-6", "addr", "add", "fd00:5::20/128", "dev", n.nsLink, "nodad")
+ for _, target := range lay.targets {
+ if netip.MustParseAddr(target).Is6() {
+ in("-6", "addr", "add", target+"/128", "dev", n.nsLink, "nodad")
+ } else {
+ in("addr", "add", target+"/32", "dev", n.nsLink)
+ }
+ }
in("link", "set", n.nsLink, "up")
- in("route", "add", "10.0.5.1/32", "dev", n.nsLink)
- in("-6", "route", "add", "fd00:5::1/128", "dev", n.nsLink)
+ in("route", "add", lay.box4+"/32", "dev", n.nsLink)
+ if lay.box6 != "" {
+ in("-6", "route", "add", lay.box6+"/128", "dev", n.nsLink)
+ }
addrs := map[string]string{}
- for _, a := range egressTargets {
+ for _, a := range lay.targets {
ln, err := egressListenIn(nsPath, net.JoinHostPort(a, "0"))
if err != nil {
t.Fatalf("listen on %s in %s: %v", a, n.ns, err)
@@ -321,7 +353,7 @@ func egressTargetNetnsAt(t *testing.T, n egressNetnsNames) (map[string]string, f
if err != nil {
t.Fatal("LocalAddresses:", err)
}
- for _, a := range egressTargets {
+ for _, a := range lay.targets {
addr := netip.MustParseAddr(a)
for _, p := range local {
if p.Contains(addr) {
@@ -807,7 +839,7 @@ func newEgressPreClaimBoxWith(t *testing.T, o egressBoxOptions) *egressBox {
if o.netns == (egressNetnsNames{}) {
b.targets = egressTargetNetns(t)
} else {
- b.targets, _ = egressTargetNetnsAt(t, o.netns)
+ b.targets, _ = egressTargetNetnsAt(t, o.netns, egressNetnsTask13Addrs)
}
// The build: the test binary, as the platform binary the templates
diff --git a/internal/host/egress_prefix_rootrunner_linux_test.go b/internal/host/egress_prefix_rootrunner_linux_test.go
index f09c89273..9d7aad764 100644
--- a/internal/host/egress_prefix_rootrunner_linux_test.go
+++ b/internal/host/egress_prefix_rootrunner_linux_test.go
@@ -6,10 +6,8 @@ import (
"context"
"errors"
"io/fs"
- "net"
"net/netip"
"os"
- "os/exec"
"path/filepath"
"sync"
"testing"
@@ -203,116 +201,31 @@ func TestRootEgressPrefixKernelProof(t *testing.T) {
}
}
-// egressPrefixTargets is the prefix witness's target fixture, built as
-// egressTargetNetnsAt builds Task 13's with its own names and addresses:
-// a namespace carlos-egr3 behind a veth pair, 10.250.96.1 on the box end,
-// 10.250.64.10 and 10.250.80.10 inside with a TCP listener on each served
-// by this process. It returns each target's host:port, keyed by address,
-// after checking each answers from the box and that no address of the
-// box lies in 10.250.64.0/20. Everything goes in t.Cleanup, last-made
-// first.
+// egressPrefixTargets is the prefix witness's target fixture: the shared
+// egressTargetNetnsAt with its own names (carlos-egr3, carlos-egr3/3n)
+// and addresses (10.250.96.1 on the box end; 10.250.64.10 and
+// 10.250.80.10 inside). Before and after it, no address of the box may lie
+// in 10.250.64.0/20: the asserter would refuse a prefix holding one, and
+// the witness must not lean on one.
func egressPrefixTargets(t *testing.T) map[string]string {
t.Helper()
- var steps []func()
- t.Cleanup(func() {
- for i := len(steps) - 1; i >= 0; i-- {
- steps[i]()
- }
- })
- cleanup := func(f func()) { steps = append(steps, f) }
-
- nsPath := filepath.Join("/run/netns", egressPrefixNetns)
- if _, err := os.Lstat(nsPath); !errors.Is(err, fs.ErrNotExist) {
- t.Fatal("network namespace already exists", nsPath, err)
- }
- if _, err := net.InterfaceByName(egressPrefixHostEnd); err == nil {
- t.Fatal("link already exists", egressPrefixHostEnd)
- }
- // Before anything is added: the asserter would refuse a prefix holding
- // an address of the box, and the fixture must not lean on one.
prefix := netip.MustParsePrefix(egressPrefixAllow)
- local, err := instancectl.LocalAddresses()
- if err != nil {
- t.Fatal("LocalAddresses:", err)
- }
- for _, p := range local {
- if p.Overlaps(prefix) {
- t.Fatalf("this box already holds %s, inside %s: the witness cannot run here", p, prefix)
- }
- }
-
- egressIP(t, "netns", "add", egressPrefixNetns)
- cleanup(func() {
- if out, err := exec.Command("ip", "netns", "del", egressPrefixNetns).CombinedOutput(); err != nil {
- t.Errorf("ip netns del %s: %v: %s", egressPrefixNetns, err, out)
- }
- if _, err := os.Lstat(nsPath); !errors.Is(err, fs.ErrNotExist) {
- t.Errorf("network namespace %s left behind: %v", nsPath, err)
- }
- })
- egressIP(t, "link", "add", egressPrefixHostEnd, "type", "veth", "peer", "name", egressPrefixNsEnd, "netns", egressPrefixNetns)
- cleanup(func() {
- if _, err := net.InterfaceByName(egressPrefixHostEnd); err == nil {
- if out, err := exec.Command("ip", "link", "del", egressPrefixHostEnd).CombinedOutput(); err != nil {
- t.Errorf("ip link del %s: %v: %s", egressPrefixHostEnd, err, out)
- }
- }
- // ip link del returns once the pair is gone.
- if _, err := net.InterfaceByName(egressPrefixHostEnd); err == nil {
- t.Errorf("link %s left behind", egressPrefixHostEnd)
- }
- })
- egressIP(t, "addr", "add", egressPrefixBoxAddr+"/32", "dev", egressPrefixHostEnd)
- egressIP(t, "link", "set", egressPrefixHostEnd, "up")
- for _, a := range []string{egressPrefixInside, egressPrefixOutside} {
- egressIP(t, "route", "add", a+"/32", "dev", egressPrefixHostEnd, "src", egressPrefixBoxAddr)
- }
-
- in := func(args ...string) {
+ noLocalInPrefix := func(when string) {
t.Helper()
- egressIP(t, append([]string{"-n", egressPrefixNetns}, args...)...)
- }
- in("link", "set", "lo", "up")
- in("addr", "add", egressPrefixInside+"/32", "dev", egressPrefixNsEnd)
- in("addr", "add", egressPrefixOutside+"/32", "dev", egressPrefixNsEnd)
- in("link", "set", egressPrefixNsEnd, "up")
- in("route", "add", egressPrefixBoxAddr+"/32", "dev", egressPrefixNsEnd)
-
- addrs := map[string]string{}
- for _, a := range []string{egressPrefixInside, egressPrefixOutside} {
- ln, err := egressListenIn(nsPath, net.JoinHostPort(a, "0"))
+ local, err := instancectl.LocalAddresses()
if err != nil {
- t.Fatalf("listen on %s in %s: %v", a, egressPrefixNetns, err)
+ t.Fatal("LocalAddresses:", err)
}
- cleanup(func() { ln.Close() })
- go func() {
- for {
- c, err := ln.Accept()
- if err != nil {
- return
- }
- c.Close()
+ for _, p := range local {
+ if p.Overlaps(prefix) {
+ t.Fatalf("%s: this box holds %s, inside %s", when, p, prefix)
}
- }()
- addrs[a] = ln.Addr().String() // an explicit port: the tenant dials host:port
- }
- // Each answers from the box itself (no cgroup filter here). IPv4 only,
- // so no neighbour-discovery wait: the dial's own SYN retries cover ARP.
- for a, hp := range addrs {
- c, err := net.DialTimeout("tcp", hp, 5*time.Second)
- if err != nil {
- t.Fatalf("target %s (%s) unreachable from the box: %v", a, hp, err)
- }
- c.Close()
- }
- // And still none inside the prefix with the fixture up.
- if local, err = instancectl.LocalAddresses(); err != nil {
- t.Fatal("LocalAddresses:", err)
- }
- for _, p := range local {
- if p.Overlaps(prefix) {
- t.Fatalf("the fixture left %s, inside %s, as an address of this box", p, prefix)
}
}
+ noLocalInPrefix("before the fixture")
+ addrs, _ := egressTargetNetnsAt(t,
+ egressNetnsNames{ns: egressPrefixNetns, hostLink: egressPrefixHostEnd, nsLink: egressPrefixNsEnd},
+ egressNetnsAddrs{box4: egressPrefixBoxAddr, targets: []string{egressPrefixInside, egressPrefixOutside}})
+ noLocalInPrefix("with the fixture up")
return addrs
}