carlos / platform Public

host: egress witnesses: revokes after a parent rewrite land within 2 s with no restart; the box clears nudge drop-ins (#328)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 9551b30cb1126aaa3c550df9fff65afd3d22df3d parent ef55bb3
2 files changed, +57 −14
  • internal/host/egress_fixtures_rootrunner_linux_test.go +11 −0
  • internal/host/egress_startpaths_rootrunner_linux_test.go +46 −14
diff --git a/internal/host/egress_fixtures_rootrunner_linux_test.go b/internal/host/egress_fixtures_rootrunner_linux_test.go
index f2c225474..66e7f2989 100644
--- a/internal/host/egress_fixtures_rootrunner_linux_test.go
+++ b/internal/host/egress_fixtures_rootrunner_linux_test.go
@@ -773,6 +773,14 @@ func newEgressPreClaimBoxWith(t *testing.T, o egressBoxOptions) *egressBox {
if state := egressShow(t, u, "LoadState"); state != "not-found" {
t.Fatal("unit already present", u, state)
}
+ // The asserter's nudge (set-property on a running unit, run
+ // 20261025T173953-8a3366) leaves a runtime drop-in here; refused if
+ // present, removed once the units have stopped.
+ for _, root := range []string{"/run/systemd/system.control", "/etc/systemd/system.control"} {
+ if _, err := os.Lstat(filepath.Join(root, u+".d")); !errors.Is(err, fs.ErrNotExist) {
+ t.Fatal("unit already has set-property drop-ins", root, u, err)
+ }
+ }
}
for _, name := range egressTemplates {
for _, dir := range []string{"/run/systemd/system", "/etc/systemd/system"} {
@@ -938,6 +946,9 @@ func newEgressPreClaimBoxWith(t *testing.T, o egressBoxOptions) *egressBox {
}
}
egressCtl("reset-failed", u)
+ if err := os.RemoveAll(filepath.Join("/run/systemd/system.control", u+".d")); err != nil {
+ t.Error(err)
+ }
}
if err := os.RemoveAll(filepath.Join("/run/systemd/system", instancectl.GenUnitName(host, egressGen)+".d")); err != nil {
t.Error(err)
diff --git a/internal/host/egress_startpaths_rootrunner_linux_test.go b/internal/host/egress_startpaths_rootrunner_linux_test.go
index fafc83028..cc29b1971 100644
--- a/internal/host/egress_startpaths_rootrunner_linux_test.go
+++ b/internal/host/egress_startpaths_rootrunner_linux_test.go
@@ -130,21 +130,43 @@ func TestRootEgressStartPathsPreClaim(t *testing.T) {
// then a revoke whose write fails answers 502 and reports failing with the
// address still held, and the next sweep closes it (Astra plan R1-11: the
// failing write has something to write). Each subtest names the branch of
-// the asserter's revoke it exercises (run 20261025T164418-7a14fe ruling):
+// the asserter's revoke it exercises (rulings on runs
+// 20261025T164418-7a14fe and 20261025T173953-8a3366):
//
// - "to empty, no parent allow": carlos-instances.slice holds nothing, so
-// each revoke to empty restarts the run unit (closeByRestart) and
+// each revoke to empty restarts the run unit (restartRunning) and
// reports "revoked (restarted)";
// - "to empty, parent allow": carlos-instances.slice holds an allow (the
-// resolver allow's stand-in, fd00:5::20), so each revoke is live: the
-// run unit keeps its invocation;
+// resolver allow's stand-in, fd00:5::20), so each change is applied by
+// the nudge (a write on the run unit's own list): the run unit keeps
+// its invocation;
// - "narrowed, no parent allow": 10.0.5.20 and 10.0.5.21 narrowed to
-// 10.0.5.21 is live with no parent allow (a non-empty result never
-// restarts).
+// 10.0.5.21 is applied by the nudge with no parent allow (a non-empty
+// result never restarts unless its nudge fails);
+// - "to empty, parent allow rewritten while running" and "narrowed,
+// parent allow rewritten while running": as the two above, but the
+// parent's allow is written again while the run unit runs, as the
+// probe's allowResolvers does every five minutes. Run
+// 20261025T173953-8a3366 found that after such a write a slice change
+// no longer reaches a running unit without the nudge: each revoke and
+// regrant must still land within 2 s, with no restart.
func TestRootEgressRevokeWhileRunning(t *testing.T) {
- t.Run("to empty, no parent allow", func(t *testing.T) { egressRevokeToEmpty(t, false) })
- t.Run("to empty, parent allow", func(t *testing.T) { egressRevokeToEmpty(t, true) })
- t.Run("narrowed, no parent allow", egressRevokeNarrowed)
+ t.Run("to empty, no parent allow", func(t *testing.T) { egressRevokeToEmpty(t, false, false) })
+ t.Run("to empty, parent allow", func(t *testing.T) { egressRevokeToEmpty(t, true, false) })
+ t.Run("narrowed, no parent allow", func(t *testing.T) { egressRevokeNarrowed(t, false) })
+ t.Run("to empty, parent allow rewritten while running", func(t *testing.T) { egressRevokeToEmpty(t, true, true) })
+ t.Run("narrowed, parent allow rewritten while running", func(t *testing.T) { egressRevokeNarrowed(t, true) })
+}
+
+// egressRewriteParent writes carlos-instances.slice's allow again, the
+// reset and then the list, exactly as allowResolvers writes the resolver
+// allow before every probe run, and checks it reads back the same.
+func egressRewriteParent(t *testing.T, prefix string) {
+ t.Helper()
+ egressMustCtl(t, "set-property", "--runtime", instancectl.InstancesSlice, "IPAddressAllow=", "IPAddressAllow="+prefix)
+ if got := egressShow(t, instancectl.InstancesSlice, "IPAddressAllow"); got != prefix {
+ t.Fatalf("parent rewrite: %s holds %q, want %q", instancectl.InstancesSlice, got, prefix)
+ }
}
// egressParentAllow gives carlos-instances.slice an allow for the test, as
@@ -206,7 +228,7 @@ func egressRevokeDeadline(restarted bool) time.Time {
return time.Now().Add(egressLiveBound)
}
-func egressRevokeToEmpty(t *testing.T, parentAllow bool) {
+func egressRevokeToEmpty(t *testing.T, parentAllow, rewrite bool) {
b := newEgressPreClaimBox(t)
ctx := t.Context()
target := b.targets["10.0.5.20"]
@@ -218,6 +240,9 @@ func egressRevokeToEmpty(t *testing.T, parentAllow bool) {
t.Fatal("the parent's allow (fd00:5::20) is not in force for the run unit")
}
}
+ if rewrite {
+ egressRewriteParent(t, "fd00:5::20/128")
+ }
b.wantAllowed(t, "start")
if !egressReach(t, c, target) {
t.Fatal("start: the tenant cannot reach 10.0.5.20")
@@ -283,11 +308,15 @@ func egressRevokeToEmpty(t *testing.T, parentAllow bool) {
}
}
-func egressRevokeNarrowed(t *testing.T) {
+func egressRevokeNarrowed(t *testing.T, rewrite bool) {
b := newEgressPreClaimBox(t)
ctx := t.Context()
c := b.startRun(t)
b.wantAllowed(t, "start")
+ if rewrite {
+ egressParentAllow(t, "fd00:5::20/128")
+ egressRewriteParent(t, "fd00:5::20/128")
+ }
if err := b.reg.SetPolicy(b.host, "10.0.5.20 10.0.5.21", "", egressExpiry()); err != nil {
t.Fatal(err)
}
@@ -309,7 +338,7 @@ func egressRevokeNarrowed(t *testing.T) {
}
if !egressWithin(t, time.Now().Add(egressLiveBound), c, false, b.targets["10.0.5.20"]) {
egressFirewallDiag(t, instancectl.UnitName(instancectl.RoleRun, b.host), b.slice, c, b.targets["10.0.5.20"])
- t.Fatal("narrow: 10.0.5.20 still reachable 2 s after POST /egress, with no parent allow")
+ t.Fatal("narrow: 10.0.5.20 still reachable 2 s after POST /egress")
}
if !egressReach(t, c, b.targets["10.0.5.21"]) {
t.Fatal("narrow: 10.0.5.21 closed with 10.0.5.20")
@@ -630,7 +659,8 @@ func (w *egressUnderClaimsWitness) check(t *testing.T, egress func(host string)
// Then each refusal is shown to be the fence and not a broken dialer: B
// granted through the production path (column, POST /egress) reaches the
// address within 2 s, and so does the stand-in given the address on its
-// own unit by hand.
+// own unit by hand. B ran through the probe's parent write, so its grant
+// lands only through the asserter's nudge (run 20261025T173953-8a3366).
//
// The target fixture uses its own names (namespace and veth carlos-egr2,
// carlos-egr2n), apart from Task 1's carlos-egr0 and Task 13's
@@ -913,7 +943,9 @@ func egressCoveringPrefixes(t *testing.T, list string) []string {
// egressGrantNotLiveDiag runs when app B's grant, written by the
// production asserter while B runs, did not reach B (run
// 20261025T173335-926c1c: the slice read back 10.0.5.20/32, B reached it
-// only after a restart). It changes no assertion: each step logs one
+// only after a restart; run 20261025T173953-8a3366 ran it and led to the
+// asserter's nudge, so with the nudge it should no longer run). It
+// changes no assertion: each step logs one
// "discriminator:" verdict, so one run tells which condition keeps a
// slice write from a running unit, and whether the live revoke branch
// (a parent allow, no restart) is affected too. In order: