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

Remove extra call to docker credentials #9545

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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 @@ -289,7 +289,10 @@ private AuthConfig runCredentialProvider(String hostName, String helperOrStoreNa
final String responseErrorMsg = data.getStdout();

if (!StringUtils.isBlank(responseErrorMsg)) {
String credentialsNotFoundMsg = getGenericCredentialsNotFoundMsg(credentialProgramName);
String credentialsNotFoundMsg = getGenericCredentialsNotFoundMsg(
responseErrorMsg,
credentialProgramName
);
if (credentialsNotFoundMsg != null && credentialsNotFoundMsg.equals(responseErrorMsg)) {
log.info(
"Credential helper/store ({}) does not have credentials for {}",
Expand Down Expand Up @@ -346,48 +349,13 @@ private String effectiveRegistryName(DockerImageName dockerImageName) {
);
}

private String getGenericCredentialsNotFoundMsg(String credentialHelperName) {
private String getGenericCredentialsNotFoundMsg(String credentialsNotFoundMsg, String credentialHelperName) {
if (!CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.containsKey(credentialHelperName)) {
String credentialsNotFoundMsg = discoverCredentialsHelperNotFoundMessage(credentialHelperName);
if (!StringUtils.isBlank(credentialsNotFoundMsg)) {
CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.put(credentialHelperName, credentialsNotFoundMsg);
}
CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.put(credentialHelperName, credentialsNotFoundMsg);
}

return CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.get(credentialHelperName);
}

private String discoverCredentialsHelperNotFoundMessage(String credentialHelperName) {
// will do fake call to given credential helper to find out with which message
// it response when there are no credentials for given hostName

// hostName should be valid, but most probably not existing
// IF its not enough, then should probably run 'list' command first to be sure...
final String notExistentFakeHostName = "https://not.a.real.registry/url";

String credentialsNotFoundMsg = null;
try {
CredentialOutput data = runCredentialProgram(notExistentFakeHostName, credentialHelperName);

if (data.getStdout() != null && !data.getStdout().isEmpty()) {
credentialsNotFoundMsg = data.getStdout();

log.debug(
"Got credentials not found error message from docker credential helper - {}",
credentialsNotFoundMsg
);
}
} catch (Exception e) {
log.warn(
"Failure running docker credential helper ({}) with fake call, expected 'credentials not found' response. Exception message: {}",
credentialHelperName,
e.getMessage()
);
}

return credentialsNotFoundMsg;
}

private CredentialOutput runCredentialProgram(String hostName, String credentialHelperName)
throws InterruptedException, TimeoutException, IOException {
String[] command = SystemUtils.IS_OS_WINDOWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void lookupAuthConfigWithCredentialsNotFound() throws URISyntaxException,

assertThat(discoveredMessage)
.as("Not correct message discovered")
.isEqualTo("Fake credentials not found on credentials store 'https://not.a.real.registry/url'");
.isEqualTo("Fake credentials not found on credentials store 'registry2.example.com'");
}

@Test
Expand Down
4 changes: 0 additions & 4 deletions core/src/test/resources/auth-config/docker-credential-fake
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ if [ "$inputLine" = "registry2.example.com" ]; then
echo Fake credentials not found on credentials store \'$inputLine\' 0>&2
exit 1
fi
if [ "$inputLine" = "https://not.a.real.registry/url" ]; then
echo Fake credentials not found on credentials store \'$inputLine\' 0>&2
exit 1
fi

if [ "$inputLine" = "registry.example.com" ]; then
echo '{' \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ if "%inputLine%" == "registry2.example.com" (
echo Fake credentials not found on credentials store '%inputLine%' 0>&2
exit 1
)
if "%inputLine%" == "https://not.a.real.registry/url" (
echo Fake credentials not found on credentials store '%inputLine%' 0>&2
exit 1
)

if "%inputLine%" == "registry.example.com" (
echo {
Expand Down
Loading