egress: the interrupted-revoke witness proves the recovery path on real systemd (#328, final review F1 witness)
Controller ruling after run 20261025T202313-2c86b7: whether the slice write alone closes the address is not pinned here (the freeze and the nudge are proven by TestRootEgressRevokeWhileRunning). After the interrupted process: the record exists and the run unit's nudge drop-in is absent or no newer than the interruption. The fresh control service's first sweep removes the record, writes the drop-in, keeps the invocation, reports nothing, and the address is closed within 2 s. Reachability before recovery is logged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+41
−13
internal/host/egress_interrupt_rootrunner_linux_test.go+41 −13
diff --git a/internal/host/egress_interrupt_rootrunner_linux_test.go b/internal/host/egress_interrupt_rootrunner_linux_test.go| index 5ccdc1b90..3734ff299 100644 |
| --- a/internal/host/egress_interrupt_rootrunner_linux_test.go |
| +++ b/internal/host/egress_interrupt_rootrunner_linux_test.go |
| @@ -85,14 +85,22 @@ func egressInterruptedAssert(host string) int { |
| // process asserts the host and exits after the slice's allow is written |
| // and before the run unit is nudged. |
| // |
| -// Then: the slice reads back empty, EgressDueDir holds the revoke, and the |
| -// running unit STILL reaches 10.0.5.20 (the freeze: without the record, |
| -// nothing would ever close the address; if it is already closed the |
| -// witness cannot tell recovery from nothing, and fails saying so). A fresh |
| -// control service's asserter starts as runWithClaim starts it (Loop: name |
| -// the slices, sweep once); within egressLiveBound of that the unit, which |
| -// keeps its invocation, no longer reaches 10.0.5.20, the record is gone, |
| -// and GET /egress on the fresh service reports nothing allowed and no state. |
| +// What it proves is the recovery path on real systemd (controller ruling |
| +// after run 20261025T202313-2c86b7: whether the slice write alone closes |
| +// the address depends on kernel conditions this witness does not pin; the |
| +// freeze and the nudge are proven by TestRootEgressRevokeWhileRunning's |
| +// parent-rewritten cases, and the record outliving the asserter by |
| +// TestEgressOwedChangeOutlivesTheControlService). After the interrupted |
| +// process exits: the slice reads back empty, EgressDueDir holds the |
| +// revoke, the nudge was not applied (the run unit's nudge drop-in under |
| +// /run/systemd/system.control is absent or no newer than the |
| +// interruption), and the unit kept its invocation. Whether 10.0.5.20 is |
| +// still reachable at that point is logged, not required. A fresh control |
| +// service's asserter starts as runWithClaim starts it (Loop: name the |
| +// slices, sweep once); that first sweep discharges the record (file gone) |
| +// and applies the nudge (the drop-in written after the interruption, the |
| +// invocation unchanged); GET /egress on the fresh service reports nothing |
| +// allowed and no state, and 10.0.5.20 is closed within egressLiveBound. |
| func TestRootEgressInterruptedRevoke(t *testing.T) { |
| b := newEgressPreClaimBoxWith(t, egressBoxOptions{noPolicy: true}) |
| ctx := t.Context() |
| @@ -129,6 +137,18 @@ func TestRootEgressInterruptedRevoke(t *testing.T) { |
| t.Fatal(err) |
| } |
| before := b.runInvocation(t) |
| + nudge := filepath.Join("/run/systemd/system.control", run+".d", "50-IPAddressAllow.conf") |
| + nudgedAt := func() (time.Time, bool) { |
| + fi, err := os.Stat(nudge) |
| + if errors.Is(err, os.ErrNotExist) { |
| + return time.Time{}, false |
| + } |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return fi.ModTime(), true |
| + } |
| + interrupted := time.Now() |
| exe, err := os.Executable() |
| if err != nil { |
| t.Fatal(err) |
| @@ -147,8 +167,13 @@ func TestRootEgressInterruptedRevoke(t *testing.T) { |
| if raw, err := os.ReadFile(record); err != nil || strings.TrimSpace(string(raw)) != "revoke" { |
| t.Fatalf("after the interruption %s = %q, %v; want revoke", record, raw, err) |
| } |
| - if !egressReach(t, c, target) { |
| - t.Fatal("after the interruption the run unit no longer reaches 10.0.5.20: the slice write alone closed it, so this witness cannot tell recovery from nothing (the kernel finding of run 20261025T173953-8a3366 did not hold here)") |
| + if at, ok := nudgedAt(); ok && at.After(interrupted) { |
| + t.Fatalf("the interrupted control service nudged the run unit (%s written %s, after the interruption at %s)", nudge, at, interrupted) |
| + } |
| + if egressReach(t, c, target) { |
| + t.Logf("before recovery the run unit still reaches 10.0.5.20: the slice write alone did not close it") |
| + } else { |
| + t.Logf("before recovery the run unit no longer reaches 10.0.5.20: the slice write alone closed it") |
| } |
| if after := b.runInvocation(t); after != before { |
| t.Fatalf("the interrupted control service restarted the run unit (%s -> %s)", before, after) |
| @@ -169,6 +194,12 @@ func TestRootEgressInterruptedRevoke(t *testing.T) { |
| client := egressServe(t, srv, filepath.Join(t.TempDir(), "control2.sock")) |
| fresh.Loop(ctx, 0) |
| deadline := time.Now().Add(egressLiveBound) |
| + if _, err := os.Lstat(record); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("the fresh control service's first sweep left %s: %v", record, err) |
| + } |
| + if at, ok := nudgedAt(); !ok || !at.After(interrupted) { |
| + t.Fatalf("the fresh control service's first sweep did not nudge the run unit: %s present %v, written %s, interruption at %s", nudge, ok, at, interrupted) |
| + } |
| if !egressWithin(t, deadline, c, false, target) { |
| egressFirewallDiag(t, run, b.slice, c, target) |
| t.Fatal("the fresh control service's first sweep did not close 10.0.5.20 on the running unit") |
| @@ -176,9 +207,6 @@ func TestRootEgressInterruptedRevoke(t *testing.T) { |
| if after := b.runInvocation(t); after != before { |
| t.Fatalf("the run unit was restarted (%s -> %s); with a parent allow the revoke is applied by the nudge", before, after) |
| } |
| - if _, err := os.Lstat(record); !errors.Is(err, os.ErrNotExist) { |
| - t.Fatalf("%s is still there after the revoke reached the run unit: %v", record, err) |
| - } |
| st, err := client.EgressStatus(ctx) |
| if err != nil { |
| t.Fatal("GET /egress:", err) |