Files
weave/reweave/test/egress/run.sh
T
levaliciousandClaude Opus 5.5 602e2da73c
images / images (push) Failing after 9m54s
lb: one egress tunnel per peer; replies and ICMP errors follow a tag
The holder could tell a member's node only by source port block, so
replies without ports never got back: ICMP errors (path-MTU "too big",
unreachable, time exceeded), ping, and port-less protocols. Now every
node pair has its own ipip tunnel (rweg-<hash of the peer>, between the
two weave bridges), so the holder knows the sending node by the device a
packet arrives on:

- it tags each connection arriving from a peer's tunnel with that peer
  (connmark: peer index in the top byte, plus 0x200000), once;
- replies and related ICMP errors restore the tag, and a policy rule per
  peer (ahead of the local table, like the port rules) routes them into
  that peer's tunnel, where the member node's conntrack translates them
  back to the member;
- an arrival on one peer's tunnel whose connection another peer already
  holds (a port-less protocol to the same remote from two nodes) is
  dropped, never delivered across;
- the stateless port-block rules stay, now for TCP, UDP and SCTP.

Members' SNAT keeps TCP, UDP and SCTP within the node's block and puts
everything else (ping, GRE, ...) on the address alone; the guard lets any
protocol into the holder's tunnel and nothing anywhere else. The holder
only accepts, per tunnel, the address with that node's ports.

Routes in the reply tables are now read with one dump per pass instead of
one per candidate table.

reweave/test/egress/run.sh also checks ping from every node, that ICMP
errors from routers beyond the holder reach a member (traceroute), and
that ping is dropped while nobody holds the address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UHXzGrsxfkGk8LmwrBbHNZ
2026-10-13 19:27:09 -04:00

