#!/usr/bin/env bash # Same two gateway apps, three release trains, three trusted-proxy settings. Writes output/20-*.txt ... 23-*.txt set -uo pipefail cd "$(dirname "$0")/.." TRAINS=("4.1.3 2025.1.3" "4.1.3 2025.1.5" "4.2.0 2026.0.0") build() { # flavour boot cloud local dir=run/probe-$1-$3 [ -d "$dir/dependency" ] && return mvn -B -q -f probes/gateway-$1/pom.xml -Dboot.version=$2 -Dcloud.version=$3 clean package ${MVN_ARGS:-} >/dev/null || exit 1 mkdir -p "$dir"; cp -r probes/gateway-$1/target/classes probes/gateway-$1/target/dependency "$dir/" } if [ "${1:-}" = "--build" ]; then for t in "${TRAINS[@]}"; do read -r boot cloud <<<"$t"; build webmvc $boot $cloud; build webflux $boot $cloud; done exit 0 fi unset JAVA_TOOL_OPTIONS # only for the runs: Maven above may need it start_gw() { # flavour cloud extra-args... local flavour=$1 cloud=$2; shift 2 java -Xmx200m -XX:+UseSerialGC -cp "run/probe-$flavour-$cloud/classes:run/probe-$flavour-$cloud/dependency/*" \ com.ankurm.upgrade.GatewayProbeApplication "$@" > run/probe.log 2>&1 & GW=$! for _ in $(seq 1 60); do curl -s -o /dev/null localhost:8090/ && return; sleep 1; done echo "gateway did not start" >&2; tail -20 run/probe.log >&2; exit 1 } stop_gw() { kill $GW; wait $GW 2>/dev/null; } java scripts/Echo.java 9091 > run/echo.log 2>&1 & ECHO=$! trap 'kill $ECHO 2>/dev/null' EXIT for _ in $(seq 1 30); do curl -s -o /dev/null localhost:9091/headers && break; sleep 1; done FORGED=(-H 'Forwarded: for=198.51.100.7;proto=https' -H 'X-Forwarded-For: 198.51.100.7' -H 'X-Forwarded-Proto: https') n=20 for flavour in webmvc webflux; do F=output/$n-trusted-proxies-$flavour.txt; : > $F { echo "# Gateway Server $flavour. The client is 127.0.0.1 and sends forged headers:" echo "# Forwarded: for=198.51.100.7;proto=https X-Forwarded-For: 198.51.100.7 X-Forwarded-Proto: https" echo "# Below: the forwarding headers the backend actually received."; } >> $F for t in "${TRAINS[@]}"; do read -r boot cloud <<<"$t" for setting in unset '10\..*' '127\.0\.0\.1'; do args=() [ "$setting" != unset ] && args=("--spring.cloud.gateway.server.$flavour.trusted-proxies=$setting") start_gw $flavour $cloud "${args[@]}" case "$setting" in unset) label="trusted-proxies not set";; '10\..*') label="trusted-proxies=$setting (caller NOT trusted)";; *) label="trusted-proxies=$setting (caller trusted)";; esac { echo; echo "=== Boot $boot / Spring Cloud $cloud | $label"; curl -s "${FORGED[@]}" localhost:8090/headers; } >> $F stop_gw done done n=$((n+1)) done # Behind a load balancer: the peer (127.0.0.1) plays the balancer and reports the real client, 203.0.113.50. H=output/24-behind-load-balancer.txt; : > $H echo "# 127.0.0.1 plays a load balancer. It sends: X-Forwarded-For: 203.0.113.50 Forwarded: for=203.0.113.50;proto=https" >> $H echo "# 203.0.113.50 is the real client. Does it survive the gateway?" >> $H LB=(-H 'X-Forwarded-For: 203.0.113.50' -H 'Forwarded: for=203.0.113.50;proto=https') for flavour in webmvc webflux; do for t in "${TRAINS[@]}"; do read -r boot cloud <<<"$t" for setting in '127\.0\.0\.1' '127\.0\.0\.1|203\.0\.113\.50'; do start_gw $flavour $cloud "--spring.cloud.gateway.server.$flavour.trusted-proxies=$setting" { echo; echo "=== $flavour | Spring Cloud $cloud | trusted-proxies=$setting"; curl -s "${LB[@]}" localhost:8090/headers | grep -E '^(x-forwarded-for|forwarded):'; } >> $H stop_gw done done done F=output/22-retry-filter-webflux.txt; : > $F echo "# WebFlux gateway, Retry filter (retries: 3, statuses: INTERNAL_SERVER_ERROR) in front of a backend that always answers 500." >> $F G=output/23-websocket-origin-webflux.txt; : > $G echo "# WebFlux gateway with a ws:// route. A handshake with a foreign Origin header." >> $G echo "# The backend is a plain HTTP server, so a handshake the gateway lets through fails further down." >> $G for t in "${TRAINS[@]}"; do read -r boot cloud <<<"$t" start_gw webflux $cloud curl -s -o /dev/null localhost:8090/count { echo; echo "=== Boot $boot / Spring Cloud $cloud" echo "client status: $(curl -s -o /dev/null -w '%{http_code}' localhost:8090/flaky)" curl -s localhost:8090/count; } >> $F { echo; echo "=== Boot $boot / Spring Cloud $cloud" curl -s -i --max-time 5 -H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' \ -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' -H 'Origin: https://evil.example' localhost:8090/ws/chat | head -1 | tr -d '\r' echo; } >> $G stop_gw done cat output/22*.txt output/23*.txt output/24*.txt