401 Unauthorized when using jib to create docker image
Asked Answered
I

13

8

I am on windows and this is the plugin configuration:

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>3.2.1</version>
    <configuration>
        <container>
            <ports>
                <port>8080</port>
            </ports>
            <format>OCI</format>
        </container>
    </configuration>
</plugin>

This is the command I run:

.\mvnw clean install jib:dockerBuild -Dimage=fullstack:v1

This is the error I keep getting no matter what I do:

[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.2.1:dockerBuild (default-cli) on project SpringBootFullStack: Build
 to Docker daemon failed, perhaps you should make sure your credentials for 'registry-1.docker.io/library/eclipse-temurin' are set up correc
tly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized f
or help: Unauthorized for registry-1.docker.io/library/eclipse-temurin: 401 Unauthorized
[ERROR] {"details":"incorrect username or password"}
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

How should I go about it? I've read the documentation on jib github repo on authenticating but I don't really understand how to procede and feel overwhelmed

UPDATE

I ran docker login and I get:

Authenticating with existing credentials...
Login Succeeded

but the error persists (and I figured I didn't include some part of the logging maybe:

[INFO] Using credentials from Docker config (C:\Users\david\.docker\config.json) for openjdk:17
[INFO] Executing tasks:                               
[INFO] [============                  ] 40.0% complete
[INFO] > building image to Docker daemon              
[INFO]                                                
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.964 s
[INFO] Finished at: 2022-05-17T19:39:12+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.2.1:dockerBuild (default-cli) on project SpringBootFullStack: Build
 to Docker daemon failed, perhaps you should make sure your credentials for 'registry-1.docker.io/library/openjdk' are set up correctly. See
 Unauthorized for registry-1.docker.io/library/openjdk: 401 Unauthorized
[ERROR] {"details":"incorrect username or password"}
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

UPDATE 2

this is also the content of the file logs refer to in order to get username and password:

{
    "auths": {
        "https://index.docker.io/v1/": {}
    },
    "credsStore": "desktop"
}

UPDATE 3

After two days of trying I decided to look for something else that would do the same job: https://spring.io/guides/gs/spring-boot-docker/ And with this the job was done in ~10 minutes. Life really is crazy

Intoxicated answered 17/5, 2022 at 15:49 Comment(6)
java version: 17Intoxicated
The problem is: registry-1.docker.io/library/eclipse-temurin: 401 Unauthorized this... do you have an account and maybe: docker.com/pricingHobbyhorse
I do have an account and I am logged in Docker Desktop and DockerHubIntoxicated
The output states different... You have not logging in via docker login...Hobbyhorse
I ran that command and it says it was successfull but then I run the jib command and it still doesnt work, I also found a line which may help [INFO] Using credentials from Docker config (C:\Users\david\.docker\config.json) for openjdk:17, and tried to add this to the pom <from><image>openjdk:17</image></from>Intoxicated
The fact that I am saving my docker password on google passwords might be a problem maybe?Intoxicated
O
23

Just delete the credsStore property from the docker-config file. You will find the config.json at your user-home dir.

the path is: $USER/.docker/config.json and suppose the file contains the followings,

{
  "auths": {
    "https://index.docker.io/v1/": {}
  },
  "credsStore": "desktop"
}

and now delete the line : "credsStore": "desktop"

So, the file will now contain the following

{
  "auths": {
    "https://index.docker.io/v1/": {}
  }
}
Oglesby answered 13/8, 2022 at 15:2 Comment(1)
I did what u mention, and then after login this add inside the file "credsStore": "wincred", and never work with JIBAntediluvian
T
4

I had the same issue on Mac. And I found 2 ways how to solve it:

  1. To do this, you can use the jib config:
<configuration>
  ...
  <from>
    <image>aws_account_id.dkr.ecr.region.amazonaws.com/my-base-image</image>
    <auth>
      <username>my_username</username>
      <password>my_password</password>
    </auth>
  </from>
  <to>
    <image>gcr.io/my-gcp-project/my-app</image>
    <auth>
      <username>${env.REGISTRY_USERNAME}</username>
      <password>${env.REGISTRY_PASSWORD}</password>
    </auth>
  </to>
  ...
</configuration>

https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/README.md#auth-object

  1. The second way is not about Windows, i fixed this issue on Mac OS but you can try to use my experience. I figured that it's strange if we're getting 401 unauthorized the most likely Jib trying to login with some wrong credentials. In my case i found 2 rows in Keychain Access:
  • The first (wrong) with email in password (instead real password))
  • The second (correct) with real password Jib tried to use first. The problem was solved after deleting the first value. In windows case you can try to use Credential Manager or find some another credentials storage.

Additionally. While i was researching it i found recommendations to change:

 "credsStore": "desktop" -> "credStore": "desktop"

But it didn't work for me.

UPD Same story on Windows use Credential Manager

Thrush answered 19/5, 2022 at 10:46 Comment(3)
thank you for your suggestions but unfortunately they didn't work for me :(Intoxicated
The "credStore": "desktop" worked for me on my Mac Mini GitLab Runner.Hierarchy
I made two changes (running on WSL2), a) credsStore -> credStore and b) desktop.exe to desktop and then surprisingly it worked. Thanks! Do you have the link referenced where you read this recommendation? is the issue that is expecting an array of credentials instead of a single one?Lehet
D
3

