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

Document how to initialize docker-credentials-pass #102

Open
pasih opened this issue May 11, 2018 · 77 comments
Open

Document how to initialize docker-credentials-pass #102

pasih opened this issue May 11, 2018 · 77 comments

Comments

@pasih
Copy link

pasih commented May 11, 2018

Hi,

the README currently says:
"pass needs to be configured for docker-credential-pass to work properly. It must be initialized with a gpg2 key ID. Make sure your GPG key exists is in gpg2 keyring as pass uses gpg2 instead of the regular gpg."

However, I could not find any documentation whatsoever on the initialization. There doesn't seem to be a docker-credentials-pass init command? It would be helpful to actually document the steps how to initialize the pass store.

(I can create a pull request for README changes once I figure out how to actually do the initialization)

@Ayrat-Kh
Copy link

Hi. I`m sorry for my English. After spending some time, i was able to setup credential store and maybe my experience will help you.

I used ubuntu 18.04 and did all action as root user.

  1. download "docker-credential-pass".
    wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz

  2. unpack tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz

  3. i couldn`t configure $PATH environment variable, so i copied unpacked file to /usr/bin directory.

  4. check that docker-credential-pass work. To do this, run command docker-credential-pass. You should see: "Usage: docker-credential-pass <store|get|erase|list|version>".

  5. install gpg and pass. apt install gpg pass

  6. gpg --generate-key. Enter your name, mail, etc. You will get gpg-id like "5BB54DF1XXXXXXXXF87XXXXXXXXXXXXXX945A". Copy it to clipboard.

  7. pass init (paste from clipboard)

  8. pass insert docker-credential-helpers/docker-pass-initialized-check and set the next password "pass is initialized" (without quotes).

  9. pass show docker-credential-helpers/docker-pass-initialized-check. You should see pass is initialized.

  10. docker-credential-pass list. You should see {} or another data. You shouldn`t see error like "pass store is uninitialized".

  11. nano ~/.docker/config.json. Set in root node the next line "credsStore": "pass" save ctrl+o.

  12. after docker login and etc.

I'm not a guru on unux based OS and some actions can be done better. I hope someone will help my answer.

@nathanfiscus
Copy link

nathanfiscus commented May 14, 2018

@pasih, here is what i did to get my docker client working with docker-credentials-pass. I have slight variations from what @Ayrat-Kh did.

  1. Install pass
sudo apt-get install pass
  1. Download, extract, make executable, and move docker-credential-pass
wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz && tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz && chmod +x docker-credential-pass && sudo mv docker-credential-pass /usr/local/bin/
  1. Create a new gpg2 key.
gpg2 --gen-key
  1. Follow prompts from gpg2 utility

  2. Initialize pass using the newly created key

pass init "<Your Name>"
  1. Add credsStore to your docker config. This can be done with sed if you don't already have credStore added to your config or you can manually add "credStore":"pass" to the config.json.
sed -i '0,/{/s/{/{\n\t"credsStore": "pass",/' ~/.docker/config.json
  1. Login to docker
docker login

References:
https://hackernoon.com/getting-rid-of-docker-plain-text-credentials-88309e07640d
https://www.passwordstore.org/

@visualex
Copy link

Another slight variation, as I needed to use /dev/urandom
apparently I was running out of entropy and gpg2 --gen-key was hanging on the "generating random numbers .... " part

wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz && tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz && chmod +x docker-credential-pass && sudo mv docker-credential-pass /usr/local/bin/

yes | sudo apt install pass
yes | sudo apt install rng-tools
yes | sudo apt install rng-tools5
gpg-agent --daemon --use-standard-socket --pinentry-program /usr/bin/pinentry-curses
sudo rngd -r /dev/urandom
gpg2 --gen-key
pass init "Your Name"
sed -i '0,/{/s/{/{\n\t"credsStore": "pass",/' ~/.docker/config.json
docker login your-registry:5000

@CodingKoopa
Copy link

CodingKoopa commented Jun 27, 2018

  1. pass insert docker-credential-helpers/docker-pass-initialized-check and set the next password "pass is initialized" (without quotes).
  2. pass show docker-credential-helpers/docker-pass-initialized-check. You should see pass is initialized.
  3. docker-credential-pass list. You should see {} or another data. You shouldn`t see error like "pass store is uninitialized".

I had to follow these steps of @Ayrat-Kh's to get docker-credential-pass list to print anything other than "pass store is uninitialized". After doing this, though, I was able to rm ~/.password-store, run pass init $ID again, and have it as expected, without having to do steps 8-10 again.

@edingroot
Copy link

If the passphrase is not empty while generating gpg key, got following error message when running docker login your-registry:5000 with version v0.6.1.

Error saving credentials: error storing credentials - err: exit status 1, out: `error fetching password during initialization: exit status 2: gpg: cancelled by user
gpg: decryption failed: No secret key`

The error was thrown by pass_linux.go#L64 which the script is trying to run

pass show ~/.password-store/docker-pass-initialized-check

Caused by a prompt popped out for asking the passphrase, due to there is no input, error message
exit status 2: gpg: cancelled by user was caught.

Thus, entering passphrase by running the command above manually could temporally solve the problem.

@neomatrix369
Copy link

neomatrix369 commented Aug 6, 2018

@nathanfiscus thanks for the steps mentioned #102 (comment), I didn't find it was very clear from the docs at
#102 - I did the extra step of downloading the docker-credentials-pass and it worked fine. I'm thinking docker-credentials-pass is the wrapper around pass so we need both of them present

👍 ❤️

@krisbalaa
Copy link

krisbalaa commented Aug 16, 2018

@nathanfiscus Excellent. Thanks for the steps. I would like to handle entering the passphrase through bash script for the following command.
pass show ~/.password-store/docker-pass-initialized-check
Is it possible?

@mkjmdski
Copy link

If you follow this guide and somehow you can't generate gpg key because gpg process is hanging, please install rng-tools and run its deamon by rngd -r /dev/urandom to generate enough random noise in your system to generate the key. You can observe your noise by cat /proc/sys/kernel/random/entropy_avail. Also using gnupg2 could help.

@olekszhel
Copy link

olekszhel commented Nov 9, 2018

Hi. I`m sorry for my English. After spending some time, i was able to setup credential store and maybe my experience will help you.

I used ubuntu 18.04 and did all action as root user.

  1. download "docker-credential-pass".
    wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz
  2. unpack tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz
  3. i couldn`t configure $PATH environment variable, so i copied unpacked file to /usr/bin directory.
  4. check that docker-credential-pass work. To do this, run command docker-credential-pass. You should see: "Usage: docker-credential-pass <store|get|erase|list|version>".
  5. install gpg and pass. apt install gpg pass
  6. gpg --generate-key. Enter your name, mail, etc. You will get gpg-id like "5BB54DF1XXXXXXXXF87XXXXXXXXXXXXXX945A". Copy it to clipboard.
  7. pass init (paste from clipboard)
  8. pass insert docker-credential-helpers/docker-pass-initialized-check and set the next password "pass is initialized" (without quotes).
  9. pass show docker-credential-helpers/docker-pass-initialized-check. You should see pass is initialized.
  10. docker-credential-pass list. You should see {} or another data. You shouldn`t see error like "pass store is uninitialized".
  11. nano ~/.docker/config.json. Set in root node the next line "credsStore": "pass" save ctrl+o.
  12. after docker login and etc.

I'm not a guru on unux based OS and some actions can be done better. I hope someone will help my answer.

@Ayrat-Kh Sorry, but where did you get this "secret knowledge" from?)

@ghost
Copy link

ghost commented Dec 16, 2018

Hi using Fedora 28 and Docker version 18.09.0, build 4d60db4.

pass is not the password store by default. Docker stores passwords bas64 encoded. The instructions above by @Ayrat-Kh and @nathanfiscus are not working for me. I keep getting the error:

Error saving credentials: error storing credentials - err: exit status 1, out: \pass store is uninitialized``

Here's my output after @Ayrat-Kh steps:

pass llst

Password Store
└── docker-credential-helpers
    └── docker-pass-initialized-check

pass show docker-credential-helpers/docker-pass-initialized-check

pass is initialized

I see the plan is to add pass as default

docker-archive/docker-ce@9337e13

but right now I can't get it working

@ghost
Copy link

ghost commented Dec 16, 2018

any ideas? @n4ss

@makville
Copy link

@jmliz I was able to solve this by running

pass insert docker-credential-helpers/docker-pass-initialized-check

and then not setting a passphrase. I just left it empty

It has been working since.

@ghost
Copy link

ghost commented Dec 26, 2018

@makville I'm still getting the same error with an empty passphrase.

@dabiddo
Copy link

dabiddo commented Jan 1, 2019

I'm getting the same error, I followed the steps for docker-credential-helper, they worked the 1st time, but after restarting the computer, same behavior continues, even if I retrace the steps for generating keys and docker login, as soon as I hit docker-compose up , I get the credentials error :(

@makville
Copy link

makville commented Jan 1, 2019

@jmliz @dabio I just experienced the same problem as you. Once I restarted the server it was all back to square one again. Oh well.

@ghost
Copy link

ghost commented Jan 1, 2019

@makville restarting doesn't help. I wasn't ever able to get it working in the first place.

@ghost
Copy link

ghost commented Jan 1, 2019

this plugin doesn't even have proper documentation. no contributor ever replied to this issue.

@nathanfiscus
Copy link

Those of you still having issues might try one of these below. I haven't looked through all the code for docker-credential-pass, but I think that the plugin is not properly triggering the gpg-agent (in all instances) that pass uses to login to and decrypt the store. Essentially the password store is locking after the default 10 minutes. I have two workarounds for this until/if the issue gets fixed:

  1. Set the timeout for the gpg-agent conf to a ridiculously high number:
$ cat ~/.gnupg/gpg-agent.conf
max-cache-ttl 60480000
default-cache-ttl 60480000

That is 400 days. This obviously is just as insecure as using the default plain text file, but gets around the warning. You will have to trigger this the first time and after 400 days or whatever you set.

  1. Manually trigger the pass store to unlock before performing a docker command that requires authentication like docker login or docker push. I have been experimenting with this bash script (this is a work in progress and bash is not a strength of mine, so feel free to clean this up. 😄)
INITMSG="$(pass show docker-credential-helpers/docker-pass-initialized-check)"
ERRMSG="Error"
LISTMSG=""

if [ "$INITMSG" = *$ERRMSG* ]
then
LISTMSG="$(docker-credential-pass list)"
else
LISTMSG="Initialized"
fi

ERRMSG2="pass store is uninitialized"
EMPTY=""

if [ "$LISTMSG" = "$ERRMSG2" ]
then
exit 1
elif [ "$LISTMSG" = "$EMPTY" ]
then
exit 1
else
exit 0
fi

I put this in my /usr/bin directory and made it executable.

Usage would be something like:

docker-pass && docker login

@ghost
Copy link

ghost commented Jan 8, 2019

@nathanfiscus I don't understand when you say "Essentially the password store is locking after the default 10 minutes". I immediately try to login after I set up pass and it doesn't work. I will give it a try though.

@spkane
Copy link

spkane commented Jan 10, 2019

I also have issues using this even immediately afterwards running docker-credential-pass list and getting {} returned.

In my case I can run docker login and it works, but it seems that the password is not actually saved into the store, and when I docker logout I get an error about it not being there, and sure enough, another list still shows everything as empty.

Maybe it depends on the version of Docker you are running? Newer versus older?

I have:

  • gpg (GnuPG) 2.2.7
  • pass version v1.7.3
  • tree v1.8.0 # which is needed by pass unfortunately.
  • Docker version 18.06.1-ce, build e68fc7a
  • docker-credential-pass 0.6.0

In my case I am building everything, but Docker and GnuPG, as I am trying to get this working on a CoreOS linux system.

@spkane
Copy link

spkane commented Jan 11, 2019

I figured out the issue in my case. This still feels a bit like a bug, but of a different sort. Using docker login against a registry that does not currently support auth (we are turning it on in a few days after some testing) works fine. It seems to log you in no matter what you use as the username/password, but docker logout breaks, as no credential is stored during login, so when you logout, and it tries to deleted the credential you get an error saying that the credential delete failed.

@ghost
Copy link

ghost commented Jan 11, 2019

@spkane how can login work if you dont have authentication? I'm not aware of docker internals but that sounds strange. nothing worked so far for me.

@jwaffe75
Copy link

jwaffe75 commented Jan 24, 2022

We're going to be coming up on the 4 year anniversary of this issue soon.

When is this going to be added to the official docs? People are linking to this issue as a tutorial.

@rodrigo-m-martins
Copy link

Hi. I`m sorry for my English. After spending some time, i was able to setup credential store and maybe my experience will help you.

I used ubuntu 18.04 and did all action as root user.

1. download "docker-credential-pass".
   wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz

2. unpack tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz

