Skip to content

Commit 56e0232

Browse files
committed
Add KMS retry logic to handle transient 500/503
KMS has been intermittently returning 500/503 errors during CI. Added exponential backoff retry (5 attempts) to all curl calls.
1 parent b8cde5b commit 56e0232

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

.github/workflows/deploy.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ jobs:
2828
set -euo pipefail
2929
KMS_URL="${KMS_URL:-https://kms.hanzo.ai}"
3030
31+
retry() {
32+
local n=0
33+
until [ $n -ge 5 ]; do
34+
"$@" && return 0
35+
n=$((n+1)); echo "::warning::Retry $n/5..."; sleep $((n*5))
36+
done
37+
return 1
38+
}
39+
3140
ACCESS_TOKEN="$(
32-
curl -fsS -X POST "${KMS_URL}/api/v1/auth/universal-auth/login" \
41+
retry curl -fsS -X POST "${KMS_URL}/api/v1/auth/universal-auth/login" \
3342
-H "Content-Type: application/json" \
3443
-d "$(jq -nc --arg cid "$KMS_CLIENT_ID" --arg cs "$KMS_CLIENT_SECRET" \
3544
'{clientId: $cid, clientSecret: $cs}')" \
@@ -40,7 +49,7 @@ jobs:
4049
echo "::error::Failed to authenticate to Hanzo KMS"; exit 1; }
4150
4251
fetch_secret() {
43-
curl -fsS "${KMS_URL}/api/v3/secrets/raw/${1}?workspaceSlug=gitops&environment=prod&secretPath=/ci&viewSecretValue=true&include_imports=true" \
52+
retry curl -fsS "${KMS_URL}/api/v3/secrets/raw/${1}?workspaceSlug=gitops&environment=prod&secretPath=/ci&viewSecretValue=true&include_imports=true" \
4453
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
4554
| jq -r '.secret.secretValue'
4655
}
@@ -111,8 +120,17 @@ jobs:
111120
set -euo pipefail
112121
KMS_URL="${KMS_URL:-https://kms.hanzo.ai}"
113122
123+
retry() {
124+
local n=0
125+
until [ $n -ge 5 ]; do
126+
"$@" && return 0
127+
n=$((n+1)); echo "::warning::Retry $n/5..."; sleep $((n*5))
128+
done
129+
return 1
130+
}
131+
114132
ACCESS_TOKEN="$(
115-
curl -fsS -X POST "${KMS_URL}/api/v1/auth/universal-auth/login" \
133+
retry curl -fsS -X POST "${KMS_URL}/api/v1/auth/universal-auth/login" \
116134
-H "Content-Type: application/json" \
117135
-d "$(jq -nc --arg cid "$KMS_CLIENT_ID" --arg cs "$KMS_CLIENT_SECRET" \
118136
'{clientId: $cid, clientSecret: $cs}')" \
@@ -122,13 +140,8 @@ jobs:
122140
[ -n "${ACCESS_TOKEN}" ] && [ "${ACCESS_TOKEN}" != "null" ] || {
123141
echo "::error::Failed to authenticate to Hanzo KMS"; exit 1; }
124142
125-
fetch_secret() {
126-
curl -fsS "${KMS_URL}/api/v3/secrets/raw/${1}?workspaceSlug=gitops&environment=prod&secretPath=/ci&viewSecretValue=true&include_imports=true" \
127-
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
128-
| jq -r '.secret.secretValue'
129-
}
130-
131-
val="$(fetch_secret "DIGITALOCEAN_ACCESS_TOKEN")"
143+
val="$(retry curl -fsS "${KMS_URL}/api/v3/secrets/raw/DIGITALOCEAN_ACCESS_TOKEN?workspaceSlug=gitops&environment=prod&secretPath=/ci&viewSecretValue=true&include_imports=true" \
144+
-H "Authorization: Bearer ${ACCESS_TOKEN}" | jq -r '.secret.secretValue')"
132145
[ -n "$val" ] && [ "$val" != "null" ] || { echo "::error::Missing KMS secret DIGITALOCEAN_ACCESS_TOKEN"; exit 1; }
133146
echo "::add-mask::${val}"
134147
echo "DIGITALOCEAN_ACCESS_TOKEN=${val}" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)