Skip to content

Conversation

@scadorel
Copy link

Fixes issue #726.
This is my first PR on this repo, let me know if I need to change anything 👍

Copy link

@thecoshman thecoshman left a comment

Choose a reason for hiding this comment

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

Changes look sensible to me, though as I'm not that familiar with js dev, what's the reason so much ended up needing to be marked as async here?

@scadorel
Copy link
Author

Thanks @thecoshman and sorry for the late reply.
For ECR, I need to call some AWS SDK methods to generate a token, which requires an await (so the getAuthPull() needed to be moved to async as well). But getAuthPull is from the parent Registry class used in various places, thus the update to async in all usage.

The alternative (what I did for a workaround at first), was to keep the generated token from authenticate() in Ecr.js inside a member property, and reuse it in the getPullAuth(). This was simpler to implement as only code changes in Ecr.js but, from my point of view, not really clean as it forces an hidden dependency between authenticate() and getPullAuth() methods, which is not really good pratices. If someone calls getPullAuth() before authenticate() in the future, it will fail; so that's why I moved to async in getPullAuth().

I'm not a javascript expert, but from what I've saw on various sources on internet, that's apparently the best practices for such cases. I would have prefered to avoid changing so much code but that's probably cleaner than my first workaround :)

Code from workaround 1:

    async authenticate(image, requestOptions) {
            // [...]
            const authorizationToken = await ecr.getAuthorizationToken().promise();
            const tokenValue = authorizationToken.authorizationData[0].authorizationToken;
            requestOptionsWithAuth.headers.Authorization = `Basic ${tokenValue}`;

            // CODE ADDED
            const auth = Buffer.from(tokenValue, 'base64').toString().split(':');
            this.pullAuth = {
                username: auth[0],
                password: auth[1],
            };
            // [...]

        return requestOptionsWithAuth;
    }

    // Before
    getAuthPull() {
        return this.configuration.accesskeyid
            ? {
                  username: this.configuration.accesskeyid,
                  password: this.configuration.secretaccesskey,
              }
            : undefined;
    }

    // After
    getAuthPull() {
        return this.configuration.accesskeyid ? this.pullAuth : undefined;
    }

@thecoshman
Copy link

@scadorel oh that makes perfect sense. Thanks for the clear explanation - certainly helps me get to grips a bit more with js dev... I've been trying to avoid it, but it's caught up with me 😅

@fmartinou
Copy link
Collaborator

Hi, looks good, thank you.
May you resolve the merge conflicts before I merge, please?

@JTufarelli-BAH
Copy link

Hello, are we able to merge this in? I would love this feature because I have the same issue with ECR as well.

@scadorel scadorel force-pushed the fix/private-ecr-auth branch from 96897e4 to 49b0b09 Compare December 15, 2025 13:17
@scadorel
Copy link
Author

Hello @fmartinou, branch rebased and updated with latest changes from main.

@JTufarelli-BAH
Copy link

Hey, just to give you some feedback. I cloned your fork @fmartinou and built the Docker container to test it out. Everything works perfectly! Once this is merged in I can start using the public build of WUD again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants