carlos / platform Public

host: egress witnesses prove the deny is in force first, and diagnose a revoke that does not land (#328)

Run 20261025T163313-7a7e8c: in TestRootEgressInstanceControlUnderClaims
the claims-on control service's first sweep reset the slice (it logged
"allow is now nothing" and the slice read back empty), yet the tenant
still reached 10.0.5.20. That run cannot tell a deny that was never in
force (fixture) from a reset that did not reach the running unit
(systemd; Task 1 proved revoke live only with an allow on the parent).

- The claims witness's tenant now starts with no allow and must be closed
  to 10.0.5.20 (baseline), and the pre-claim grant is then written live.
- The pre-claim run start checks the tenant is closed to 10.0.5.21, which
  nothing grants.
- Every reachability failure logs the unit's, slice's and parents' IP
  properties, bpftool's effective programs when present, and whether the
  address is reachable after a restart of the unit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 3300d15c2c6364d6098eea6cfd37ad1252df6772 parent 07000bd
1 file changed, +58 −5
  • internal/host/egress_startpaths_rootrunner_linux_test.go +58 −5
diff --git a/internal/host/egress_startpaths_rootrunner_linux_test.go b/internal/host/egress_startpaths_rootrunner_linux_test.go
index e27b6a680..a88899056 100644
--- a/internal/host/egress_startpaths_rootrunner_linux_test.go
+++ b/internal/host/egress_startpaths_rootrunner_linux_test.go
@@ -413,6 +413,36 @@ func egressWithin(t *testing.T, deadline time.Time, c *http.Client, want bool, a
}
}
+// egressFirewallDiag logs, for a tenant whose reachability was not what
+// the test wanted, what systemd shows for the unit, its slice and the
+// parents, and the kernel's effective programs (bpftool, when present).
+// Then it restarts the unit and probes once more: unreachable after the
+// restart means the slice's allow was right but did not reach the running
+// unit; still reachable means the deny is not in force for the unit at all.
+// The caller fails the test.
+func egressFirewallDiag(t *testing.T, unit, slice string, c *http.Client, target string) {
+ t.Helper()
+ for _, u := range []string{unit, slice, instancectl.InstancesSlice, "carlos.slice"} {
+ out, _ := egressCtl("show", "-p", "IPAddressAllow", "-p", "IPAddressDeny", "-p", "ControlGroup", "-p", "ActiveState", u)
+ t.Logf("diag: %s: %q", u, out)
+ }
+ if cg, _ := egressCtl("show", "-p", "ControlGroup", "--value", unit); cg != "" {
+ if _, err := exec.LookPath("bpftool"); err == nil {
+ out, _ := exec.Command("bpftool", "cgroup", "show", filepath.Join("/sys/fs/cgroup", cg), "effective").CombinedOutput()
+ t.Logf("diag: bpftool cgroup show %s effective:\n%s", cg, out)
+ } else {
+ t.Logf("diag: no bpftool on this box")
+ }
+ }
+ t.Logf("diag: before a restart of %s, %s reachable: %v", unit, target, egressReach(t, c, target))
+ if out, err := egressCtl("restart", unit); err != nil {
+ t.Logf("diag: restart %s: %v: %s", unit, err, out)
+ return
+ }
+ egressServing(t, unit, c)
+ t.Logf("diag: after a restart of %s, %s reachable: %v", unit, target, egressReach(t, c, target))
+}
+
// egressPeerIsSelf is a PeerOK that accepts only this process: the test
// is the control service's one client.
func egressPeerIsSelf(c net.Conn) error {
@@ -928,7 +958,13 @@ func (b *egressBox) startRun(t *testing.T) *http.Client {
if _, err := b.client.Start(t.Context(), b.host, instancectl.RoleRun, cgroup.TierDefault.MemoryMax); err != nil {
t.Fatalf("POST /start run: %v\n%s", err, egressJournal(unit))
}
- return b.tenant(t, unit, "run.sock")
+ c := b.tenant(t, unit, "run.sock")
+ // The template's deny is in force: an address nothing grants is closed.
+ if egressReach(t, c, b.targets["10.0.5.21"]) {
+ egressFirewallDiag(t, unit, b.slice, c, b.targets["10.0.5.21"])
+ t.Fatal("run: the tenant reaches 10.0.5.21, which nothing allows: the template's deny is not in force")
+ }
+ return c
}
// TestRootEgressStartPathsPreClaim: through the real control service and
@@ -1052,6 +1088,7 @@ func TestRootEgressRevokeWhileRunning(t *testing.T) {
t.Fatal("POST /egress (revoke):", err)
}
if !egressWithin(t, time.Now().Add(2*time.Second), c, false, target) {
+ egressFirewallDiag(t, instancectl.UnitName(instancectl.RoleRun, b.host), b.slice, c, target)
t.Fatal("revoke: 10.0.5.20 still reachable 2 s after POST /egress")
}
if got := b.allow(t); got != "" {
@@ -1102,6 +1139,7 @@ func TestRootEgressRevokeWhileRunning(t *testing.T) {
t.Fatalf("sweep: slice holds %q", got)
}
if !egressWithin(t, deadline, c, false, target) {
+ egressFirewallDiag(t, instancectl.UnitName(instancectl.RoleRun, b.host), b.slice, c, target)
t.Fatal("sweep: 10.0.5.20 still reachable 2 s after the sweep")
}
if rep := b.report(t); rep.State != "" || len(rep.Allowed) != 0 {
@@ -1135,6 +1173,7 @@ func TestRootEgressMixedBoxWritesNothing(t *testing.T) {
t.Fatal("POST /egress:", err)
}
if !egressWithin(t, time.Now().Add(2*time.Second), c, false, target) {
+ egressFirewallDiag(t, instancectl.UnitName(instancectl.RoleRun, b.host), b.slice, c, target)
t.Fatal("mixed box: 10.0.5.20 still reachable 2 s after POST /egress")
}
if got := b.allow(t); got != "" {
@@ -1228,6 +1267,7 @@ func plan14EgressClaimChecks(t *testing.T, host string, tenant *http.Client, tar
t.Fatalf("under claims: slice holds %q after the claim launch, want nothing", got)
}
if egressReach(t, tenant, targets["10.0.5.20"]) {
+ egressFirewallDiag(t, instancectl.UnitName(instancectl.RoleRun, host), slice, tenant, targets["10.0.5.20"])
t.Fatal("under claims: the claim-launched tenant reached 10.0.5.20")
}
client := egressServe(t, &instancectl.Server{ClaimStop: http.NotFoundHandler(), Egress: egress, Logf: t.Logf}, filepath.Join(t.TempDir(), "control.sock"))
@@ -1302,19 +1342,30 @@ func (w *egressUnderClaimsWitness) prepare(t *testing.T) {
t.Fatal(err)
}
egressSliceProperties(t, w.slice)
- // The allow a pre-claim root wrote, then a tenant running under it.
- egressMustCtl(t, "set-property", "--runtime", w.slice, "IPAddressAllow=", "IPAddressAllow=10.0.5.20/32")
scratch, err := os.MkdirTemp("/run", "egr-")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.RemoveAll(scratch) })
- w.tenant = egressUnitTenant(t, "carlos-egress-claims", w.slice, egressTemplateDeny(t), filepath.Join(scratch, "tenant.sock"))
- if !egressReach(t, w.tenant, w.targets["10.0.5.20"]) {
+ // A tenant under the template's deny, closed to 10.0.5.20 while
+ // nothing grants it (the baseline: the deny is in force), then the
+ // allow a pre-claim root wrote, live.
+ w.tenant = egressUnitTenant(t, egressClaimsUnit, w.slice, egressTemplateDeny(t), filepath.Join(scratch, "tenant.sock"))
+ target := w.targets["10.0.5.20"]
+ if egressReach(t, w.tenant, target) {
+ egressFirewallDiag(t, egressClaimsUnit+".service", w.slice, w.tenant, target)
+ t.Fatal("baseline: the tenant reaches 10.0.5.20 with no allow: the template's deny is not in force")
+ }
+ egressMustCtl(t, "set-property", "--runtime", w.slice, "IPAddressAllow=", "IPAddressAllow=10.0.5.20/32")
+ if !egressWithin(t, time.Now().Add(2*time.Second), w.tenant, true, target) {
+ egressFirewallDiag(t, egressClaimsUnit+".service", w.slice, w.tenant, target)
t.Fatal("pre-claim: the tenant cannot reach 10.0.5.20 under the hand grant")
}
}
+// egressClaimsUnit is the claims witness's tenant unit.
+const egressClaimsUnit = "carlos-egress-claims"
+
func (w *egressUnderClaimsWitness) check(t *testing.T, egress func(host string) servingPeerReply) {
t.Helper()
target := w.targets["10.0.5.20"]
@@ -1326,6 +1377,7 @@ func (w *egressUnderClaimsWitness) check(t *testing.T, egress func(host string)
}
}
if !egressWithin(t, time.Now().Add(2*time.Second), w.tenant, false, target) {
+ egressFirewallDiag(t, egressClaimsUnit+".service", w.slice, w.tenant, target)
t.Fatal("under claims: 10.0.5.20 reachable after the sweep reset the slice")
}
@@ -1344,6 +1396,7 @@ func (w *egressUnderClaimsWitness) check(t *testing.T, egress func(host string)
t.Fatalf("under claims: slice holds %q after POST /egress", got)
}
if !egressWithin(t, deadline, w.tenant, false, target) {
+ egressFirewallDiag(t, egressClaimsUnit+".service", w.slice, w.tenant, target)
t.Fatal("under claims: 10.0.5.20 reachable 2 s after POST /egress")
}
}