3. i couldn`t configure $PATH environment variable, so i copied unpacked file to /usr/bin directory.

4. check that docker-credential-pass work. To do this, run command docker-credential-pass. You should see: "Usage: docker-credential-pass <store|get|erase|list|version>".

5. install gpg and pass. apt install gpg pass

6. gpg --generate-key. Enter your name, mail, etc. You will get gpg-id like "5BB54DF1XXXXXXXXF87XXXXXXXXXXXXXX945A". Copy it to clipboard.

7. pass init  (paste from clipboard)

8. pass insert docker-credential-helpers/docker-pass-initialized-check and set the next password "pass is initialized" (without quotes).

9. pass show docker-credential-helpers/docker-pass-initialized-check. You should see pass is initialized.

10. docker-credential-pass list. You should see {} or another data. You shouldn`t see error like "pass store is uninitialized".

11. nano ~/.docker/config.json. Set in root node the next line "credsStore": "pass" save ctrl+o.

12. after docker login and etc.

I'm not a guru on unux based OS and some actions can be done better. I hope someone will help my answer.

You're not a guru but still helping.
Thanks for your help.

@creztfallen
Copy link

I made this work! See if it will work out for you as well. I'm using MX Linux, this should work on other versions.

By default, when you use docker login will look for .docker/config.json from the root of your system. Specifically, $cd /root/.docker. However, you cannot access this just by adding sudo on cd.

Enough with the appetizer, here is the main dish:

From your terminal, you can start anywhere even in your $HOME directory (Ctrl + Alt + T):

  1. Download, extract, make executable, and move to make it available to $PATH

    $ wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.4/docker-credential-pass-v0.6.4-amd64.tar.gz
    $ tar -xf docker-credential-pass-v0.6.4-amd64.tar.gz
    $ chmod +x docker-credential-pass
    $ mv docker-credential-pass /usr/local/bin
  2. Change directory to system root

    $ sudo su
    $ cd /root
  3. Edit the docker config.json using nano, or if you have better options

    $ nano .docker/config.json

    Your file should look like this:

    { 
            "credsStore": "pass",
            "auths": {}
    }

    Generate gpg key and copy the ID. It is a bit long strings of character all in caps (e.g. KJSADUSN831RHAM)
    $ gpg --gen-keys
    Initialize pass
    $ pass init

  4. Lastly, login to docker

    $ sudo docker login

    You will finally see the password store tree by using pass command. Make sure you are in the system /root directory and have sudo su activated.

    $ pass

    It should look like this:

    └── docker-credential-helpers
       └── aHR0cHM7Ly9pbmrleC5kb2NrZXIuaW8vdjEv
          └── blitzdex27

That's it! I hope it worked for you too.

Note that you do not need to intentionally create the docker-credential-helpers by using pass insert docker-credential-helpers. Docker will do that for you. I realized this after reading the passwordstore documentation and trying it out myself, and I felt strange too when I had to create it intentionally.

Reference:

PS: This is my first time posting here so please tell me how to improve. Thank you :)

You saved my life. Thank you so much.

@blitzdex27
Copy link

I made this work! See if it will work out for you as well. I'm using MX Linux, this should work on other versions.
By default, when you use docker login will look for .docker/config.json from the root of your system. Specifically, $cd /root/.docker. However, you cannot access this just by adding sudo on cd.
Enough with the appetizer, here is the main dish:
From your terminal, you can start anywhere even in your $HOME directory (Ctrl + Alt + T):

  1. Download, extract, make executable, and move to make it available to $PATH

    $ wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.4/docker-credential-pass-v0.6.4-amd64.tar.gz
    $ tar -xf docker-credential-pass-v0.6.4-amd64.tar.gz
    $ chmod +x docker-credential-pass
    $ mv docker-credential-pass /usr/local/bin
  2. Change directory to system root

    $ sudo su
    $ cd /root
  3. Edit the docker config.json using nano, or if you have better options

    $ nano .docker/config.json

    Your file should look like this:

    { 
            "credsStore": "pass",
            "auths": {}
    }

    Generate gpg key and copy the ID. It is a bit long strings of character all in caps (e.g. KJSADUSN831RHAM)
    $ gpg --gen-keys
    Initialize pass
    $ pass init

  4. Lastly, login to docker

    $ sudo docker login

    You will finally see the password store tree by using pass command. Make sure you are in the system /root directory and have sudo su activated.

    $ pass

    It should look like this:

    └── docker-credential-helpers
       └── aHR0cHM7Ly9pbmrleC5kb2NrZXIuaW8vdjEv
          └── blitzdex27

