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

ImageFromDockerfile does not support authenticated pulls #1799

Open
rnorth opened this issue Aug 27, 2019 · 6 comments · Fixed by #2201
Open

ImageFromDockerfile does not support authenticated pulls #1799

rnorth opened this issue Aug 27, 2019 · 6 comments · Fixed by #2201

Comments

@rnorth
Copy link
Member

rnorth commented Aug 27, 2019

ImageFromDockerfile doesn't work if base layer(s) need to be pulled from an authenticated registry and if those images are not already pulled.

For example:

# Dockerfile
FROM my.authenticated.registry/somerepo/someimage

will result in a failure at image build time, even if the user has working credentials available on their machine (for example, a CLI docker pull or docker build works).

It looks like BuildImageCmd's withBuildAuthConfigs(AuthConfigurations); gives us an opportunity to improve this - however we'd have to perform a lookup for credentials for each image first.

I think it should be feasible to:

  • do a minimal parse of the Dockerfile to extract any FROM x [--as=y] declarations
  • run each image name found through RegistryAuthLocator and obtain an auth configuration for each registry
  • provide the auth configurations to BuildImageCmd

The main difficulty would be that we have a few different ways in which the Dockerfile flows through Testcontainers, so we'd need to make sure we capture Dockerfile content at the right time.

@stale
Copy link

stale bot commented Nov 25, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

@stale stale bot added the stale label Nov 25, 2019
@stale
Copy link

stale bot commented Dec 9, 2019

This issue has been automatically closed due to inactivity. We apologise if this is still an active problem for you, and would ask you to re-open the issue if this is the case.

@stale stale bot closed this as completed Dec 9, 2019
@rnorth
Copy link
Member Author

rnorth commented Dec 17, 2019

Reopening, as this is still an annoyance.

@rnorth rnorth reopened this Dec 17, 2019
@stale stale bot removed the stale label Dec 17, 2019
@stale stale bot removed the stale label Dec 17, 2019
@rnorth rnorth self-assigned this Dec 20, 2019
rnorth added a commit that referenced this issue Dec 20, 2019
So that ImageFromDockerfile and Docker Compose can use images from authenticated registries when building temporary images

Fixes #1799
rnorth added a commit that referenced this issue Apr 5, 2020
* Pre-pull images required for Dockerfile/Compose image builds
So that ImageFromDockerfile and Docker Compose can use images from authenticated registries when building temporary images

Fixes #1799

* Restore wider test scope
@rnorth
Copy link
Member Author

rnorth commented Apr 13, 2020

Discovered a bug in 1.14.0's release of #2201. I'll follow up with a patch fix shortly.

@rnorth rnorth reopened this Apr 13, 2020
quincy pushed a commit to quincy/testcontainers-java that referenced this issue May 28, 2020
…tainers#2201)

* Pre-pull images required for Dockerfile/Compose image builds
So that ImageFromDockerfile and Docker Compose can use images from authenticated registries when building temporary images

Fixes testcontainers#1799

* Restore wider test scope
@tazle
Copy link

tazle commented Apr 27, 2021

So, the overall solution in TestContainers appears to to parse the Dockerfile and pre-pull.

We have some image builds that take the base image as build arg, and the current parsing doesn't account for that. For docker configurations without credsStore, the builds still work for us (probably because something in the TestContainers global docker client injects the X-Auth-Config information to the build POST request, but we haven't actually verified that yet).

I think I understand why the pre-pull route is necessary for docker-compose, but could there be an option to disable it for the normal case?

Overall idea is to add an option to: 1) Disable pre-pull, 2) pass all the available credentials to the build command.

The alternative, to support base-image-as-build-args, would be to parse build args. Do you think that approach would be better?

@erohana
Copy link

erohana commented May 2, 2021

what is the status of this bug ?
as I'm experiencing this issue in my build after I'm using my company's ECR from base image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants