Set Up Docker Credential Store on VMware Photon

Photon OS

If you’re using ESXi hypervisors and Docker, you’re probably using VIC or running it on an Ubuntu VM. But recently we tried VMware’s new “Minimal Linux Container Host”, Photon OS.

With Photon, you can install packages using tdnf. To keep it minimalist, we avoided adding any additional repositories, but this made it surprisingly difficult to set up the credential store. We decided to set up pass to protect our login. Otherwise, credentials will appear in cleartext in the ~/.docker/config.json file.

Install Packages from tdnf

To make this easier you’ll want all of the below packages.

  • wget
  • tar
  • make
  • gnupg
  • tree
root@photon-machine [ ~ ]# tdnf -y install wget tar make gnupg tree

Login to Docker

Log in to Docker at least once if you have not already done so. This will automatically create the ~/.docker/config.json file for you.

root@photon-machine [ ~ ]# docker login
Login with your Docker ID to push and pull images from 

Docker Hub

. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: pandatech0
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
root@photon-machine [ ~ ]# docker logout
Removing login credentials for https://index.docker.io/v1/

Manually Install pass

None of the built-in repositories in Photon come with pass. Be sure to check the official site in case there is a newer version than what is in the instructions below.

root@photon-machine [ ~ ]# wget https://git.zx2c4.com/password-store/snapshot/password-store-1.7.3.tar.xz
root@photon-machine [ ~ ]# tar -xf password-store-1.7.3.tar.xz 
root@photon-machine [ ~ ]# cd password-store-1.7.3/
root@photon-machine [ ~ ]# make install

Manually Install docker-credential-pass

Once pass is installed, you can download and install docker-credential-pass from Docker’s GitHub.

root@photon-machine [ ~ ]# wget https://github.com/docker/docker-credential-helpers/releases/download/v0.6.0/docker-credential-pass-v0.6.0-amd64.tar.gz
root@photon-machine [ ~ ]# tar -xf docker-credential-pass-v0.6.0-amd64.tar.gz
root@photon-machine [ ~ ]# chmod +x docker-credential-pass 
root@photon-machine [ ~ ]# mv docker-credential-pass /usr/local/bin/

Update the Docker Config File

root@photon-machine [ ~ ]# vi ~/.docker/config.json

This file should have been automatically created the first time you ran docker login. Add line 8 as seen below:

{
    "auths": {
        "https://index.docker.io/v1/": {}
    },
    "HttpHeaders": {
        "User-Agent": "Docker-Client/18.06.2 (linux)"
    },
    "credsStore": "pass"
}

Generate Keys for the Store

Before you can properly use pass, you’ll need to generate a key for encrypting all your passwords. For simplicity we used the simple command. You may want to consider using gpg --full-generate-key to view all of the possible key creation options.

root@photon-machine [ ~ ]# gpg --generate-key

You’ll be prompted for email address, and then you’ll be asked to create and confirm a password for the store. Below is the sample output. This may take a while to generate the key. I usually set it to run before bed.

gpg (GnuPG) 2.2.10; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Note: Use "gpg --full-generate-key" for a full featured key generation dialog.

GnuPG needs to construct a user ID to identify your key.

Real name: 
Email address: a.shen@pandatech.co
You selected this USER-ID:
    "a.shen@pandatech.co"

Change (N)ame, (E)mail, or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.

Initialize Pass

First, verify that a new, valid key was created with the below:

root@photon-machine [ ~ ]# gpg --list-keys
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2020-02-27
/root/.gnupg/pubring.kbx
------------------------
pub   rsa2048 2018-02-28 [SC] [expires: 2020-02-27]
      FFFFFFFFFFFFFFF0000000000000000000000000
uid           [ultimate] a.shen@pandatech.co
sub   rsa2048 2018-02-28 [E] [expires: 2020-02-27]

After verification, initialize pass using the email address you created a key with. You’ll be prompted to create and confirm a password for the store.

root@photon-machine [ ~ ]# pass init a.shen@pandatech.co
Password store initialized for a.shen@pandatech.co

Initialize docker-credential-pass

Using pass show you should see the docker-credential-helpers. If not, try running docker login and docker logout again. You may receive an error that “pass store is uninitialized”. Run the below to initialize the docker-credential-helpers. You may get a prompt for your store’s password again (the password you created in the previous step).

root@photon-machine [ ~ ]# pass show
Password Store
└── docker-credential-helpers
    └── docker-pass-initialized-check

root@photon-machine [ ~ ]# pass show docker-credential-helpers/docker-pass-initialized-check 
pass is initialized

root@photon-machine [ ~ ]# pass show
Password Store
└── docker-credential-helpers
    └── sHR0cHM6Ly0pdNRLeC5kb2NrZXIvyW8vdjFW
        └── pandatech0

Conclusion

You should be all set now. But now logging in will sometimes be a two-step process because the store will time out after some time:

root@photon-machine [ ~ ]# pass show docker-credential-helpers/docker-pass-initialized-check 
pass is initialized

root@photon-machine [ ~ ]# docker login
Authenticating with existing credentials...
Login Succeeded

After docker login, you can check cat ~/.docker/config.json, and you should not see any of your credentials in cleartext. Now you are finally ready to safely push and pull containers through your Docker Hub account.