That's it! I hope it worked for you too.
Note that you do not need to intentionally create the docker-credential-helpers by using pass insert docker-credential-helpers. Docker will do that for you. I realized this after reading the passwordstore documentation and trying it out myself, and I felt strange too when I had to create it intentionally.
Reference:

PS: This is my first time posting here so please tell me how to improve. Thank you :)

You saved my life. Thank you so much.

You are welcome, brother! And good thing you read my solution. Keep up the good work! :)

@yenaras
Copy link

yenaras commented Aug 24, 2022

We're going to be coming up on the 4 year anniversary of this issue soon.

When is this going to be added to the official docs? People are linking to this issue as a tutorial.

Took me an hour to find this thread after going through official docs for docker and pass and nothing worked except this thread.

@4r7if3x
Copy link

4r7if3x commented Sep 27, 2022

Please note that all docker, gpg, and pass have different environments per user, so running one command with sudo and the other without it, would cause issues here. Other than that, there is no need to use sudo if you have a non-root user, if you've already created anything with sudo, you'd better remove it.

@opticSquid
Copy link

I mistakenly deleted the GPG key that I used for docker desktop login. I had passed it in pass init command. Now how do I reinitialise pass with a different GPG key

@frhndas
Copy link

frhndas commented Nov 21, 2022

**nathanfiscus ** commented May 15, 2018

i still can't login docker and the error is Error saving credentials: error storing credentials - err: exit status 1, out: error getting credentials - err: exit status 1, out: no usernames for https://index.docker.io/v1/``. what can i do ?

@AndrewSav
Copy link

Fellow users, does anyone know what the credential helper actually does when used with pass? I was expecting it to store my password, but after following the instructions above I'm required to login to docker and enter the registry password every time I have a new ssh session. May be that's exactly what it is intended to do - keep credentials cached in memory until reconnect - I can confirm that they are no longer stored in config.json, but surely, they would not need pass or another keychain for that? So why cannot it pickup the credentials from pass after re-connect?

@yenaras
Copy link

yenaras commented Dec 8, 2022

Fellow users, does anyone know what the credential helper actually does when used with pass? I was expecting it to store my password, but after following the instructions above I'm required to login to docker and enter the registry password every time I have a new ssh session. May be that's exactly what it is intended to do - keep credentials cached in memory until reconnect - I can confirm that they are no longer stored in config.json, but surely, they would not need pass or another keychain for that? So why cannot it pickup the credentials from pass after re-connect?

The purpose is to make sure your password is not stored in a plain text file like config.json. If you don't want to enter a password for ssh, just don't use a password for your ssh key, although this is less secure so I recommend continuing to use your password for ssh.

@AndrewSav
Copy link

The purpose is to make sure your password is not stored in a plain text file like config.json. If you don't want to enter a password for ssh, just don't use a password for your ssh key, although this is less secure so I recommend continuing to use your password for ssh.

ssh password is out of the picture, I do not believe it has anything to do at all with docker-credential-pass helper. I was referring to docker registry password, not sure why it needs to be entered every time after re-establishing ssh session.

@MichaelJCole
Copy link

MichaelJCole commented Dec 10, 2022

Does anyone else find it odd that to plug this "plain-text password security hole" you are in some back-alley github issue copy/pasting bash code to download rando unsigned binary code, make it executable, and add it to your path?

Here's another option

1. remove credsStore and auth key from ~/.docker/config.json
2. do docker login, if you get this warning, you are good to go:

[2022-02-25 14:18:33] WARNING! Your password will be stored unencrypted in xxx/.docker/config.json.
[2022-02-25 14:18:33] Configure a credential helper to remove this warning. See
[2022-02-25 14:18:33] https://docs.docker.com/engine/reference/commandline/login/#credentials-store

3. If you don't see that warning, remove docker-credential-* from apt or /Applications/Docker.app/Contents/Resources/bin/ (windows? Mac?)

@AndrewSav
Copy link

@MichaelJCole you might have got it wrong: this is not "some back-alley GitHub issue" - this is the official docker credential helper repository hosted under the docker organisation. And it is not "rando unsigned binary code" it is the official binaries of the said repository. What you linked is not an option if you do not want unencrypted credentials, and most people who end up here do not want that.

@Abdurahman-hassan
Copy link

