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

Support pulling images from different registries with authentication #24547

Open
WqyJh opened this issue Dec 17, 2020 · 7 comments
Open

Support pulling images from different registries with authentication #24547

WqyJh opened this issue Dec 17, 2020 · 7 comments
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Milestone

Comments

@WqyJh
Copy link

WqyJh commented Dec 17, 2020

This is my base image built upon paketobuildpacks/run:base named docker.example.com/run:base which has been pushed to my private registry with basic auth.

FROM paketobuildpacks/run:base

# Install packages (ffmpeg)
RUN echo "debconf debconf/frontend select noninteractive" | debconf-set-selections && \
  export DEBIAN_FRONTEND=noninteractive && \
  apt-get -y update && \
  apt-get -y upgrade && \
  apt-get -y --no-install-recommends install ffmpeg && \
  find /usr/share/doc/*/* ! -name copyright | xargs rm -rf && \
  rm -rf \
    /usr/share/man/* /usr/share/info/* \
    /usr/share/groff/* /usr/share/lintian/* /usr/share/linda/* \
    /var/lib/apt/lists/* /tmp/*

ARG cnb_uid=1000
ARG cnb_gid=1000
ARG distro_name="Ubuntu"
ARG distro_version="18.04"
ARG homepage="https://github.com/paketo-buildpacks/stacks"
ARG maintainer="Paketo Buildpacks"
ARG stack_id="io.buildpacks.stacks.bionic"
ARG description="ubuntu:bionic + openssl + CA certs + ffmpeg"
ARG released

RUN groupadd cnb --gid ${cnb_gid} && \
  useradd --uid ${cnb_uid} --gid ${cnb_gid} -m -s /bin/bash cnb

USER ${cnb_uid}:${cnb_gid}
LABEL io.buildpacks.stack.description=${description}
LABEL io.buildpacks.stack.distro.name=${distro_name}
LABEL io.buildpacks.stack.distro.version=${distro_version}
LABEL io.buildpacks.stack.homepage=${homepage}
LABEL io.buildpacks.stack.id=${stack_id}
LABEL io.buildpacks.stack.maintainer=${maintainer}
LABEL io.buildpacks.stack.metadata=${fully_qualified_base_image}
LABEL io.buildpacks.stack.mixins=${mixins}
LABEL io.buildpacks.stack.released=${released}

This is how I config bootBuildImage.

bootBuildImage {
    docker {
        builderRegistry {
            username = "username"
            password = "password"
            url = "https://docker.example.com/v1/"
        }
    }
    imageName = "docker.example.com/app"
    runImage = "docker.example.com/run:base"
}

But I've got the following problem when executing bootBuildImage task.

* What went wrong:
Execution failed for task ':app:bootBuildImage'.
> Docker API call to 'localhost/v1.24/images/create?fromImage=docker.io%2Fpaketobuildpacks%2Fbuilder%3Abase' failed with status code 500 "Internal Server Error" and message "Head https://registry-1.docker.io/v2/paketobuildpacks/builder/manifests/base: unauthorized: incorrect username or password"

Because a basic auth was applied to docker.io when pulling paketobuildpacks/builder:base which is a public registry with no authentication required.

I've dive into the source code and found the following code, which performs the basic auth configured for images from all registries, which I think, should only be applied when the image was matched with the registry configured.

@scottfrederick
Copy link
Contributor

@WqyJh The Spring Boot image-building Maven goal and Gradle task apply the builderRegistry credentials to both the builder and run image by design.

We can discuss enhancing this so that different authentication can be supplied for the builder and run images. Your suggested fix solves your use case of one image in a private repository and one image in a public repository, but does not support the use case of each of the two images being in different private repositories. Because of this, I don't think your suggestion is the right fix.

You'll need to re-tag and push the builder image to the same repository as the run image if you need the run image to be in a private repository. I'll tag the issue for team attention so we can discuss an approach to addressing additional use cases.

@scottfrederick scottfrederick added the for: team-attention An issue we'd like other members of the team to review label Dec 17, 2020
@scottfrederick
Copy link
Contributor

scottfrederick commented Dec 17, 2020

I've opened a new issue(#24552) to enforce that both the builder and run images are in the same registry when an authenticated registry is configured. For the use case raised in this issue, that would require the builder image to be copied to the private registry with something like:

$ docker pull paketobuildpacks/builder:base
$ docker tag paketobuildpacks/builder:base docker.example.com/builder:base
$ docker push docker.example.com/builder:base

We'll leave this issue open to consider enhancing the plugin configuration to allow the builder and run images to be pulled from different registries - either one public and one private registry, or different private registries.

@scottfrederick scottfrederick added status: pending-design-work Needs design work before any code can be developed and removed for: team-attention An issue we'd like other members of the team to review labels Dec 17, 2020
@scottfrederick scottfrederick added this to the 2.x milestone Dec 17, 2020
@scottfrederick scottfrederick changed the title Not work for both private registry and public registry Support builder and run images in different registries with authentication Dec 17, 2020
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 13, 2021
@scottfrederick
Copy link
Contributor

We'll leave this issue open to consider enhancing the plugin configuration to allow the builder and run images to be pulled from different registries - either one public and one private registry, or different private registries.

This should now include pulling buildpack images from different authenticated registries in addition to builder and run images (see #21722).

@scottfrederick scottfrederick changed the title Support builder and run images in different registries with authentication Support pulling images from different registries with authentication Feb 23, 2021
@pgalache
Copy link

pgalache commented Jun 4, 2021

I had opened #26759 but closed it as I saw this one opened.

We faced the same problem and think that allowing different authentication parameters for builder and runImage (docker.runImageRegistry) would solve this problem and give developers more flexibility.

@philwebb philwebb modified the milestones: 2.x, 3.x Aug 19, 2022
@tukez
Copy link

tukez commented Nov 2, 2022

I think a more generic solution would be better than just separate builderRegistry and runImageRegistry. Same problem occurs if you define your own buildpacks (for example changing the JVM to Adoptium).

@Mobe91
Copy link

Mobe91 commented Jul 7, 2023

This is still an issue and I couldn't figure out how #24547 (comment) would help. I ended up using the workaround described in #24547 (comment).

@piercemar
Copy link

Hello.
I just faced the same issue when starting to fiddle with runImage.
Wouldn't a solution based on maven's elements be both more flexible and more secure (supporting encryption and so on) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

9 participants