diff --git a/tools/bazel/go_test_offline.sh b/tools/bazel/go_test_offline.sh index b0718fe52..726cb053c 100755 --- a/tools/bazel/go_test_offline.sh +++ b/tools/bazel/go_test_offline.sh @@ -8,8 +8,23 @@ # code under test needs no outbound network. The workers allow unprivileged # user namespaces; a host that does not fails here rather than running the # test with the network it is meant to be without. +# +# The rbe-west fork tier forbids nested namespaces (unshare fails with ENOSPC) +# but already runs every action loopback only. There, and anywhere else +# unshare is unavailable, the binary runs as is, but only after the same +# outbound probe proves the network is absent; a host with network and no +# namespaces still fails. set -euo pipefail export GO_TEST_RUN_FROM_BAZEL=1 +if ! unshare --user --map-root-user --net -- true 2>/dev/null; then + if timeout 3 bash -c "exec 3<>/dev/tcp/1.1.1.1/443" 2>/dev/null; then + echo "go_test_offline: no network namespace available (unshare failed) and outbound network is reachable" >&2 + exit 1 + fi + bin="$1" + shift + exec "./$bin" "$@" +fi exec unshare --user --map-root-user --net -- bash -euc ' ip link set lo up # Prove the namespace really has no outbound network before trusting