status --layout: say per box whether same-box calls are on (#990)
Task 6 of the edge-fence plan, and two fixes from the drill on the load-test box. /ready carries the fence's state (on, off with why, or not needed where the public address is not on the box and calls already go out and back). The agent reads it beside the exec-sandbox state into the layout report, the console passes it through, and carlos status --layout prints one line per box after exec-sandbox: leo-bookbinding same-box calls: on Drill fixes: a fence that failed to load (a refresh racing a stop of carlos.slice) is retried every tick instead of waiting for the next probe, with the whole deny standing meanwhile and set once; and box-addr-edge accepts the edge on 80 as well as 443.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 files changed,
+305
−22
internal/console/apistatuslayout.go+2 −0internal/console/apistatuslayout_test.go+6 −2internal/host/agent.go+1 −0internal/host/execsandboxstatus.go+24 −0internal/host/layoutleg.go+2 −1internal/instancectl/client.go+13 −0internal/instancectl/edgefence.go+37 −4internal/instancectl/edgefence_test.go+88 −0internal/instancectl/hardening.go+4 −3internal/instancectl/names.go+21 −0internal/instancectl/server.go+2 −0internal/instanceexec/probe_hardening.go+15 −7internal/instanceexec/probe_hardening_test.go+15 −2internal/status/snapshot.go+14 −3status_instances.go+31 −0status_instances_test.go+30 −0
diff --git a/internal/console/apistatuslayout.go b/internal/console/apistatuslayout.go| index b52d04258..e78c69aa7 100644 |
| --- a/internal/console/apistatuslayout.go |
| +++ b/internal/console/apistatuslayout.go |
| @@ -73,6 +73,7 @@ func egressView(h status.HostEgress, ok bool, conflicts map[string]string) *apiE |
| // other private reader of status/boxes/ uses), and its rows. |
| type apiStatusLayoutBox struct { |
| ExecSandbox *status.ExecSandbox `json:"exec_sandbox,omitempty"` |
| + EdgeFence *status.EdgeFence `json:"edge_fence,omitempty"` |
| Box string `json:"box"` |
| Mode string `json:"mode"` |
| // Region and RegionName are the box's placement code and label from |
| @@ -163,6 +164,7 @@ func (s *Server) handleAPIStatusLayout(w http.ResponseWriter, r *http.Request) { |
| out = append(out, apiStatusLayoutBox{ |
| Box: b.Label, |
| ExecSandbox: b.Metrics.Layout.ExecSandbox, |
| + EdgeFence: b.Metrics.Layout.EdgeFence, |
| Region: region, |
| RegionName: regionName, |
| Mode: b.Metrics.Layout.Mode, |
diff --git a/internal/console/apistatuslayout_test.go b/internal/console/apistatuslayout_test.go| index 549f97ba1..402ee7364 100644 |
| --- a/internal/console/apistatuslayout_test.go |
| +++ b/internal/console/apistatuslayout_test.go |
| @@ -340,7 +340,7 @@ func TestStatusLayoutSandbox(t *testing.T) { |
| if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil { |
| t.Fatal(err) |
| } |
| - report := &status.LayoutReport{Mode: "nested", ExecSandbox: &status.ExecSandbox{Configured: "auto", Effective: "gvisor", Runsc: &status.RunscStatus{Version: "release-20261102.0", SHA256: "pin"}, Ready: false, Blocked: "probe-blocked"}, Rows: map[string]status.RowLayout{"demo.example.com": {Layout: "nested", Sandbox: "gvisor"}, "sleep.example.com": {Layout: "nested"}}} |
| + report := &status.LayoutReport{Mode: "nested", ExecSandbox: &status.ExecSandbox{Configured: "auto", Effective: "gvisor", Runsc: &status.RunscStatus{Version: "release-20261102.0", SHA256: "pin"}, Ready: false, Blocked: "probe-blocked"}, EdgeFence: &status.EdgeFence{State: "off", Reason: "host claims mode"}, Rows: map[string]status.RowLayout{"demo.example.com": {Layout: "nested", Sandbox: "gvisor"}, "sleep.example.com": {Layout: "nested"}}} |
| seedLayoutBox(t, fx.rel, "fresh", time.Now(), report) |
| seedLayoutBox(t, fx.rel, "old", time.Now(), &status.LayoutReport{Mode: "nested"}) |
| seedLayoutBox(t, fx.rel, "stale", time.Now().Add(-time.Hour), report) |
| @@ -359,7 +359,7 @@ func TestStatusLayoutSandbox(t *testing.T) { |
| } |
| for _, b := range out.Boxes { |
| if b.Box == "old" { |
| - if b.ExecSandbox != nil { |
| + if b.ExecSandbox != nil || b.EdgeFence != nil { |
| t.Fatal("old box has guessed status") |
| } |
| continue |
| @@ -367,5 +367,9 @@ func TestStatusLayoutSandbox(t *testing.T) { |
| if b.ExecSandbox == nil || b.ExecSandbox.Ready || b.ExecSandbox.Runsc.SHA256 != "pin" || b.ExecSandbox.Blocked != "probe-blocked" || b.Rows[0].Sandbox != "gvisor" || b.Rows[1].Sandbox != "" || b.Stale != (b.Box == "stale") { |
| t.Fatalf("projection: %+v", b) |
| } |
| + // #990: the edge fence report passes through as the box sent it. |
| + if b.EdgeFence == nil || b.EdgeFence.State != "off" || b.EdgeFence.Reason != "host claims mode" { |
| + t.Fatalf("edge fence projection: %+v", b.EdgeFence) |
| + } |
| } |
| } |
diff --git a/internal/host/agent.go b/internal/host/agent.go| index b77c3e24b..50a5c1d02 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -604,6 +604,7 @@ func runAgent(args []string, buildClaims ClaimFactory) { |
| eb.Control = ctl |
| egressStatus = ctl |
| armExecSandboxStatus(ctl.SandboxStatus) |
| + armEdgeFenceStatus(ctl.EdgeFence) |
| // A grant or revoke the agent converged into the registry reaches |
| // root on the next 2 s beat rather than root's 30 s loop (#328). |
| go egressNudgeLoop(agentCtx, reg, ctl) |
diff --git a/internal/host/execsandboxstatus.go b/internal/host/execsandboxstatus.go| index 04ad61a47..9a6cef23f 100644 |
| --- a/internal/host/execsandboxstatus.go |
| +++ b/internal/host/execsandboxstatus.go |
| @@ -39,3 +39,27 @@ func execSandboxStatusReport() *status.ExecSandbox { |
| } |
| return report |
| } |
| + |
| +type edgeFenceStatusReader func(context.Context) (*instancectl.EdgeFenceReport, error) |
| + |
| +var armedEdgeFenceStatus atomic.Pointer[edgeFenceStatusReader] |
| + |
| +func armEdgeFenceStatus(read edgeFenceStatusReader) { |
| + armedEdgeFenceStatus.Store(&read) |
| +} |
| + |
| +// edgeFenceStatusReport is root's edge fence state (#990) for the layout |
| +// report; nil (unknown) when root cannot be asked or does not say. |
| +func edgeFenceStatusReport() *status.EdgeFence { |
| + read := armedEdgeFenceStatus.Load() |
| + if read == nil { |
| + return nil |
| + } |
| + ctx, cancel := context.WithTimeout(context.Background(), instancectl.DeadlineReady) |
| + defer cancel() |
| + rep, err := (*read)(ctx) |
| + if err != nil || rep == nil { |
| + return nil |
| + } |
| + return &status.EdgeFence{State: rep.State, Reason: rep.Reason} |
| +} |
diff --git a/internal/host/layoutleg.go b/internal/host/layoutleg.go| index 497c93be7..909082b7d 100644 |
| --- a/internal/host/layoutleg.go |
| +++ b/internal/host/layoutleg.go |
| @@ -187,6 +187,7 @@ func layoutStatusReport(routes []registry.Route) *status.LayoutReport { |
| if pass == nil { |
| report := unmanagedLayoutReport(routes) |
| report.ExecSandbox = execSandboxStatusReport() |
| + report.EdgeFence = edgeFenceStatusReport() |
| return report |
| } |
| mode := lastLayoutIntent() |
| @@ -224,7 +225,7 @@ func layoutStatusReport(routes []registry.Route) *status.LayoutReport { |
| rows[rt.Host] = status.RowLayout{Layout: "external"} |
| } |
| } |
| - return &status.LayoutReport{Mode: mode, Rows: rows, Default: def.Applied, DefaultBlocked: def.Blocked, ExecSandbox: execSandboxStatusReport()} |
| + return &status.LayoutReport{Mode: mode, Rows: rows, Default: def.Applied, DefaultBlocked: def.Blocked, ExecSandbox: execSandboxStatusReport(), EdgeFence: edgeFenceStatusReport()} |
| } |
| // Copy for a platform alias's row in `carlos status --layout` (#338, |
diff --git a/internal/instancectl/client.go b/internal/instancectl/client.go| index 6120c8245..29f4ddb6b 100644 |
| --- a/internal/instancectl/client.go |
| +++ b/internal/instancectl/client.go |
| @@ -479,6 +479,19 @@ func (c *Client) SandboxStatus(ctx context.Context) (execsandbox.State, error) { |
| return state, err |
| } |
| +// EdgeFence is the control service's edge fence state (#990), from its |
| +// /ready answer whether or not the box is ready. Nil, with no error, from |
| +// a control service too old to report it or one that has applied no deny |
| +// yet. |
| +func (c *Client) EdgeFence(ctx context.Context) (*EdgeFenceReport, error) { |
| + rep, err := c.readyReport(ctx, "/ready", false) |
| + var notReady *NotReadyError |
| + if err != nil && !errors.As(err, ¬Ready) { |
| + return nil, err |
| + } |
| + return rep.EdgeFence, nil |
| +} |
| + |
| // Egress asks root to re-assert host's egress allow now (#328), after |
| // the agent changed the host's registry column. The request names only |
| // the host: root reads the addresses from its own source. A 502 carries |
diff --git a/internal/instancectl/edgefence.go b/internal/instancectl/edgefence.go| index 72bbc84cf..7e894cbbb 100644 |
| --- a/internal/instancectl/edgefence.go |
| +++ b/internal/instancectl/edgefence.go |
| @@ -50,11 +50,11 @@ type fenceInternalKey struct{} |
| // Reasons the fence is not exempting, as the box reports them. |
| const ( |
| - fenceOffSwitch = "off on this box (" + EdgeFenceEnv + "=off)" |
| - fenceOffGroup = "group box: the region HA hairpin applies" |
| - fenceOffNoAddr = "this box has no public address of its own" |
| + fenceOffSwitch = "turned off with " + EdgeFenceEnv + "=off" |
| + fenceOffGroup = "a region group box: the group hairpin decides" |
| + fenceOffNoAddr = "the public address is not on this box, so calls already go out and back" |
| fenceOffUnwired = "not wired" |
| - fenceOffClaims = "host claims mode: claim units start outside the fence check" |
| + fenceOffClaims = "host claims mode" |
| ) |
| // EdgeFenceState is what the box reports: whether same-box calls are on, |
| @@ -147,9 +147,25 @@ func (s *Server) recordFence(exempt []netip.Addr, reason string) { |
| } |
| s.fenceAddrs = slices.Clone(exempt) |
| s.fenceReason = reason |
| + s.fenceRetry = len(exempt) == 0 && !fenceOffSettled(reason) |
| s.denyApplied = true |
| } |
| +// fenceOffSettled reports a reason the fence stays off for until the box |
| +// itself changes: the switch, a group box, claims mode, no public address, |
| +// no nft wired. Any other reason is a failure (a load, a readback, the |
| +// slice's start), which denyLoop retries every tick: the deny is whole |
| +// meanwhile, and same-box calls come back without waiting for a probe. |
| +// (Drill 2026-11-13: a refresh racing `systemctl stop carlos.slice` found |
| +// no slice to load against and stayed off until the next probe.) |
| +func fenceOffSettled(reason string) bool { |
| + switch reason { |
| + case fenceOffSwitch, fenceOffGroup, fenceOffNoAddr, fenceOffUnwired, fenceOffClaims: |
| + return true |
| + } |
| + return false |
| +} |
| + |
| // errFenceUnknown refuses a start before this service has applied any |
| // deny: a deny drop-in left by an earlier process may exempt an address |
| // whose fence nobody has checked. |
| @@ -221,3 +237,20 @@ func (s *Server) bindEgressFence() { |
| return nil |
| } |
| } |
| + |
| +// edgeFenceReport is the fence's state for /ready, or nil before this |
| +// service has applied any deny (nothing to report yet). |
| +func (s *Server) edgeFenceReport() *EdgeFenceReport { |
| + s.mu.Lock() |
| + defer s.mu.Unlock() |
| + if !s.denyApplied { |
| + return nil |
| + } |
| + switch { |
| + case len(s.fenceAddrs) > 0: |
| + return &EdgeFenceReport{State: EdgeFenceOn} |
| + case s.fenceReason == fenceOffNoAddr: |
| + return &EdgeFenceReport{State: EdgeFenceNotNeeded, Reason: s.fenceReason} |
| + } |
| + return &EdgeFenceReport{State: EdgeFenceOff, Reason: s.fenceReason} |
| +} |
diff --git a/internal/instancectl/edgefence_test.go b/internal/instancectl/edgefence_test.go| index 8f80c6a05..79fb3f565 100644 |
| --- a/internal/instancectl/edgefence_test.go |
| +++ b/internal/instancectl/edgefence_test.go |
| @@ -388,3 +388,91 @@ func TestEveryStartIsSeenByTheFenceCheck(t *testing.T) { |
| t.Fatalf("found %d start sites; the pattern has stopped matching them", seen) |
| } |
| } |
| + |
| +// /ready carries the fence's state once a deny has been applied: on, off |
| +// with the reason, or not needed where the public address is not on the |
| +// box (EC2 without IPv6), where a call already leaves the box. |
| +func TestEdgeFenceReport(t *testing.T) { |
| + s, _, _ := fenceServer(t) |
| + if r := s.edgeFenceReport(); r != nil { |
| + t.Fatalf("before any deny: %+v", r) |
| + } |
| + if err := s.denyLocalAddrs(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if r := s.edgeFenceReport(); r == nil || r.State != EdgeFenceOn || r.Reason != "" { |
| + t.Fatalf("fence on: %+v", r) |
| + } |
| + s.EdgeFenceOff = true |
| + if err := s.denyLocalAddrs(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if r := s.edgeFenceReport(); r == nil || r.State != EdgeFenceOff || r.Reason != fenceOffSwitch { |
| + t.Fatalf("switched off: %+v", r) |
| + } |
| + s.EdgeFenceOff = false |
| + s.LocalAddrs = func() ([]netip.Prefix, error) { return parsePrefixes("127.0.0.0/8", "172.31.7.19/32"), nil } |
| + if err := s.denyLocalAddrs(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if r := s.edgeFenceReport(); r == nil || r.State != EdgeFenceNotNeeded { |
| + t.Fatalf("no public address on the box: %+v", r) |
| + } |
| +} |
| + |
| +// The agent reads the state from /ready whether or not the box is ready. |
| +func TestClientReadsTheEdgeFenceFromANotReadyBox(t *testing.T) { |
| + notGroup(t) |
| + nft := &fakeNFT{} |
| + ctl := &fakeCtl{} |
| + s, sock := serveOnSocket(t, ctl, func(s *Server) { s.LocalAddrs, s.NFT = fenceLocal, nft.run }) |
| + if err := s.denyLocalAddrs(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.mu.Lock() |
| + s.report, s.probed = ProbeReport{Ready: false, Lines: []VerdictLine{{Check: "x", Verdict: "fail"}}}, true |
| + s.mu.Unlock() |
| + c := &Client{Path: sock} |
| + got, err := c.EdgeFence(context.Background()) |
| + if err != nil || got == nil || got.State != EdgeFenceOn { |
| + t.Fatalf("EdgeFence = %+v, %v", got, err) |
| + } |
| +} |
| + |
| +// A fence that failed to load is tried again on every tick, with the |
| +// whole deny standing meanwhile and set only once, and comes back on |
| +// without waiting for the next probe. A settled reason (the off switch) |
| +// is not retried. |
| +func TestDenyLoopRetriesAFailedFence(t *testing.T) { |
| + s, ctl, nft := fenceServer(t) |
| + nft.set(func(f *fakeNFT) { f.failLoad = errors.New("exit status 1") }) |
| + ticks, handled := make(chan time.Time), make(chan struct{}) |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + defer cancel() |
| + go s.denyLoopWith(ctx, ticks, func() { handled <- struct{}{} }) |
| + tick := func() { ticks <- time.Time{}; <-handled } |
| + |
| + tick() |
| + tick() |
| + tick() |
| + if n := ctl.count(wholeDeny); n != 1 { |
| + t.Fatalf("whole deny set %d times over 3 failing ticks, want 1; %q", n, ctl.joined()) |
| + } |
| + if loads, _ := nft.counts(); loads != 3 { |
| + t.Fatalf("%d loads over 3 failing ticks, want 3", loads) |
| + } |
| + nft.set(func(f *fakeNFT) { f.failLoad = nil }) |
| + tick() |
| + if !s.EdgeFence().On || ctl.count(fencedDeny) != 1 { |
| + t.Fatalf("the fence did not come back on the next tick: %+v %q", s.EdgeFence(), ctl.joined()) |
| + } |
| + |
| + s.EdgeFenceOff = true |
| + tick() |
| + loads, _ := nft.counts() |
| + tick() |
| + tick() |
| + if l, _ := nft.counts(); l != loads { |
| + t.Fatal("a fence switched off was retried") |
| + } |
| +} |
diff --git a/internal/instancectl/hardening.go b/internal/instancectl/hardening.go| index 1d67484c7..4b5a1aee1 100644 |
| --- a/internal/instancectl/hardening.go |
| +++ b/internal/instancectl/hardening.go |
| @@ -324,7 +324,7 @@ func (s *Server) denyLocalAddrsLocked(ctx context.Context, refresh bool) error { |
| return hairpinErr |
| } |
| deny, exempt, reason := s.edgeFenceDeny(ctx, local) |
| - if refresh && len(exempt) > 0 { |
| + if refresh { |
| s.mu.Lock() |
| unchanged := slices.Equal(denySet(deny), s.lastDeny) |
| s.mu.Unlock() |
| @@ -432,8 +432,9 @@ func (s *Server) denyLoopWith(ctx context.Context, ticks <-chan time.Time, done |
| unchanged := slices.Equal(denySet(local), previous) |
| active := s.hairpinActive |
| // #990: while the edge fence exempts, every tick re-reads it, |
| - // addresses changed or not. |
| - fence := len(s.fenceAddrs) > 0 |
| + // addresses changed or not; while it is off after a failure, |
| + // every tick tries it again. |
| + fence := len(s.fenceAddrs) > 0 || s.fenceRetry |
| s.mu.Unlock() |
| if !unchanged || active || fence { |
| err := s.denyLocalAddrsWith(ctx, fence) |
diff --git a/internal/instancectl/names.go b/internal/instancectl/names.go| index 4abb878fd..d4f71d13f 100644 |
| --- a/internal/instancectl/names.go |
| +++ b/internal/instancectl/names.go |
| @@ -655,8 +655,29 @@ type ProbeReport struct { |
| Ready bool `json:"ready"` |
| Lines []VerdictLine `json:"lines"` |
| Nonce string `json:"nonce,omitempty"` |
| + // EdgeFence is the edge fence's state (#990), added by /ready from the |
| + // deny last applied; the probe never sets it. Absent from an older |
| + // control service. |
| + EdgeFence *EdgeFenceReport `json:"edge_fence,omitempty"` |
| } |
| +// EdgeFenceReport is whether instances on this box can call other apps on |
| +// it through the edge (#990): State is EdgeFenceOn, EdgeFenceOff or |
| +// EdgeFenceNotNeeded (the box's public address is not on the box, so a |
| +// call already leaves it and comes back through the edge); Reason says |
| +// why when it is not on. |
| +type EdgeFenceReport struct { |
| + State string `json:"state"` |
| + Reason string `json:"reason,omitempty"` |
| +} |
| + |
| +// The edge fence report's states. |
| +const ( |
| + EdgeFenceOn = "on" |
| + EdgeFenceOff = "off" |
| + EdgeFenceNotNeeded = "not_needed" |
| +) |
| + |
| // BuildHeader carries the control service's version.Build on every /ready |
| // answer (#256). The agent compares it with its own: both are meant to be |
| // /opt/carlos/carlos, and a service that reports another build, or none |
diff --git a/internal/instancectl/server.go b/internal/instancectl/server.go| index 07f3f6d50..a0e487a55 100644 |
| --- a/internal/instancectl/server.go |
| +++ b/internal/instancectl/server.go |
| @@ -249,6 +249,7 @@ type Server struct { |
| // refuses starts until one has). |
| fenceAddrs []netip.Addr |
| fenceReason string |
| + fenceRetry bool |
| denyApplied bool |
| // denyMu runs one denyLocalAddrs at a time (RunProbe's and denyLoop's), |
| // so an older read of the addresses is never applied over a newer one. |
| @@ -1439,6 +1440,7 @@ func (s *Server) handleReady(w http.ResponseWriter, r *http.Request) { |
| w.Header().Set(BuildHeader, s.Build) |
| } |
| rep, ready := s.Ready() |
| + rep.EdgeFence = s.edgeFenceReport() |
| if ready { |
| writeJSON(w, http.StatusOK, rep) |
| return |
diff --git a/internal/instanceexec/probe_hardening.go b/internal/instanceexec/probe_hardening.go| index 06c769c6f..8ccafb6b7 100644 |
| --- a/internal/instanceexec/probe_hardening.go |
| +++ b/internal/instanceexec/probe_hardening.go |
| @@ -344,9 +344,10 @@ func boxAddrPorts(e probeEnv) (verdict, detail string) { |
| } |
| // boxAddrEdge (#990): on every address the edge fence exempts, the edge |
| -// answers on TCP 443. It never fails the probe: an edge that is down or |
| -// restarting is not an isolation fault. It says "unverified" when the |
| -// fence is off on this box or the edge did not answer. |
| +// answers on TCP 443 or 80 (a box may serve only one). It never fails |
| +// the probe: an edge that is down or restarting is not an isolation |
| +// fault. It says "unverified" when the fence is off on this box or the |
| +// edge did not answer. |
| func boxAddrEdge(e probeEnv) (verdict, detail string) { |
| addrs, err := readBoxAddrs(e) |
| if err != nil { |
| @@ -357,11 +358,18 @@ func boxAddrEdge(e probeEnv) (verdict, detail string) { |
| if !b.fence { |
| continue |
| } |
| - target := netip.AddrPortFrom(b.addr, 443).String() |
| - fenced = append(fenced, target) |
| - if err := e.connectTCP(target, 2*time.Second); err != nil { |
| - missed = append(missed, fmt.Sprintf("%s: %v", target, err)) |
| + fenced = append(fenced, b.addr.String()) |
| + var errs []string |
| + for _, port := range []uint16{443, 80} { |
| + target := netip.AddrPortFrom(b.addr, port).String() |
| + err := e.connectTCP(target, 2*time.Second) |
| + if err == nil { |
| + errs = nil |
| + break |
| + } |
| + errs = append(errs, fmt.Sprintf("%s: %v", target, err)) |
| } |
| + missed = append(missed, errs...) |
| } |
| switch { |
| case len(fenced) == 0: |
diff --git a/internal/instanceexec/probe_hardening_test.go b/internal/instanceexec/probe_hardening_test.go| index 9805a638f..2c866e227 100644 |
| --- a/internal/instanceexec/probe_hardening_test.go |
| +++ b/internal/instanceexec/probe_hardening_test.go |
| @@ -310,7 +310,7 @@ func TestProbeEdgeFenceLines(t *testing.T) { |
| t.Errorf("did not dial %s: %v", want, dialled) |
| } |
| } |
| - if slices.Contains(dialled, "10.0.3.17:443") { |
| + if slices.Contains(dialled, "10.0.3.17:443") || slices.Contains(dialled, "203.0.113.7:80") { |
| t.Error("dialled the edge on an address the fence does not exempt") |
| } |
| @@ -326,6 +326,18 @@ func TestProbeEdgeFenceLines(t *testing.T) { |
| t.Errorf("a connected port 22 passed: %s %s", verdict(r, "box-addr-ports"), detail(r, "box-addr-ports")) |
| } |
| + // An edge serving only plain HTTP answers on 80: ok. |
| + e = fenced(t) |
| + e.connectTCP = func(addr string, _ time.Duration) error { |
| + if strings.HasSuffix(addr, ":80") { |
| + return nil |
| + } |
| + return refused |
| + } |
| + if r := runChecks(e); verdict(r, "box-addr-edge") != "ok" { |
| + t.Errorf("edge on 80 only: %s %s", verdict(r, "box-addr-edge"), detail(r, "box-addr-edge")) |
| + } |
| + |
| // The edge is down: unverified, and the box stays ready. |
| e = fenced(t) |
| e.connectTCP = func(string, time.Duration) error { return refused } |
| @@ -341,7 +353,8 @@ func TestProbeEdgeFenceLines(t *testing.T) { |
| t.Errorf("fence off: ready=%v box-addr-edge=%s %s", r.Ready, verdict(r, "box-addr-edge"), detail(r, "box-addr-edge")) |
| } |
| for _, d := range dialled { |
| - if strings.HasSuffix(d, ":443") { |
| + box := strings.HasPrefix(d, "10.0.3.17:") || strings.HasPrefix(d, "[2001:db8::7]:") |
| + if box && (strings.HasSuffix(d, ":443") || strings.HasSuffix(d, ":80")) { |
| t.Errorf("dialled the edge with the fence off: %s", d) |
| } |
| } |
diff --git a/internal/status/snapshot.go b/internal/status/snapshot.go| index 222022e9d..d9fae9a20 100644 |
| --- a/internal/status/snapshot.go |
| +++ b/internal/status/snapshot.go |
| @@ -310,6 +310,13 @@ type ExecSandbox struct { |
| Blocked string `json:"blocked,omitempty"` |
| } |
| +// EdgeFence is root's edge fence report (#990): State is "on", "off" or |
| +// "not_needed", and Reason says why when it is not on. |
| +type EdgeFence struct { |
| + State string `json:"state"` |
| + Reason string `json:"reason,omitempty"` |
| +} |
| + |
| type RunscStatus struct { |
| Version string `json:"version"` |
| SHA256 string `json:"sha256"` |
| @@ -322,9 +329,13 @@ type RunscStatus struct { |
| // the box, keyed by host. It carries real hostnames, so โ like RowLayout |
| // above โ it is private: BoxMetrics.Layout, never a field on Box itself. |
| type LayoutReport struct { |
| - ExecSandbox *ExecSandbox `json:"exec_sandbox,omitempty"` |
| - Mode string `json:"mode"` |
| - Rows map[string]RowLayout `json:"rows"` |
| + ExecSandbox *ExecSandbox `json:"exec_sandbox,omitempty"` |
| + // EdgeFence is whether instances here can call other apps on this box |
| + // through the edge (#990). Absent when root did not say (an older |
| + // control service, or none reachable): unknown. |
| + EdgeFence *EdgeFence `json:"edge_fence,omitempty"` |
| + Mode string `json:"mode"` |
| + Rows map[string]RowLayout `json:"rows"` |
| // Default is set when Mode is nested by the deployment's default |
| // rather than by a recorded intent (design ยง8.6, "Nested by |
| // default"); DefaultBlocked is why the default is not in force on a |
diff --git a/status_instances.go b/status_instances.go| index 366c15748..479d614c4 100644 |
| --- a/status_instances.go |
| +++ b/status_instances.go |
| @@ -188,6 +188,7 @@ const ( |
| // statusLayoutBox is one box's layout report. |
| type statusLayoutBox struct { |
| ExecSandbox *statusExecSandbox `json:"exec_sandbox"` |
| + EdgeFence *statusEdgeFence `json:"edge_fence"` |
| Box string `json:"box"` |
| Mode string `json:"mode"` |
| Stale bool `json:"stale"` |
| @@ -312,6 +313,7 @@ func printStatusLayout(w io.Writer, boxes []statusLayoutBox) { |
| fmt.Fprintf(w, "%s %s %s %s %s %s %s %s\n", l.box, l.region, l.host, l.layout, l.sandbox, l.size, l.egress, reason) |
| } |
| printExecSandboxStatus(w, boxes) |
| + printEdgeFenceStatus(w, boxes) |
| // A size cell "in>want" is a new size waiting for a cold start (a |
| // populated slice is not shrunk live, and under host claims no size |
| // changes live). Said once, whatever the number of such rows. |
| @@ -353,6 +355,35 @@ type statusExecSandbox struct { |
| Blocked string `json:"blocked"` |
| } |
| +// statusEdgeFence is a box's edge fence report (#990). |
| +type statusEdgeFence struct { |
| + State string `json:"state"` |
| + Reason string `json:"reason"` |
| +} |
| + |
| +// printEdgeFenceStatus says, one line per box, whether instances there can |
| +// call other apps on the same box by hostname (#990): on, off with why, |
| +// not needed with why, or unknown. |
| +func printEdgeFenceStatus(w io.Writer, boxes []statusLayoutBox) { |
| + sorted := append([]statusLayoutBox(nil), boxes...) |
| + sort.Slice(sorted, func(i, j int) bool { return sorted[i].Box < sorted[j].Box }) |
| + for _, b := range sorted { |
| + f := b.EdgeFence |
| + switch { |
| + case b.Stale: |
| + fmt.Fprintf(w, "%s same-box calls: unknown (stale report)\n", b.Box) |
| + case f == nil || f.State == "": |
| + fmt.Fprintf(w, "%s same-box calls: unknown\n", b.Box) |
| + case f.State == "on": |
| + fmt.Fprintf(w, "%s same-box calls: on\n", b.Box) |
| + case f.State == "not_needed": |
| + fmt.Fprintf(w, "%s same-box calls: not needed (%s)\n", b.Box, f.Reason) |
| + default: |
| + fmt.Fprintf(w, "%s same-box calls: %s (%s)\n", b.Box, f.State, sandboxWord(f.Reason)) |
| + } |
| + } |
| +} |
| + |
| type statusRunsc struct { |
| Version string `json:"version"` |
| SHA256 string `json:"sha256"` |
diff --git a/status_instances_test.go b/status_instances_test.go| index 5a0e9a254..7b0f4efcf 100644 |
| --- a/status_instances_test.go |
| +++ b/status_instances_test.go |
| @@ -318,3 +318,33 @@ func TestStatusLayoutSandbox(t *testing.T) { |
| t.Fatalf("expected one line per box: %s", &out) |
| } |
| } |
| + |
| +// #990: one line per box saying whether instances there can call another |
| +// app on the same box by hostname, from the console's JSON. |
| +func TestStatusLayoutSameBoxCalls(t *testing.T) { |
| + var boxes []statusLayoutBox |
| + raw := `[{"box":"leo","edge_fence":{"state":"on"},"rows":[]},` + |
| + `{"box":"ec2","edge_fence":{"state":"not_needed","reason":"the public address is not on this box, so calls already go out and back"},"rows":[]},` + |
| + `{"box":"held","edge_fence":{"state":"off","reason":"turned off with CARLOS_EDGE_FENCE=off"},"rows":[]},` + |
| + `{"box":"old","rows":[]},` + |
| + `{"box":"stale","stale":true,"edge_fence":{"state":"on"},"rows":[]}]` |
| + if err := json.Unmarshal([]byte(raw), &boxes); err != nil { |
| + t.Fatal(err) |
| + } |
| + var out bytes.Buffer |
| + printStatusLayout(&out, boxes) |
| + for _, want := range []string{ |
| + "leo same-box calls: on\n", |
| + "ec2 same-box calls: not needed (the public address is not on this box, so calls already go out and back)\n", |
| + "held same-box calls: off (turned off with CARLOS_EDGE_FENCE=off)\n", |
| + "old same-box calls: unknown\n", |
| + "stale same-box calls: unknown (stale report)\n", |
| + } { |
| + if !strings.Contains(out.String(), want) { |
| + t.Errorf("missing %q:\n%s", want, &out) |
| + } |
| + } |
| + if n := strings.Count(out.String(), "same-box calls:"); n != 5 { |
| + t.Fatalf("%d same-box lines, want one per box:\n%s", n, &out) |
| + } |
| +} |