carlos / platform Public

egress: a change-owed record that cannot be written never holds back the write; the interrupted-revoke witness makes the frozen state first (#328, final review F1 follow-up)

Root-runner run 20261025T200733-fcb343: in the claims witness's namespace
/run/carlos-control did not exist, so recording the owed change failed and
the asserter wrote nothing, leaving a revoked allow open. The record only
guards against the control service exiting mid-change: a failure is now
logged and the write goes ahead, owed in memory.

TestRootEgressInterruptedRevoke now starts the unit with no policy, rewrites
carlos-instances.slice's allow while it runs, and only then grants (the
nudge applies it), so the interrupted revoke's slice write alone leaves the
address open, as run 20261025T173953-8a3366 found.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev dddb49c2a4f3ed09715afaa3f1c1d201a3017fc1 parent 318db54
3 files changed, +104 −35
  • internal/host/egress_interrupt_rootrunner_linux_test.go +31 −15
  • internal/instancectl/egress.go +8 −6
  • internal/instancectl/egress_due_linux_test.go +65 −14
diff --git a/internal/host/egress_interrupt_rootrunner_linux_test.go b/internal/host/egress_interrupt_rootrunner_linux_test.go
index 659f0ef32..ba5b229b0 100644
--- a/internal/host/egress_interrupt_rootrunner_linux_test.go
+++ b/internal/host/egress_interrupt_rootrunner_linux_test.go
@@ -71,33 +71,49 @@ func egressInterruptedAssert(host string) int {
}
// TestRootEgressInterruptedRevoke is final review F1's witness, through
-// real systemd and the production asserter. The run unit serves with an
-// allow for 10.0.5.20, and carlos-instances.slice's allow is rewritten
-// while it runs (as the probe's allowResolvers does every five minutes),
-// so a change of the host slice's allow no longer reaches the unit without
-// the nudge (run 20261025T173953-8a3366). The column is cleared, and a
+// real systemd and the production asserter. It first makes the state in
+// which a change of the host slice's allow does not reach a running unit
+// on its own (run 20261025T173953-8a3366): the run unit starts with no
+// policy, carlos-instances.slice's allow is rewritten while it runs (as
+// RunProbe's allowResolvers does every five minutes), and only then is
+// 10.0.5.20 granted, through POST /egress, whose nudge (a write on the
+// unit's own list) makes it reachable. The column is then cleared, and a
// control service 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 obligation is real: without
-// it, nothing would ever close the address). 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.
+// 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.
func TestRootEgressInterruptedRevoke(t *testing.T) {
- b := newEgressPreClaimBox(t)
+ b := newEgressPreClaimBoxWith(t, egressBoxOptions{noPolicy: true})
ctx := t.Context()
target := b.targets["10.0.5.20"]
run := instancectl.UnitName(instancectl.RoleRun, b.host)
c := b.startRun(t)
+ if egressReach(t, c, target) {
+ t.Fatal("start: the tenant reaches 10.0.5.20 with no policy")
+ }
+ // The parent's allow, rewritten while the run unit runs.
egressParentAllow(t, "fd00:5::20/128")
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")
+
+ // The grant, after the rewrite: applied by POST /egress's nudge.
+ if err := b.reg.SetPolicy(b.host, "10.0.5.20", "", egressExpiry()); err != nil {
+ t.Fatal(err)
+ }
+ if err := b.client.Egress(ctx, b.host); err != nil {
+ t.Fatal("POST /egress (grant):", err)
+ }
+ if !egressWithin(t, time.Now().Add(egressLiveBound), c, true, target) {
+ egressFirewallDiag(t, run, b.slice, c, target)
+ t.Fatal("grant: 10.0.5.20 not reachable 2 s after POST /egress")
}
+ b.wantAllowed(t, "grant")
// The revoke, and the control service that dies doing it.
if err := b.reg.SetPolicy(b.host, "", "", ""); err != nil {
diff --git a/internal/instancectl/egress.go b/internal/instancectl/egress.go
index af2a5586c..3899a8111 100644
--- a/internal/instancectl/egress.go
+++ b/internal/instancectl/egress.go
@@ -303,13 +303,16 @@ func (e *EgressAsserter) assert(ctx context.Context, host string, start bool) er
// control service that exits before reach is done, must not lose it,
// or the next Assert would find the slice as wanted and stop there. A
// change that removes an address, or whose before is unknown, is a
- // revoke. A record that cannot be kept writes nothing.
+ // revoke. A file that cannot be written is logged and the write goes
+ // ahead, owed in memory: refusing it would leave a revoke's address
+ // open, where the file only guards against this service exiting before
+ // the change reaches the running units.
owe := dueGrant
if !readBefore || held.removes(want) || e.dueOf(slice) == dueRevoke {
owe = dueRevoke
}
if err := e.setDue(slice, owe); err != nil {
- return fail("recording the change it will owe its running services: " + err.Error() + "; nothing written")
+ e.logf("egress: %s: recording the change it will owe its running services in %s: %v; writing it all the same, owed in memory only", slice, e.DueDir, err)
}
args := []string{"set-property", "--runtime", slice, "IPAddressAllow="}
if len(want) > 0 {
@@ -1045,11 +1048,10 @@ func (e *EgressAsserter) closeUnnamed(ctx context.Context, slice string) (string
}
return "", false
}
- // Before the reset, as Assert records it; a record that cannot be
- // kept writes nothing.
+ // Before the reset, as Assert records it; a file that cannot be
+ // written is logged and the reset goes ahead, owed in memory.
if err := e.setDue(slice, dueRevoke); err != nil {
- e.logf("egress: %s: no host for this slice; recording the revoke it will owe: %v; nothing written", slice, err)
- return "", false
+ e.logf("egress: %s: no host for this slice; recording the revoke it will owe in %s: %v; resetting it all the same", slice, e.DueDir, err)
}
if out, err := e.Systemctl(ctx, "set-property", "--runtime", slice, "IPAddressAllow="); err != nil {
e.logf("egress: %s: no host for this slice; closing its allow: set-property: %s: %v", slice, strings.TrimSpace(out), err)
diff --git a/internal/instancectl/egress_due_linux_test.go b/internal/instancectl/egress_due_linux_test.go
index 772803d29..ccb929e03 100644
--- a/internal/instancectl/egress_due_linux_test.go
+++ b/internal/instancectl/egress_due_linux_test.go
@@ -11,6 +11,7 @@ package instancectl
import (
"context"
+ "fmt"
"os"
"path/filepath"
"runtime"
@@ -217,23 +218,73 @@ func TestEgressDueDirTornRecordIsARevoke(t *testing.T) {
}
}
-func TestEgressDueRecordFailureWritesNothing(t *testing.T) {
+// TestEgressDueRecordFailureNeverHoldsARevoke: a DueDir that cannot be
+// written (here its parent is missing, as /run/carlos-control was in the
+// claims witness's namespace, run 20261025T200733-fcb343) is logged, and
+// the revoke goes ahead, owed in memory: before claims (nudged), under
+// claims (restarted, ruling 9), and the sweep's reset of a slice it cannot
+// name. Refusing the write would leave the address open.
+func TestEgressDueRecordFailureNeverHoldsARevoke(t *testing.T) {
slice := SliceName(egressHost)
- notDir := filepath.Join(t.TempDir(), "file")
- if err := os.WriteFile(notDir, nil, 0o600); err != nil {
- t.Fatal(err)
- }
- ctl := newEgressCtl()
- ctl.setHeld(slice, "10.0.5.20/32")
- e := newEgressAsserter(ctl, staticSource(EgressPolicy{}, nil))
- e.DueDir = filepath.Join(notDir, "egress-due") // its parent is a file
- if err := e.Assert(context.Background(), egressHost); err == nil {
- t.Fatal("Assert succeeded though the owed change could not be recorded")
+ run := UnitName(RoleRun, egressHost)
+ box := func(t *testing.T, s string, p EgressPolicy, claims bool) (*egressCtl, *EgressAsserter, *[]string) {
+ t.Helper()
+ root := t.TempDir()
+ cgroupSlice(t, root, s, true)
+ cgroupService(t, root, s, run, true)
+ ctl := newEgressCtl()
+ ctl.setHeld(s, "10.0.5.20/32")
+ ctl.setHeld(InstancesSlice, "10.0.5.53/32")
+ ctl.active[run] = "active"
+ e := newEgressAsserter(ctl, staticSource(p, nil))
+ e.CgroupRoot, e.UnderClaims = root, claims
+ e.DueDir = filepath.Join(t.TempDir(), "carlos-control", "egress-due") // its parent is missing
+ var logs []string
+ e.Logf = func(f string, a ...any) { logs = append(logs, fmt.Sprintf(f, a...)) }
+ return ctl, e, &logs
}
- wantCalls(t, ctl.takeCalls(), showCall(egressHost))
- if rep := e.Reports()[egressHost]; rep.State != EgressFailing || !slices.Equal(rep.Allowed, []string{"10.0.5.20"}) {
- t.Fatalf("report = %+v, want failing with the allow still held", rep)
+ logged := func(t *testing.T, logs []string) {
+ t.Helper()
+ if !slices.ContainsFunc(logs, func(l string) bool { return strings.Contains(l, "all the same") }) {
+ t.Fatalf("the failed record was not logged: %q", logs)
+ }
}
+
+ t.Run("before claims: the revoke is written and nudged", func(t *testing.T) {
+ ctl, e, logs := box(t, slice, EgressPolicy{}, false)
+ rep := mustAssert(t, e, egressHost)
+ calls := ctl.takeCalls()
+ if !slices.Contains(calls, setCall(egressHost)) || !slices.Contains(calls, "set-property --runtime "+run+" IPAddressAllow=") {
+ t.Fatalf("calls %q, want the slice reset and the run unit nudged", calls)
+ }
+ if rep.State != "" || len(rep.Allowed) != 0 {
+ t.Fatalf("report = %+v", rep)
+ }
+ logged(t, *logs)
+ })
+ t.Run("under claims: the reset is written and the units restart", func(t *testing.T) {
+ claims := EgressPolicy{Closed: EgressUnderClaims, Detail: "not yet supported under claims"}
+ ctl, e, logs := box(t, slice, claims, true)
+ rep := mustAssert(t, e, egressHost)
+ calls := ctl.takeCalls()
+ if !slices.Contains(calls, setCall(egressHost)) || !slices.Contains(calls, "try-restart "+run) {
+ t.Fatalf("calls %q, want the slice reset and the run unit restarted", calls)
+ }
+ if rep.State != EgressUnderClaims || rep.Detail != "not yet supported under claims; "+egressRestarted || len(rep.Allowed) != 0 {
+ t.Fatalf("report = %+v", rep)
+ }
+ logged(t, *logs)
+ })
+ t.Run("a slice the sweep cannot name is reset", func(t *testing.T) {
+ unnamed := SliceName(longEgressHost)
+ ctl, e, logs := box(t, unnamed, EgressPolicy{}, true)
+ e.Sweep(context.Background())
+ calls := ctl.takeCalls()
+ if !slices.Contains(calls, "set-property --runtime "+unnamed+" IPAddressAllow=") || !slices.Contains(calls, "try-restart "+run) {
+ t.Fatalf("calls %q, want the unnamed slice reset and its unit restarted", calls)
+ }
+ logged(t, *logs)
+ })
}
func TestEgressDueFileIsPrivateAndGoesWhenDone(t *testing.T) {