Skip to content

Commit

Permalink
fix: handle not-logged-in public repos with credsStore (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahhem authored Jan 25, 2025
1 parent a911e9e commit c9d63b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
11 changes: 11 additions & 0 deletions e2e/assertion/credential-helper/docker-credential-devpod-esque
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
read -r URL


if [[ "$URL" != "localhost:1447" ]]; then
echo "expected registry url to be localhost:1447";
exit 1
fi

echo "{\"ServerURL\": \"$URL\", \"Username\": \"\", \"Secret\": \"\"}"

15 changes: 14 additions & 1 deletion e2e/assertion/oci_pull_auth_tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,17 @@ EOF
update_assert '{"Authorization": ["Basic not_match"]}'
run bazel build @empty_image//... $BAZEL_FLAGS
assert_failure
}
}

@test "empty username and password succeeds" {
cat > "$DOCKER_CONFIG/config.json" <<EOF
{
"credHelpers": {
"localhost:1447": "devpod-esque"
}
}
EOF
update_assert ''
run bazel build @empty_image//... $BAZEL_FLAGS
assert_success
}
2 changes: 1 addition & 1 deletion oci/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _digest(name, **kwargs):
jq(
name = name + ".digest",
args = ["--raw-output"],
srcs = ["_{}_index.json".format(name)],
srcs = ["{}_index.json".format(name)],
filter = """.manifests[0].digest""",
out = name + ".json.sha256", # path chosen to match rules_docker for easy migration
**kwargs
Expand Down
5 changes: 5 additions & 0 deletions oci/private/authn.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ exec "docker-credential-{}" get <<< "$1" """.format(helper_name),

response = json.decode(result.stdout)

# If the username and secret are empty, the user does not have a login.
# Returning {} avoids sending invalid Basic auth headers that result in 401's
if response["Username"] == "" and response["Secret"] == "":
return {}

return {
"type": "basic",
"login": response["Username"],
Expand Down

0 comments on commit c9d63b9

Please sign in to comment.