Skip to content

Commit 3e840cc

Browse files
committed
fix: use env -i for az login to strip GHA env pollution
1 parent ffa8e8f commit 3e840cc

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

.github/workflows/e2e-release-validation.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,32 @@ jobs:
123123
124124
- name: Azure Login (Managed Identity)
125125
run: |
126-
# GitHub Actions injects IDENTITY_ENDPOINT / IDENTITY_HEADER which
127-
# cause az CLI to bypass IMDS and hit the Actions OIDC endpoint.
128-
# Unsetting them forces az CLI to use the VM's IMDS for managed identity.
129-
unset IDENTITY_ENDPOINT IDENTITY_HEADER
130-
unset MSI_ENDPOINT MSI_SECRET
131-
unset ACTIONS_ID_TOKEN_REQUEST_URL ACTIONS_ID_TOKEN_REQUEST_TOKEN
126+
set -euo pipefail
132127
133128
if [ -z "$AZURE_CLIENT_ID" ]; then
134129
echo "::error::AZURE_CLIENT_ID secret is empty or not set"
135130
exit 1
136131
fi
137132
138-
echo "Authenticating via user-assigned managed identity..."
139-
az login --identity \
140-
--client-id "$AZURE_CLIENT_ID" \
141-
--output none
142-
az account set --subscription "$E2E_AZURE_SUBSCRIPTION_ID"
133+
# Debug: show identity-related env vars that may confuse az CLI
134+
echo "=== Identity-related env vars in GHA runner ==="
135+
env | sort | grep -iE '^(IDENTITY|MSI_|ACTIONS_ID|AZURE_)' \
136+
| sed 's/=.*/=<set>/' || echo "(none)"
137+
echo "=== end ==="
138+
139+
# Run az login in a stripped environment so that no GHA/OIDC/App-Service
140+
# variables trick azure-identity into a non-IMDS code-path.
141+
CLIENT_ID="$AZURE_CLIENT_ID"
142+
SUB_ID="$E2E_AZURE_SUBSCRIPTION_ID"
143+
144+
env -i \
145+
HOME="$HOME" \
146+
PATH="$PATH" \
147+
LANG="${LANG:-C.UTF-8}" \
148+
AZURE_CONFIG_DIR="${AZURE_CONFIG_DIR:-$HOME/.azure}" \
149+
bash -c "az login --identity --client-id '${CLIENT_ID}' --output none"
150+
151+
az account set --subscription "$SUB_ID"
143152
echo "Logged in. Active subscription:"
144153
az account show --query '{name:name, id:id}' -o table
145154

0 commit comments

Comments
 (0)