carlos / platform Public

egress: the fleet report keeps a conflict until a full read of its box shows it ended (#328, final review F4)

Each pass started from an empty conflict map, so a box whose changed edges
file could not be fetched, or that published no address list, lost its
warning though its allow stayed in force. A finding is now cleared only
when the pass establishes the end: the address no longer allowed, the box's
file read with an address list that lacks it, or the file gone from a
listing with nothing unreadable. Otherwise the last finding is kept, with
no new alert, and the log says so.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 6fde8c54154768cf3c476724644cb527b09007c2 parent 3b07b73
2 files changed, +128 −0
  • internal/console/egressfleet.go +44 −0
  • internal/console/egressfleet_test.go +84 −0
diff --git a/internal/console/egressfleet.go b/internal/console/egressfleet.go
index cbeeb47ef..01593e5e7 100644
--- a/internal/console/egressfleet.go
+++ b/internal/console/egressfleet.go
@@ -333,6 +333,13 @@ func (s *Server) egressReportDue(now time.Time) bool {
// a send that fails gives its slot back. The findings replace the last
// pass's at the end; a pass that fails leaves them as they were. With no
// live allow it reads no store and clears the findings.
+//
+// A finding is cleared only when this pass establishes that it ended
+// (final review F4): its address is no longer allowed, or the box was read
+// in full and does not hold it (its file read with an address list, or the
+// file gone from a listing with nothing unreadable). Where the box's file
+// could not be read this time, or publishes no address list, the last
+// finding is kept as it was, with no new alert, and the log says so.
func (s *Server) egressReportPass(ctx context.Context) error {
now := s.egressClock()
gen, genOK := s.egressEdgesGen()
@@ -361,7 +368,9 @@ func (s *Server) egressReportPass(ctx context.Context) error {
if len(inv.Unreadable) > 0 {
s.policyLogf("console: egress report: unreadable edges files, their addresses not checked: %s", strings.Join(inv.Unreadable, ", "))
}
+ allowed := map[string]bool{}
for _, a := range allows {
+ allowed[a.addr.String()] = true
box, ok := inv.Holder(a.addr)
if !ok {
continue
@@ -369,6 +378,21 @@ func (s *Server) egressReportPass(ctx context.Context) error {
conflicts[a.addr.String()] = box
s.egressAlert(ctx, a, box, now)
}
+ st.mu.Lock()
+ last := maps.Clone(st.conflicts)
+ st.mu.Unlock()
+ var kept []string
+ for addr, box := range last {
+ if _, found := conflicts[addr]; found || !allowed[addr] || egressBoxReadInFull(inv, box) {
+ continue
+ }
+ conflicts[addr] = box
+ kept = append(kept, addr+" on "+box)
+ }
+ if len(kept) > 0 {
+ slices.Sort(kept)
+ s.policyLogf("console: egress report: kept, the box's addresses were not read in full: %s", strings.Join(kept, ", "))
+ }
}
st.mu.Lock()
st.conflicts = conflicts
@@ -376,6 +400,26 @@ func (s *Server) egressReportPass(ctx context.Context) error {
return nil
}
+// egressBoxReadInFull is whether inv establishes box's whole address list:
+// its file read with an address list, and no file of it unreadable or
+// without one; or no file of it listed at all while every listed file was
+// read (an unreadable file might be its). An unreadable file is matched to
+// its box by its key (control/edges/<box>.json).
+func egressBoxReadInFull(inv edgesfile.AddrInventory, box string) bool {
+ if slices.Contains(inv.Missing, box) {
+ return false
+ }
+ for _, key := range inv.Unreadable {
+ if edgesKeyBox(key) == box {
+ return false
+ }
+ }
+ if _, ok := inv.Boxes[box]; ok {
+ return true
+ }
+ return len(inv.Unreadable) == 0
+}
+
// egressAlert sends a's alert unless one went out for the same app and
// address within egressAlertEvery. The slot is taken before the send and
// given back if it fails, so the next pass tries again.
diff --git a/internal/console/egressfleet_test.go b/internal/console/egressfleet_test.go
index 8fce3d98c..327382cad 100644
--- a/internal/console/egressfleet_test.go
+++ b/internal/console/egressfleet_test.go
@@ -373,6 +373,7 @@ type reportCountingStore struct {
mu sync.Mutex
calls map[string]int // "<op> <key or prefix>"
failIndex bool // every read of the change index fails
+ failGet string // a Get of this key fails
}
func (c *reportCountingStore) indexDown(on bool) {
@@ -417,9 +418,21 @@ func (c *reportCountingStore) ListETags(ctx context.Context, prefix string) ([]r
func (c *reportCountingStore) Get(ctx context.Context, key string) ([]byte, string, error) {
c.note("Get", key)
+ c.mu.Lock()
+ fail := key == c.failGet
+ c.mu.Unlock()
+ if fail {
+ return nil, "", errors.New("get refused")
+ }
return c.DirStore.Get(ctx, key)
}
+func (c *reportCountingStore) failGetOf(key string) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ c.failGet = key
+}
+
func (c *reportCountingStore) GetIfChanged(ctx context.Context, key, etag string) ([]byte, string, bool, error) {
c.note("Get", key)
c.mu.Lock()
@@ -887,3 +900,74 @@ func TestEgressReportKeepsTheRequestBudget(t *testing.T) {
t.Fatalf("the pass after one edges write made %d requests (%v), want 1 ETag listing and 1 Get", total, under)
}
}
+
+// TestEgressReportKeepsAConflictItCannotRead is final review F4: an
+// established finding survives a pass that cannot read the box's whole
+// address list (its changed file's Get fails; it republishes with no
+// addrs; another file is unreadable after the box's went), with no new
+// alert, and is cleared only once a pass establishes the end: the box's
+// file read without the address, or gone from a listing with nothing
+// unreadable, or the address no longer allowed.
+func TestEgressReportKeepsAConflictItCannotRead(t *testing.T) {
+ t.Parallel()
+ fx := newReportFx(t, "code-egress-report-keep")
+ first := fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.20","10.0.5.21"]}`, policyCreate)
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"})
+ putEdgesAddrs(t, fx.cs, "annie", []string{"10.0.1.5"})
+ held := map[string]string{"10.0.5.20": "betty"}
+ pass := func(step string, want map[string]string) {
+ t.Helper()
+ if n := fx.ticks(t, reportBackstopTo); n != 1 {
+ t.Fatalf("%s: %d passes, want 1", step, n)
+ }
+ if got := fx.srv.egressConflicts(); !maps.Equal(got, want) {
+ t.Fatalf("%s: conflicts = %v, want %v", step, got, want)
+ }
+ }
+ if !fx.tick(t) {
+ t.Fatal("no first pass")
+ }
+ if got := fx.srv.egressConflicts(); !maps.Equal(got, held) || len(fx.sent()) != 1 {
+ t.Fatalf("established: conflicts %v, pages %q", got, fx.sent())
+ }
+
+ // betty's file changes and cannot be fetched: kept.
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.9.9"})
+ fx.cs.failGetOf(edgesfile.Key("betty"))
+ pass("betty's changed file unreadable", held)
+ fx.cs.failGetOf("")
+
+ // betty republishes with no address list: kept.
+ putEdgesAddrs(t, fx.cs, "betty", nil)
+ pass("betty publishes addrs null", held)
+ if got := fx.sent(); len(got) != 1 {
+ t.Fatalf("a kept finding paged again: %q", got)
+ }
+
+ // betty's file read in full, without the address: cleared.
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.9.9"})
+ pass("betty read without it", map[string]string{})
+
+ // Again; then betty's file goes while annie's cannot be read: kept,
+ // since the unreadable file might be betty's.
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"})
+ pass("betty holds it again", held)
+ if err := fx.cs.DirStore.Delete(context.Background(), edgesfile.Key("betty")); err != nil {
+ t.Fatal(err)
+ }
+ putEdgesAddrs(t, fx.cs, "annie", []string{"10.0.1.6"})
+ fx.cs.failGetOf(edgesfile.Key("annie"))
+ pass("betty's file gone, annie's unreadable", held)
+ fx.cs.failGetOf("")
+
+ // Every listed file read and betty's not among them: cleared.
+ pass("betty's file gone, every file read", map[string]string{})
+
+ // A kept finding goes with its allow.
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"})
+ pass("betty back", held)
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20", "10.0.9.9"})
+ fx.cs.failGetOf(edgesfile.Key("betty"))
+ fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.21"]}`, policyIfMatch(first.ETag))
+ pass("the allow narrowed while betty is unreadable", map[string]string{})
+}