Skip to content

Commit ba7bc0a

Browse files
authored
fix: add retry to curl downloads for transient network failures (#210)
Transient network errors during the cosign download can cause the action to fail. This is particularly problematic when the action runs after images have been pushed to a registry, resulting in unsigned images. Add --retry 3 to all curl calls. By default, curl uses exponential backoff: it waits 1 second before the first retry, then doubles the wait time for each subsequent retry up to a maximum of 10 minutes. It also respects Retry-After headers in the response. Closes: #209 Signed-off-by: Jose Fernandez <me@jrfernandez.com>
1 parent 5a292e1 commit ba7bc0a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

action.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ runs:
4646
fi
4747
set -e
4848
49+
CURL_RETRIES=3
50+
4951
# This function helps compare versions.
5052
# Returns 0 if version1 >= version2, 1 otherwise.
5153
# Usage: is_version_ge "3.0.0" "$version_num"
@@ -187,7 +189,7 @@ runs:
187189
188190
expected_bootstrap_version_digest=${bootstrap_sha}
189191
log_info "Downloading bootstrap version '${bootstrap_version}' of cosign to verify version to be installed...\n https://github.com/sigstore/cosign/releases/download/${bootstrap_version}/${bootstrap_filename}"
190-
$SUDO curl -fsSL "https://github.com/sigstore/cosign/releases/download/${bootstrap_version}/${bootstrap_filename}" -o "${cosign_executable_name}"
192+
$SUDO curl --retry "${CURL_RETRIES}" -fsSL "https://github.com/sigstore/cosign/releases/download/${bootstrap_version}/${bootstrap_filename}" -o "${cosign_executable_name}"
191193
shaBootstrap=$(shaprog "${cosign_executable_name}")
192194
if [[ "$shaBootstrap" != "${expected_bootstrap_version_digest}" ]]; then
193195
log_error "Unable to validate cosign version: '${input_cosign_release}'"
@@ -211,7 +213,7 @@ runs:
211213
212214
# Download custom cosign
213215
log_info "Downloading platform-specific version '${input_cosign_release}' of cosign...\n https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${desired_cosign_filename}"
214-
$SUDO curl -fsSL "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${desired_cosign_filename}" -o "cosign_${input_cosign_release}"
216+
$SUDO curl --retry "${CURL_RETRIES}" -fsSL "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${desired_cosign_filename}" -o "cosign_${input_cosign_release}"
215217
shaCustom=$(shaprog "cosign_${input_cosign_release}");
216218
217219
# same hash means it is the same release
@@ -221,7 +223,7 @@ runs:
221223
RELEASE_COSIGN_PUB_KEY_SHA='f4cea466e5e887a45da5031757fa1d32655d83420639dc1758749b744179f126'
222224
223225
log_info "Verifying public key matches expected value"
224-
$SUDO curl -fsSL "$RELEASE_COSIGN_PUB_KEY" -o public.key
226+
$SUDO curl --retry "${CURL_RETRIES}" -fsSL "$RELEASE_COSIGN_PUB_KEY" -o public.key
225227
sha_fetched_key=$(shaprog public.key)
226228
if [[ "$sha_fetched_key" != "$RELEASE_COSIGN_PUB_KEY_SHA" ]]; then
227229
log_error "Fetched public key does not match expected digest, exiting"
@@ -232,7 +234,7 @@ runs:
232234
# we're trying to get something greater than or equal to v3.0.1
233235
keyless_signature_file=${desired_cosign_filename}.sigstore.json
234236
log_info "Downloading keyless verification bundle for platform-specific '${input_cosign_release}' of cosign...\n https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${keyless_signature_file}"
235-
$SUDO curl -fsSLO "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${keyless_signature_file}"
237+
$SUDO curl --retry "${CURL_RETRIES}" -fsSLO "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${keyless_signature_file}"
236238
237239
log_info "Using bootstrap cosign to verify keyless signature of desired cosign version"
238240
"./${cosign_executable_name}" verify-blob --certificate-identity=keyless@projectsigstore.iam.gserviceaccount.com --certificate-oidc-issuer=https://accounts.google.com --bundle "${keyless_signature_file}" "cosign_${input_cosign_release}"
@@ -241,15 +243,15 @@ runs:
241243
# we're trying to get something greater than or equal to v3.0.3
242244
kms_signature_file=${desired_cosign_filename}-kms.sigstore.json
243245
log_info "Downloading KMS verification bundle for platform-specific '${input_cosign_release}' of cosign...\n https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${kms_signature_file}"
244-
$SUDO curl -fsSLO "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${kms_signature_file}"
246+
$SUDO curl --retry "${CURL_RETRIES}" -fsSLO "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${kms_signature_file}"
245247
246248
log_info "Using bootstrap cosign to verify signature of desired cosign version"
247249
"./${cosign_executable_name}" verify-blob --key public.key --bundle "${kms_signature_file}" "cosign_${input_cosign_release}"
248250
fi
249251
else
250252
signature_file=${desired_cosign_filename}.sig
251253
log_info "Downloading detached signature for platform-specific '${input_cosign_release}' of cosign...\n https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${signature_file}"
252-
$SUDO curl -fsSLO "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${signature_file}"
254+
$SUDO curl --retry "${CURL_RETRIES}" -fsSLO "https://github.com/sigstore/cosign/releases/download/${input_cosign_release}/${signature_file}"
253255
254256
log_info "Using bootstrap cosign to verify signature of desired cosign version"
255257
"./${cosign_executable_name}" verify-blob --key public.key --signature "${signature_file}" "cosign_${input_cosign_release}"

0 commit comments

Comments
 (0)