Skip to content

DockerRegistryConfigAuthentication uses the wrong serverUrl as a fallback for the Credentials helper #45345

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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 @@ -85,14 +85,13 @@ private String getServerUrl(ImageReference imageReference) {
private DockerRegistryAuthentication getAuthentication(String serverUrl) {
Credential credentialsFromHelper = getCredentialsFromHelper(serverUrl);
Map.Entry<String, Auth> authConfigEntry = getAuthConfigEntry(serverUrl);
serverUrl = (authConfigEntry != null) ? authConfigEntry.getKey() : serverUrl;
Auth authConfig = (authConfigEntry != null) ? authConfigEntry.getValue() : null;
if (credentialsFromHelper != null) {
return getAuthentication(credentialsFromHelper, authConfig, serverUrl);
}
if (authConfigEntry != null) {
return DockerRegistryAuthentication.user(authConfig.getUsername(), authConfig.getPassword(), serverUrl,
authConfig.getEmail());
if (authConfig != null) {
return DockerRegistryAuthentication.user(authConfig.getUsername(), authConfig.getPassword(),
authConfigEntry.getKey(), authConfig.getEmail());
}
return this.fallback;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,36 @@ void getAuthHeaderReturnsFallbackWhenImageReferenceNull(@ResourcesRoot Path dire
then(desktopHelper).should(never()).get(any(String.class));
}

@WithResource(name = "config.json", content = """
{
"auths": {
"https://my-registry.example.com": {
"email": "test@gmail.com"
}
},
"credsStore": "desktop"
}
""")
@WithResource(name = "credentials.json", content = """
{
"Username": "username",
"Secret": "secret"
}
""")
@Test
void getAuthHeaderWhenUsingHelperFromCredHelpersUsesImageReferenceServerUrlAsFallback(@ResourcesRoot Path directory)
throws Exception {
this.environment.put("DOCKER_CONFIG", directory.toString());
mockHelper("desktop", "my-registry.example.com", "credentials.json");
ImageReference imageReference = ImageReference.of("my-registry.example.com/ubuntu:latest");
String authHeader = getAuthHeader(imageReference);
assertThat(decode(authHeader)).hasSize(4)
.containsEntry("serveraddress", "my-registry.example.com")
.containsEntry("username", "username")
.containsEntry("password", "secret")
.containsEntry("email", "test@gmail.com");
}

private String getAuthHeader(ImageReference imageReference) {
return getAuthHeader(imageReference, null);
}
Expand Down