Watch
0
0
Fork
You've already forked hyperhive
0

k8s: stt's pod gets a network policy: dns and four host ports out, nothing in

This commit is contained in:
atlas 2026-11-23 13:36:51 +01:00 • committed by maia
commit 2259b5f27b

View file

@ -13,7 +13,8 @@
# token, read its client secret and minted a token with it. The router
# routes an event and a deleted pod exits 0 within its grace period; the
# speech-to-text pod carries its limits and keeps its cache in an emptyDir,
# with no claim and no state gate;
# with no claim and no state gate, and its NetworkPolicy lets a queue request
# reach it, and it reach DNS and four host ports, and nothing else;
# - the poller's Job completes against a forge that lists one run, pushes it to
# its own route of the swarm collector, holds no Secret, and keeps its cursor
# in a volume, so a second Job pushes nothing, and starts with no state
@ -347,6 +348,7 @@ pkgs.testers.runNixOSTest {
pkgs.jq
pkgs.openssl
pkgs.natscli
pkgs.dig
];
environment.variables.KUBECONFIG = "/etc/rancher/k3s/k3s.yaml";
# The store paths each daemon's `claude` pulls in, so the script can find
@ -742,6 +744,55 @@ pkgs.testers.runNixOSTest {
mounts = stt_spec["containers"][0]["volumeMounts"]
assert any(m["name"] == "state" and m["mountPath"] == "/var/lib/swarm-stt" for m in mounts), mounts
def pod_pid(service: str) -> str:
container = machine.succeed(f"k3s crictl ps --name '^{service}$' --state running -q").split()[0]
return machine.succeed(f"k3s crictl inspect {container} | jq -r .info.pid").strip()
def dials(pid: str, address: str, port: int) -> str:
"""A command that opens a TCP connection from the network namespace of
the process `pid`, as the pod in it would."""
return f"nsenter --target {pid} --net -- timeout 5 bash -c '</dev/tcp/{address}/{port}'"
with subtest("the speech-to-text pod answers a request on the queue, the path production uses, with its decoder running"):
assert json.loads(kube(machine, f"get networkpolicy {STT} -o json"))["spec"]["policyTypes"] == ["Ingress", "Egress"]
out = machine.succeed(f"nats {NATS} req '$SWARM.stt.transcribe.{AGENT}' 'OggS not really audio' --timeout 90s 2>/dev/null")
reply = json.loads([line for line in out.splitlines() if line.startswith("{")][-1])
print(f"stt reply: {reply}")
# The audio looks like Ogg, so ffmpeg is started in the pod and refuses it.
assert reply == {"status": "failed", "message": "the audio could not be decoded"}, reply
with subtest("the speech-to-text pod reaches the host ports its policy names and the cluster's DNS, and no other port of the host"):
stt_pid = pod_pid(STT)
router_pid = pod_pid(SERVICE)
# A listener on a port no policy names, on the bridge's address. The
# host and the router's pod, which has no policy, reach it: the control
# that the listener is up and a pod can dial it.
machine.succeed("systemd-run --unit=exfil-standin ${pkgs.socat}/bin/socat TCP-LISTEN:9999,bind=${bridgeIp},reuseaddr,fork /dev/null")
machine.wait_until_succeeds("timeout 5 bash -c '</dev/tcp/${bridgeIp}/9999'", timeout=30)
machine.succeed(dials(router_pid, "${bridgeIp}", 9999))
for port in (${toString podPort}, 443, ${toString natsPort}):
machine.succeed(dials(stt_pid, "${bridgeIp}", port))
cluster_dns = kube(machine, "-n kube-system get service kube-dns -o jsonpath='{.spec.clusterIP}'").strip()
machine.succeed(f"nsenter --target {stt_pid} --net -- dig +short +time=5 +tries=1 @{cluster_dns} ${baoName} | grep -qx ${bridgeIp}")
# The pod's own policy refuses what it names no port for. Waited for
# first: the policy engine syncs a moment after the pod starts.
machine.wait_until_fails(dials(stt_pid, "${bridgeIp}", 9999), timeout=60)
for _ in range(3):
assert machine.execute(dials(stt_pid, "${bridgeIp}", 9999))[0] != 0
classifier_ip = kube(machine, f"get pod {DAEMON_PODS[CLASSIFIER]} -o jsonpath='{{.status.podIP}}'").strip()
machine.succeed(dials(router_pid, classifier_ip, 8080))
assert machine.execute(dials(stt_pid, classifier_ip, 8080))[0] != 0
with subtest("no peer pod reaches the speech-to-text pod, and the kubelet's probes still do"):
stt_ip = kube(machine, f"get pod {stt_pod} -o jsonpath='{{.status.podIP}}'").strip()
# Another pod reaches a pod with no policy on its health port, and
# the node reaches the speech-to-text pod's.
machine.succeed(dials(router_pid, classifier_ip, 8080))
machine.succeed(f"timeout 5 bash -c '</dev/tcp/{stt_ip}/8080'")
machine.wait_until_fails(dials(router_pid, stt_ip, 8080), timeout=60)
status = json.loads(kube(machine, f"get pod {stt_pod} -o json"))["status"]
assert status["containerStatuses"][0]["ready"] and status["containerStatuses"][0]["restartCount"] == 0, status
with subtest("the poller's Job completes against the forge and pushes the run to the poller's own route with a token the identity provider minted"):
tokens_before = int(machine.succeed(f"grep -cF '/api/oidc/token ${ci}:{CI_SECRET}' ${tokenLog} || true"))
job_log = ci_job(f"{CI}-first")
@ -1010,6 +1061,7 @@ pkgs.testers.runNixOSTest {
assert service_pods(STT) == [], service_pods(STT)
assert machine.execute(f"kubectl -n {NS} get deployment {STT}")[0] != 0
assert machine.execute(f"kubectl -n kube-system get addons.k3s.cattle.io {STT}")[0] != 0
assert machine.execute(f"kubectl -n {NS} get networkpolicy {STT}")[0] != 0
assert machine.execute(f"test -e {MANIFESTS}/{STT}.yaml")[0] != 0
assert machine.execute(f"test -e {MANIFESTS}/{STT}.yaml.pruning")[0] != 0
pruned_stt = int(machine.succeed(f"systemctl show -p ExecMainExitTimestampMonotonic --value {STT_PRUNE}.service"))