Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

JIB: Unauthorized registry exception for "from" registry #1763

Closed
yadavnikhil opened this issue Nov 25, 2019 · 10 comments
Closed

JIB: Unauthorized registry exception for "from" registry #1763

yadavnikhil opened this issue Nov 25, 2019 · 10 comments
Assignees

Comments

@yadavnikhil
Copy link

Description

I'm getting registry unauthorized exception when using Jib when "from" image registry is from a authenticated registry.

Failed to execute the build: java.lang.UnsupportedOperationException: java.lang.IllegalStateException: com.google.cloud.tools.jib.api.RegistryUnauthorizedException

The relevant credentials are set in maven settings.xml. On debugging it looks like for baseImageConfiguration object, no credentials are getting set for CredentialsRetreiver.

Info

  • Maven version (mvn -v) :
maven 3.5.0
@rohanKanojia
Copy link
Member

@yadavnikhil : I haven't tested it with credentials in setings.xml. Does it work for you when credentials are in docker config?

@rohanKanojia
Copy link
Member

Description

I'm getting registry unauthorized exception when using Jib when "from" image registry is from a authenticated registry.

Failed to execute the build: java.lang.UnsupportedOperationException: java.lang.IllegalStateException: com.google.cloud.tools.jib.api.RegistryUnauthorizedException

The relevant credentials are set in maven settings.xml. On debugging it looks like for baseImageConfiguration object, no credentials are getting set for CredentialsRetreiver.

Could you please elaborate which CredentialsRetreiver you're referring to? I couldn't find any object like this in Docker maven plugin source code.

Info

  • Maven version (mvn -v) :
maven 3.5.0

@rohanKanojia
Copy link
Member

Hmm, I think you're right. It's not that registry authentication is not working. I just tried and push seemed to be working when credentials are in settings.xml. But It couldn't work when from image was from some private registry. It seems to be always pulling from dockerhub and does not consider credentials while pulling images.

@erikgb : Were you able to find some solution for authentication for pulling images in jib? I remember you filed an issue on Jib repo querying this issue.

@rohanKanojia
Copy link
Member

Shall we try to upgrade jib-core and see if it resolves this issue. I think we're using 5 months old version

@erikgb
Copy link
Contributor

erikgb commented Nov 25, 2019

@rohanKanojia : JIB API (java) supports it: https://www.javadoc.io/static/com.google.cloud.tools/jib-core/0.12.0/com/google/cloud/tools/jib/api/RegistryImage.html

The main issue here seems to be to get the credential details in f-m-p. But you probably know how to do it.... 😄

@erikgb
Copy link
Contributor

erikgb commented Nov 25, 2019

Relates to #1738

@rohanKanojia
Copy link
Member

@erikgb You're right. We don't seem to be adding RegistryImage object for from image. we're only doing it for final image; that's why it works in case of push:

private static RegistryImage getRegistryImage(ImageConfiguration imageConfiguration, MojoParameters mojoParameters, Credential credential) throws InvalidImageReferenceException {
String username = "", password = "";
String targetImage = imageConfiguration.getName();
ImageReference imageReference = ImageReference.parse(targetImage);
if (imageConfiguration.getBuildConfiguration().getTags() != null) {
// Pick first not null tag
String tag = null;
for (String currentTag : imageConfiguration.getBuildConfiguration().getTags()) {
if (currentTag != null) {
tag = currentTag;
break;
}
}
targetImage = new ImageName(imageConfiguration.getName(), tag).getFullName();
}
if (credential != null) {
username = credential.getUsername();
password = credential.getPassword();
if (targetImage.contains(DEFAULT_USER_NAME)) {
targetImage = targetImage.replaceFirst(DEFAULT_USER_NAME, username + "/");
}
}
String registry = getPropertyFromMojoParameter(mojoParameters, FABRIC8_GENERATOR_REGISTRY) != null ?
getPropertyFromMojoParameter(mojoParameters, FABRIC8_GENERATOR_REGISTRY) : imageConfiguration.getRegistry();
if (registry != null) {
imageReference = ImageReference.parse(new ImageName(targetImage).getFullName(registry));
}
return RegistryImage.named(imageReference).addCredential(username, password);
}

@yadavnikhil
Copy link
Author

@rohanKanojia Thanks a lot for commenting, yes push works fine with authentication, its the issue with ‘from’ image authentication.

I tried just using jib to test and the standalone use worked fine for me. So, fix needed to authenticate base image registry whenever needed in fabric8 maven.

@rohanKanojia
Copy link
Member

@yadavnikhil : No problem. I'm preparing a PR to fix this issue.

rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Nov 25, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Nov 25, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Nov 25, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Nov 25, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Nov 26, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Nov 27, 2019
@rohanKanojia rohanKanojia self-assigned this Dec 3, 2019
@rohanKanojia rohanKanojia removed their assignment Dec 18, 2019
@devang-gaur
Copy link
Contributor

Closing since #1766 has been merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants