carlos / platform Public

console: egress report runs when the edges watch recovers, and on rows that do not open (#328)

A pass that ran while the watch could not vouch marked no generation; the
watch's recovery now makes a pass due instead of adopting the observed
generation unread. A policy row that does not open makes a scheduled pass
due, which logs it and requests nothing from the bucket.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev b17fc7af26c917b6a8636e4cfc6fe602546279e8 parent 64b6f19
2 files changed, +95 −17
  • internal/console/egressfleet.go +12 −15
  • internal/console/egressfleet_test.go +83 −2
diff --git a/internal/console/egressfleet.go b/internal/console/egressfleet.go
index 55d475ae2..cbeeb47ef 100644
--- a/internal/console/egressfleet.go
+++ b/internal/console/egressfleet.go
@@ -287,29 +287,25 @@ func (s *Server) StartEgressReport(ctx context.Context) {
// store request: it reads the report's memory, the watch's last
// observation, and (only when one of those makes a pass due) the console's
// own policy rows. A pass is due when one of these holds and at least one
-// live allow exists, or the last pass left findings to clear:
+// live allow exists, a row does not open (the pass logs it and requests
+// nothing), or the last pass left findings to clear:
//
// - no pass has run in this process;
// - the backstop deadline has passed;
// - the watch's control/edges generation differs from the one the last
-// pass marked.
+// pass marked, or the watch vouches for one now and the last pass
+// marked none (it ran while the watch could not vouch, so a write in
+// between is not known to have been read).
//
-// A nil or unusable watch leaves only the first pass and the backstop. When
-// the last pass marked no generation (the watch could not vouch then), the
-// first generation observed after it is adopted as the mark without a pass:
-// a change in between waits for the backstop, rather than every recovery
-// of a flapping index costing a listing.
+// A nil or unusable watch leaves only the first pass and the backstop. The
+// pass marks the generation before it reads, so recovery costs one pass.
func (s *Server) egressReportDue(now time.Time) bool {
st := &s.egressReport
st.mu.Lock()
due := !st.ran || !now.Before(st.next)
if !due {
if gen, ok := s.egressEdgesGen(); ok {
- if !st.genOK {
- st.gen, st.genOK = gen, true
- } else if gen != st.gen {
- due = true
- }
+ due = !st.genOK || gen != st.gen
}
}
findings := len(st.conflicts) > 0
@@ -322,9 +318,10 @@ func (s *Server) egressReportDue(now time.Time) bool {
}
ctx, cancel := context.WithTimeout(context.Background(), egressReportTick)
defer cancel()
- allows, _, err := s.egressLiveAllows(ctx)
- // A failed read is due, so the pass says why (and marks the schedule).
- return err != nil || len(allows) > 0
+ allows, unopened, err := s.egressLiveAllows(ctx)
+ // A failed read, or a row that does not open, is due, so the pass says
+ // why (and marks the schedule); with no allow it requests nothing.
+ return err != nil || len(allows) > 0 || len(unopened) > 0
}
// egressReportPass checks every live allow against every box's published
diff --git a/internal/console/egressfleet_test.go b/internal/console/egressfleet_test.go
index 7b996d7d7..8fce3d98c 100644
--- a/internal/console/egressfleet_test.go
+++ b/internal/console/egressfleet_test.go
@@ -2,6 +2,7 @@ package console
import (
"context"
+ "crypto/ed25519"
"encoding/json"
"errors"
"maps"
@@ -369,8 +370,15 @@ func TestPolicyDoorWritesNothingWhenTheCheckRefuses(t *testing.T) {
// answers them.
type reportCountingStore struct {
*release.DirStore
- mu sync.Mutex
- calls map[string]int // "<op> <key or prefix>"
+ mu sync.Mutex
+ calls map[string]int // "<op> <key or prefix>"
+ failIndex bool // every read of the change index fails
+}
+
+func (c *reportCountingStore) indexDown(on bool) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ c.failIndex = on
}
func (c *reportCountingStore) note(op, key string) {
@@ -414,6 +422,12 @@ func (c *reportCountingStore) Get(ctx context.Context, key string) ([]byte, stri
func (c *reportCountingStore) GetIfChanged(ctx context.Context, key, etag string) ([]byte, string, bool, error) {
c.note("Get", key)
+ c.mu.Lock()
+ down := c.failIndex && key == release.ChangeIndexKey
+ c.mu.Unlock()
+ if down {
+ return nil, "", false, errors.New("index unreachable")
+ }
return c.DirStore.GetIfChanged(ctx, key, etag)
}
@@ -669,6 +683,73 @@ func TestEgressReportRunsOnEdgesGeneration(t *testing.T) {
}
}
+// A pass that ran while the watch could not vouch marked no generation, so
+// the watch's recovery is due: an edges write made in between is read on
+// the first tick after it, not at the backstop.
+func TestEgressReportRunsWhenTheWatchRecovers(t *testing.T) {
+ t.Parallel()
+ fx := newReportFx(t, "code-egress-report-recover")
+ fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.20"]}`, policyCreate)
+ putEdgesAddrs(t, fx.cs, "annie", []string{"10.0.1.5"})
+ v := armRecordView(t, fx.srv, fx.cs)
+ fx.cs.indexDown(true)
+ _ = v.Refresh(context.Background()) // the poll fails: the watch cannot vouch
+ if v.Watch().Usable() {
+ t.Fatal("the watch is still usable; the fixture tests nothing")
+ }
+ if !fx.tick(t) {
+ t.Fatal("no first pass")
+ }
+ if fx.tick(t) {
+ t.Fatal("a tick with the watch still unusable ran a pass")
+ }
+
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"})
+ fx.cs.indexDown(false)
+ if err := v.Refresh(context.Background()); err != nil {
+ t.Fatal(err)
+ }
+ if !fx.tick(t) {
+ t.Fatal("the tick after the watch recovered ran no pass")
+ }
+ if got := fx.srv.egressConflicts(); got["10.0.5.20"] != "betty" || len(fx.sent()) != 1 {
+ t.Fatalf("the recovery pass = %v, pages %q", got, fx.sent())
+ }
+ if fx.tick(t) {
+ t.Fatal("a second tick on the recovered generation ran a pass")
+ }
+}
+
+// A policy row that does not open (here: the console's key has changed
+// since it was signed) is not checked, and the pass says so, on the
+// schedule, with no request of the bucket.
+func TestEgressReportLogsRowsThatDoNotOpen(t *testing.T) {
+ t.Parallel()
+ fx := newReportFx(t, "code-egress-report-unopened")
+ fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.20"]}`, policyCreate)
+ putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"})
+ _, other, err := ed25519.GenerateKey(nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ fx.srv.cfg.Key = other
+ fx.cs.taken()
+ if !fx.tick(t) {
+ t.Fatal("no pass with a row that does not open")
+ }
+ fx.logs.has(t, "console: egress report: not checked, the recorded policy does not open: "+fx.sqid+"/shop")
+ passes := fx.ticks(t, reportDay)
+ if passes < 43 || passes > 48 {
+ t.Fatalf("%d diagnostic passes in a day, want the backstop's 43 to 48", passes)
+ }
+ if total, under := fx.cs.taken(); total != 0 {
+ t.Fatalf("diagnostic passes made %d requests: %v", total, under)
+ }
+ if got := fx.srv.egressConflicts(); got == nil || len(got) != 0 || len(fx.sent()) != 0 {
+ t.Fatalf("conflicts %v, pages %q", got, fx.sent())
+ }
+}
+
// The report is read-only and runs on every console (ruling C6): a console
// that is not the policy writer, and whose writer lease would be refused,
// still reports, and asks for no lease to do it.