I made this work! See if it will work out for you as well. I'm using MX Linux, this should work on other versions.
By default, when you use docker login will look for .docker/config.json from the root of your system. Specifically, $cd /root/.docker. However, you cannot access this just by adding sudo on cd.
Enough with the appetizer, here is the main dish:
From your terminal, you can start anywhere even in your $HOME directory (Ctrl + Alt + T):

  1. Download, extract, make executable, and move to make it available to $PATH

    $ wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.4/docker-credential-pass-v0.6.4-amd64.tar.gz
    $ tar -xf docker-credential-pass-v0.6.4-amd64.tar.gz
    $ chmod +x docker-credential-pass
    $ mv docker-credential-pass /usr/local/bin
  2. Change directory to system root

    $ sudo su
    $ cd /root
  3. Edit the docker config.json using nano, or if you have better options

    $ nano .docker/config.json

    Your file should look like this:

    { 
            "credsStore": "pass",
            "auths": {}
    }

    Generate gpg key and copy the ID. It is a bit long strings of character all in caps (e.g. KJSADUSN831RHAM)
    $ gpg --gen-keys
    Initialize pass
    $ pass init

  4. Lastly, login to docker

    $ sudo docker login

    You will finally see the password store tree by using pass command. Make sure you are in the system /root directory and have sudo su activated.

    $ pass

    It should look like this:

    └── docker-credential-helpers
       └── aHR0cHM7Ly9pbmrleC5kb2NrZXIuaW8vdjEv
          └── blitzdex27

That's it! I hope it worked for you too.
Note that you do not need to intentionally create the docker-credential-helpers by using pass insert docker-credential-helpers. Docker will do that for you. I realized this after reading the passwordstore documentation and trying it out myself, and I felt strange too when I had to create it intentionally.
Reference:

PS: This is my first time posting here so please tell me how to improve. Thank you :)

You saved my life. Thank you so much.

You are welcome, brother! And good thing you read my solution. Keep up the good work! :)

Thank you, so much

@AndreasNasman
Copy link

AndreasNasman commented Feb 6, 2023

Edit: Fixed


I have a hunch this might not be the correct repo to ask this question, but here goes anyway. I've searched this repo and the web for similar questions but haven't been able to find any.

I have experimented with Docker Desktop on Arch following the Docker documentation:

Everything is working fine except credential verification. I'm able to log in manually by following the instructions in this comment with docker login. However, every time I launch Docker Desktop, ~/.docker/config.json has its content changed to this:

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

I have docker-credential-desktop in my PATH but it doesn't seem to work. My current workaround is to manually edit the ~/.docker/config.json file, switch the context with docker context use desktop-linux, and then run docker login.

Does anyone know how I can make docker-credential-desktop function correctly or make Docker Desktop always use docker-credential-pass? docker-credential-desktop constantly gives a gpg: decryption failed: No secret key error.

@AndreasNasman
Copy link

I was able to solve my problem above. The gpg: decryption failed: No secret key error was a bit cryptic, but adding export GPG_TTY=$(tty) to my .bashrc (found here) fixed the problem! 🎉

With the fix above, docker login started asking to unlock my OpenPGP secret key instead of the regular username/password prompt. I didn't realize this was the intended behavior, but with the solution in hand, it kinda makes sense. Would have been much easier to debug if the error message was something along the lines of GPG_TTY not defined 😄

@HiGein
Copy link

HiGein commented Feb 28, 2023

docker-credential-pass still doesn't work for non-root users

@pablovazquezg
Copy link

pablovazquezg commented Apr 26, 2023

@nathanfiscus

These kind of thorough / clear / super helpful responses never fail to strengthen my faith in humankind. Thank you!

@emandret
Copy link

If for some reasons, after installing docker-credential-pass and initializing pass with a GPG RSA key, you still can't pull without re-authenticating, try this:

export GPG_TTY=$(tty)

@rubyhcm
Copy link

rubyhcm commented Oct 10, 2023

Hi. I`m sorry for my English. After spending some time, i was able to setup credential store and maybe my experience will help you.

I used ubuntu 18.04 and did all action as root user.

1. download "docker-credential-pass".
   wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz

2. unpack tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz

3. i couldn`t configure $PATH environment variable, so i copied unpacked file to /usr/bin directory.

4. check that docker-credential-pass work. To do this, run command docker-credential-pass. You should see: "Usage: docker-credential-pass <store|get|erase|list|version>".

