Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bin/test_git_credential_hive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ echo "ghs_stubtoken" >"$TOKEN_CACHE"
# never shadow the HIVE_AGENT_MODE env var the harness sets.
TEST_AGENT="cred-harness-$$"

# The unique name alone is not enough on a live per-UID hive: the helper
# derives AGENT from /var/run/hive/uid-map.json whenever it runs as a
# per-agent UID (>= 2001) — deliberately ignoring HIVE_AGENT, which an agent
# could spoof. Run there, the harness's own UID resolved to the REAL agent
# name, and the helper read that agent's live /tmp/.hive-mode-<agent> instead
# of the mode each case sets — so the mode-notice assertions passed or failed
# with the host's deployment state, not the code. Stub `id -u` to report a
# sub-2001 UID so the helper takes the HIVE_AGENT/HIVE_AGENT_MODE path the
# harness controls; every other `id` invocation passes through.
STUB_BIN="${WORK}/bin"
mkdir -p "$STUB_BIN"
REAL_ID="$(command -v id)"
cat >"$STUB_BIN/id" <<EOF
#!/bin/sh
if [ "\${1:-}" = "-u" ] && [ \$# -eq 1 ]; then echo 1000; exit 0; fi
exec "$REAL_ID" "\$@"
EOF
chmod +x "$STUB_BIN/id"

# run_helper <mode> <acmm> <token_file> <stdin> -- <helper args...>
# Echoes "exit=<code>\n<combined stdout+stderr>" for the assertions below.
run_helper() {
Expand All @@ -38,6 +57,7 @@ run_helper() {
local out rc
out="$(
printf '%b' "$stdin" | \
PATH="${STUB_BIN}:${PATH}" \
HIVE_AGENT="$TEST_AGENT" \
HIVE_AGENT_MODE="$mode" \
HIVE_ACMM_LEVEL="$acmm" \
Expand Down
1 change: 1 addition & 0 deletions changelog.d/fixed-6178-cred-helper-test-hermetic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `bin/test_git_credential_hive.sh` no longer tests the live host instead of itself on per-UID hives. Run as an agent UID (>= 2001), the credential helper derives the agent name from the uid-map — deliberately ignoring the `HIVE_AGENT` the harness sets — and reads that real agent's live `/tmp/.hive-mode-<agent>`, so the two mode-notice assertions failed (or passed vacuously) with the host's deployment state. The harness now stubs `id -u` to a sub-2001 UID so the helper takes the env-var path the harness controls; the helper's own uid-map trust model is untouched.
Loading