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

Add function for fetching ECR registry credentials that are compatible with pulumi-docker & pulumi-docker-build #5029

Open
flostadler opened this issue Jan 3, 2025 · 1 comment
Labels
area/patch An issue describing an existing patch on upstream and the criteria to close it. impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features

Comments

@flostadler
Copy link
Contributor

Using the existing aws.ecr.getCredentials returns credentials that cannot directly be used with pulumi-docker or pulumi-docker-build.
Right now it returns a base64-encoded authorization token containing the username AWS and the password.
In order to make use of them, users first need to base64 decode it, split the string apart and then create the authorization data for the docker providers. This is not intuitive or easy to find. I'm not aware of any scenario where a user would want the raw base64 encoded version because all container tools I know expect user/pass as separate arguments.

The current way of using ECR with the pulumi-docker providers looks like this:

const registryInfo = repo.registryId.apply(async id => {
    const credentials = await aws.ecr.getCredentials({ registryId: id });
    const decodedCredentials = Buffer.from(credentials.authorizationToken, "base64").toString();
    const [username, password] = decodedCredentials.split(":");
    if (!password || !username) {
        throw new Error("Invalid credentials");
    }
    return {
        address: credentials.proxyEndpoint,
        username: username,
        password: password,
    };
});

// or alternatively docker.Image, docker-build.Image
const ecrProvider = new docker.Provider("ecr-provider", {
    registryAuth: [registryInfo],
});

If we had a convenience function that directly returns the data in the right format it could be simplified to this:

const registryInfo = aws.ecr.getDockerCredentialsOutput({ registryId: repo.registryId });
const ecrProvider = new docker.Provider("ecr-provider", {
    registryAuth: [registryInfo],
});

Additionally, the registryId could be made optional because it's the account ID of the ECR repo. If users do not specify a registryId we can default it to the current AWS account.

NOTE: The existing aws.ecr.getCredentials function is implemented as a patch: #4678. When tackling this, we could think about promoting it to a native provider function.

@flostadler flostadler added area/patch An issue describing an existing patch on upstream and the criteria to close it. impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features labels Jan 3, 2025
@flostadler
Copy link
Contributor Author

Turns out there's a function from upstream now, which we can use for that: aws.ecr.getAuthorizationToken. It's a bit unfortunate that a lot of users (me included) would pick aws.ecr.getCredentials over aws.ecr.getAuthorizationToken because they're looking for Credentials...

We should mark getCredentials as deprecated in favor of getAuthorizationToken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/patch An issue describing an existing patch on upstream and the criteria to close it. impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

1 participant