units, probe: switch the edge fence on and check it from inside (#990)
Tasks 4 and 5 of the edge-fence plan. Units: instance-control gains AF_NETLINK, so nft runs and the fence loads on every non-group box; both carlos.slice and carlos-instances.slice refuse manual stop (a recreated slice leaves the fence matching nothing; the check before every start is what closes that, the refusal is defence in depth). The claims-mode control unit rewrite matched the old families line exactly and would have silently dropped AF_INET/AF_INET6; it now matches the new one. Probe: box-addrs marks each address the fence exempts with " edge". box-addr is unchanged (UDP EPERM everywhere). New box-addr-ports fails if TCP 22 connects on any box address; new box-addr-edge checks the edge answers on 443 where the fence is on, and is only ever unverified, so an edge restart never takes the box out of service. Guard: TestOnlyTheEdgeBindsAPrivilegedPort pins the three facts that rule out the fence's residual (plan evidence 8).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+282
−26
internal/edgefence/edgefence_test.go+60 −0internal/host/claimunit.go+3 −1internal/host/claimunit_test.go+2 −2internal/host/group_hairpin_test.go+6 −1internal/host/units/carlos-instance-control.service+7 −1internal/host/units/carlos-instances.slice+11 −0internal/host/units/carlos.slice+6 −0internal/instancectl/hardening.go+8 −2internal/instancectl/names.go+3 −0internal/instanceexec/probe_hardening.go+95 −19internal/instanceexec/probe_hardening_test.go+81 −0
diff --git a/internal/edgefence/edgefence_test.go b/internal/edgefence/edgefence_test.go| index d3bdaf31e..8acf07716 100644 |
| --- a/internal/edgefence/edgefence_test.go |
| +++ b/internal/edgefence/edgefence_test.go |
| @@ -210,3 +210,63 @@ func TestStaticDenyMatchesTemplates(t *testing.T) { |
| t.Fatal("no IPAddressDeny= line in any template") |
| } |
| } |
| + |
| +// TestOnlyTheEdgeBindsAPrivilegedPort keeps true the three facts the plan |
| +// (evidence 8) rests on to rule out the fence's one residual: a process |
| +// outside the instances slice, bound to source port 80 or 443 on a box |
| +// address, can talk to an instance's TCP listener through it. Binding |
| +// below 1024 needs root or CAP_NET_BIND_SERVICE, so: |
| +// |
| +// 1. carlos-app@ (the legacy tenants outside the slice) has an empty |
| +// CapabilityBoundingSet=; |
| +// 2. the only unit the platform installs that grants CAP_NET_BIND_SERVICE |
| +// is carlos-edge.service, which holds :80 and :443 itself; the |
| +// capability renderer (internal/caps) grants no capability at all; |
| +// 3. nothing the tree installs lowers net.ipv4.ip_unprivileged_port_start. |
| +// |
| +// If one of these has to change, the residual has to be closed some other |
| +// way first (conntrack, or a BPF filter on the slice). |
| +func TestOnlyTheEdgeBindsAPrivilegedPort(t *testing.T) { |
| + units := filepath.Join("..", "host", "units") |
| + app, err := os.ReadFile(filepath.Join(units, "carlos-app@.service")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !strings.Contains("\n"+string(app), "\nCapabilityBoundingSet=\n") { |
| + t.Error("carlos-app@.service must keep an empty CapabilityBoundingSet=") |
| + } |
| + paths, _ := filepath.Glob(filepath.Join(units, "*")) |
| + for _, p := range paths { |
| + b, err := os.ReadFile(p) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, line := range strings.Split(string(b), "\n") { |
| + if strings.HasPrefix(line, "AmbientCapabilities=") && strings.Contains(line, "CAP_NET_BIND_SERVICE") && filepath.Base(p) != "carlos-edge.service" { |
| + t.Errorf("%s grants CAP_NET_BIND_SERVICE: %s", filepath.Base(p), line) |
| + } |
| + } |
| + } |
| + renderers, _ := filepath.Glob(filepath.Join("..", "caps", "*.go")) |
| + for _, p := range renderers { |
| + if strings.HasSuffix(p, "_test.go") { |
| + continue |
| + } |
| + b, _ := os.ReadFile(p) |
| + if strings.Contains(string(b), "AmbientCapabilities") || strings.Contains(string(b), "CAP_NET_BIND_SERVICE") { |
| + t.Errorf("%s renders a capability grant", p) |
| + } |
| + } |
| + for _, root := range []string{filepath.Join("..", "host"), filepath.Join("..", "provision"), filepath.Join("..", "..", "infra")} { |
| + _ = filepath.WalkDir(root, func(p string, d os.DirEntry, err error) error { |
| + if err != nil || d.IsDir() || strings.HasSuffix(p, "_test.go") || strings.Contains(p, "testdata") { |
| + return nil |
| + } |
| + b, _ := os.ReadFile(p) |
| + if strings.Contains(string(b), "ip_unprivileged_port_start") { |
| + t.Errorf("%s sets ip_unprivileged_port_start", p) |
| + } |
| + return nil |
| + }) |
| + } |
| +} |
diff --git a/internal/host/claimunit.go b/internal/host/claimunit.go| index b84640416..8eba28c5d 100644 |
| --- a/internal/host/claimunit.go |
| +++ b/internal/host/claimunit.go |
| @@ -184,7 +184,9 @@ func claimUnitContent(name string, content []byte, cfg claimUnitSettings) []byte |
| } |
| content = bytes.Replace(content, []byte("[Service]\n"), []byte("[Service]\nStateDirectory=carlos-claims\nStateDirectoryMode=0700\n"), 1) |
| content = bytes.Replace(content, []byte("ReadWritePaths=/run/carlos-control /run/systemd/system\n"), []byte("ReadWritePaths="+strings.Join(roots, " ")+"\n"), 1) |
| - content = bytes.Replace(content, []byte("RestrictAddressFamilies=AF_UNIX\n"), []byte("RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6\n"), 1) |
| + // The base unit's families carry AF_NETLINK for the edge fence (#990); |
| + // claim mode keeps it (the fence is off in claim mode) and adds IP. |
| + content = bytes.Replace(content, []byte("RestrictAddressFamilies=AF_UNIX AF_NETLINK\n"), []byte("RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6\n"), 1) |
| // Claim mode adds the root journal service, the offline legacy migration |
| // (up to 16 MiB of decoded, validated and re-marshalled rows) and the AWS |
| // fence pass to this process. 64M leaves no headroom over the Go runtime |
diff --git a/internal/host/claimunit_test.go b/internal/host/claimunit_test.go| index 9015c23d4..f03ad4e91 100644 |
| --- a/internal/host/claimunit_test.go |
| +++ b/internal/host/claimunit_test.go |
| @@ -82,7 +82,7 @@ func TestClaimControlUnitInstallers(t *testing.T) { |
| "StateDirectory": {"carlos-claims"}, |
| "StateDirectoryMode": {"0700"}, |
| "ReadWritePaths": {"/run/carlos-control /run/carlos /var/lib/carlos-claims /var/lib/carlos-release/private /run/systemd/system /data /opt/carlos /etc/systemd/system /sys/fs/cgroup", "-/var/lib/carlos/oci-rootfs"}, |
| - "RestrictAddressFamilies": {"AF_UNIX AF_INET AF_INET6"}, |
| + "RestrictAddressFamilies": {"AF_UNIX AF_NETLINK AF_INET AF_INET6"}, |
| "ProtectSystem": {"strict"}, |
| "ProtectHome": {"yes"}, |
| } { |
| @@ -294,7 +294,7 @@ func TestClaimBadUnitSettingsStillRepairSystemUnits(t *testing.T) { |
| } |
| func TestPlan14RootRetryUnitDirectoryScope(t *testing.T) { |
| - raw := []byte("[Service]\nReadWritePaths=/run/carlos-control /run/systemd/system\nRestrictAddressFamilies=AF_UNIX\nMemoryMax=64M\n") |
| + raw := []byte("[Service]\nReadWritePaths=/run/carlos-control /run/systemd/system\nRestrictAddressFamilies=AF_UNIX AF_NETLINK\nMemoryMax=64M\n") |
| legacy := claimUnitContent(claimControlUnit, raw, claimUnitSettings{enabled: true, data: "/data", opt: "/opt/carlos"}) |
| if bytes.Contains(legacy, []byte(rootRetryProjection)) { |
| t.Fatal("no-census unit received E3 write access") |
diff --git a/internal/host/group_hairpin_test.go b/internal/host/group_hairpin_test.go| index 34d9278a3..19f69d306 100644 |
| --- a/internal/host/group_hairpin_test.go |
| +++ b/internal/host/group_hairpin_test.go |
| @@ -108,7 +108,12 @@ func TestHairpinControlGroupDropIn(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if strings.Contains(string(base), "carlos-hairpin") || strings.Contains(string(base), "AF_NETLINK") { |
| + // AF_NETLINK is in the fixed unit too since #990 (the edge fence runs |
| + // nft on every non-group box); the hairpin's runtime directory is not. |
| + if strings.Contains(string(base), "carlos-hairpin") { |
| t.Fatal("group hairpin hardening escaped into fixed unit") |
| } |
| + if !strings.Contains(string(base), "\nRestrictAddressFamilies=AF_UNIX AF_NETLINK\n") { |
| + t.Fatal("the fixed control unit must allow netlink for the edge fence (#990)") |
| + } |
| } |
diff --git a/internal/host/units/carlos-instance-control.service b/internal/host/units/carlos-instance-control.service| index dc47099a4..e5bb95044 100644 |
| --- a/internal/host/units/carlos-instance-control.service |
| +++ b/internal/host/units/carlos-instance-control.service |
| @@ -52,6 +52,12 @@ PrivateDevices=yes |
| ProtectKernelTunables=yes |
| ProtectKernelModules=yes |
| ProtectKernelLogs=yes |
| -RestrictAddressFamilies=AF_UNIX |
| +# AF_NETLINK is nft's (#990, the edge fence): this service loads and reads |
| +# back the carlos_edge_fence table before it lets an instance reach the |
| +# edge on the box's own address. Without it nft fails and the whole #367 |
| +# deny stays. The group drop-in (60-hairpin.conf) already adds it on group |
| +# boxes. nft's modules (nft_socket, nft_reject_inet) autoload despite |
| +# ProtectKernelModules=: the kernel's helper loads them outside this unit. |
| +RestrictAddressFamilies=AF_UNIX AF_NETLINK |
| MemoryDenyWriteExecute=yes |
| MemoryMax=64M |
diff --git a/internal/host/units/carlos-instances.slice b/internal/host/units/carlos-instances.slice| index 2930ac8bc..b6d9b2c26 100644 |
| --- a/internal/host/units/carlos-instances.slice |
| +++ b/internal/host/units/carlos-instances.slice |
| @@ -4,7 +4,18 @@ |
| # walls are the per-host slices the control service sets the tier on. This |
| # level exists so the sampler has one root to scan and so an operator can |
| # `systemctl status carlos-instances.slice`. |
| +# |
| +# RefuseManualStop (#990, the edge fence): the fence's nft rules name this |
| +# slice by the cgroup id it had when they loaded, so a stop and a fresh |
| +# start leave them matching nothing. instance-control checks the fence |
| +# before every start it makes, and that check is what closes the gap; the |
| +# refusal is defence in depth against a unit started by hand after a |
| +# slice restart. Shutdown is unaffected. To stop every tenant at once: |
| +# systemctl stop 'carlos-instances-*.slice' |
| +# or, to signal them without stopping the units: |
| +# systemctl kill carlos-instances.slice |
| [Unit] |
| Description=carlos exec-backed instances |
| +RefuseManualStop=yes |
| [Slice] |
diff --git a/internal/host/units/carlos.slice b/internal/host/units/carlos.slice| index 6f78ac1a9..ac5bb32fe 100644 |
| --- a/internal/host/units/carlos.slice |
| +++ b/internal/host/units/carlos.slice |
| @@ -10,8 +10,14 @@ |
| # |
| # Percentages so one file fits a t4g.micro and a t4g.medium; 80% leaves what |
| # the box's other units (keymail, console, ssm, litestream, journald) use. |
| +# |
| +# RefuseManualStop (#990): a stop here propagates to carlos-instances.slice |
| +# and recreates it, which a refusal on that slice alone does not catch (a |
| +# propagated stop is not a manual one). See carlos-instances.slice. Stop |
| +# the edge with `systemctl stop carlos-edge.service`, as before. |
| [Unit] |
| Description=carlos (edge, activator and every exec-backed instance) |
| +RefuseManualStop=yes |
| [Slice] |
| MemoryHigh=70% |
diff --git a/internal/instancectl/hardening.go b/internal/instancectl/hardening.go| index 6f37c6a36..1d67484c7 100644 |
| --- a/internal/instancectl/hardening.go |
| +++ b/internal/instancectl/hardening.go |
| @@ -487,7 +487,8 @@ func probeBoxAddrs(local []netip.Prefix) []netip.Addr { |
| } |
| // writeProbeBoxAddrs writes probeBoxAddrs of the box's addresses to |
| -// dir/ProbeBoxAddrsName, one address a line, 0644, through a temp file |
| +// dir/ProbeBoxAddrsName, one address a line, followed by " edge" where |
| +// the edge fence exempts it (#990), 0644, through a temp file |
| // renamed into place (root's file; the probe binds it read-only). When |
| // the addresses cannot be read it writes nothing and returns the error. |
| func (s *Server) writeProbeBoxAddrs(dir string) error { |
| @@ -495,9 +496,14 @@ func (s *Server) writeProbeBoxAddrs(dir string) error { |
| if err != nil { |
| return fmt.Errorf("this box's addresses: %w", err) |
| } |
| + fenced := s.EdgeFence().Addresses |
| var b strings.Builder |
| for _, a := range probeBoxAddrs(local) { |
| - b.WriteString(a.String() + "\n") |
| + b.WriteString(a.String()) |
| + if slices.Contains(fenced, a) { |
| + b.WriteString(" " + BoxAddrFenceMark) |
| + } |
| + b.WriteString("\n") |
| } |
| return writeFileExcl(filepath.Join(dir, ProbeBoxAddrsName), []byte(b.String()), 0o644) |
| } |
diff --git a/internal/instancectl/names.go b/internal/instancectl/names.go| index f151c68cf..4abb878fd 100644 |
| --- a/internal/instancectl/names.go |
| +++ b/internal/instancectl/names.go |
| @@ -565,6 +565,9 @@ const RootfsReadyPath = "/ready/rootfs" |
| const ( |
| BoxAddrsPath = "/opt/carlos/box-addrs" |
| ProbeBoxAddrsName = "box-addrs" |
| + // BoxAddrFenceMark follows an address in box-addrs when the edge fence |
| + // exempts it (#990): the probe then expects the edge to answer there. |
| + BoxAddrFenceMark = "edge" |
| ) |
| // ProbePtsPrivateEnv is the binary probe unit's advertisement that its |
diff --git a/internal/instanceexec/probe_hardening.go b/internal/instanceexec/probe_hardening.go| index 16ab95f04..06c769c6f 100644 |
| --- a/internal/instanceexec/probe_hardening.go |
| +++ b/internal/instanceexec/probe_hardening.go |
| @@ -158,6 +158,12 @@ func networkAndIPCChecks(e probeEnv, add func(check, verdict, detail string), pa |
| // #367: the box's own addresses are closed, as the private ranges are. |
| bv, bd := boxAddrClosed(e) |
| add("box-addr", bv, bd) |
| + // #990: no other TCP port opens on the box's addresses, and where the |
| + // edge fence exempts one, the edge answers there. |
| + pv, pd := boxAddrPorts(e) |
| + add("box-addr-ports", pv, pd) |
| + ev, ed := boxAddrEdge(e) |
| + add("box-addr-edge", ev, ed) |
| // #178: an IPC namespace of its own, and no host mqueue mount. |
| ino, ierr := e.ipcInode() |
| @@ -245,35 +251,51 @@ func ptsPrivate(e probeEnv) (detail string, ok bool) { |
| return d, empty && perr != nil |
| } |
| -// boxAddrClosed is the box-addr line (#367): every address in root's list |
| -// of the box's own (e.boxAddrs, one per line) answers EPERM to a datagram, |
| -// as the private ranges do. An address that answers anything else fails |
| -// the line and is named. An IPv6 address the box has no route for is |
| -// unverified, as private-v6 is. A list that is missing, unreadable, holds |
| -// a line that is not an address, or holds no address at all fails: root |
| -// writes it before every run, so its absence is a fault, never a pass. |
| -func boxAddrClosed(e probeEnv) (verdict, detail string) { |
| +// boxAddr is one line of root's box-addrs file: an address of the box, |
| +// and whether the edge fence (#990) exempts it, so that an instance |
| +// reaches the edge there on TCP 80 and 443. |
| +type boxAddr struct { |
| + addr netip.Addr |
| + fence bool |
| +} |
| + |
| +// readBoxAddrs reads root's box-addrs file: one address a line, followed |
| +// by " edge" when the edge fence exempts it. |
| +func readBoxAddrs(e probeEnv) ([]boxAddr, error) { |
| b, err := os.ReadFile(e.boxAddrs) |
| if err != nil { |
| - return "fail", err.Error() |
| + return nil, err |
| } |
| - var addrs []netip.Addr |
| + var out []boxAddr |
| for _, line := range strings.Split(string(b), "\n") { |
| - line = strings.TrimSpace(line) |
| - if line == "" { |
| + fields := strings.Fields(line) |
| + if len(fields) == 0 { |
| continue |
| } |
| - a, err := netip.ParseAddr(line) |
| - if err != nil { |
| - return "fail", fmt.Sprintf("%s: %q is not an address", e.boxAddrs, line) |
| + a, err := netip.ParseAddr(fields[0]) |
| + if err != nil || len(fields) > 2 || (len(fields) == 2 && fields[1] != instancectl.BoxAddrFenceMark) { |
| + return nil, fmt.Errorf("%s: %q is not an address line", e.boxAddrs, line) |
| } |
| - addrs = append(addrs, a) |
| + out = append(out, boxAddr{addr: a, fence: len(fields) == 2}) |
| } |
| - if len(addrs) == 0 { |
| - return "fail", "no address in " + e.boxAddrs |
| + if len(out) == 0 { |
| + return nil, fmt.Errorf("no address in %s", e.boxAddrs) |
| + } |
| + return out, nil |
| +} |
| + |
| +// boxAddrClosed is the #367 line: a datagram to every address of the box |
| +// is refused (EPERM), fenced or not. Under the edge fence the refusal is |
| +// the fence's drop rule rather than the slice deny, so this line also |
| +// shows the fence's cgroup match is live. |
| +func boxAddrClosed(e probeEnv) (verdict, detail string) { |
| + addrs, err := readBoxAddrs(e) |
| + if err != nil { |
| + return "fail", err.Error() |
| } |
| var failed, unrouted []string |
| - for _, a := range addrs { |
| + for _, b := range addrs { |
| + a := b.addr |
| network := "udp4" |
| if a.Is6() { |
| network = "udp6" |
| @@ -296,6 +318,60 @@ func boxAddrClosed(e probeEnv) (verdict, detail string) { |
| return "ok", "" |
| } |
| +// boxAddrPortsProbe is the TCP port box-addr-ports dials: ssh's, the |
| +// listener a box most often has on all its addresses. |
| +const boxAddrPortsProbe = 22 |
| + |
| +// boxAddrPorts (#990): a TCP connection to a port other than the edge's |
| +// on any address of the box does not open, fenced or not. A refusal, an |
| +// EPERM or a timeout all pass; only a connection fails. |
| +func boxAddrPorts(e probeEnv) (verdict, detail string) { |
| + addrs, err := readBoxAddrs(e) |
| + if err != nil { |
| + return "fail", err.Error() |
| + } |
| + var failed []string |
| + for _, b := range addrs { |
| + target := netip.AddrPortFrom(b.addr, boxAddrPortsProbe).String() |
| + if err := e.connectTCP(target, 2*time.Second); err == nil { |
| + failed = append(failed, target+": connected") |
| + } |
| + } |
| + if len(failed) > 0 { |
| + return "fail", strings.Join(failed, "; ") |
| + } |
| + return "ok", "" |
| +} |
| + |
| +// 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. |
| +func boxAddrEdge(e probeEnv) (verdict, detail string) { |
| + addrs, err := readBoxAddrs(e) |
| + if err != nil { |
| + return "unverified", err.Error() |
| + } |
| + var fenced, missed []string |
| + for _, b := range addrs { |
| + 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)) |
| + } |
| + } |
| + switch { |
| + case len(fenced) == 0: |
| + return "unverified", "same-box calls are off on this box" |
| + case len(missed) > 0: |
| + return "unverified", "the edge did not answer: " + strings.Join(missed, "; ") |
| + } |
| + return "ok", "" |
| +} |
| + |
| // noV6 is an answer that means the box has no IPv6 path for that |
| // address, so the fence was never asked. |
| func noV6(err error) bool { |
diff --git a/internal/instanceexec/probe_hardening_test.go b/internal/instanceexec/probe_hardening_test.go| index 2f4b54d5a..9805a638f 100644 |
| --- a/internal/instanceexec/probe_hardening_test.go |
| +++ b/internal/instanceexec/probe_hardening_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "os" |
| "path/filepath" |
| "runtime" |
| + "slices" |
| "strings" |
| "syscall" |
| "testing" |
| @@ -274,3 +275,83 @@ func countLines(r instancectl.ProbeReport, check string) int { |
| } |
| return n |
| } |
| + |
| +// #990: box-addr-ports fails only when a non-edge TCP port connects on a |
| +// box address; box-addr-edge reads the " edge" mark root writes beside an |
| +// address the edge fence exempts, and never fails the probe. |
| +func TestProbeEdgeFenceLines(t *testing.T) { |
| + fenced := func(t *testing.T) probeEnv { |
| + e := goodEnv(t) |
| + if err := os.WriteFile(e.boxAddrs, []byte("10.0.3.17\n203.0.113.7 edge\n2001:db8::7 edge\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + return e |
| + } |
| + refused := errors.New("connect: connection refused") |
| + |
| + // Fence on, edge answering on 443, every other port refused. |
| + e := fenced(t) |
| + var dialled []string |
| + e.connectTCP = func(addr string, _ time.Duration) error { |
| + dialled = append(dialled, addr) |
| + if strings.HasSuffix(addr, ":443") { |
| + return nil |
| + } |
| + return refused |
| + } |
| + r := runChecks(e) |
| + for _, line := range []string{"box-addr", "box-addr-ports", "box-addr-edge"} { |
| + if verdict(r, line) != "ok" { |
| + t.Errorf("%s = %s: %s", line, verdict(r, line), detail(r, line)) |
| + } |
| + } |
| + for _, want := range []string{"10.0.3.17:22", "203.0.113.7:22", "[2001:db8::7]:22", "203.0.113.7:443", "[2001:db8::7]:443"} { |
| + if !slices.Contains(dialled, want) { |
| + t.Errorf("did not dial %s: %v", want, dialled) |
| + } |
| + } |
| + if slices.Contains(dialled, "10.0.3.17:443") { |
| + t.Error("dialled the edge on an address the fence does not exempt") |
| + } |
| + |
| + // Port 22 connects on a fenced address: the fence is not holding. |
| + e = fenced(t) |
| + e.connectTCP = func(addr string, _ time.Duration) error { |
| + if strings.HasPrefix(addr, "203.0.113.7:") { |
| + return nil |
| + } |
| + return refused |
| + } |
| + if r := runChecks(e); r.Ready || verdict(r, "box-addr-ports") != "fail" || !strings.Contains(detail(r, "box-addr-ports"), "203.0.113.7:22") { |
| + t.Errorf("a connected port 22 passed: %s %s", verdict(r, "box-addr-ports"), detail(r, "box-addr-ports")) |
| + } |
| + |
| + // The edge is down: unverified, and the box stays ready. |
| + e = fenced(t) |
| + e.connectTCP = func(string, time.Duration) error { return refused } |
| + if r := runChecks(e); !r.Ready || verdict(r, "box-addr-edge") != "unverified" { |
| + t.Errorf("edge down: ready=%v box-addr-edge=%s %s", r.Ready, verdict(r, "box-addr-edge"), detail(r, "box-addr-edge")) |
| + } |
| + |
| + // The fence is off: no edge dial, unverified, ready. |
| + e = goodEnv(t) |
| + dialled = nil |
| + e.connectTCP = func(addr string, _ time.Duration) error { dialled = append(dialled, addr); return refused } |
| + if r := runChecks(e); !r.Ready || verdict(r, "box-addr-edge") != "unverified" || !strings.Contains(detail(r, "box-addr-edge"), "off") { |
| + 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") { |
| + t.Errorf("dialled the edge with the fence off: %s", d) |
| + } |
| + } |
| + |
| + // A mark root never writes is refused, failing box-addr. |
| + e = goodEnv(t) |
| + if err := os.WriteFile(e.boxAddrs, []byte("203.0.113.7 open\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + if r := runChecks(e); r.Ready || verdict(r, "box-addr") != "fail" { |
| + t.Errorf("an unknown mark passed: %s %s", verdict(r, "box-addr"), detail(r, "box-addr")) |
| + } |
| +} |