Skip to content

Commit 3d795c8

Browse files
oharboeclaude
andcommitted
bazel-hermetic: preserve bazelisk/token env; robust id -un fallback
Two findings from the latest Gemini pass: - Preserve BAZELISK_HOME, BAZELISK_BASE_URL, BAZELISK_GITHUB_TOKEN and GITHUB_TOKEN through the pruned env. These are cache-location / mirror / auth configuration (same class as the proxy and TLS vars already passed), and they matter when the resolved bazel is a bazelisk wrapper used directly via the fallback path: a custom cache dir, an enterprise mirror, or GitHub rate-limit tokens would otherwise be lost. - USER/LOGNAME fall back to `id -un 2>/dev/null || echo nobody`. In a minimal container running under an arbitrary UID with no /etc/passwd entry, `id -un` fails; under set -e the bare `$(id -un)` aborted the exec. Verified with a stubbed failing id: the script now completes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 1c303c7 commit 3d795c8

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

etc/bazel-hermetic

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,14 @@ esac
178178

179179
# Network, auth, TLS and cache/tmp configuration is not toolchain leakage:
180180
# downloads must work behind corporate proxies, custom CAs, and git-over-ssh
181-
# overrides, and users may relocate caches and tmp.
181+
# overrides, and users may relocate caches and tmp. The BAZELISK_* / token
182+
# vars matter when the resolved bazel is a bazelisk wrapper used directly
183+
# (custom cache location, enterprise mirror, GitHub rate limits).
182184
preserved_env=()
183185
for var in http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY \
184186
SSH_AUTH_SOCK SSL_CERT_FILE SSL_CERT_DIR XDG_CACHE_HOME TMPDIR \
185-
DISPLAY WAYLAND_DISPLAY XAUTHORITY; do
187+
DISPLAY WAYLAND_DISPLAY XAUTHORITY \
188+
BAZELISK_HOME BAZELISK_BASE_URL BAZELISK_GITHUB_TOKEN GITHUB_TOKEN; do
186189
# Pure-bash lookup via eval: no subprocess (vs printenv, which also
187190
# silently drops everything if it isn't on PATH), and no ${!var}/-v,
188191
# which are unreliable on the bash 3.2 macOS ships. The names come from
@@ -222,8 +225,8 @@ esac
222225
# an empty HOME; the array guards give the set -u / bash 3.2 safety.
223226
exec env -i \
224227
HOME="${HOME:?etc/bazel-hermetic: HOME must be set}" \
225-
USER="${USER:-$(id -un)}" \
226-
LOGNAME="${LOGNAME:-$(id -un)}" \
228+
USER="${USER:-$(id -un 2>/dev/null || echo nobody)}" \
229+
LOGNAME="${LOGNAME:-$(id -un 2>/dev/null || echo nobody)}" \
227230
TERM="${TERM:-dumb}" \
228231
LANG="${lang}" \
229232
PATH="${TOOLBOX}" \

0 commit comments

Comments
 (0)