5. install gpg and pass. apt install gpg pass

6. gpg --generate-key. Enter your name, mail, etc. You will get gpg-id like "5BB54DF1XXXXXXXXF87XXXXXXXXXXXXXX945A". Copy it to clipboard.

7. pass init  (paste from clipboard)

8. pass insert docker-credential-helpers/docker-pass-initialized-check and set the next password "pass is initialized" (without quotes).

9. pass show docker-credential-helpers/docker-pass-initialized-check. You should see pass is initialized.

10. docker-credential-pass list. You should see {} or another data. You shouldn`t see error like "pass store is uninitialized".

11. nano ~/.docker/config.json. Set in root node the next line "credsStore": "pass" save ctrl+o.

12. after docker login and etc.

I'm not a guru on unux based OS and some actions can be done better. I hope someone will help my answer.

Now, it still works

@baloan
Copy link

baloan commented Oct 25, 2023

For me (Ubuntu 20.04) the .docker config directory is located at /root/snap/docker/2893/.docker

@tapyu
Copy link

tapyu commented Nov 16, 2023

For Linux users who are lazy enough to manually install docker-credential-pass, the following one-line command make it for you (assuming 64-bits architecture):

sudo curl -o /usr/bin/docker-credential-pass -LO $(curl -s https://api.github.com/repos/docker/docker-credential-helpers/releases/latest | grep browser_download_url | grep docker-credential-pass | grep linux-amd64 | cut -d '"' -f 4); sudo chmod a+x /usr/bin/docker-credential-pass

@juanmarcoso
Copy link

Hi. I`m sorry for my English. After spending some time, i was able to setup credential store and maybe my experience will help you.
I used ubuntu 18.04 and did all action as root user.

  1. download "docker-credential-pass".
    wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz
  2. unpack tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz
  3. i couldn`t configure $PATH environment variable, so i copied unpacked file to /usr/bin directory.
  4. check that docker-credential-pass work. To do this, run command docker-credential-pass. You should see: "Usage: docker-credential-pass <store|get|erase|list|version>".
  5. install gpg and pass. apt install gpg pass
  6. gpg --generate-key. Enter your name, mail, etc. You will get gpg-id like "5BB54DF1XXXXXXXXF87XXXXXXXXXXXXXX945A". Copy it to clipboard.
  7. pass init (paste from clipboard)
  8. pass insert docker-credential-helpers/docker-pass-initialized-check and set the next password "pass is initialized" (without quotes).
  9. pass show docker-credential-helpers/docker-pass-initialized-check. You should see pass is initialized.
  10. docker-credential-pass list. You should see {} or another data. You shouldn`t see error like "pass store is uninitialized".
  11. nano ~/.docker/config.json. Set in root node the next line "credsStore": "pass" save ctrl+o.
  12. after docker login and etc.

I'm not a guru on unux based OS and some actions can be done better. I hope someone will help my answer.

@Ayrat-Kh Sorry, but where did you get this "secret knowledge" from?)

Genial!!! Me ayudaste un monton!!! Muchas gracias por tu aporte!

@agirault
Copy link

agirault commented Dec 1, 2023

pass insert docker-credential-helpers/docker-pass-initialized-check and set the next password "pass is initialized"

I believe this is obsolete?

gpg --generate-key

Should we be using gpg2?

pass init ""

I see some references to "Your name", some to the gpg-id generated from the command above. Could someone clarify?


This is my solution (part of this gist):

#!/bin/bash
set -exu
set -o pipefail

# Based on https://github.com/docker/docker-credential-helpers/issues/102

# Check for sudo
if [[ $EUID -eq 0 ]]; then
   echo "This script must not be run as root"
   exit 1
fi

# vars
arch=$(dpkg --print-architecture)
rel=$(. /etc/os-release && echo "$VERSION_CODENAME")

# Install docker if needed
if ! command -v docker > /dev/null; then
   docker_gpg_path="/etc/apt/keyrings/docker.gpg"
   sudo install -m 0755 -d $(dirname "$docker_gpg_path")
   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --yes --dearmor -o "$docker_gpg_path"
   sudo chmod a+r "$docker_gpg_path"
   echo "deb [arch="$arch" signed-by="$docker_gpg_path"] https://download.docker.com/linux/ubuntu "$rel" stable" | \
     sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
   sudo apt-get update
   sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
fi

# Add user to docker group
sudo groupadd docker || true
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world

