diff --git a/deploy/containerlab/README.md b/deploy/containerlab/README.md index 24cca5eeb..ec079bf37 100644 --- a/deploy/containerlab/README.md +++ b/deploy/containerlab/README.md @@ -562,6 +562,7 @@ task deploy | `verify:ns40` | Verify ns40 ping (iad only, 2 pods) | | `verify:traffic-policy` | Every binding installed; each path forwards what it grants and drops, and counts, what it does not | | `verify:masque-service` | Run the shipped MASQUE service and grant authority against dfw's gVPC workloads (about 20 min; restarts dfw-worker2; not in `verify`) | +| `verify:masque-listener` | Reach the shipped MASQUE service through dfw's public listener from remote-host (needs gateway local delivery; not in `verify`) | | `deploy:looking-glass` | Enable the Looking Glass service on dfw in the documented order (restarts dfw's FRR twice); issue its test certificates | | `verify:looking-glass` | Qualify the Looking Glass service on dfw with the independent client, with faults (about 45 min; not in `verify`) | | `undeploy:looking-glass` | Switch the Looking Glass service off on dfw and roll its enabling steps back (restarts dfw's FRR twice) | diff --git a/deploy/containerlab/Taskfile.yaml b/deploy/containerlab/Taskfile.yaml index 928660157..9684cc02d 100644 --- a/deploy/containerlab/Taskfile.yaml +++ b/deploy/containerlab/Taskfile.yaml @@ -1357,6 +1357,23 @@ tasks: cmds: - EDGE_CONFORMANCE_KUBECONFIG={{.ROOT_DIR}}/dfw.kubeconfig go test -count=1 -v -timeout 60m -run '^TestMASQUEService$' ./tests/edgeconformance/ + # Not part of verify: Phase 5 of docs/designs/edge-public-listener.md + # (#1512). It deploys the shipped MASQUE service like verify:masque-service, + # but through resources/masque-service/provider-listener, so clients reach + # it on dfw's public listener rather than the pod. It pins the listener's + # VIPs on tr1 to dfw-worker3's gateway, connects from remote-host over + # HTTP/3 and HTTP/2 on both families, again over HTTP/2 with remote-host's + # UDP/443 blocked, and removes everything it created. Needs galactic-edge + # deployed with the controller overlay's --edge-ingress-* flags + # (deploy:galactic-edge), the images verify:masque-service needs, and + # gateway local delivery (#1526), since every dfw edge node runs a gateway. + # Results land in bin/edge-conformance/. + "verify:masque-listener": + desc: Reach the shipped MASQUE service through dfw's public listener from remote-host + dir: ../.. + cmds: + - EDGE_CONFORMANCE_KUBECONFIG={{.ROOT_DIR}}/dfw.kubeconfig LAB={{.LAB}} go test -count=1 -v -timeout 40m -run '^TestMASQUEPublicListener$' ./tests/edgeconformance/ + "verify:ns10": desc: Verify ns10 ping (IPv6-only, 3-site mesh) cmds: diff --git a/deploy/containerlab/resources/galactic-edge/controller/kustomization.yaml b/deploy/containerlab/resources/galactic-edge/controller/kustomization.yaml index 106fcd7c9..7e0cecc8f 100644 --- a/deploy/containerlab/resources/galactic-edge/controller/kustomization.yaml +++ b/deploy/containerlab/resources/galactic-edge/controller/kustomization.yaml @@ -1,6 +1,15 @@ # The lab's galactic-controller --role=cell (resources/galactic-controller) # with Galactic Edge's control plane turned on. scripts/deploy-galactic-edge.sh # applies config/galactic-edge, whose RBAC and policies --edge needs, first. +# +# The public listener (docs/designs/edge-public-listener.md): the masque +# provider's ingress gVPC takes fabric VPC identity 96 and a /64 from +# fd00:ed96::/48, which no lab tenant or test uses (TestListenerBackend's +# hand-made ingress VPC is 95 in fd00:ed95::/32). A listener's addresses +# must fall in dfw's gateway VIP prefixes, the ones dfw's edge nodes +# originate to the transit (resources/galactic-gateway). The gVPC exists +# only once the masque provider is registered and approved, which +# task verify:masque-listener does. resources: - ../../galactic-controller patches: @@ -11,3 +20,12 @@ patches: - op: add path: /spec/template/spec/containers/0/args/- value: --edge + - op: add + path: /spec/template/spec/containers/0/args/- + value: --edge-ingress-identity=masque=96 + - op: add + path: /spec/template/spec/containers/0/args/- + value: --edge-ingress-prefix=fd00:ed96::/48 + - op: add + path: /spec/template/spec/containers/0/args/- + value: --edge-listener-vip-prefixes=2001:db8:6060:1::/64,198.51.100.0/26 diff --git a/deploy/containerlab/resources/masque-service/provider-listener/kustomization.yaml b/deploy/containerlab/resources/masque-service/provider-listener/kustomization.yaml new file mode 100644 index 000000000..7a319428f --- /dev/null +++ b/deploy/containerlab/resources/masque-service/provider-listener/kustomization.yaml @@ -0,0 +1,23 @@ +# The lab's CONNECT-IP service served through dfw's public listener: the +# provider/ overlay plus config/masque/provider/components/public-listener, +# with the listener on dfw's VIPs 2001:db8:6060:1::443 and 198.51.100.43, +# inside the prefixes galactic-controller accepts +# (../../galactic-edge/controller/kustomization.yaml) and unused by ns60 (::1, +# .1) and TestListenerBackend (::95, .30). +# +# Not applied as-is: the EdgeService's vpcRef.uid and clientPool are +# placeholders, and both are immutable. TestMASQUEPublicListener +# (task verify:masque-listener) reads them from the edge-ingress-masque VPC +# and applies this overlay through one more that patches them in. +resources: + - ../provider +components: + - ../../../../../config/masque/provider/components/public-listener +patches: + - target: + kind: EdgeListener + name: masque-public + patch: |- + - op: replace + path: /spec/addresses + value: ["2001:db8:6060:1::443", "198.51.100.43"] diff --git a/docs/designs/masque/acceptance.md b/docs/designs/masque/acceptance.md index a914f4b60..8c2ae161c 100644 --- a/docs/designs/masque/acceptance.md +++ b/docs/designs/masque/acceptance.md @@ -38,6 +38,9 @@ Run packet, authentication, isolation and failure cases on both HTTP/3 and HTTP/ | M18 | Authority refresh and service turnover | Repeated 5 s validUntil refresh causes no unintended drain/policy outage at capacity. Freeze one service's refresh, renew other connectors, rotate credentials, and race authority leaders and revocation. Old incarnation is never recreated/refreshed. Retire old service, await Released, recreate successor with retained pool and take the stable route; no overlap or duplicate allocation. | [#976](https://github.com/datum-cloud/galactic/issues/976), [#977](https://github.com/datum-cloud/galactic/issues/977), [#978](https://github.com/datum-cloud/galactic/issues/978), [#984](https://github.com/datum-cloud/galactic/issues/984) | | M19 | Runnable artifacts and operator setup | Build separate provider and authority artifacts; document internal configuration, scoped test grants, readiness and shutdown. Operator can issue/revoke a test credential without portal/public API/client changes; provider cannot mint an EdgeService. | [#975](https://github.com/datum-cloud/galactic/issues/975), [#977](https://github.com/datum-cloud/galactic/issues/977), [#980](https://github.com/datum-cloud/galactic/issues/980) | | M20 | Integrated completion | Reproduce every row on pinned qualified core; include foundation evidence below and all finding dispositions. Independent-provider results remain separate. Failed protocol/platform proofs require design revision and a passing retest. Publish results and cleanup, not only a checklist. | [#985](https://github.com/datum-cloud/galactic/issues/985) | +| M21 | Public listener: independent client | From the off-fabric host, an independent client connects through the listener's VIP over HTTP/3 and HTTP/2, over IPv6 and IPv4, and exchanges 1280-byte packets in both directions with a workload in its gVPC. `task verify:masque-listener`. | [#1512](https://github.com/datum-cloud/galactic/issues/1512) | +| M22 | Public listener: UDP blocked | With the client's UDP/443 blocked, an HTTP/3 attempt fails and HTTP/2 through the listener still connects and delivers on both families. `task verify:masque-listener`. | [#1512](https://github.com/datum-cloud/galactic/issues/1512) | +| M23 | Public listener: unprivileged provider | The provider pod serving the listener has no host namespaces, hostPath or added capability, and the `EdgeListener` is Accepted and Programmed with its attachment serving. `task verify:masque-listener`. | [#1512](https://github.com/datum-cloud/galactic/issues/1512) | The one-service-per-connector design avoids a new foundation deadline API. M05 and M18 are mandatory feasibility gates before [#980](https://github.com/datum-cloud/galactic/issues/980)/#981 expose this path. If either fails, [#976](https://github.com/datum-cloud/galactic/issues/976) records the required extension under [#992](https://github.com/datum-cloud/galactic/issues/992) with its own contract and qualification evidence; dependent integration stays blocked. A design review may complete [#972](https://github.com/datum-cloud/galactic/issues/972) while those implementation checks remain assigned, but cannot mark [#970](https://github.com/datum-cloud/galactic/issues/970) integrated acceptance complete. diff --git a/docs/edge/masque-service.md b/docs/edge/masque-service.md index 86c1e1d02..ea569f85e 100644 --- a/docs/edge/masque-service.md +++ b/docs/edge/masque-service.md @@ -279,3 +279,5 @@ Step 3 has 20 seconds, so give the pod a termination grace period of at least 30 - a restart of the provider's node container (`scripts/restart-node.sh` restores the lab links the restart removes). The [lab README](../../deploy/containerlab/README.md#masque-service) lists what the overlays change for the lab. + +`task verify:masque-listener` deploys the same service through `deploy/containerlab/resources/masque-service/provider-listener`, the [public listener](#public-listener), and from the lab's off-fabric host connects through dfw's listener VIPs over HTTP/3 and HTTP/2 on both families, again over HTTP/2 with the client's UDP/443 blocked, and checks the provider pod stays unprivileged. It needs gateway local delivery ([#1526](https://github.com/datum-cloud/galactic/issues/1526)), since every lab edge node also runs a gateway. diff --git a/tests/edgeconformance/masque_listener_test.go b/tests/edgeconformance/masque_listener_test.go new file mode 100644 index 000000000..7b007ae71 --- /dev/null +++ b/tests/edgeconformance/masque_listener_test.go @@ -0,0 +1,482 @@ +// Copyright 2026 Datum Cloud, Inc. +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +package edgeconformance_test + +import ( + "context" + "encoding/json" + "fmt" + "net/netip" + "os" + "os/exec" + "path/filepath" + "slices" + "strconv" + "strings" + "testing" + "time" + + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + + galacticv1alpha1 "go.datum.net/galactic/api/v1alpha1" +) + +// TestMASQUEPublicListener is Phase 5 of the Edge public listener design +// (docs/designs/edge-public-listener.md, #1512): the shipped MASQUE service +// served through dfw's public listener instead of a Service. It deploys the +// service as TestMASQUEService does, but with the provider overlay that +// includes config/masque/provider/components/public-listener, and checks: +// +// - the provider pod runs with no host namespace, hostPath or added +// capability; +// - the EdgeListener is Accepted and Programmed, with the provider's +// listener attachment serving; +// - an off-fabric client on remote-host connects to the listener's VIPs +// over HTTP/3 and HTTP/2, over IPv6 and IPv4, and exchanges 1280-byte +// packets in both directions with a workload in its gVPC; +// - HTTP/2 still connects with the client's UDP/443 blocked, which an +// HTTP/3 attempt proves. +// +// The provider runs on edgeNode1, and every dfw edge node also runs a +// gateway, so the VIPs are pinned on tr1 to edgeNode2's gateway: the +// gateway that receives each packet is not the backend's node. The listener +// serves only once core counts the backend, which needs gateway local +// delivery (#1526) or a backend node without a gateway. Needs galactic-edge +// deployed with the lab controller overlay's ingress flags. Run it with +// task verify:masque-listener. +func TestMASQUEPublicListener(t *testing.T) { + l := getLab(t) + t.Cleanup(func() { l.writeSummary(t) }) + s := &service{l: l, ca: newTestCA(t, "masque listener CA"), otherCA: newTestCA(t, "masque other CA"), + links: map[string]string{}, unrelated: map[string]types.UID{}} + pl := &publicListener{s: s} + if os.Getenv("EDGE_CONFORMANCE_KEEP") == "" { + t.Cleanup(func() { pl.teardown(t) }) + t.Cleanup(pl.unpin) + } + if !t.Run("setup", pl.setup) { + t.FailNow() + } + t.Run("unprivileged", pl.rowUnprivileged) + if !t.Run("listener-serving", pl.rowServing) { + t.FailNow() + } + for _, f := range listenerVIPs { + for _, transport := range []string{"h3", "h2"} { + t.Run(transport+"-"+f.name, func(t *testing.T) { pl.rowConnect(t, f, transport) }) + } + } + t.Run("h2-udp-blocked", pl.rowUDPBlocked) +} + +// The listener's fixed values: the EdgeListener the component and the lab +// overlay define, and the ingress gVPC galactic-controller creates for the +// masque provider. +const ( + plNamespace = "galactic-system" + plListener = "masque-public" + plService = "masque-ingress" + plIngressVPC = "edge-ingress-masque" + plPort = 443 + plProbeOnHost = "/usr/local/bin/edgeprobe" + plCAOnHost = "/usr/local/share/masque-listener-ca.pem" + // plBackendNode runs the provider; plGateway receives the client's + // packets. + plBackendNode = edgeNode1 + plGateway = edgeNode2 +) + +// listenerVIPs are the listener's VIPs, with tr1's uplinks to each dfw +// gateway as TestListenerBackend's families list them. +var listenerVIPs = []listenerFamily{ + {name: "ipv6", vip: "2001:db8:6060:1::443", client: listenerFamilies[0].client, uplinks: listenerFamilies[0].uplinks}, + {name: "ipv4", vip: "198.51.100.43", client: listenerFamilies[1].client, uplinks: listenerFamilies[1].uplinks}, +} + +// publicListener is the service under test, served through the listener. +type publicListener struct { + s *service + // overlayDir is the rendered overlay applied, which teardown deletes. + overlayDir string + // blocked records that the client's UDP/443 is blocked, for teardown. + blocked bool + // pins are the tr1 host routes pin changed, in order, each with the + // route it replaced, so unpin restores exactly those. + pins []pinnedRoute +} + +// pinnedRoute is one tr1 host route pin changed and the route it replaced. +type pinnedRoute struct { + family, route string + // prior is the route tr1 held before, as ip route show prints it, or + // empty when it held none. + prior string +} + +func (pl *publicListener) setup(t *testing.T) { + s, l := pl.s, pl.s.l + for i := 1; i <= 3; i++ { + p := l.clientPod(t, svcTenant10, i) + s.unrelated[p.Namespace+"/"+p.Name] = p.UID + } + pl.installClient(t) + // The registration, approval and tenant bindings, then the authority, + // as TestMASQUEService applies them. Approving the provider makes core + // create its ingress gVPC. + if _, err := l.kubectl("apply", "-k", s.overlay()); err != nil { + t.Fatal(err) + } + svcCert, svcKey := s.ca.issue(t, strings.Split(svcAuthority, ":")[0]) + pl.applySecret(t, svcCert, svcKey) + if _, err := l.kubectl("apply", "-k", s.overlay("authority")); err != nil { + t.Fatal(err) + } + s.waitReady(t, "masque-authority", computeNode, "") + if _, err := s.authority(t, "ledger", "init", "--vpc", svcTenant10.vpcNamespace+"/"+svcTenant10.vpc, + "--cell", svcCell, "--connectors", svcConnectors, "--pools", svcPools); err != nil { + t.Fatal(err) + } + s.c10 = s.grant(t, "c10", svcTenant10, 0x5a10, 0) + l.record(t, "VPC 10 connector /96", s.c10.issued.Prefix) + + // The ingress gVPC's UID and /64 are immutable in the EdgeService, so + // they are read first and patched in before the first apply. + var uid, network string + eventually(t, 2*time.Minute, 2*time.Second, "ingress gVPC "+plIngressVPC, func() (bool, error) { + out, err := l.kubectl("-n", plNamespace, "get", "vpc", plIngressVPC, "-o", + "jsonpath={.metadata.uid} {.spec.networks[0]}") + if err != nil { + return false, fmt.Errorf("%w (is galactic-controller deployed with the lab's --edge-ingress-* flags?)", err) + } + f := strings.Fields(out) + if len(f) != 2 { + return false, fmt.Errorf("read %q", out) + } + uid, network = f[0], f[1] + return true, nil + }) + l.record(t, "ingress gVPC", uid+" "+network) + pl.overlayDir = filepath.Join(l.artifacts, "overlays", "masque-listener") + l.applyOverlayOf(t, s.overlay("provider-listener"), "masque-listener", fmt.Sprintf(`patches: + - target: {kind: EdgeService, name: %s} + patch: |- + - {op: replace, path: /spec/vpcRef/uid, value: %q} + - {op: replace, path: /spec/clientPool, value: %q} +`, plService, uid, network), nil) + s.pod = s.waitReady(t, "masque-provider", plBackendNode, "") + + // Every packet enters at plGateway, not the backend's node. + for _, f := range listenerVIPs { + pl.pin(t, f, plGateway) + } +} + +// artifact writes b to the run's artifacts as name and returns its path. +func (pl *publicListener) artifact(t *testing.T, name string, b []byte) string { + t.Helper() + path := filepath.Join(pl.s.l.artifacts, name) + if err := os.WriteFile(path, b, 0o600); err != nil { + t.Fatal(err) + } + return path +} + +// applySecret creates or replaces the provider's TLS Secret. +func (pl *publicListener) applySecret(t *testing.T, cert, key []byte) { + t.Helper() + yaml, err := pl.s.l.kubectl("-n", svcNS, "create", "secret", "tls", "masque-provider-tls", + "--cert="+pl.artifact(t, "masque-provider.crt", cert), "--key="+pl.artifact(t, "masque-provider.key", key), + "--dry-run=client", "-o", "yaml") + if err != nil { + t.Fatal(err) + } + if _, err := pl.s.l.kubectl("apply", "-f", pl.artifact(t, "masque-provider-tls.yaml", []byte(yaml))); err != nil { + t.Fatal(err) + } +} + +// installClient copies edgeprobe, a static binary, and the CA that signed +// the service's certificate onto the off-fabric host. +func (pl *publicListener) installClient(t *testing.T) { + t.Helper() + l := pl.s.l + ca := pl.artifact(t, "masque-listener-ca.pem", pl.s.ca.pem) + for src, dst := range map[string]string{l.probeBin: plProbeOnHost, ca: plCAOnHost} { + cp := exec.CommandContext(context.Background(), "docker", "cp", src, transitHost()+":"+dst) + if out, err := cp.CombinedOutput(); err != nil { + t.Fatalf("copy %s to %s: %v: %s", src, transitHost(), err, out) + } + } +} + +// hostRoute is the ip family flag and the host route of f's VIP. +func hostRoute(f listenerFamily) (family, route string) { + a := netip.MustParseAddr(f.vip) + family = "-6" + if a.Is4() { + family = "-4" + } + return family, netip.PrefixFrom(a, a.BitLen()).String() +} + +// pin routes f's VIP from tr1 to gateway only, as TestListenerBackend does. +// It records the host route tr1 held before, the first time it changes that +// route, so unpin can put it back. +func (pl *publicListener) pin(t *testing.T, f listenerFamily, gateway string) { + t.Helper() + up := f.uplinks[gateway] + fam, route := hostRoute(f) + if !slices.ContainsFunc(pl.pins, func(p pinnedRoute) bool { return p.family == fam && p.route == route }) { + prior, err := nodeExec(transitRouter(), "ip", fam, "route", "show", "exact", route) + if err != nil { + t.Fatalf("read tr1's route to %s before pinning it: %v", route, err) + } + // Recorded before the change, so a replace that fails partway is + // still undone. + pl.pins = append(pl.pins, pinnedRoute{family: fam, route: route, prior: strings.TrimSpace(prior)}) + } + if _, err := nodeExec(transitRouter(), "ip", fam, "route", "replace", route, "via", up[0], "dev", + up[1]); err != nil { + t.Fatal(err) + } +} + +// unpin restores each host route pin changed, newest first: the route it +// replaced, or no route when there was none. Routes pin never touched are +// left alone, including when setup failed before pinning. +func (pl *publicListener) unpin() { + for _, p := range slices.Backward(pl.pins) { + if p.prior == "" { + if out, err := nodeExec(transitRouter(), "ip", p.family, "route", "del", p.route); err != nil && + !strings.Contains(out+err.Error(), "No such process") { + fmt.Fprintf(os.Stderr, "unpin: delete tr1's route to %s: %v: %s\n", p.route, err, out) + } + continue + } + // ip route show prints a multipath route over several lines; replace + // takes the same words on one. + args := append([]string{"ip", p.family, "route", "replace"}, strings.Fields(p.prior)...) + if out, err := nodeExec(transitRouter(), args...); err != nil { + fmt.Fprintf(os.Stderr, "unpin: restore tr1's route %q: %v: %s\n", p.prior, err, out) + } + } + pl.pins = nil +} + +func (pl *publicListener) rowUnprivileged(t *testing.T) { + spec := pl.s.pod.Spec + if spec.HostNetwork || spec.HostPID || spec.HostIPC { + t.Errorf("provider pod shares a host namespace: network %v, PID %v, IPC %v", spec.HostNetwork, spec.HostPID, + spec.HostIPC) + } + for _, v := range spec.Volumes { + if v.HostPath != nil { + t.Errorf("provider pod mounts hostPath %s as volume %s", v.HostPath.Path, v.Name) + } + } + for _, c := range spec.Containers { + sc := c.SecurityContext + switch { + case sc == nil || sc.Capabilities == nil: + t.Errorf("container %s drops no capabilities", c.Name) + case len(sc.Capabilities.Add) > 0: + t.Errorf("container %s adds capabilities %v", c.Name, sc.Capabilities.Add) + case sc.Privileged != nil && *sc.Privileged: + t.Errorf("container %s is privileged", c.Name) + case sc.AllowPrivilegeEscalation == nil || *sc.AllowPrivilegeEscalation: + t.Errorf("container %s allows privilege escalation", c.Name) + } + } + pl.s.l.record(t, "provider pod", fmt.Sprintf("%s on %s, unprivileged", pl.s.pod.Name, pl.s.pod.Spec.NodeName)) +} + +// rowServing waits for the EdgeListener to be Accepted and Programmed with +// the provider pod's attachment serving. +func (pl *publicListener) rowServing(t *testing.T) { + l := pl.s.l + var lst galacticv1alpha1.EdgeListener + eventually(t, 3*time.Minute, 2*time.Second, "EdgeListener "+plListener+" serving", func() (bool, error) { + if err := l.c.Get(context.Background(), client.ObjectKey{Namespace: plNamespace, Name: plListener}, + &lst); err != nil { + return false, err + } + acc := meta.FindStatusCondition(lst.Status.Conditions, galacticv1alpha1.EdgeListenerAccepted) + prog := meta.FindStatusCondition(lst.Status.Conditions, galacticv1alpha1.EdgeListenerProgrammed) + if acc == nil || acc.Status != "True" { + return false, fmt.Errorf("Accepted %+v", acc) + } + if prog == nil || prog.Status != "True" { + return false, fmt.Errorf("Programmed %+v (LocalBackendsExcluded needs gateway local delivery, #1526)", prog) + } + for _, b := range lst.Status.Backends { + if b.Serving && b.Node == plBackendNode { + return true, nil + } + } + return false, fmt.Errorf("no serving backend on %s in %+v", plBackendNode, lst.Status.Backends) + }) + for _, b := range lst.Status.Backends { + l.record(t, "backend "+b.Attachment, fmt.Sprintf("node %s address %s serving %v", b.Node, b.Address, + b.Serving)) + } +} + +// remoteArgs are edgeprobe's arguments for one request of c from the +// off-fabric host to f's VIP over transport, sending packetSize-byte echo +// requests to dsts for d. +func (pl *publicListener) remoteArgs(f listenerFamily, c *svcConnector, transport string, d time.Duration, + dsts ...string) []string { + args := cipServer{pod: &corev1.Pod{}, port: plPort, authority: svcAuthority, ca: plCAOnHost}.args( + c.issued.Credential, c.vpc(), c.echo, d, dsts) + // cipServer dials a pod address; the client here dials the VIP. + args[2] = netip.AddrPortFrom(netip.MustParseAddr(f.vip), plPort).String() + return append(args, "-transport", transport, "-size", strconv.Itoa(packetSize)) +} + +// remote runs one request from the off-fabric host and returns its events. +func (pl *publicListener) remote(args []string) ([]event, error) { + out, err := nodeExec(transitHost(), append([]string{"timeout", "60", plProbeOnHost}, args...)...) + if err != nil { + return nil, err + } + var evs []event + for _, line := range strings.Split(out, "\n") { + if !strings.HasPrefix(line, "{") { + continue + } + var e event + if err := json.Unmarshal([]byte(line), &e); err != nil { + return nil, fmt.Errorf("edgeprobe printed %q: %w", line, err) + } + evs = append(evs, e) + } + return evs, nil +} + +// rowConnect connects through f's VIP over transport, first until the +// listener answers, then for a whole window that must deliver. +func (pl *publicListener) rowConnect(t *testing.T, f listenerFamily, transport string) { + s, l := pl.s, pl.s.l + c := s.c10 + w := l.workloadOn(t, c.tn, computeNode) + eventually(t, 2*time.Minute, 2*time.Second, transport+" through "+f.vip, func() (bool, error) { + evs, err := pl.remote(pl.remoteArgs(f, c, transport, time.Second, w.addr)) + if err != nil { + return false, err + } + return len(echoes(evs, w.addr)) > 0, fmt.Errorf("status %d", status(evs)) + }) + before := l.rulePackets(t, plGateway, f.vip) + evs, err := pl.remote(pl.remoteArgs(f, c, transport, lifecycleWindow, w.addr)) + if err != nil { + t.Fatal(err) + } + s.requireDelivered(t, transport+" through "+f.vip, c, transport, evs, w) + if after := l.rulePackets(t, plGateway, f.vip); after <= before { + t.Errorf("%s counted no packets for %s: another gateway served the VIP", plGateway, f.vip) + } +} + +// rowUDPBlocked blocks the client's UDP to port 443 on the off-fabric host, +// proves the block with an HTTP/3 attempt that must fail, and connects over +// HTTP/2 on both families. +func (pl *publicListener) rowUDPBlocked(t *testing.T) { + s, l := pl.s, pl.s.l + c := s.c10 + w := l.workloadOn(t, c.tn, computeNode) + pl.blockUDP(t) + for _, f := range listenerVIPs { + evs, err := pl.remote(pl.remoteArgs(f, c, "h3", time.Second, w.addr)) + if err == nil && status(evs) == 200 { + t.Fatalf("HTTP/3 to %s connected with UDP/443 blocked", f.vip) + } + l.record(t, "HTTP/3 to "+f.vip+" with UDP/443 blocked", fmt.Sprintf("refused (%v)", err)) + evs, err = pl.remote(pl.remoteArgs(f, c, "h2", lifecycleWindow, w.addr)) + if err != nil { + t.Fatal(err) + } + s.requireDelivered(t, "h2 through "+f.vip+" with UDP/443 blocked", c, "h2", evs, w) + } +} + +// blockUDP prohibits UDP to port 443 from the off-fabric host, both +// families, with policy routing rules: its image has no packet filter. +func (pl *publicListener) blockUDP(t *testing.T) { + t.Helper() + pl.blocked = true + for _, fam := range []string{"-4", "-6"} { + if _, err := nodeExec(transitHost(), "ip", fam, "rule", "add", "pref", "100", "ipproto", "udp", "dport", + strconv.Itoa(plPort), "prohibit"); err != nil { + t.Fatal(err) + } + } +} + +// unblockUDP removes blockUDP's rules. +func (pl *publicListener) unblockUDP() { + for _, fam := range []string{"-4", "-6"} { + _, _ = nodeExec(transitHost(), "ip", fam, "rule", "del", "pref", "100", "ipproto", "udp", "dport", + strconv.Itoa(plPort), "prohibit") + } + pl.blocked = false +} + +// teardown removes everything setup created: the provider and its listener +// objects first, so its attachment and the listener's NetworkServices go +// before the authority and the registration. +func (pl *publicListener) teardown(t *testing.T) { + s, l, ctx := pl.s, pl.s.l, context.Background() + if pl.blocked { + pl.unblockUDP() + } + if pl.overlayDir != "" { + if _, err := l.kubectl("delete", "-k", pl.overlayDir, "--ignore-not-found", "--wait=true", + "--timeout=180s"); err != nil { + t.Error(err) + } + } + eventually(t, 2*time.Minute, time.Second, "provider pods gone", func() (bool, error) { + var pods corev1.PodList + err := l.c.List(ctx, &pods, client.InNamespace(svcNS), client.MatchingLabels{nameLabel: "masque-provider"}) + return err == nil && len(pods.Items) == 0, err + }) + l.waitEdgeObjectsGone(t, svcNS) + if _, err := l.kubectl("delete", "-k", s.overlay("authority"), "--ignore-not-found", "--wait=true", + "--timeout=120s"); err != nil { + t.Error(err) + } + var svcs galacticv1alpha1.EdgeServiceList + if err := l.c.List(ctx, &svcs, client.InNamespace(svcTenant10.vpcNamespace)); err != nil { + t.Error(err) + } + for i := range svcs.Items { + if svcs.Items[i].Spec.ProviderRef.Name == svcProvider { + l.deleteAndWait(t, &svcs.Items[i]) + } + } + if _, err := l.kubectl("delete", "-k", s.overlay(), "--ignore-not-found", "--wait=true", + "--timeout=180s"); err != nil { + t.Error(err) + } + if _, err := l.kubectl("-n", svcNS, "delete", "secret", "masque-provider-tls", "--ignore-not-found"); err != nil { + t.Error(err) + } + l.requireNoEdgeAdvertisements(t, svcNS) + for _, path := range []string{plProbeOnHost, plCAOnHost} { + if _, err := nodeExec(transitHost(), "rm", "-f", path); err != nil { + t.Error(err) + } + } + for key, uid := range s.unrelated { + ns, name, _ := strings.Cut(key, "/") + var p corev1.Pod + if err := l.c.Get(ctx, client.ObjectKey{Namespace: ns, Name: name}, &p); err != nil || p.UID != uid { + t.Errorf("unrelated pod %s was replaced or removed", key) + } + } +}