121 lines
6.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# End-to-end test of EgressService against a live cluster (assertions A1-A6 of the design, plus the first
# packet). Members ask outside services which address they come from: api.ipify.org (TCP) and OpenDNS's
# myip.opendns.com (UDP).
#
# CP="ssh ... root@<cp>" HOLDER_SSH="ssh ... root@<holder>" REMOTE_SSH="ssh ... root@<remote>" \
# ADDR=<address HOLDER holds> HOLDER=<node> REMOTE=<node> OTHER=<node> \
# reweave/test/egress/run.sh
#
# Asserts, in order:
# 0. the holder writes the status: host, address, a port block for every node
# 1. the first packet of a member started after the EgressService leaves as ADDR (CNI admission)
# A1/A2. members on every node leave as ADDR (TCP and UDP) and get their replies; ping works from every node
# ICMP errors from routers on the way (traceroute's time-exceeded) reach a member on another node
# A4. a non-member pod on the same node as a member leaves as its node (untouched), and no rule names it
# A3. a member talking to a pod sees its own pod address there (east-west untouched)
# A5. naming an address nobody holds clears the status, and members' outside traffic (TCP, ping) is dropped
# A6. deleting the EgressService removes its state: members leave as their node again, rules are gone
# Leaves nothing behind (namespace egtest is deleted, also on failure).
set -euo pipefail
: "${CP:?}" "${HOLDER_SSH:?}" "${REMOTE_SSH:?}" "${ADDR:?}" "${HOLDER:?}" "${REMOTE:?}" "${OTHER:?}"
here=$(cd "$(dirname "$0")" && pwd)
k() { $CP "KUBECONFIG=/etc/kubernetes/admin.conf kubectl $*"; }
fail() { echo "FAIL: $*" >&2; exit 1; }
ok() { echo "ok: $*"; }
cleanup() { k delete namespace egtest --ignore-not-found --wait=false >/dev/null 2>&1 || true; }
trap cleanup EXIT
eventually() {
local n=$1; shift
for _ in $(seq "$n"); do
if "$@" >/dev/null 2>&1; then return 0; fi
sleep 1
done
return 1
}
whoami_tcp() { k -n egtest exec "$1" -- curl -s --max-time 10 https://api.ipify.org; }
# each check re-reads on every try of eventually
tcp_is() { [ "$(whoami_tcp "$1" || true)" = "$2" ]; }
whoami_udp() { k -n egtest exec "$1" -- dig +short +time=5 +tries=1 myip.opendns.com @208.67.222.222; }
node_ip() { k get node "$1" -o "jsonpath='{.status.addresses[?(@.type==\"InternalIP\")].address}'"; }
remote_ip=$(node_ip "$REMOTE")
[ -n "$remote_ip" ] || fail "no address for $REMOTE"
sed -e "s/\bADDR\b/$ADDR/g; s/\bHOLDER\b/$HOLDER/g; s/\bREMOTE\b/$REMOTE/g; s/\bOTHER\b/$OTHER/g" \
"$here/egress-test.yaml" | $CP "KUBECONFIG=/etc/kubernetes/admin.conf kubectl apply -f -" >/dev/null
k -n egtest wait --for=condition=Ready pod --all --timeout=300s >/dev/null || fail "test pods not ready"
status() { k -n egtest get egressservice mail -o "jsonpath='{.status.host} {.status.address} {.status.blocks[*].node}'"; }
status_is() { [ "$(status)" = "$1" ]; }
first_line() { k -n egtest logs member-first 2>/dev/null | head -1; }
said_something() { [ -n "$(first_line)" ]; }
want="$HOLDER $ADDR $(printf '%s\n' "$HOLDER" "$REMOTE" "$OTHER" | sort | tr '\n' ' ' | sed 's/ $//')"
eventually 60 status_is "$want" || fail "status: '$(status)', want '$want'"
ok "0. status: host $HOLDER, address $ADDR, a port block for each node"
# a member created now: its very first connection must already leave as ADDR
$CP "KUBECONFIG=/etc/kubernetes/admin.conf kubectl -n egtest run member-first --labels egress=member --restart=Never \
--overrides='{\"spec\":{\"nodeName\":\"$REMOTE\"}}' --image=curlimages/curl:8.10.1 --command -- \
sh -c 'curl -s --max-time 10 https://api.ipify.org; echo; sleep 3600'" >/dev/null
eventually 120 said_something || fail "member-first said nothing"
first=$(first_line)
[ "$first" = "$ADDR" ] || fail "member-first's first connection left as '$first', want $ADDR"
ok "1. a new member's first connection leaves as $ADDR"
for p in member-remote member-other member-holder; do
got=$(whoami_tcp $p || true)
[ "$got" = "$ADDR" ] || fail "A1: $p left as '$got', want $ADDR"
done
got=$(whoami_udp member-dns || true)
[ "$got" = "$ADDR" ] || fail "A1: member-dns (UDP) left as '$got', want $ADDR"
ok "A1/A2. members on $REMOTE, $OTHER and $HOLDER leave as $ADDR over TCP and UDP, replies come back"
for p in member-remote member-other member-holder; do
k -n egtest exec $p -- ping -c 2 -W 3 1.1.1.1 >/dev/null || fail "ping from $p got no reply"
done
ok "ping from members on all three nodes gets its replies"
# hop 1 is the member's own node, hop 2 the holder (it answers its own address, the member cannot see it); every
# later hop is a router on the internet whose time-exceeded comes back to ADDR and must find the member
hops=$(k -n egtest exec member-remote -- traceroute -n -m 8 -q 1 -w 2 1.1.1.1 2>&1 || true)
echo "$hops" | awk '$1 >= 3 && $2 ~ /^[0-9]+\./ {found=1} END {exit !found}' \
|| fail "no router beyond the holder answered the member's traceroute:
$hops"
ok "ICMP errors from routers beyond the holder reach a member on $REMOTE (traceroute)"
got=$(whoami_tcp plain || true)
[ "$got" = "$remote_ip" ] || fail "A4: non-member left as '$got', want its node $remote_ip"
plain_ip=$(k -n egtest get pod plain -o "jsonpath='{.status.podIP}'")
if $REMOTE_SSH "iptables-save | grep -F -- '$plain_ip/32'; ip rule | grep -F -- '$plain_ip'"; then
fail "A4: a rule names the non-member $plain_ip"
fi
ok "A4. the non-member leaves as its node ($remote_ip); no rule names it"
echo_ip=$(k -n egtest get pod echo -o "jsonpath='{.status.podIP}'")
member_ip=$(k -n egtest get pod member-remote -o "jsonpath='{.status.podIP}'")
got=$(k -n egtest exec member-remote -- curl -s --max-time 5 "http://$echo_ip:8080/clientip" || true)
[ "${got%:*}" = "$member_ip" ] || fail "A3: echo saw '$got', want the member's pod address $member_ip"
ok "A3. east-west: the echo pod sees the member's own address ($member_ip)"
k -n egtest patch svc mail --type merge -p "'{\"spec\":{\"loadBalancerIP\":\"192.0.2.1\"}}'" >/dev/null
eventually 60 status_is " " || fail "A5: status not cleared: '$(status)'"
got=$(whoami_tcp member-remote || true)
[ -z "$got" ] || fail "A5: with no holder a member still got out, as '$got'"
if k -n egtest exec member-remote -- ping -c 1 -W 3 1.1.1.1 >/dev/null 2>&1; then
fail "A5: with no holder a member's ping still got out"
fi
k -n egtest patch svc mail --type merge -p "'{\"spec\":{\"loadBalancerIP\":\"$ADDR\"}}'" >/dev/null
eventually 60 status_is "$want" || fail "status not restored: '$(status)'"
eventually 30 tcp_is member-remote "$ADDR" || fail "member did not get back out as $ADDR"
ok "A5. no holder: status cleared, members dropped (not leaked); restored afterwards"
k -n egtest delete egressservice mail >/dev/null
eventually 60 tcp_is member-remote "$remote_ip" || fail "A6: after delete, member left as '$(whoami_tcp member-remote || true)'"
if $REMOTE_SSH "ip rule | grep -E '^9100:'"; then fail "A6: member rules left on $REMOTE"; fi
if $HOLDER_SSH "ip rule | grep -E '^90:'"; then fail "A6: holder rules left on $HOLDER"; fi
ok "A6. EgressService deleted: members leave as their node again, no rules left"
echo PASS