Skip to content
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
2 changes: 1 addition & 1 deletion src/registry-auth-locator/auths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Auths implements RegistryAuthLocator {
const authEntries = dockerConfig.auths ?? {};

for (const key in authEntries) {
if (key === registry || key.includes(`://${registry}`)) {
if (key.includes(registry)) {
return authEntries[key];
}
}
Expand Down
26 changes: 16 additions & 10 deletions src/registry-auth-locator/credential-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export abstract class CredentialProvider implements RegistryAuthLocator {
log.debug(`Executing Docker credential provider: ${programName}`);

const credentials = await this.listCredentials(programName);
if (!Object.keys(credentials).some((credential) => credential.includes(registry))) {

const resolvedRegistry = Object.keys(credentials).find((aRegistry) => aRegistry.includes(registry));
if (resolvedRegistry === undefined) {
log.debug(`No credential found for registry: "${registry}"`);
return undefined;
}

const response = await this.runCredentialProvider(registry, programName);
const response = await this.runCredentialProvider(resolvedRegistry, programName);
const authConfig: AuthConfig = {
username: response.Username,
password: response.Secret,
Expand All @@ -40,15 +42,17 @@ export abstract class CredentialProvider implements RegistryAuthLocator {
return new Promise((resolve, reject) => {
exec(`${providerName} list`, (err, stdout) => {
if (err) {
log.error(`An error occurred listing credentials: ${err}`);
return reject(new Error("An error occurred listing credentials"));
const errorMessage = `An error occurred listing credentials: ${err}`;
log.error(errorMessage);
return reject(new Error(errorMessage));
}
try {
const response = JSON.parse(stdout);
return resolve(response);
} catch (e) {
log.error(`Unexpected response from Docker credential provider LIST command: "${stdout}"`);
return reject(new Error("Unexpected response from Docker credential provider LIST command"));
const errorMessage = `Unexpected response from Docker credential provider LIST command: "${stdout}"`;
log.error(errorMessage);
return reject(new Error(errorMessage));
}
});
});
Expand All @@ -63,17 +67,19 @@ export abstract class CredentialProvider implements RegistryAuthLocator {

sink.on("close", (code) => {
if (code !== 0) {
log.error(`An error occurred getting a credential: ${code}`);
return reject(new Error("An error occurred getting a credential"));
const errorMessage = `An error occurred getting a credential. Code: ${code}. Message: ${chunks.join("")}`;
log.error(errorMessage);
return reject(new Error(errorMessage));
}

const response = chunks.join("");
try {
const parsedResponse = JSON.parse(response);
return resolve(parsedResponse);
} catch (e) {
log.error(`Unexpected response from Docker credential provider GET command: "${response}"`);
return reject(new Error("Unexpected response from Docker credential provider GET command"));
const errorMessage = `Unexpected response from Docker credential provider GET command: "${response}"`;
log.error(errorMessage);
return reject(new Error(errorMessage));
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/registry-auth-locator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RegistryAuthLocator } from "./registry-auth-locator";
import { log } from "../logger";
import { AuthConfig } from "../docker/types";

const DEFAULT_REGISTRY = "https://index.docker.io/v1/";
const DEFAULT_REGISTRY = "https://index.docker.io";
Copy link
Contributor

@HofmeisterAn HofmeisterAn Dec 23, 2022

Choose a reason for hiding this comment

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

I think https://index.docker.io/v1/ is correct. That's what Docker Desktop resolves too, see:

What I meant by my comment in Slack is, that the GitLab example uses https://index.docker.io as key, but our default key is https://index.docker.io/v1/. Might be addressed due to key.includes(registry).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@HofmeisterAn Understood, and I found that for the credential provider it didn't work in this case. We check the substring when listing the credentials, but when we go to get the credential we lookup the original registry, which isn't found


const dockerConfigLocation = process.env.DOCKER_CONFIG || `${os.homedir()}/.docker`;

Expand Down