I had the issue on windows and solved the problem as follows:

Control Panel\All Control Panel Items\Credential Manager

From here I have removed in the Generic Credentials section all the entries related to docker

The from the powershell prompt:

docker login

and it worked!

Duarte answered 3/11, 2022 at 16:1 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Aidaaidan
B
2
{"details":"incorrect username or password"}

The response from the server is clear. Credentials were given to the server, and it says they are wrong.

Indeed, Jib did retrieve some (probably non-working) credentials from the Docker config.json file:

[INFO] Using credentials from Docker config (C:\Users\david\.docker\config.json) for openjdk:17

Try emptying config.json entirely or have just an empty {} block. Particularly, remove the entry for "https://index.docker.io/v1/" and credsStore. Deleting the file may or may not work, as Docker or other tools can regenerate it with wrong credentials again.

Probably the same kind of issue to this Stack Overflow question. Also take a look at this GitHub issue on the Jib repo.

Bounce answered 26/5, 2022 at 15:34 Comment(2)
deleting config.json never worked cause it's generated again with auths & credsStoreAntediluvian
Chanseok Oh, Could you please mention resources about how to implement Docker-Credential-helper for windows ?Antediluvian
T
1

I ran into the same problem on Windows. Try removing the following creds:

  • ..docker../acces-token
  • ..docker../refresh-token

https://i.stack.imgur.com/G9aGR.png

Thrush answered 14/6, 2022 at 15:57 Comment(1)
Thanks bro, it works for me. But how you figure out this method? What's your thought process behind thinking this solution.Sakhuja
N
1

If you don't want to go the extra credentials configuration step, pass them when running mvn package as below:

mvn package -D jib.to.auth.username="yourdockerUsername" -Djib.to.auth.password="yourDockerPassword"

It will build and push to docker Hub as required.

Numerate answered 19/6, 2022 at 4:14 Comment(0)
S
1

For me the only sollution which worked has to logout, then login using a generated access token:

docker login -u username

Enter access token

token here

Then it should work.

Smorgasbord answered 21/3 at 12:52 Comment(0)
S
0

faced same issue on win10 ... had to close docker desktop, I got some WARN related to credentials though, but it created the img

Spacing answered 30/12, 2022 at 16:47 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Aidaaidan
G
0

Use userId and NOT email to logon to docker hub. You should have an account on docker hub

Glennaglennie answered 27/3, 2023 at 10:59 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Aidaaidan
P
0

I tried almost every possible solution here and other sources, none of them worked for me. Follow the below steps to fix this.

I am using the Windows 11 OS.

Below is what I want to push to docker hub.

<to>
                <image>registry.hub.docker.com/<docker-hub-username>/${project.artifactId}:1.0</image>
            </to>

.config/config.json file

Do not delete this file. Keep it open in notepad.

Before you login to docker hub in CMD, just remove credStore key-value from config.json file.

Now go to Windows CMD to login to docker hub as follows and hit the enter button. It will ask for the password. Use access token/password for the docker hub.

docker login -u <docker-hub-username>

Output: enter image description here

It should add auth key-value in your config.json file as following.

{
"auths": {
    "https://index.docker.io/v1/": {
        "auth": "<auto-generated-base64-encoded-username-password-for-docker-hub>"
    }
}

}

Now push the image to docker hub using Jib.

 mvn clean compile jib:build
Poaceous answered 15/7, 2023 at 19:3 Comment(0)
D
0

"docker logout" worked for me. It says that it's a meaningless error and happens sometimes.

Connection to registry-1.docker.io fails "unauthorized: incorrect username or password"

Deimos answered 21/12, 2023 at 11:29 Comment(0)
G
0

I faced this issue before I tried this solution, and it's worked for me. first you need to logout from docker :-

docker logout

after that run your command :-

mvnw clean install jib:dockerBuild -Dimage=fullstack:v1

and login again into Docker.

Gangster answered 10/1 at 10:42 Comment(0)
W
0
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <offline/>
  <pluginGroups/>
  <servers>
    <server>
      <id>registry-1.docker.io</id>
      <username>dockeranhduong</username>
      <password>.....</password>
    </server>
    <server>
      <id>registry.hub.docker.com</id>
      <username>dockeranhduong</username>
      <password>......</password>
    </server>
  </servers>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>
Wyandotte answered 15/4 at 3:26 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Aidaaidan

© 2022 - 2024 — McMap. All rights reserved.