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

docker basic Auth failure #2116

Closed
pmbsa opened this issue Mar 31, 2023 · 16 comments · Fixed by #2183
Closed

docker basic Auth failure #2116

pmbsa opened this issue Mar 31, 2023 · 16 comments · Fixed by #2183
Assignees
Labels
bug Something isn't working
Milestone

Comments

@pmbsa
Copy link

pmbsa commented Mar 31, 2023

Describe the bug

I am trying to build and push my image. I have a local docker registry configured and working fine with docker cmdline interactions.
For auth I have gone with a simple server section in the ~/.m2/settings.yml

    <servers>               
        <server>
            <id>myregistry.127.0.0.1.nip.io</id>
            <username>user</username>
            <password>pwd123</password>
        </server>             
    </servers>

the base image is called myregistry.127.0.0.1.nip.io/eclipse-temurin:11.0.18_10-jdk-alpine
When I run k8s:build for example the build fails pulling the base image "no basic auth".
If I pass the docker creds in on the cmdline it works so its like its not matching the registry in the image to the registry in the server section in the settings.xml

any advice would be appreciated

Eclipse JKube version

1.11.0

Component

Kubernetes Maven Plugin

Apache Maven version

3.8.5

Gradle version

None

Steps to reproduce

as above

Expected behavior

image should be pulled from registry

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.25.3

Environment

Linux

Eclipse JKube Logs

No response

Sample Reproducer Project

No response

Additional context

No response

@pmbsa pmbsa added the bug Something isn't working label Mar 31, 2023
@manusa
Copy link
Member

manusa commented Mar 31, 2023

Might be related to #1929

@rohanKanojia
Copy link
Member

@pmbsa : Does it work when you modify it to specify port as well myregistry.127.0.0.1.nip.io:80/eclipse-temurin:11.0.18_10-jdk-alpine

@pmbsa
Copy link
Author

pmbsa commented Mar 31, 2023

looks the same, is that down to the way the dns name is structured with "-"?

@rohanKanojia
Copy link
Member

Maybe it's because there is no user element in image name. In #1929 Our logic is assuming that myregistry.127.0.0.1.nip.io is user

@pmbsa pmbsa closed this as completed Mar 31, 2023
@pmbsa
Copy link
Author

pmbsa commented Mar 31, 2023

aargh, apologies, I didnt mean to close it

@pmbsa pmbsa reopened this Mar 31, 2023
@pmbsa
Copy link
Author

pmbsa commented Mar 31, 2023

I will have a go at a few things and see if i can get more details

@pmbsa
Copy link
Author

pmbsa commented Mar 31, 2023

yes, works perfectly when I add a port!

@rohanKanojia
Copy link
Member

@pmbsa : I see. I think it's the same as #1929 then

@rohanKanojia
Copy link
Member

Duplicate of #1929

@rohanKanojia rohanKanojia marked this as a duplicate of #1929 Apr 3, 2023
@rohanKanojia
Copy link
Member

@pmbsa : Could you please provide some details about your setup? I see you're using a local registry. How are you running it? How have your set up authentication? Would really appreciate if you could help us in reproducing this issue.

@pmbsa
Copy link
Author

pmbsa commented Apr 10, 2023

Hi @rohanKanojia. I am running sonatype nexus from the provided helm charts. I dont do any specialisations on that, just a basic install and then create a hosted docker registry listening on http (but via an https ingress configured in the charts). The authentication is nexus's basic admin user. I dont do anything beyond that. I have configured the registry in docker as 'insecure'. I can think of anything beyond that. The maven settings.xml are just the basic server config with username and password

@rohanKanojia
Copy link
Member

@pmbsa : Thanks a lot! I can reproduce the issue now with this setup.

The issue seems to be at this line where we consider token as a registry only if it contains a colon:
https://github.com/eclipse/jkube/blob/34c6f4d6db099641100886903dc41cff963e9627/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/ImageName.java#L300

Now we're back at the same problem as #1929 . How can we determine whether a given token should be considered a domain or a user name?

@rohanKanojia
Copy link
Member

@pmbsa : I can think of a simple workaround. We can check whether the given token is a valid host by trying to access it. This would however make ImageName require internet access.

     private void checkWhetherFirstElementIsUserOrRegistryAndAssign(String[] parts) {
-        if (containsColon(parts[0])) {
+        if (containsColon(parts[0]) || isKnownHost(parts[0])) {
             assignRegistryAndRepository(parts);
         } else {
             assignUserAndRepository(parts);
         }
     }
 
+    private static boolean isKnownHost(String host) {
+        try {
+            InetAddress resolvedIpAddress = InetAddress.getByName(host);
+            return resolvedIpAddress.getHostAddress() != null;
+        } catch (UnknownHostException unknownHostException) {
+            return false;
+        }
+    }

What do you think about this?

@pmbsa
Copy link
Author

pmbsa commented Apr 14, 2023

personally, I think the current solution of simply adding a port is fine. It was an easy understandable fix and doesnt require internet access. Just feels a cleaner way for me anyway. Maybe just needs stressing in the doco or FAQ's and thats enough?

@rohanKanojia
Copy link
Member

@pmbsa : We finally managed to close the issue :-) . Could you please try out our 1.14-SNAPSHOT build on your project and provide feedback? You might need to add this to your pom.xml:

  <pluginRepositories>
    <pluginRepository>
      <id>oss.sonatype.org</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>

@pmbsa
Copy link
Author

pmbsa commented Jul 7, 2023

hey @rohanKanojia , that worked a treat thanks. I reverted my settings back to

    <servers>               
        <server>
            <id>myregistry.127.0.0.1.nip.io</id>
            <username>user</username>
            <password>pwd123</password>
        </server>             
    </servers>

and its working perfectly
thanks again everyone, awesome project.

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 a pull request may close this issue.

3 participants