Docker1 has one of the most gentle learning slopes of a new technology to
enter the mainstream in a long time. A developer can get up and running in a very
short amount of time2 and begin realizing value almost immediately with
Docker, but the hard part comes when trying to secure the new technology for
use in a production like environment. Production has a much higher standard when
it comes to availability, security, and repeatability. This can lead to problems
as the differences between the development and production environment are both:
Fairly complex to replicate in a secure way: It is not feasible to pass around
the private key for your production certificate in the name of development
environment automation. On the other hand, to generate a full CA and all of the
certificates and keys required can be daunting.
Functionally quite a large delta: The difference between an insecure, non-tls
environment and an SSL one can be significant. For instance, at this exact
exact point in time it appears that Ansible does not yet support a TLS enabled
Docker host3.
In order to attack this problem, we should attempt to replicate the prod
environment when it is feasible and especially if it is easy and cheap. To this
end, let’s create the full certificate chain needed to run a secure Docker Swarm4
cluster. I think you will find that it is both easy and cheap :)
The script
This is a bash script I used5 that will output everything within the
directory it is run. It accomplishes the following things:
Creates a Certificate Authority
Creates a cert/key for Docker Swarm (supporting both client and server auth)
Generates 3 certificates for the individual Docker hosts with SAN IPs
It is required to set a config as we need to add a SAN IP Address entry to the
certificate and CSR. This is required because without it, Swarm will spit out
the following error:
Disclaimer: I am no SSL wizard and so some of the settings in the openssl.cnf
may be insecure, not needed, or even both. In addition, you can see that this is
totally insecure as
the password is in the script
the passwords are removed from the keys
many other reasons
Please don’t use these exact script or the generated certs for production use!
gen_ssl.sh
openssl.cnf
Installation
Once you have generated the TLS keys and certificates they must be installed on
the target machine. I prefer to just copy the certificate and the key files into
/etc/pki/tls/certs/ and /etc/pki/tls/private/ respectively. Once they are
installed, you can then fire up your Docker and Swarm daemons like so:
Now in order to use the Docker daemon, you will have to present a client cert
that was generated from the same CA as the certificate Docker/Swarm is using. We
have generated one here and more can be made if needed. Set the following
environment variables in order to tell the Docker client what to use for the TLS
config:
This will now enable the Docker client to communicate ‘securely’ with Docker
Swarm and Docker Swarm to communicate securely with the Docker nodes behind it.
Matt has been working on big art recently, including Double Diamond and Moonrock Mountain. They are both large-scale sculptures that incorporate everything he has learned throughout his career. Continue reading