carlos / platform Public

host: the isolation witness compares the stand-in's deny with the probe's by the addresses denied (#328)

Run 20261025T172932-9b27b2: systemd's IPAddressDeny read-back lists a
set in no fixed order, and the stand-in's dropped the two prefixes
another entry covers (169.254.169.254/32, fd00:ec2::254/128) where the
probe unit's kept them. The stand-in's unit file is checked to carry
the probe template's line verbatim; the two read-backs are compared
reduced to the prefixes no other entry covers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 1e4d850b874269dd2ca70e5d276669b335bcb94b parent 44db9eb
1 file changed, +42 −3
  • internal/host/egress_startpaths_rootrunner_linux_test.go +42 −3
diff --git a/internal/host/egress_startpaths_rootrunner_linux_test.go b/internal/host/egress_startpaths_rootrunner_linux_test.go
index 2b02253c5..0a6df832b 100644
--- a/internal/host/egress_startpaths_rootrunner_linux_test.go
+++ b/internal/host/egress_startpaths_rootrunner_linux_test.go
@@ -704,9 +704,21 @@ func TestRootEgressIsolation(t *testing.T) {
t.Cleanup(func() { os.RemoveAll(scratch) })
const standin = "carlos-egress-probe-standin"
standinUnit := standin + ".service"
- sc := egressUnitTenant(t, standin, parent, egressUnitDeny(t, egressProbeUnit), filepath.Join(scratch, "tenant.sock"))
- if got, want := egressShow(t, standinUnit, "IPAddressDeny"), egressShow(t, egressProbeUnit, "IPAddressDeny"); got != want || got == "" {
- t.Fatalf("the stand-in's deny %q is not the loaded probe unit's %q", got, want)
+ probeDeny := egressUnitDeny(t, egressProbeUnit)
+ sc := egressUnitTenant(t, standin, parent, probeDeny, filepath.Join(scratch, "tenant.sock"))
+ // The stand-in's unit file carries the probe template's line verbatim.
+ if raw, err := os.ReadFile(filepath.Join("/run/systemd/system", standinUnit)); err != nil || !strings.Contains(string(raw), "\nIPAddressDeny="+probeDeny+"\n") {
+ t.Fatalf("the stand-in's unit file does not carry the probe template's IPAddressDeny= line verbatim: %v\n%s", err, raw)
+ }
+ // And systemd denies the same addresses for both. Its read-back lists
+ // a set in no fixed order, and may or may not have dropped prefixes
+ // another entry covers (run 20261025T172932-9b27b2: the stand-in's
+ // lost 169.254.169.254/32 and fd00:ec2::254/128, the probe's kept
+ // them), so each side is compared reduced to the prefixes no other
+ // entry covers.
+ got, want := egressShow(t, standinUnit, "IPAddressDeny"), egressShow(t, egressProbeUnit, "IPAddressDeny")
+ if g, w := egressCoveringPrefixes(t, got), egressCoveringPrefixes(t, want); len(w) == 0 || !slices.Equal(g, w) {
+ t.Fatalf("the stand-in's deny %q is not the loaded probe unit's %q (reduced: %q, %q)", got, want, g, w)
}
if got := egressShow(t, standinUnit, "IPAddressAllow"); got != "" {
t.Fatalf("the stand-in holds an allow: %q", got)
@@ -868,3 +880,30 @@ func egressSameProbe(t *testing.T, before, after instancectl.ProbeReport) {
t.Fatalf("the probe's verdicts changed with app A granted:\nbefore %v\nafter %v", b, a)
}
}
+
+// egressCoveringPrefixes parses a systemd IPAddressAllow=/IPAddressDeny=
+// read-back and returns its prefixes, masked, with every prefix another
+// entry of the same family covers removed, sorted: the addresses the list
+// matches, in one canonical form.
+func egressCoveringPrefixes(t *testing.T, list string) []string {
+ t.Helper()
+ var ps []netip.Prefix
+ for _, f := range strings.Fields(list) {
+ p, err := netip.ParsePrefix(f)
+ if err != nil {
+ t.Fatalf("read-back %q: %v", list, err)
+ }
+ ps = append(ps, p.Masked())
+ }
+ var out []string
+ for i, p := range ps {
+ covered := slices.ContainsFunc(ps, func(q netip.Prefix) bool {
+ return q != p && q.Addr().Is4() == p.Addr().Is4() && q.Bits() < p.Bits() && q.Contains(p.Addr())
+ })
+ if !covered && !slices.Contains(ps[:i], p) {
+ out = append(out, p.String())
+ }
+ }
+ slices.Sort(out)
+ return out
+}