Docker-DCO-1.1-Signed-off-by: Sven Dowideit <SvenDowideit@docker.com> (github: SvenDowideit)
| ... | ... |
@@ -1,8 +1,8 @@ |
| 1 |
-page_title: Running Docker with HTTPS |
|
| 1 |
+page_title: Protecting the Docker daemon Socket with HTTPS |
|
| 2 | 2 |
page_description: How to setup and run Docker with HTTPS |
| 3 | 3 |
page_keywords: docker, docs, article, example, https, daemon, tls, ca, certificate |
| 4 | 4 |
|
| 5 |
-# Running Docker with https |
|
| 5 |
+# Protecting the Docker daemon Socket with HTTPS |
|
| 6 | 6 |
|
| 7 | 7 |
By default, Docker runs via a non-networked Unix socket. It can also |
| 8 | 8 |
optionally communicate using a HTTP socket. |
| ... | ... |
@@ -26,6 +26,9 @@ it will only connect to servers with a certificate signed by that CA. |
| 26 | 26 |
|
| 27 | 27 |
## Create a CA, server and client keys with OpenSSL |
| 28 | 28 |
|
| 29 |
+> **Note:** replace all instances of `$HOST` in the following example with the |
|
| 30 |
+> DNS name of your Docker daemon's host. |
|
| 31 |
+ |
|
| 29 | 32 |
First generate CA private and public keys: |
| 30 | 33 |
|
| 31 | 34 |
$ openssl genrsa -aes256 -out ca-key.pem 2048 |
| ... | ... |
@@ -49,19 +52,22 @@ First generate CA private and public keys: |
| 49 | 49 |
Locality Name (eg, city) []:Brisbane |
| 50 | 50 |
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Docker Inc |
| 51 | 51 |
Organizational Unit Name (eg, section) []:Boot2Docker |
| 52 |
- Common Name (e.g. server FQDN or YOUR name) []:your.host.com |
|
| 52 |
+ Common Name (e.g. server FQDN or YOUR name) []:$HOST |
|
| 53 | 53 |
Email Address []:Sven@home.org.au |
| 54 | 54 |
|
| 55 | 55 |
Now that we have a CA, you can create a server key and certificate |
| 56 | 56 |
signing request (CSR). Make sure that "Common Name" (i.e. server FQDN or YOUR |
| 57 | 57 |
name) matches the hostname you will use to connect to Docker: |
| 58 | 58 |
|
| 59 |
+> **Note:** replace all instances of `$HOST` in the following example with the |
|
| 60 |
+> DNS name of your Docker daemon's host. |
|
| 61 |
+ |
|
| 59 | 62 |
$ openssl genrsa -out server-key.pem 2048 |
| 60 | 63 |
Generating RSA private key, 2048 bit long modulus |
| 61 | 64 |
......................................................+++ |
| 62 | 65 |
............................................+++ |
| 63 | 66 |
e is 65537 (0x10001) |
| 64 |
- $ openssl req -subj '/CN=<Your Hostname Here>' -new -key server-key.pem -out server.csr |
|
| 67 |
+ $ openssl req -subj "/CN=$HOST" -new -key server-key.pem -out server.csr |
|
| 65 | 68 |
|
| 66 | 69 |
Next, we're going to sign the key with our CA: |
| 67 | 70 |
|
| ... | ... |
@@ -105,8 +111,11 @@ providing a certificate trusted by our CA: |
| 105 | 105 |
To be able to connect to Docker and validate its certificate, you now |
| 106 | 106 |
need to provide your client keys, certificates and trusted CA: |
| 107 | 107 |
|
| 108 |
+> **Note:** replace all instances of `$HOST` in the following example with the |
|
| 109 |
+> DNS name of your Docker daemon's host. |
|
| 110 |
+ |
|
| 108 | 111 |
$ docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem \ |
| 109 |
- -H=dns-name-of-docker-host:2376 version |
|
| 112 |
+ -H=$HOST:2376 version |
|
| 110 | 113 |
|
| 111 | 114 |
> **Note**: |
| 112 | 115 |
> Docker over TLS should run on TCP port 2376. |
| ... | ... |
@@ -125,6 +134,7 @@ the files to the `.docker` directory in your home directory - and set the |
| 125 | 125 |
`DOCKER_HOST` and `DOCKER_TLS_VERIFY` variables as well (instead of passing |
| 126 | 126 |
`-H=tcp://:2376` and `--tlsverify` on every call). |
| 127 | 127 |
|
| 128 |
+ $ mkdir -p ~/.docker |
|
| 128 | 129 |
$ cp ca.pem ~/.docker/ca.pem |
| 129 | 130 |
$ cp cert.pem ~/.docker/cert.pem |
| 130 | 131 |
$ cp key.pem ~/.docker/key.pem |
| ... | ... |
@@ -167,7 +177,7 @@ location using the environment variable `DOCKER_CERT_PATH`. |
| 167 | 167 |
To use `curl` to make test API requests, you need to use three extra command line |
| 168 | 168 |
flags: |
| 169 | 169 |
|
| 170 |
- $ curl https://boot2docker:2376/images/json \ |
|
| 170 |
+ $ curl https://$HOST:2376/images/json \ |
|
| 171 | 171 |
--cert ~/.docker/cert.pem \ |
| 172 | 172 |
--key ~/.docker/key.pem \ |
| 173 | 173 |
--cacert ~/.docker/ca.pem |
| 0 | 10 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+ |
|
| 1 |
+HOST:=boot2docker |
|
| 2 |
+ |
|
| 3 |
+makescript: |
|
| 4 |
+ ./parsedocs.sh > make_certs.sh |
|
| 5 |
+ |
|
| 6 |
+build: makescript |
|
| 7 |
+ docker build -t makecerts . |
|
| 8 |
+ |
|
| 9 |
+cert: build |
|
| 10 |
+ docker run --rm -it -v $(CURDIR):/data -e HOST=$(HOST) makecerts |
|
| 11 |
+ |
|
| 12 |
+certs: cert |
|
| 13 |
+ |
|
| 14 |
+run: |
|
| 15 |
+ docker -d -D --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem -H=0.0.0.0:6666 --pidfile=$(pwd)/docker.pid --graph=$(pwd)/graph |
|
| 16 |
+ |
|
| 17 |
+client: |
|
| 18 |
+ docker --tls --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem -H=$(HOST):6666 version |
|
| 19 |
+ docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem -H=$(HOST):6666 info |
|
| 20 |
+ |
|
| 21 |
+clean: |
|
| 22 |
+ rm ca-key.pem ca.pem ca.srl cert.pem client.csr extfile.cnf key.pem server-cert.pem server-key.pem server.csr |
| 0 | 23 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,26 @@ |
| 0 |
+ |
|
| 1 |
+ |
|
| 2 |
+This is an initial attempt to make it easier to test the examples in the https.md |
|
| 3 |
+doc |
|
| 4 |
+ |
|
| 5 |
+at this point, it has to be a manual thing, and I've been running it in boot2docker |
|
| 6 |
+ |
|
| 7 |
+so my process is |
|
| 8 |
+ |
|
| 9 |
+$ boot2docker ssh |
|
| 10 |
+$$ git clone https://github.com/docker/docker |
|
| 11 |
+$$ cd docker/docs/sources/articles/https |
|
| 12 |
+$$ make cert |
|
| 13 |
+lots of things to see and manually answer, as openssl wants to be interactive |
|
| 14 |
+**NOTE:** make sure you enter the hostname (`boot2docker` in my case) when prompted for `Computer Name`) |
|
| 15 |
+$$ sudo make run |
|
| 16 |
+ |
|
| 17 |
+start another terminal |
|
| 18 |
+ |
|
| 19 |
+$ boot2docker ssh |
|
| 20 |
+$$ cd docker/docs/sources/articles/https |
|
| 21 |
+$$ make client |
|
| 22 |
+ |
|
| 23 |
+the last will connect first with `--tls` and then with `--tlsverify` |
|
| 24 |
+ |
|
| 25 |
+both should succeed |
| 0 | 26 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+ |
|
| 2 |
+openssl genrsa -aes256 -out ca-key.pem 2048 |
|
| 3 |
+ |
|
| 4 |
+echo "enter your Docker daemon's hostname as the 'Common Name'= ($HOST)" |
|
| 5 |
+ |
|
| 6 |
+#TODO add this as an ENV to docker run? |
|
| 7 |
+openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem |
|
| 8 |
+ |
|
| 9 |
+ |
|
| 10 |
+# server cert |
|
| 11 |
+openssl genrsa -out server-key.pem 2048 |
|
| 12 |
+openssl req -subj "/CN=$HOST" -new -key server-key.pem -out server.csr |
|
| 13 |
+openssl x509 -req -days 365 -in server.csr -CA ca.pem -CAkey ca-key.pem \ |
|
| 14 |
+ -CAcreateserial -out server-cert.pem |
|
| 15 |
+ |
|
| 16 |
+#client cert |
|
| 17 |
+openssl genrsa -out key.pem 2048 |
|
| 18 |
+openssl req -subj '/CN=client' -new -key key.pem -out client.csr |
|
| 19 |
+ |
|
| 20 |
+echo extendedKeyUsage = clientAuth > extfile.cnf |
|
| 21 |
+openssl x509 -req -days 365 -in client.csr -CA ca.pem -CAkey ca-key.pem \ |
|
| 22 |
+ -CAcreateserial -out cert.pem -extfile extfile.cnf |