Docker Client Certs

Submitted by code_admin on Wed, 08/22/2018 - 14:31

My process for setting up client authentication.

I use my Personal Infrastructure CAClientCerts utilities.

Create a new CA

Create a brand new CA. Make it's name match the host of the docker machine to control. Server key can have a password.

Create server Certs

Create the server Certs.

Copy files to server

I put the files in the following locations:

  1. /var/docker/ca.pem
  2. /var/docker/server-cert.pem
  3. /var/docker/server-key.pem

Root permissions for these files seems to be ok.

I also create a file /etc/docker/daemon.json to make server use options:

  1. {
  2.     "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2376"],
  3.     "tlscacert": "/var/docker/ca.pem",
  4.     "tlscert": "/var/docker/server-cert.pem",
  5.     "tlskey": "/var/docker/server-key.pem",
  6.     "tlsverify": true
  7. }

https://docs.docker.com/engine/security/https/#secure-by-default

Test the settings:

  1. sudo systemctl stop docker
  2. sudo dockerd

(New connection)

  1. #Test socket connections still work
  2. docker version
  3.  
  4. #Test connection via Internet fails (Should give a no TLS error)
  5.  docker -H=127.0.0.1:2376 version
  6.  
  7. #Test connection with keys
  8. CLICERTDIR=TMP LOCATION to place client certs
  9. docker --tlsverify --tlscacert=/var/docker/ca.pem --tlscert=${CLICERTDIR}/client-cert.pem --tlskey=${CLICERTDIR}/client-key.pem -H=127.0.0.1:2376 version

Utils:

View errors

  1. sudo journalctl -fu docker.service

I found the systemd service file by looking at the output from:

  1. systemctl status docker

it was /lib/systemd/system/docker.service

I then removed the -H flag.
Then ran
systemctl daemon-reload

This setup dies when the certificate runs out.
View the certificate: keytool -printcert -file certificate.pem (Must copy cert locally)

RJM Article Type
Quick Reference