Skip to content

Commit 580590a

Browse files
authored
fix(create-github-app-token): use temporary file w/ trap for oidc response (#1477)
fix: use temporary file w/ trap for oidc response
1 parent a555663 commit 580590a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

actions/create-github-app-token/auth_vault.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#!/bin/bash
22
set -euo pipefail
33

4+
TEMP_FILE=$(mktemp)
5+
echo "Using temporary file: ${TEMP_FILE}"
6+
trap 'rm -f "${TEMP_FILE}"' EXIT
7+
48
MAX_ATTEMPTS=3
59
for attempt in $(seq 1 "${MAX_ATTEMPTS}"); do
610
echo "Attempt ${attempt} to authenticate with Vault..."
711

8-
RESPONSE=$(curl -sS -w "%{http_code}" -o response.json \
12+
RESPONSE=$(curl -sS -w "%{http_code}" -o "${TEMP_FILE}" \
913
-X POST "${VAULT_URL}/v1/auth/github-actions-oidc/login" \
1014
-H "Content-Type: application/json" \
1115
-H "Proxy-Authorization-Token: Bearer ${GITHUB_JWT_PROXY}" \
@@ -15,14 +19,14 @@ for attempt in $(seq 1 "${MAX_ATTEMPTS}"); do
1519
}" || true)
1620

1721
if [[ "${RESPONSE}" -eq 200 ]]; then
18-
TOKEN=$(jq -r '.auth.client_token' response.json)
22+
TOKEN=$(jq -r '.auth.client_token' "${TEMP_FILE}")
1923
echo "::add-mask::$TOKEN"
2024
echo "vault_token=${TOKEN}" >> "${GITHUB_OUTPUT}"
2125
echo "Vault auth done!"
2226
exit 0
2327
else
2428
echo "Vault auth failed (HTTP ${RESPONSE})"
25-
cat response.json || true
29+
cat "${TEMP_FILE}" || true
2630
sleep $((attempt * 5))
2731
fi
2832
done

0 commit comments

Comments
 (0)