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

fix: Prepend Docker Hub namespace to repository #1287

Conversation

HofmeisterAn
Copy link
Collaborator

@HofmeisterAn HofmeisterAn commented Nov 4, 2024

What does this PR do?

If the TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX custom configuration contains a namespace, such as registry.example.com/library, Testcontainers retains the namespace when attempting to locate registry credentials. However, the registry credentials key does not (may not) include the namespace, preventing Testcontainers for .NET from finding and using existing credentials. This PR ensures that the namespace is prepended to the repository and that only the hostname is used to resolve registry credentials.

When we use the custom configuration from above, Testcontainers will resolve the following property values:

Property Value
Registry registry.example.com
Repository library/testcontainers/helloworld
Tag latest
GetHostname() registry.example.com

Why is it important?

Fixes an issue where Testcontainers for .NET is unable to find existing and valid configured private registry credentials. This is a regression.

Related issues

@HofmeisterAn HofmeisterAn added the bug Something isn't working label Nov 4, 2024
Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 0bd48ab
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/672e2b3c8dccc30008835238
😎 Deploy Preview https://deploy-preview-1287--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@HofmeisterAn
Copy link
Collaborator Author

@kiview @mdelapenya, I need your guidance and expertise on how you handle this in other languages.

The Azure DevOps pipeline task Docker@2 (command: 'login') stores the Docker Registry credentials in Base64 in the config.json file. The pipeline task uses the exact Docker Registry value from the Azure DevOps service connection as key. E.g. for the Docker Registry value https://registry.example.com/library the JSON value will look like:

{"auths":{"https://registry.example.com/library":{"auth":"...","email":""}},"HttpHeaders":{"X-Meta-Source-Client":"VSTS"}}

The Base64Provider implementation does not expect a namespace (/library) segment. It only expects the Docker Registry hostname.

This results in that Testcontainers is unable to find matching credentials to authenticate against the Docker Registry. Right now, valid keys are:

However, the Docker CLI seams not that strict, it is still able to pull images with the configuration above.

As a workaround, users can change the Docker Registry service connection value to https://registry.example.com (remove the namespace segment). But this prevents users from configuring different credentials for different namespaces (not sure if that’s a use case; which this PR breaks already).

@HofmeisterAn HofmeisterAn changed the title fix: Prepend Docker Hub namespace prefix to repository fix: Prepend Docker Hub namespace to repository Nov 8, 2024
@HofmeisterAn HofmeisterAn merged commit db02434 into develop Nov 8, 2024
14 checks passed
@HofmeisterAn HofmeisterAn deleted the bugfix/1286-remove-namespace-from-docker-hub-substitution branch November 8, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Docker registry credential not found using TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX (regression in 4.0.0)
1 participant