resolve k3d API through runner network gateway
Kube-bench CIS scan / Scan ephemeral K3s cluster (push) Failing after 1m14s

This commit is contained in:
2026-08-11 17:04:27 -04:00
parent c0a6c050b5
commit 048575fa18
+11 -2
View File
@@ -47,8 +47,17 @@ jobs:
api_host=127.0.0.1 api_host=127.0.0.1
if getent hosts host.docker.internal >/dev/null 2>&1; then if getent hosts host.docker.internal >/dev/null 2>&1; then
api_host=host.docker.internal api_host=host.docker.internal
elif command -v ip >/dev/null 2>&1; then elif command -v docker >/dev/null 2>&1; then
api_host="$(ip route | awk '/default/ {print $3; exit}')" docker_gateway="$(docker network inspect bridge --format '{{(index .IPAM.Config 0).Gateway}}' 2>/dev/null || true)"
if [[ -n "$docker_gateway" ]]; then
api_host="$docker_gateway"
fi
fi
if [[ "$api_host" == 127.0.0.1 && -r /proc/net/route ]]; then
gateway_hex="$(awk '$2 == "00000000" {print $3; exit}' /proc/net/route)"
if [[ "$gateway_hex" =~ ^[0-9A-Fa-f]{8}$ ]]; then
api_host="$((16#${gateway_hex:6:2})).$((16#${gateway_hex:4:2})).$((16#${gateway_hex:2:2})).$((16#${gateway_hex:0:2}))"
fi
fi fi
sed -i -E "s#https://0\.0\.0\.0:#https://${api_host}:#" "$HOME/.kube/config" sed -i -E "s#https://0\.0\.0\.0:#https://${api_host}:#" "$HOME/.kube/config"
kubectl wait --for=condition=Ready nodes --all --timeout=180s kubectl wait --for=condition=Ready nodes --all --timeout=180s