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

Possible NPE from DockerConfigCredentialRetriever with 2.4.0 #2535

Closed
chanseokoh opened this issue Jun 19, 2020 · 5 comments · Fixed by #2536
Closed

Possible NPE from DockerConfigCredentialRetriever with 2.4.0 #2535

chanseokoh opened this issue Jun 19, 2020 · 5 comments · Fixed by #2536
Assignees
Milestone

Comments

@chanseokoh
Copy link
Member

chanseokoh commented Jun 19, 2020

@Gsealy reported NPE on Jib 2.4.0. This looks like a regression introduced by #2489.


Environment:
Windows Terminal

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
Maven home: C:\apache-maven\bin\..
Java version: 11, vendor: Oracle Corporation, runtime: C:\Java\jdk-11
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

docker for windows version:

docker desktop: 2.3.0(45519)
Docker version 19.03.8, build afacb8b
Credntial Helper: 0.6.3

jib-maven-plugin Configuration:

     <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <from>
            <image>hub.gsealy.cn/base-image/jdk:11.0</image>
          </from>
          <to>
            <image>spring-boot-jib</image>
          </to>
          <allowInsecureRegistries>true</allowInsecureRegistries>
          <container>
            <ports>
              <port>9999</port>
            </ports>
          </container>
        </configuration>
      </plugin>

description:
we are use harbor for docker registry at inner network, and use Let's encrypt cert for ssl. 2.3.0 also print warning but build succeed.
I don't find docker-credential-desktop.cmd in system, just have docker-credential-desktop.exe

... omit ...
[DEBUG] trying docker-credential-desktop for hub.gsealy.cn
[WARNING] Cannot run program "docker-credential-desktop.cmd": CreateProcess error=2, cannot find the file.
[WARNING]   Caused by: CreateProcess error=2, cannot find the file.
... omit ...

but 2.4.0 was facing the NPE

[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.4.0:buildTar (default-cli) on project
 jib: (null exception message): NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.4.0:buildTar (default-cli) on project jib: (null exception message)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: (null exception message)
    at com.google.cloud.tools.jib.maven.BuildTarMojo.execute (BuildTarMojo.java:140)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.NullPointerException
    at java.lang.String.<init> (String.java:561)
    at com.google.cloud.tools.jib.registry.credentials.DockerConfigCredentialRetriever.retrieve (DockerConfigCredentialRetriever.java:146)
    at com.google.cloud.tools.jib.registry.credentials.DockerConfigCredentialRetriever.retrieve (DockerConfigCredentialRetriever.java:104)
    at com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory.lambda$dockerConfig$4 (CredentialRetrieverFactory.java:277)
    at com.google.cloud.tools.jib.builder.steps.RegistryCredentialRetriever.retrieve (RegistryCredentialRetriever.java:47)
    at com.google.cloud.tools.jib.builder.steps.RegistryCredentialRetriever.getBaseImageCredential (RegistryCredentialRetriever.java:34)
    at com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.call (PullBaseImageStep.java:134)
    at com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.call (PullBaseImageStep.java:56)
    at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly (TrustedListenableFutureTask.java:125)
    at com.google.common.util.concurrent.InterruptibleTask.run (InterruptibleTask.java:69)
    at com.google.common.util.concurrent.TrustedListenableFutureTask.run (TrustedListenableFutureTask.java:78)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
    at java.lang.Thread.run (Thread.java:834)

Originally posted by @Gsealy in #2527 (comment)

@chanseokoh chanseokoh added this to the v2.5.0 milestone Jun 19, 2020
@chanseokoh chanseokoh self-assigned this Jun 19, 2020
@chanseokoh
Copy link
Member Author

chanseokoh commented Jun 19, 2020

@Gsealy we will fix this bug in the upcoming release (most likely 2.5.0).

However, this is unrelated to #2527 (that is, the issue about the .cmd or .exe suffix). I don't think a credential helper was ever used, even in 2.3.0.

The triggering factor is probably that there is an entry in the auths section in ~/.docker/config.json that doesn't have an "auth": field. For example,

{
    "auths": {
        "docker.pkg.github.com": {
            "auth": ...      <-- For example, this entry has "auth".
        },
        "hub.gsealy.cn": {      <-- Maybe your entry doesn't have "auth"? (Not that this is wrong.)
            "identityToken": ...
        },

So, if it worked with 2.3.0, I think a workaround would be to remove the "hub.gsealy.cn" entry that does not have the "auth": field. And I also suggest you test removing all the entries that don't have "auth": or the entire auths section.

In any case, we will fix this, and the next version will not throw NPE whether or not an entry has the auth field.

@Gsealy
Copy link

Gsealy commented Jun 20, 2020

yes, in config.json, hub.gsealy.cn auth: field was empty. remove auth field will build success

{
	"auths": {
		"hub.gsealy.cn": {}
	},
	"HttpHeaders": {
		"User-Agent": "Docker-Client/19.03.8 (windows)"
	},
	"credsStore": "desktop",
	"stackOrchestrator": "swarm"
}

use docker-credential-desktop will return auth info. why not use this credential ?

PS D:\IDEAWorkSpaces\docker-build-with-jib> echo -n hub.gsealy.cn | docker-credential-desktop.exe get
{"ServerURL":"hub.gsealy.cn","Username":"username","Secret":"password"}

@chanseokoh
Copy link
Member Author

chanseokoh commented Jun 22, 2020

@Gsealy until we release Jib 2.5.0, for now (2.4.0) you can set

"credsStore": "desktop.exe",

Or, in pom.xml,

<from>
  <image>...</image>
  <credHelper>desktop.exe</credHelper>
</from>

You can also do this on the command-line with -Djib.from.credHelper=desktop.exe (or -Djib.to.credhelper).

This issue that Jib doesn't try .exe is fixed (#2527), so you will be able to restore the values back to desktop with the next Jib 2.5.0 release.

@Gsealy
Copy link

Gsealy commented Jun 23, 2020

@chanseokoh thanks!

@chanseokoh
Copy link
Member Author

chanseokoh commented Aug 7, 2020

@Gsealy Jib Maven 2.5.2 and Jib Gradle 2.5.0 are released with the fix. It should be OK to have an auths entry without the auth property.

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

Successfully merging a pull request may close this issue.

2 participants