Skip to content

Instantly share code, notes, and snippets.

@riy
Last active January 16, 2016 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riy/fd387bb452b19f0ec4ba to your computer and use it in GitHub Desktop.
Save riy/fd387bb452b19f0ec4ba to your computer and use it in GitHub Desktop.
Create Docker Certificate Authority, Server and Client Certificates
#!/bin/bash
HOST_IP=`ifconfig eth0| awk '/inet addr/{print substr($2,6)}'`
mkdir docker-ca
chmod 0700 docker-ca
cd docker-ca
openssl genrsa -aes256 -out ca-key.pem 2048
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
openssl genrsa -out server-key.pem 2048
openssl req -subj "/CN=${HOST_IP}" -new -key server-key.pem -out server.csr
echo subjectAltName = IP:${HOST_IP},IP:127.0.0.1 > extfile.cnf
openssl x509 -req -days 365 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile extfile.cnf
openssl genrsa -out client-key.pem 2048
openssl req -subj '/CN=client' -new -key client-key.pem -out client.csr
echo extendedKeyUsage = clientAuth > extfile.cnf
openssl x509 -req -days 365 -in client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out client-cert.pem -extfile extfile.cnf
chmod -v 0400 ca-key.pem client-key.pem server-key.pem
chmod -v 0444 ca.pem server-cert.pem client-cert.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment