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

JKube is not picking docker credentials from ~/.docker/config.json file #2290

Closed
anurag-rajawat opened this issue Jul 19, 2023 · 3 comments · Fixed by #2313
Closed

JKube is not picking docker credentials from ~/.docker/config.json file #2290

anurag-rajawat opened this issue Jul 19, 2023 · 3 comments · Fixed by #2313
Assignees
Labels
bug Something isn't working component/gradle-plugin Related to the Gradle Plugins
Milestone

Comments

@anurag-rajawat
Copy link
Contributor

Describe the bug

I have successfully configured my Docker credentials in the ~/.docker/config.json file. However, when I try to push an image to the Docker registry using the k8sPush task, the task fails with the error requested access to the resource is denied.

I have also tried hard-coding my Docker credentials in the build.gradle file. In this case, the build process works as expected.

Eclipse JKube version

1.13.1

Component

Kubernetes Gradle Plugin

Apache Maven version

None

Gradle version

other (please specify in additional context)

Steps to reproduce

  1. Login to docker using docker login
  2. Run ./gradlew bootJar k8sBuild k8sPush

Expected behavior

When JKube is used to push an image to a Docker registry, it should first look for Docker credentials in the ~/.docker/config.json file. If the credentials are found, JKube should use them to authenticate with the Docker registry and push the image successfully.

Runtime

minikube

Kubernetes API Server version

1.25.3

Environment

macOS

Eclipse JKube Logs

./gradlew bootJar k8sBuild k8sPush

> Task :k8sBuild
k8s: Using Dockerfile: /Users/anurag/Playground/catalog-service/Dockerfile
k8s: Using Docker Context Directory: /Users/anurag/Playground/catalog-service
k8s: Building container image in Kubernetes mode
k8s: [anuragrajawat/catalog-service:0.0.1-SNAPSHOT]: Created docker-build.tar in 65 milliseconds
k8s: [anuragrajawat/catalog-service:0.0.1-SNAPSHOT]: Built image sha256:590f4

> Task :k8sPush
k8s: Using Dockerfile: /Users/anurag/Playground/catalog-service/Dockerfile
k8s: Using Docker Context Directory: /Users/anurag/Playground/catalog-service
k8s: Target image 'docker.io/anuragrajawat/catalog-service:0.0.1-SNAPSHOT' already exists. Tagging of 'anuragrajawat/catalog-service:0.0.1-SNAPSHOT' will replace existing image
k8s: The push refers to repository [docker.io/anuragrajawat/catalog-service]
k8s: Tagged image 'docker.io/anuragrajawat/catalog-service:0.0.1-SNAPSHOT' won't be removed after tagging as it already existed

> Task :k8sPush FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':k8sPush'.
> Error in pushing image: Error while trying to push the image: Unable to push 'anuragrajawat/catalog-service:0.0.1-SNAPSHOT' to registry 'docker.io' : denied: requested access to the resource is denied

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
6 actionable tasks: 6 executed

Sample Reproducer Project

https://github.com/anurag-rajawat/catalog-service

Additional context

Gradle version: 8.1.1

@anurag-rajawat anurag-rajawat added the bug Something isn't working label Jul 19, 2023
@rohanKanojia rohanKanojia added the component/gradle-plugin Related to the Gradle Plugins label Jul 24, 2023
@rohanKanojia
Copy link
Member

I'm observing this behavior is only on Kubernetes gradle plugin, not Kubernetes maven plugin.

It seems to be happening because we're having a default value of jkube.docker.registry property as docker.io in Kubernetes Gradle Plugin
https://github.com/eclipse/jkube/blob/1ffc921c99a345320ce2a59e2e8bf5bcb5469277/gradle-plugin/kubernetes/src/main/java/org/eclipse/jkube/gradle/plugin/KubernetesExtension.java#L607

However, in maven plugin we don't provide any default value:
https://github.com/eclipse/jkube/blob/1ffc921c99a345320ce2a59e2e8bf5bcb5469277/kubernetes-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/AbstractDockerMojo.java#L223-L224

In AuthConfigFactory, we're relying on the registry to be null in order to correctly pick https://index.docker.io/v1/ as default docker login registry:

https://github.com/eclipse/jkube/blob/1ffc921c99a345320ce2a59e2e8bf5bcb5469277/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/auth/AuthConfigFactory.java#L418

Setting default value of jkube.docker.registry property to null in KubernetesExtension seems to fix this issue:

-    return getOrDefaultString("jkube.docker.registry", this::getRegistry, "docker.io");
+    return getOrDefaultString("jkube.docker.registry", this::getRegistry, null);

@rohanKanojia
Copy link
Member

@anurag-rajawat : Would this be something you would like to pick up? You might also need to update KubernetesExtensionPropertyTest with updated default values.

@anurag-rajawat
Copy link
Contributor Author

Would this be something you would like to pick up?

Sure please assign this to me.

anurag-rajawat added a commit to anurag-rajawat/jkube that referenced this issue Jul 28, 2023
…g.json` file (eclipse-jkube#2290)

Signed-off-by: Anurag Rajawat <anuragsinghrajawat22@gmail.com>
@manusa manusa added this to the 1.14.0 milestone Jul 31, 2023
manusa pushed a commit to anurag-rajawat/jkube that referenced this issue Jul 31, 2023
…g.json` file (eclipse-jkube#2290)

Signed-off-by: Anurag Rajawat <anuragsinghrajawat22@gmail.com>
manusa pushed a commit that referenced this issue Jul 31, 2023
…g.json` file (#2290)

Signed-off-by: Anurag Rajawat <anuragsinghrajawat22@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component/gradle-plugin Related to the Gradle Plugins
Projects
None yet
3 participants