# Install dependencies for securing docker credentials
sudo apt-get update
sudo apt-get install -y ca-certificates gnupg gnupg2 pass

# Install docker-credential-pass
docker_creds_pass_version="v0.8.0"
docker_creds_pass_url="https://github.com/docker/docker-credential-helpers/releases/download/$docker_creds_pass_version/docker-credential-pass-$docker_creds_pass_version.linux-$arch"
docker_creds_pass_path="/usr/local/bin/docker-credential-pass"
sudo wget "$docker_creds_pass_url" -O "$docker_creds_pass_path"
sudo chown $USER "$docker_creds_pass_path"
sudo chmod u+x "$docker_creds_pass_path"

# Make docker use the docker-credential-pass
docker_config_path="$HOME/.docker.config.json"
docker_creds_config='"credsStore": "pass"'
if [[ -f "$docker_config_path" ]]; then
   if ! grep -qF "$docker_creds_config" "$docker_config_path"; then
      # Append to config
      sed -i "0,/{/s|{|{\n\t$docker_creds_config,|" "$docker_config_path"
   fi
else
   # Create config
   printf "{\n\t$docker_creds_config\n}\n" > "$docker_config_path"
fi

# Generate GPG key and add to pass
gpg_id=$(gpg2 --generate-key | grep -oP '^\s*\K[[:alnum:]]+$')
pass init $gpg_id
docker-credential-pass list >/dev/null # errors out if not setup properly

# Enable TTY pinentry when there is no display
# https://superuser.com/questions/520980/how-to-force-gpg-to-use-console-mode-pinentry-to-prompt-for-passwords
tty_comment="\n# Enable TTY pinentry for GPG password when there is no display\n"
fish_tty_cmd='set -gx GPG_TTY $(tty)'
fish_config_path="$HOME/.config/fish/config.fish"
bash_tty_cmd='export GPG_TTY=$(tty)'
bash_config_path="$HOME/.bashrc"
if ! grep -qF "$fish_tty_cmd" "$fish_config_path"; then
   printf "${tty_comment}${fish_tty_cmd}\n" >> "$fish_config_path"
fi
if ! grep -qF "$bash_tty_cmd" "$bash_config_path"; then
   printf "${tty_comment}${bash_tty_cmd}\n" >> "$bash_config_path"
fi

@joh4nd
Copy link

joh4nd commented Jan 10, 2024

Anyone else who keep getting prompted for the passphrase? docker/desktop-linux#115

@ryparker
Copy link

Hi using Fedora 28 and Docker version 18.09.0, build 4d60db4.

pass is not the password store by default. Docker stores passwords bas64 encoded. The instructions above by @Ayrat-Kh and @nathanfiscus are not working for me. I keep getting the error:

Error saving credentials: error storing credentials - err: exit status 1, out: \pass store is uninitialized``

Here's my output after @Ayrat-Kh steps:

pass llst

Password Store
└── docker-credential-helpers
    └── docker-pass-initialized-check

pass show docker-credential-helpers/docker-pass-initialized-check

pass is initialized

I see the plan is to add pass as default

docker/docker-ce@9337e13

but right now I can't get it working

You're either not using the correct binary or downloading the binary incorrectly. Check the size of the download to verify you're downloading correctly. If using curl be sure to pass -L to follow GitHub's redirects.

e.g. for arm64

 curl -L "https://github.com/docker/docker-credential-helpers/releases/download/v0.8.1/docker-credential-pass-v0.8.1.linux-arm64" -o "docker-credential-pass"    

@qrkourier
Copy link

If for some reasons, after installing docker-credential-pass and initializing pass with a GPG RSA key, you still can't pull without re-authenticating, try this:

export GPG_TTY=$(tty)

This has sometimes allowed me to type the GnuPG passphrase in the pinentry TUI when headless, and other times the SSH session appears to crash due to terminal corruption. When it "crashes," the pinentry TUI appears, but passphrase keystrokes result in literal characters printed at bottom left, not as masked * in the TUI's passphrase field. Moments later, the SSH session terminates.

@attributeofextension
Copy link

I've been banging my head against this problem for 3 days and the only way I found to properly secure docker was by resorting to installing Docker Desktop. The essential problem is that you are never prompted to enter the passkey once you have successfully used pass etc to store the pass token. What if I want to install Docker on a very small device without a Desktop GUI? I think more work needs to be done around the docker-credential-helper for pass.

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

No branches or pull requests