Fix authentication fallback when X-Registry-Auth header contains empty JSON object #27458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When Docker Compose client sends authentication headers, it may send
X-Registry-Auth: e30=(which decodes to{}), representing an empty JSON object. Currently, Podman checks if the authentication header is empty ornull, but doesn't handle the case where the header contains an empty JSON object with credentials. This prevents Podman from falling back to using authentication files on the filesystem.I've noticed this issue when I started using testcontainers-go compose module in CI environment which has no direct internet access and podman configured with mirrors which requires authentication. Since compose client is not aware about mirrors, is not setting the proper value for
X-Registry-Auth(for example compose client thinks that image is being pulled fromdocker.iowhile the correct hostname should be the one of the mirror). Basically the docker compose client doesn't have the full context and it's better to rely on podman selecting the proper authentication token based on the mirror hostnameSolution
This PR extends the authentication header parsing logic to detect and handle empty JSON objects in authentication headers. When an empty authentication configuration is detected (empty username and password), Podman now properly falls back to using the authentication files stored on the filesystem instead of attempting to use the empty header value.
Changes
pkg/auth/auth.gonullor missing headerspkg/auth/auth_test.goTesting
X-Registry-Auth: e30=is sentCompatibility
This change maintains compatibility with Docker Compose and other Docker-compatible clients that send empty authentication objects while expecting Podman to use local credentials stored in authentication files.
Checklist
Ensure you have completed the following checklist for your pull request to be reviewed:
commits. (
git commit -s). (If needed, usegit commit -s --amend). The author email must matchthe sign-off email address. See CONTRIBUTING.md
for more information.
Fixes: #00000in commit message (if applicable)make validatepr(format/lint checks)Noneif no user-facing changes)Does this PR introduce a user-facing change?