Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download-sbom: make auth work with curl < 7.83.0 #1286

Merged
merged 2 commits into from
Aug 12, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,34 @@ spec:
# -> https://registry.com/v2/namespace/repo/blobs/sha256:digest
blob_url=$(sed -E 's;([^/]*)/(.*)@(.*);https://\1/v2/\2/blobs/\3;' <<< "$blob_ref")

local tmp_dest=$(mktemp --tmpdir)
local tmp_dest
tmp_dest=$(mktemp --tmpdir download-sbom-task.out.XXXXXX)

local headers_file
headers_file=$(mktemp --tmpdir download-sbom-task.headers.XXXXXX)

local common_curl_opts=(--silent --show-error --retry "${HTTP_RETRIES:-3}")

echo "GET $blob_url" >&2
local outputs
mapfile -t outputs < <(curl \
local response_code
response_code=$(curl \
"${common_curl_opts[@]}" \
-L \
--write-out '%header{www-authenticate}\n%{response_code}' \
--write-out '%{response_code}' \
--output "$tmp_dest" \
--dump-header "$headers_file" \
"$blob_url"
)
local www_authenticate=${outputs[0]}
local response_code=${outputs[1]}

if [[ "$response_code" -eq 200 ]]; then
# Blob download didn't require auth, we're done
:
elif [[ "$response_code" -eq 401 ]]; then
echo "Got 401, trying to authenticate" >&2

local www_authenticate
www_authenticate=$(sed -n 's/^www-authenticate:\s*//ip' "$headers_file")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.


local realm service scope token_url
realm=$(get_from_www_auth_header "$www_authenticate" realm)
service=$(get_from_www_auth_header "$www_authenticate" service)
Expand Down
Loading