Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
setup_tls_for_docker/setup_docker_tls.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
36 lines (19 sloc)
1011 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
hostname=${1} | |
cd ~/.docker/ | |
openssl genrsa -aes256 -out ca-key.pem 4096 | |
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem | |
openssl genrsa -out server-key.pem 4096 | |
openssl req -subj "/CN=$hostname" -sha256 -new -key server-key.pem -out server.csr | |
echo subjectAltName = DNS:$hostname,IP:10.10.10.20,IP:127.0.0.1 >> extfile.cnf | |
echo extendedKeyUsage = serverAuth >> extfile.cnf | |
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \ | |
-CAcreateserial -out server-cert.pem -extfile extfile.cnf | |
openssl genrsa -out key.pem 4096 | |
openssl req -subj '/CN=client' -new -key key.pem -out client.csr | |
echo extendedKeyUsage = clientAuth > extfile-client.cnf | |
openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem \ | |
-CAcreateserial -out cert.pem -extfile extfile-client.cnf | |
rm -v client.csr server.csr extfile.cnf extfile-client.cnf | |
chmod -v 0400 ca-key.pem key.pem server-key.pem | |
chmod -v 0444 ca.pem server-cert.pem cert.pem |