egress: a member sees held addresses only on a clean report (#328, final review F3 residual)
When a host name passes to another tenant and root's reset of the slice fails, root's report carries the new tenant's name with the previous tenant's allow still held (state failing), and the agent publishes it under the new tenant. The member projection now shows held addresses only when the report has no state, which root records only when the slice reads back exactly the desired list; otherwise the member sees the state word and its fixed reason. The operator view is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+108
−5
internal/console/apiinstances.go+12 −1internal/console/apiinstances_test.go+15 −4internal/host/egress_status_test.go+81 −0
CI failed — run details
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index 844d7bd31..0c9d184d4 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -248,11 +248,22 @@ const ( |
| // their word; every other state (the policy unreadable, unverifiable or |
| // expired, the box not wholly nested, claims on, or one this console does |
| // not know) and a refusal with no state are "not_available". |
| +// |
| +// The held addresses are shown only on a clean report: no state, which |
| +// root records only when the slice reads back exactly the desired list |
| +// (final review F3 residual). With any state the slice may still hold what |
| +// it held before the change: after a host name passes to another tenant |
| +// and the reset fails, that is the previous tenant's allow, reported under |
| +// the new tenant's name. Then a member sees the state word and its fixed |
| +// reason only. The operator view shows the held list whatever the state. |
| func memberEgressView(h status.HostEgress, ok bool) *memberEgress { |
| if !ok { |
| return nil |
| } |
| - e := &memberEgress{Allowed: h.Allowed} |
| + e := &memberEgress{} |
| + if h.State == "" { |
| + e.Allowed = h.Allowed |
| + } |
| switch { |
| case h.State == memberEgressFailing: |
| e.State, e.Reason = memberEgressFailing, memberEgressFailingReason |
diff --git a/internal/console/apiinstances_test.go b/internal/console/apiinstances_test.go| index b431d071a..c1d0ca749 100644 |
| --- a/internal/console/apiinstances_test.go |
| +++ b/internal/console/apiinstances_test.go |
| @@ -2670,7 +2670,10 @@ func TestAPIInstancesJoinsEgress(t *testing.T) { |
| const localRefusal = "10.0.9.7: an address of this box (10.0.9.0/24)" |
| fresh := status.CollectBox(nil, status.Probes{MachineID: "box1"}, time.Now()) |
| fresh.Metrics = &status.BoxMetrics{Egress: map[string]status.HostEgress{ |
| - "shop-a.example.com": {Allowed: []string{"10.0.5.20", "fd00:5::20"}, State: "failing", |
| + // shop-a's host name came to this tenant from another, and the reset |
| + // of the previous tenant's allow failed: root reports what the slice |
| + // still holds under this tenant's name (final review F3 residual). |
| + "shop-a.example.com": {Allowed: []string{"10.0.6.1", "fd00:6::1"}, State: "failing", |
| Detail: "restarted to close 10.0.5.21", Refused: []string{localRefusal}, Account: "bab", App: "shop"}, |
| "shop-b.example.com": {State: "not_nested", Detail: otherTenant, Refused: []string{localRefusal}, Account: "bab", App: "shop"}, |
| "shop-d.example.com": {Allowed: []string{"10.0.5.20"}, Refused: []string{localRefusal}, Account: "bab", App: "shop"}, |
| @@ -2696,7 +2699,7 @@ func TestAPIInstancesJoinsEgress(t *testing.T) { |
| if code != http.StatusOK { |
| t.Fatalf("list = %d %s", code, out) |
| } |
| - for _, leak := range []string{"blog-z", "carlos-named", "10.0.9.", "10.0.5.21", "conflicts", "box-b", "refused", "detail", "10.0.7.", "zzz"} { |
| + for _, leak := range []string{"blog-z", "carlos-named", "10.0.9.", "10.0.5.21", "conflicts", "box-b", "refused", "detail", "10.0.7.", "zzz", "10.0.6.", "fd00:6:"} { |
| if strings.Contains(out, leak) { |
| t.Fatalf("a member's list carries %q: %s", leak, out) |
| } |
| @@ -2712,7 +2715,7 @@ func TestAPIInstancesJoinsEgress(t *testing.T) { |
| } |
| notAvailable := fmt.Sprintf(`"state":%q,"reason":%q}`, memberEgressNotAvailable, memberEgressNotAvailableReason) |
| want := map[string]string{ |
| - "shop-a.example.com": fmt.Sprintf(`{"allowed":["10.0.5.20","fd00:5::20"],"state":%q,"reason":%q}`, memberEgressFailing, memberEgressFailingReason), |
| + "shop-a.example.com": fmt.Sprintf(`{"state":%q,"reason":%q}`, memberEgressFailing, memberEgressFailingReason), |
| "shop-b.example.com": `{` + notAvailable, |
| "shop-c.example.com": ``, |
| "shop-d.example.com": `{"allowed":["10.0.5.20"],` + notAvailable, |
| @@ -2745,7 +2748,11 @@ func TestMemberEgressViewStates(t *testing.T) { |
| }{ |
| {status.HostEgress{Allowed: []string{"10.0.5.20"}}, ""}, |
| {status.HostEgress{State: "failing", Detail: "restarted to close 10.0.5.21"}, memberEgressFailing}, |
| + // A failing reset holds what the slice held before: never shown. |
| + {status.HostEgress{Allowed: []string{"10.0.6.1"}, State: "failing"}, memberEgressFailing}, |
| {status.HostEgress{State: "pending"}, memberEgressPending}, |
| + {status.HostEgress{Allowed: []string{"10.0.6.1"}, State: "pending"}, memberEgressPending}, |
| + {status.HostEgress{Allowed: []string{"10.0.6.1"}, State: "not_nested"}, memberEgressNotAvailable}, |
| {status.HostEgress{State: "unreadable"}, memberEgressNotAvailable}, |
| {status.HostEgress{State: "unverifiable"}, memberEgressNotAvailable}, |
| {status.HostEgress{State: "expired"}, memberEgressNotAvailable}, |
| @@ -2755,7 +2762,11 @@ func TestMemberEgressViewStates(t *testing.T) { |
| {status.HostEgress{Refused: []string{"10.0.9.7: an address of this box (10.0.9.0/24)"}}, memberEgressNotAvailable}, |
| } { |
| got := memberEgressView(c.in, true) |
| - if got.State != c.state || !slices.Equal(got.Allowed, c.in.Allowed) { |
| + var wantAllowed []string |
| + if c.in.State == "" { |
| + wantAllowed = c.in.Allowed // a clean report only |
| + } |
| + if got.State != c.state || !slices.Equal(got.Allowed, wantAllowed) { |
| t.Errorf("%+v: view %+v, want state %q", c.in, got, c.state) |
| } |
| if (got.State == "") != (got.Reason == "") { |
diff --git a/internal/host/egress_status_test.go b/internal/host/egress_status_test.go| index 2cdb06fa0..8141a6ff9 100644 |
| --- a/internal/host/egress_status_test.go |
| +++ b/internal/host/egress_status_test.go |
| @@ -4,8 +4,10 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "net/netip" |
| "reflect" |
| "strings" |
| + "sync" |
| "testing" |
| "time" |
| @@ -222,3 +224,82 @@ func TestEgressStatusProbeHostnameReuse(t *testing.T) { |
| t.Fatalf("probe = %+v\nwant %+v", got, want) |
| } |
| } |
| + |
| +// TestEgressStatusProbeHostnameMovedResetFails is the F3 residual's |
| +// sequence on root's and the agent's side: shop-a.example.com is abc/shop's |
| +// with 10.0.5.20 allowed and held; the host name passes to zzz/blog (no |
| +// allow), and root's reset of the slice fails. Root's report then carries |
| +// zzz/blog's name with the previous tenant's address still held, state |
| +// failing, and the agent publishes it under zzz/blog. The operator view |
| +// keeps the address; TestAPIInstancesJoinsEgress's shop-a (the same shape) |
| +// pins that a member of the new tenant sees only "failing" and its reason, |
| +// no address (memberEgressView shows held addresses on a clean report only). |
| +func TestEgressStatusProbeHostnameMovedResetFails(t *testing.T) { |
| + t.Parallel() |
| + const host = "shop-a.example.com" |
| + reg, dd := egressRegistry(t) |
| + clock := &testClock{now: time.Date(2026, 10, 25, 9, 0, 0, 0, time.UTC)} |
| + old := nestedRow(dd, host) |
| + old.Account, old.App = "abc", "shop" |
| + upsertRows(t, reg, old) |
| + setAllow(t, reg, host, "10.0.5.20", unixText(clock.Now().Add(time.Hour))) |
| + |
| + var mu sync.Mutex |
| + held, failWrites := "", false |
| + slice := instancectl.SliceName(host) |
| + e := &instancectl.EgressAsserter{ |
| + Systemctl: func(_ context.Context, args ...string) (string, error) { |
| + mu.Lock() |
| + defer mu.Unlock() |
| + switch { |
| + case len(args) == 5 && args[0] == "show" && args[4] == slice: |
| + return held + "\n", nil |
| + case len(args) == 5 && args[0] == "show": |
| + return "\n", nil // the parent holds nothing |
| + case len(args) >= 4 && args[0] == "set-property" && args[2] == slice: |
| + if failWrites { |
| + return "Failed to set unit properties", errors.New("exit status 1") |
| + } |
| + held = strings.TrimPrefix(args[len(args)-1], "IPAddressAllow=") |
| + return "", nil |
| + } |
| + return "", errors.New("unexpected call: " + strings.Join(args, " ")) |
| + }, |
| + Source: testEgressSource(t, dd, clock.Now), |
| + LocalAddrs: func() ([]netip.Prefix, error) { return []netip.Prefix{netip.MustParsePrefix("127.0.0.0/8")}, nil }, |
| + CgroupRoot: t.TempDir(), |
| + Logf: func(string, ...any) {}, |
| + } |
| + if err := e.Assert(context.Background(), host); err != nil { |
| + t.Fatal(err) |
| + } |
| + if rep := e.Reports()[host]; rep.Account != "abc" || !reflect.DeepEqual(rep.Allowed, []string{"10.0.5.20"}) { |
| + t.Fatalf("abc/shop's grant: %+v", rep) |
| + } |
| + |
| + // The host name passes to zzz/blog; the reset of the old allow fails. |
| + if err := reg.Delete(host); err != nil { |
| + t.Fatal(err) |
| + } |
| + moved := nestedRow(dd, host) |
| + moved.Account, moved.App = "zzz", "blog" |
| + upsertRows(t, reg, moved) |
| + mu.Lock() |
| + failWrites = true |
| + mu.Unlock() |
| + if err := e.Assert(context.Background(), host); err == nil { |
| + t.Fatal("the failed reset reported success") |
| + } |
| + rep := e.Reports()[host] |
| + if rep.State != instancectl.EgressFailing || rep.Account != "zzz" || rep.App != "blog" || !reflect.DeepEqual(rep.Allowed, []string{"10.0.5.20"}) { |
| + t.Fatalf("root's report after the failed reset = %+v, want failing under zzz/blog holding abc/shop's 10.0.5.20", rep) |
| + } |
| + rows, err := reg.List() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + got := egressStatusProbe(rootReports(e.Reports()), rows, nil)[host] |
| + if got.State != "failing" || got.Account != "zzz" || got.App != "blog" || !reflect.DeepEqual(got.Allowed, []string{"10.0.5.20"}) { |
| + t.Fatalf("published entry = %+v, want failing under zzz/blog with the held address (operators see it)", got) |
| + } |
| +} |