Browse code

Fixing missing certs article; consolidating security material Entering comments from reviewers Updating with Derek's comments Fixing bad links reported by build

Signed-off-by: Mary Anthony <mary@docker.com>

Mary Anthony authored on 2016/01/21 05:46:40
Showing 20 changed files
1 1
deleted file mode 100644
... ...
@@ -1,17 +0,0 @@
1
-<!--[metadata]>
2
-+++
3
-title = "Using certificates for repository client verification"
4
-description = "How to set up and use certificates with a registry to verify access"
5
-keywords = ["Usage, registry, repository, client, root, certificate, docker, apache, ssl, tls, documentation, examples, articles,  tutorials"]
6
-[menu.main]
7
-parent = "mn_docker_hub"
8
-weight = 7
9
-+++
10
-<![end-metadata]-->
11
-
12
-# Using certificates for repository client verification
13
-
14
-The original content was deprecated. For information about configuring
15
-certificates, see  [deploying a registry
16
-server](http://docs.docker.com/registry/deploying). To reach an older version
17
-of this content, refer to an older version of the documentation. 
18 1
deleted file mode 100644
... ...
@@ -1,211 +0,0 @@
1
-<!--[metadata]>
2
-+++
3
-title = "Protect the Docker daemon socket"
4
-description = "How to setup and run Docker with HTTPS"
5
-keywords = ["docker, docs, article, example, https, daemon, tls, ca,  certificate"]
6
-[menu.main]
7
-parent = "smn_administrate"
8
-weight = 5
9
-+++
10
-<![end-metadata]-->
11
-
12
-# Protect the Docker daemon socket
13
-
14
-By default, Docker runs via a non-networked Unix socket. It can also
15
-optionally communicate using a HTTP socket.
16
-
17
-If you need Docker to be reachable via the network in a safe manner, you can
18
-enable TLS by specifying the `tlsverify` flag and pointing Docker's
19
-`tlscacert` flag to a trusted CA certificate.
20
-
21
-In the daemon mode, it will only allow connections from clients
22
-authenticated by a certificate signed by that CA. In the client mode,
23
-it will only connect to servers with a certificate signed by that CA.
24
-
25
-> **Warning**:
26
-> Using TLS and managing a CA is an advanced topic. Please familiarize yourself
27
-> with OpenSSL, x509 and TLS before using it in production.
28
-
29
-> **Warning**:
30
-> These TLS commands will only generate a working set of certificates on Linux.
31
-> Mac OS X comes with a version of OpenSSL that is incompatible with the
32
-> certificates that Docker requires.
33
-
34
-## Create a CA, server and client keys with OpenSSL
35
-
36
-> **Note**: replace all instances of `$HOST` in the following example with the
37
-> DNS name of your Docker daemon's host.
38
-
39
-First generate CA private and public keys:
40
-
41
-    $ openssl genrsa -aes256 -out ca-key.pem 4096
42
-    Generating RSA private key, 4096 bit long modulus
43
-    ............................................................................................................................................................................................++
44
-    ........++
45
-    e is 65537 (0x10001)
46
-    Enter pass phrase for ca-key.pem:
47
-    Verifying - Enter pass phrase for ca-key.pem:
48
-    $ openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
49
-    Enter pass phrase for ca-key.pem:
50
-    You are about to be asked to enter information that will be incorporated
51
-    into your certificate request.
52
-    What you are about to enter is what is called a Distinguished Name or a DN.
53
-    There are quite a few fields but you can leave some blank
54
-    For some fields there will be a default value,
55
-    If you enter '.', the field will be left blank.
56
-    -----
57
-    Country Name (2 letter code) [AU]:
58
-    State or Province Name (full name) [Some-State]:Queensland
59
-    Locality Name (eg, city) []:Brisbane
60
-    Organization Name (eg, company) [Internet Widgits Pty Ltd]:Docker Inc
61
-    Organizational Unit Name (eg, section) []:Sales
62
-    Common Name (e.g. server FQDN or YOUR name) []:$HOST
63
-    Email Address []:Sven@home.org.au
64
-
65
-Now that we have a CA, you can create a server key and certificate
66
-signing request (CSR). Make sure that "Common Name" (i.e., server FQDN or YOUR
67
-name) matches the hostname you will use to connect to Docker:
68
-
69
-> **Note**: replace all instances of `$HOST` in the following example with the
70
-> DNS name of your Docker daemon's host.
71
-
72
-    $ openssl genrsa -out server-key.pem 4096
73
-    Generating RSA private key, 4096 bit long modulus
74
-    .....................................................................++
75
-    .................................................................................................++
76
-    e is 65537 (0x10001)
77
-    $ openssl req -subj "/CN=$HOST" -sha256 -new -key server-key.pem -out server.csr
78
-
79
-Next, we're going to sign the public key with our CA:
80
-
81
-Since TLS connections can be made via IP address as well as DNS name, they need
82
-to be specified when creating the certificate. For example, to allow connections
83
-using `10.10.10.20` and `127.0.0.1`:
84
-
85
-    $ echo subjectAltName = IP:10.10.10.20,IP:127.0.0.1 > extfile.cnf
86
-
87
-    $ openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \
88
-      -CAcreateserial -out server-cert.pem -extfile extfile.cnf
89
-    Signature ok
90
-    subject=/CN=your.host.com
91
-    Getting CA Private Key
92
-    Enter pass phrase for ca-key.pem:
93
-
94
-For client authentication, create a client key and certificate signing
95
-request:
96
-
97
-    $ openssl genrsa -out key.pem 4096
98
-    Generating RSA private key, 4096 bit long modulus
99
-    .........................................................++
100
-    ................++
101
-    e is 65537 (0x10001)
102
-    $ openssl req -subj '/CN=client' -new -key key.pem -out client.csr
103
-
104
-To make the key suitable for client authentication, create an extensions
105
-config file:
106
-
107
-    $ echo extendedKeyUsage = clientAuth > extfile.cnf
108
-
109
-Now sign the public key:
110
-
111
-    $ openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem \
112
-      -CAcreateserial -out cert.pem -extfile extfile.cnf
113
-    Signature ok
114
-    subject=/CN=client
115
-    Getting CA Private Key
116
-    Enter pass phrase for ca-key.pem:
117
-
118
-After generating `cert.pem` and `server-cert.pem` you can safely remove the
119
-two certificate signing requests:
120
-
121
-    $ rm -v client.csr server.csr
122
-
123
-With a default `umask` of 022, your secret keys will be *world-readable* and
124
-writable for you and your group.
125
-
126
-In order to protect your keys from accidental damage, you will want to remove their
127
-write permissions. To make them only readable by you, change file modes as follows:
128
-
129
-    $ chmod -v 0400 ca-key.pem key.pem server-key.pem
130
-
131
-Certificates can be world-readable, but you might want to remove write access to
132
-prevent accidental damage:
133
-
134
-    $ chmod -v 0444 ca.pem server-cert.pem cert.pem
135
-
136
-Now you can make the Docker daemon only accept connections from clients
137
-providing a certificate trusted by our CA:
138
-
139
-    $ docker daemon --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem \
140
-      -H=0.0.0.0:2376
141
-
142
-To be able to connect to Docker and validate its certificate, you now
143
-need to provide your client keys, certificates and trusted CA:
144
-
145
-> **Note**: replace all instances of `$HOST` in the following example with the
146
-> DNS name of your Docker daemon's host.
147
-
148
-    $ docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem \
149
-      -H=$HOST:2376 version
150
-
151
-> **Note**:
152
-> Docker over TLS should run on TCP port 2376.
153
-
154
-> **Warning**:
155
-> As shown in the example above, you don't have to run the `docker` client
156
-> with `sudo` or the `docker` group when you use certificate authentication.
157
-> That means anyone with the keys can give any instructions to your Docker
158
-> daemon, giving them root access to the machine hosting the daemon. Guard
159
-> these keys as you would a root password!
160
-
161
-## Secure by default
162
-
163
-If you want to secure your Docker client connections by default, you can move
164
-the files to the `.docker` directory in your home directory -- and set the
165
-`DOCKER_HOST` and `DOCKER_TLS_VERIFY` variables as well (instead of passing
166
-`-H=tcp://$HOST:2376` and `--tlsverify` on every call).
167
-
168
-    $ mkdir -pv ~/.docker
169
-    $ cp -v {ca,cert,key}.pem ~/.docker
170
-    $ export DOCKER_HOST=tcp://$HOST:2376 DOCKER_TLS_VERIFY=1
171
-
172
-Docker will now connect securely by default:
173
-
174
-    $ docker ps
175
-
176
-## Other modes
177
-
178
-If you don't want to have complete two-way authentication, you can run
179
-Docker in various other modes by mixing the flags.
180
-
181
-### Daemon modes
182
-
183
- - `tlsverify`, `tlscacert`, `tlscert`, `tlskey` set: Authenticate clients
184
- - `tls`, `tlscert`, `tlskey`: Do not authenticate clients
185
-
186
-### Client modes
187
-
188
- - `tls`: Authenticate server based on public/default CA pool
189
- - `tlsverify`, `tlscacert`: Authenticate server based on given CA
190
- - `tls`, `tlscert`, `tlskey`: Authenticate with client certificate, do not
191
-   authenticate server based on given CA
192
- - `tlsverify`, `tlscacert`, `tlscert`, `tlskey`: Authenticate with client
193
-   certificate and authenticate server based on given CA
194
-
195
-If found, the client will send its client certificate, so you just need
196
-to drop your keys into `~/.docker/{ca,cert,key}.pem`. Alternatively,
197
-if you want to store your keys in another location, you can specify that
198
-location using the environment variable `DOCKER_CERT_PATH`.
199
-
200
-    $ export DOCKER_CERT_PATH=~/.docker/zone1/
201
-    $ docker --tlsverify ps
202
-
203
-### Connecting to the secure Docker port using `curl`
204
-
205
-To use `curl` to make test API requests, you need to use three extra command line
206
-flags:
207
-
208
-    $ curl https://$HOST:2376/images/json \
209
-      --cert ~/.docker/cert.pem \
210
-      --key ~/.docker/key.pem \
211
-      --cacert ~/.docker/ca.pem
212 1
deleted file mode 100644
... ...
@@ -1,10 +0,0 @@
1
-FROM debian
2
-
3
-RUN apt-get update && apt-get install -yq openssl
4
-
5
-ADD make_certs.sh /
6
-
7
-
8
-WORKDIR /data
9
-VOLUME ["/data"]
10
-CMD /make_certs.sh
11 1
deleted file mode 100644
... ...
@@ -1,24 +0,0 @@
1
-
2
-HOST:=boot2docker
3
-
4
-makescript:
5
-	./parsedocs.sh > make_certs.sh
6
-
7
-build: clean makescript
8
-	docker build -t makecerts .
9
-
10
-cert: build
11
-	docker run --rm -it -v $(CURDIR):/data -e HOST=$(HOST) -e YOUR_PUBLIC_IP=$(shell ip a | grep "inet " | sed "s/.*inet \([0-9.]*\)\/.*/\1/" | xargs echo | sed "s/ /,IP:/g") makecerts
12
-
13
-certs: cert
14
-
15
-run:
16
-	sudo docker daemon -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
17
-
18
-client:
19
-	sudo docker --tls --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem   -H=$(HOST):6666 version
20
-	sudo docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem   -H=$(HOST):6666 info
21
-	sudo curl https://$(HOST):6666/images/json --cert ./cert.pem --key ./key.pem --cacert ./ca.pem
22
-
23
-clean:
24
-	rm -f ca-key.pem ca.pem ca.srl cert.pem client.csr extfile.cnf key.pem server-cert.pem server-key.pem server.csr extfile.cnf
25 1
deleted file mode 100644
... ...
@@ -1,32 +0,0 @@
1
-<!--[metadata]>
2
-+++
3
-draft = true
4
-+++
5
-<![end-metadata]-->
6
-
7
-
8
-
9
-This is an initial attempt to make it easier to test the examples in the https.md
10
-doc
11
-
12
-at this point, it has to be a manual thing, and I've been running it in boot2docker
13
-
14
-so my process is
15
-
16
-$ boot2docker ssh
17
-$$ git clone https://github.com/docker/docker
18
-$$ cd docker/docs/articles/https
19
-$$ make cert
20
-lots of things to see and manually answer, as openssl wants to be interactive
21
-**NOTE:** make sure you enter the hostname (`boot2docker` in my case) when prompted for `Computer Name`)
22
-$$ sudo make run
23
-
24
-start another terminal
25
-
26
-$ boot2docker ssh
27
-$$ cd docker/docs/articles/https
28
-$$ make client
29
-
30
-the last will connect first with `--tls` and then with `--tlsverify`
31
-
32
-both should succeed
33 1
deleted file mode 100755
... ...
@@ -1,23 +0,0 @@
1
-#!/bin/sh
2
-openssl genrsa -aes256 -out ca-key.pem 2048
3
-openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
4
-openssl genrsa -out server-key.pem 2048
5
-openssl req -subj "/CN=$HOST" -new -key server-key.pem -out server.csr
6
-echo subjectAltName = IP:$YOUR_PUBLIC_IP > extfile.cnf
7
-openssl x509 -req -days 365 -in server.csr -CA ca.pem -CAkey ca-key.pem       -CAcreateserial -out server-cert.pem -extfile extfile.cnf
8
-openssl genrsa -out key.pem 2048
9
-openssl req -subj '/CN=client' -new -key key.pem -out client.csr
10
-echo extendedKeyUsage = clientAuth > extfile.cnf
11
-openssl x509 -req -days 365 -in client.csr -CA ca.pem -CAkey ca-key.pem       -CAcreateserial -out cert.pem -extfile extfile.cnf
12
-rm -v client.csr server.csr
13
-chmod -v 0400 ca-key.pem key.pem server-key.pem
14
-chmod -v 0444 ca.pem server-cert.pem cert.pem
15
-# docker -d --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem       -H=0.0.0.0:7778
16
-# docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem       -H=$HOST:7778 version
17
-mkdir -pv ~/.docker
18
-cp -v {ca,cert,key}.pem ~/.docker
19
-export DOCKER_HOST=tcp://$HOST:7778 DOCKER_TLS_VERIFY=1
20
-# docker ps
21
-export DOCKER_CERT_PATH=~/.docker/zone1/
22
-# docker --tlsverify ps
23
-# curl https://$HOST:7778/images/json       --cert ~/.docker/cert.pem       --key ~/.docker/key.pem       --cacert ~/.docker/ca.pem
24 1
deleted file mode 100755
... ...
@@ -1,10 +0,0 @@
1
-#!/bin/sh
2
-
3
-echo "#!/bin/sh"
4
-cat ../https.md | awk '{if (sub(/\\$/,"")) printf "%s", $0; else print $0}' \
5
-        | grep '   $ ' \
6
-        | sed 's/    $ //g' \
7
-        | sed 's/2375/7777/g' \
8
-        | sed 's/2376/7778/g' \
9
-        | sed 's/^docker/# docker/g' \
10
-        | sed 's/^curl/# curl/g'
... ...
@@ -86,7 +86,7 @@ membership.
86 86
 If you need to access the Docker daemon remotely, you need to enable the `tcp`
87 87
 Socket. Beware that the default setup provides un-encrypted and
88 88
 un-authenticated direct access to the Docker daemon - and should be secured
89
-either using the [built in HTTPS encrypted socket](../../articles/https/), or by
89
+either using the [built in HTTPS encrypted socket](../../security/https/), or by
90 90
 putting a secure web proxy in front of it. You can listen on port `2375` on all
91 91
 network interfaces with `-H tcp://0.0.0.0:2375`, or on a particular network
92 92
 interface using its IP address: `-H tcp://192.168.59.103:2375`. It is
... ...
@@ -220,15 +220,15 @@ options for `zfs` start with `zfs`.
220 220
     the empty case the larger the device is.
221 221
 
222 222
     The base device size can be increased at daemon restart which will allow
223
-    all future images and containers (based on those new images) to be of the 
223
+    all future images and containers (based on those new images) to be of the
224 224
     new base device size.
225 225
 
226
-    Example use: 
226
+    Example use:
227 227
 
228 228
         $ docker daemon --storage-opt dm.basesize=50G
229 229
 
230
-    This will increase the base device size to 50G. The Docker daemon will throw an 
231
-    error if existing base device size is larger than 50G. A user can use 
230
+    This will increase the base device size to 50G. The Docker daemon will throw an
231
+    error if existing base device size is larger than 50G. A user can use
232 232
     this option to expand the base device size however shrinking is not permitted.
233 233
 
234 234
     This value affects the system-wide "base" empty filesystem
... ...
@@ -727,7 +727,7 @@ when querying the system for the subordinate group ID range.
727 727
 
728 728
 ### Detailed information on `subuid`/`subgid` ranges
729 729
 
730
-Given potential advanced use of the subordinate ID ranges by power users, the 
730
+Given potential advanced use of the subordinate ID ranges by power users, the
731 731
 following paragraphs define how the Docker daemon currently uses the range entries
732 732
 found within the subordinate range files.
733 733
 
... ...
@@ -5,6 +5,7 @@ description = "Enabling AppArmor in Docker"
5 5
 keywords = ["AppArmor, security, docker, documentation"]
6 6
 [menu.main]
7 7
 parent= "smn_secure_docker"
8
+weight=5
8 9
 +++
9 10
 <![end-metadata]-->
10 11
 
11 12
new file mode 100644
... ...
@@ -0,0 +1,85 @@
0
+<!--[metadata]>
1
+aliases = ["/articles/certificates/"]
2
+title = "Using certificates for repository client verification"
3
+description = "How to set up and use certificates with a registry to verify access"
4
+keywords = ["Usage, registry, repository, client, root, certificate, docker, apache, ssl, tls, documentation, examples, articles,  tutorials"]
5
+[menu.main]
6
+parent = "smn_secure_docker"
7
+<![end-metadata]-->
8
+
9
+# Using certificates for repository client verification
10
+
11
+In [Running Docker with HTTPS](https.md), you learned that, by default,
12
+Docker runs via a non-networked Unix socket and TLS must be enabled in order
13
+to have the Docker client and the daemon communicate securely over HTTPS.  TLS ensures authenticity of the registry endpoint and that traffic to/from registry is encrypted.
14
+
15
+This article demonstrates how to ensure the traffic between the Docker registry (i.e., *a server*) and the Docker daemon (i.e., *a client*) traffic is encrypted and a properly authenticated using *certificate-based client-server authentication*.
16
+
17
+We will show you how to install a Certificate Authority (CA) root certificate
18
+for the registry and how to set the client TLS certificate for verification.
19
+
20
+## Understanding the configuration
21
+
22
+A custom certificate is configured by creating a directory under
23
+`/etc/docker/certs.d` using the same name as the registry's hostname (e.g.,
24
+`localhost`). All `*.crt` files are added to this directory as CA roots.
25
+
26
+> **Note:**
27
+> In the absence of any root certificate authorities, Docker
28
+> will use the system default (i.e., host's root CA set).
29
+
30
+The presence of one or more `<filename>.key/cert` pairs indicates to Docker
31
+that there are custom certificates required for access to the desired
32
+repository.
33
+
34
+> **Note:**
35
+> If there are multiple certificates, each will be tried in alphabetical
36
+> order. If there is an authentication error (e.g., 403, 404, 5xx, etc.), Docker
37
+> will continue to try with the next certificate.
38
+
39
+The following illustrates a configuration with multiple certs:
40
+
41
+```
42
+    /etc/docker/certs.d/        <-- Certificate directory
43
+    └── localhost               <-- Hostname
44
+       ├── client.cert          <-- Client certificate
45
+       ├── client.key           <-- Client key
46
+       └── localhost.crt        <-- Certificate authority that signed
47
+                                    the registry certificate
48
+```
49
+
50
+The preceding example is operating-system specific and is for illustrative
51
+purposes only. You should consult your operating system documentation for
52
+creating an os-provided bundled certificate chain.
53
+
54
+
55
+## Creating the client certificates
56
+
57
+You will use OpenSSL's `genrsa` and `req` commands to first generate an RSA
58
+key and then use the key to create the certificate.   
59
+
60
+    $ openssl genrsa -out client.key 4096
61
+    $ openssl req -new -x509 -text -key client.key -out client.cert
62
+
63
+> **Note:**
64
+> These TLS commands will only generate a working set of certificates on Linux.
65
+> The version of OpenSSL in Mac OS X is incompatible with the type of
66
+> certificate Docker requires.
67
+
68
+## Troubleshooting tips
69
+
70
+The Docker daemon interprets ``.crt` files as CA certificates and `.cert` files
71
+as client certificates. If a CA certificate is accidentally given the extension
72
+`.cert` instead of the correct `.crt` extension, the Docker daemon logs the
73
+following error message:
74
+
75
+```
76
+Missing key KEY_NAME for client certificate CERT_NAME. Note that CA certificates should use the extension .crt.
77
+```
78
+
79
+## Related Information
80
+
81
+* [Use trusted images](index.md)
82
+* [Protect the Docker daemon socket](https.md)
0 83
new file mode 100644
... ...
@@ -0,0 +1,216 @@
0
+<!--[metadata]>
1
+aliases = ["/engine/articles/https/"]
2
+title = "Protect the Docker daemon socket"
3
+description = "How to setup and run Docker with HTTPS"
4
+keywords = ["docker, docs, article, example, https, daemon, tls, ca,  certificate"]
5
+[menu.main]
6
+parent = "smn_secure_docker"
7
+<![end-metadata]-->
8
+
9
+# Protect the Docker daemon socket
10
+
11
+By default, Docker runs via a non-networked Unix socket. It can also
12
+optionally communicate using a HTTP socket.
13
+
14
+If you need Docker to be reachable via the network in a safe manner, you can
15
+enable TLS by specifying the `tlsverify` flag and pointing Docker's
16
+`tlscacert` flag to a trusted CA certificate.
17
+
18
+In the daemon mode, it will only allow connections from clients
19
+authenticated by a certificate signed by that CA. In the client mode,
20
+it will only connect to servers with a certificate signed by that CA.
21
+
22
+> **Warning**:
23
+> Using TLS and managing a CA is an advanced topic. Please familiarize yourself
24
+> with OpenSSL, x509 and TLS before using it in production.
25
+
26
+> **Warning**:
27
+> These TLS commands will only generate a working set of certificates on Linux.
28
+> Mac OS X comes with a version of OpenSSL that is incompatible with the
29
+> certificates that Docker requires.
30
+
31
+## Create a CA, server and client keys with OpenSSL
32
+
33
+> **Note**: replace all instances of `$HOST` in the following example with the
34
+> DNS name of your Docker daemon's host.
35
+
36
+First generate CA private and public keys:
37
+
38
+    $ openssl genrsa -aes256 -out ca-key.pem 4096
39
+    Generating RSA private key, 4096 bit long modulus
40
+    ............................................................................................................................................................................................++
41
+    ........++
42
+    e is 65537 (0x10001)
43
+    Enter pass phrase for ca-key.pem:
44
+    Verifying - Enter pass phrase for ca-key.pem:
45
+    $ openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
46
+    Enter pass phrase for ca-key.pem:
47
+    You are about to be asked to enter information that will be incorporated
48
+    into your certificate request.
49
+    What you are about to enter is what is called a Distinguished Name or a DN.
50
+    There are quite a few fields but you can leave some blank
51
+    For some fields there will be a default value,
52
+    If you enter '.', the field will be left blank.
53
+    -----
54
+    Country Name (2 letter code) [AU]:
55
+    State or Province Name (full name) [Some-State]:Queensland
56
+    Locality Name (eg, city) []:Brisbane
57
+    Organization Name (eg, company) [Internet Widgits Pty Ltd]:Docker Inc
58
+    Organizational Unit Name (eg, section) []:Sales
59
+    Common Name (e.g. server FQDN or YOUR name) []:$HOST
60
+    Email Address []:Sven@home.org.au
61
+
62
+Now that we have a CA, you can create a server key and certificate
63
+signing request (CSR). Make sure that "Common Name" (i.e., server FQDN or YOUR
64
+name) matches the hostname you will use to connect to Docker:
65
+
66
+> **Note**: replace all instances of `$HOST` in the following example with the
67
+> DNS name of your Docker daemon's host.
68
+
69
+    $ openssl genrsa -out server-key.pem 4096
70
+    Generating RSA private key, 4096 bit long modulus
71
+    .....................................................................++
72
+    .................................................................................................++
73
+    e is 65537 (0x10001)
74
+    $ openssl req -subj "/CN=$HOST" -sha256 -new -key server-key.pem -out server.csr
75
+
76
+Next, we're going to sign the public key with our CA:
77
+
78
+Since TLS connections can be made via IP address as well as DNS name, they need
79
+to be specified when creating the certificate. For example, to allow connections
80
+using `10.10.10.20` and `127.0.0.1`:
81
+
82
+    $ echo subjectAltName = IP:10.10.10.20,IP:127.0.0.1 > extfile.cnf
83
+
84
+    $ openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \
85
+      -CAcreateserial -out server-cert.pem -extfile extfile.cnf
86
+    Signature ok
87
+    subject=/CN=your.host.com
88
+    Getting CA Private Key
89
+    Enter pass phrase for ca-key.pem:
90
+
91
+For client authentication, create a client key and certificate signing
92
+request:
93
+
94
+    $ openssl genrsa -out key.pem 4096
95
+    Generating RSA private key, 4096 bit long modulus
96
+    .........................................................++
97
+    ................++
98
+    e is 65537 (0x10001)
99
+    $ openssl req -subj '/CN=client' -new -key key.pem -out client.csr
100
+
101
+To make the key suitable for client authentication, create an extensions
102
+config file:
103
+
104
+    $ echo extendedKeyUsage = clientAuth > extfile.cnf
105
+
106
+Now sign the public key:
107
+
108
+    $ openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem \
109
+      -CAcreateserial -out cert.pem -extfile extfile.cnf
110
+    Signature ok
111
+    subject=/CN=client
112
+    Getting CA Private Key
113
+    Enter pass phrase for ca-key.pem:
114
+
115
+After generating `cert.pem` and `server-cert.pem` you can safely remove the
116
+two certificate signing requests:
117
+
118
+    $ rm -v client.csr server.csr
119
+
120
+With a default `umask` of 022, your secret keys will be *world-readable* and
121
+writable for you and your group.
122
+
123
+In order to protect your keys from accidental damage, you will want to remove their
124
+write permissions. To make them only readable by you, change file modes as follows:
125
+
126
+    $ chmod -v 0400 ca-key.pem key.pem server-key.pem
127
+
128
+Certificates can be world-readable, but you might want to remove write access to
129
+prevent accidental damage:
130
+
131
+    $ chmod -v 0444 ca.pem server-cert.pem cert.pem
132
+
133
+Now you can make the Docker daemon only accept connections from clients
134
+providing a certificate trusted by our CA:
135
+
136
+    $ docker daemon --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem \
137
+      -H=0.0.0.0:2376
138
+
139
+To be able to connect to Docker and validate its certificate, you now
140
+need to provide your client keys, certificates and trusted CA:
141
+
142
+> **Note**: replace all instances of `$HOST` in the following example with the
143
+> DNS name of your Docker daemon's host.
144
+
145
+    $ docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem \
146
+      -H=$HOST:2376 version
147
+
148
+> **Note**:
149
+> Docker over TLS should run on TCP port 2376.
150
+
151
+> **Warning**:
152
+> As shown in the example above, you don't have to run the `docker` client
153
+> with `sudo` or the `docker` group when you use certificate authentication.
154
+> That means anyone with the keys can give any instructions to your Docker
155
+> daemon, giving them root access to the machine hosting the daemon. Guard
156
+> these keys as you would a root password!
157
+
158
+## Secure by default
159
+
160
+If you want to secure your Docker client connections by default, you can move
161
+the files to the `.docker` directory in your home directory -- and set the
162
+`DOCKER_HOST` and `DOCKER_TLS_VERIFY` variables as well (instead of passing
163
+`-H=tcp://$HOST:2376` and `--tlsverify` on every call).
164
+
165
+    $ mkdir -pv ~/.docker
166
+    $ cp -v {ca,cert,key}.pem ~/.docker
167
+    $ export DOCKER_HOST=tcp://$HOST:2376 DOCKER_TLS_VERIFY=1
168
+
169
+Docker will now connect securely by default:
170
+
171
+    $ docker ps
172
+
173
+## Other modes
174
+
175
+If you don't want to have complete two-way authentication, you can run
176
+Docker in various other modes by mixing the flags.
177
+
178
+### Daemon modes
179
+
180
+ - `tlsverify`, `tlscacert`, `tlscert`, `tlskey` set: Authenticate clients
181
+ - `tls`, `tlscert`, `tlskey`: Do not authenticate clients
182
+
183
+### Client modes
184
+
185
+ - `tls`: Authenticate server based on public/default CA pool
186
+ - `tlsverify`, `tlscacert`: Authenticate server based on given CA
187
+ - `tls`, `tlscert`, `tlskey`: Authenticate with client certificate, do not
188
+   authenticate server based on given CA
189
+ - `tlsverify`, `tlscacert`, `tlscert`, `tlskey`: Authenticate with client
190
+   certificate and authenticate server based on given CA
191
+
192
+If found, the client will send its client certificate, so you just need
193
+to drop your keys into `~/.docker/{ca,cert,key}.pem`. Alternatively,
194
+if you want to store your keys in another location, you can specify that
195
+location using the environment variable `DOCKER_CERT_PATH`.
196
+
197
+    $ export DOCKER_CERT_PATH=~/.docker/zone1/
198
+    $ docker --tlsverify ps
199
+
200
+### Connecting to the secure Docker port using `curl`
201
+
202
+To use `curl` to make test API requests, you need to use three extra command line
203
+flags:
204
+
205
+    $ curl https://$HOST:2376/images/json \
206
+      --cert ~/.docker/cert.pem \
207
+      --key ~/.docker/key.pem \
208
+      --cacert ~/.docker/ca.pem
209
+
210
+## Related information
211
+
212
+* [Using certificates for repository client verification](certificates.md)
213
+* [Use trusted images](trust/index.md)
0 214
new file mode 100644
... ...
@@ -0,0 +1,10 @@
0
+FROM debian
1
+
2
+RUN apt-get update && apt-get install -yq openssl
3
+
4
+ADD make_certs.sh /
5
+
6
+
7
+WORKDIR /data
8
+VOLUME ["/data"]
9
+CMD /make_certs.sh
0 10
new file mode 100644
... ...
@@ -0,0 +1,24 @@
0
+
1
+HOST:=boot2docker
2
+
3
+makescript:
4
+	./parsedocs.sh > make_certs.sh
5
+
6
+build: clean makescript
7
+	docker build -t makecerts .
8
+
9
+cert: build
10
+	docker run --rm -it -v $(CURDIR):/data -e HOST=$(HOST) -e YOUR_PUBLIC_IP=$(shell ip a | grep "inet " | sed "s/.*inet \([0-9.]*\)\/.*/\1/" | xargs echo | sed "s/ /,IP:/g") makecerts
11
+
12
+certs: cert
13
+
14
+run:
15
+	sudo docker daemon -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
+	sudo docker --tls --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem   -H=$(HOST):6666 version
19
+	sudo docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem   -H=$(HOST):6666 info
20
+	sudo curl https://$(HOST):6666/images/json --cert ./cert.pem --key ./key.pem --cacert ./ca.pem
21
+
22
+clean:
23
+	rm -f ca-key.pem ca.pem ca.srl cert.pem client.csr extfile.cnf key.pem server-cert.pem server-key.pem server.csr extfile.cnf
0 24
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+<!--[metadata]>
1
+draft = true
2
+<![end-metadata]-->
3
+
4
+
5
+
6
+This is an initial attempt to make it easier to test the examples in the https.md
7
+doc
8
+
9
+at this point, it has to be a manual thing, and I've been running it in boot2docker
10
+
11
+so my process is
12
+
13
+$ boot2docker ssh
14
+$$ git clone https://github.com/docker/docker
15
+$$ cd docker/docs/articles/https
16
+$$ make cert
17
+lots of things to see and manually answer, as openssl wants to be interactive
18
+**NOTE:** make sure you enter the hostname (`boot2docker` in my case) when prompted for `Computer Name`)
19
+$$ sudo make run
20
+
21
+start another terminal
22
+
23
+$ boot2docker ssh
24
+$$ cd docker/docs/articles/https
25
+$$ make client
26
+
27
+the last will connect first with `--tls` and then with `--tlsverify`
28
+
29
+both should succeed
0 30
new file mode 100755
... ...
@@ -0,0 +1,23 @@
0
+#!/bin/sh
1
+openssl genrsa -aes256 -out ca-key.pem 2048
2
+openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
3
+openssl genrsa -out server-key.pem 2048
4
+openssl req -subj "/CN=$HOST" -new -key server-key.pem -out server.csr
5
+echo subjectAltName = IP:$YOUR_PUBLIC_IP > extfile.cnf
6
+openssl x509 -req -days 365 -in server.csr -CA ca.pem -CAkey ca-key.pem       -CAcreateserial -out server-cert.pem -extfile extfile.cnf
7
+openssl genrsa -out key.pem 2048
8
+openssl req -subj '/CN=client' -new -key key.pem -out client.csr
9
+echo extendedKeyUsage = clientAuth > extfile.cnf
10
+openssl x509 -req -days 365 -in client.csr -CA ca.pem -CAkey ca-key.pem       -CAcreateserial -out cert.pem -extfile extfile.cnf
11
+rm -v client.csr server.csr
12
+chmod -v 0400 ca-key.pem key.pem server-key.pem
13
+chmod -v 0444 ca.pem server-cert.pem cert.pem
14
+# docker -d --tlsverify --tlscacert=ca.pem --tlscert=server-cert.pem --tlskey=server-key.pem       -H=0.0.0.0:7778
15
+# docker --tlsverify --tlscacert=ca.pem --tlscert=cert.pem --tlskey=key.pem       -H=$HOST:7778 version
16
+mkdir -pv ~/.docker
17
+cp -v {ca,cert,key}.pem ~/.docker
18
+export DOCKER_HOST=tcp://$HOST:7778 DOCKER_TLS_VERIFY=1
19
+# docker ps
20
+export DOCKER_CERT_PATH=~/.docker/zone1/
21
+# docker --tlsverify ps
22
+# curl https://$HOST:7778/images/json       --cert ~/.docker/cert.pem       --key ~/.docker/key.pem       --cacert ~/.docker/ca.pem
0 23
new file mode 100755
... ...
@@ -0,0 +1,10 @@
0
+#!/bin/sh
1
+
2
+echo "#!/bin/sh"
3
+cat ../https.md | awk '{if (sub(/\\$/,"")) printf "%s", $0; else print $0}' \
4
+        | grep '   $ ' \
5
+        | sed 's/    $ //g' \
6
+        | sed 's/2375/7777/g' \
7
+        | sed 's/2376/7778/g' \
8
+        | sed 's/^docker/# docker/g' \
9
+        | sed 's/^curl/# curl/g'
... ...
@@ -15,6 +15,10 @@ This section discusses the security features you can configure and use within yo
15 15
 
16 16
 * You can configure Docker's trust features so that your users can push and pull trusted images. To learn how to do this, see [Use trusted images](trust/index.md) in this section.
17 17
 
18
+* You can protect the Docker daemon socket and ensure only trusted Docker client connections. For more information, [Protect the Docker daemon socket](https.md)
19
+
20
+* You can use certificate-based client-server authentication to verify a Docker daemon has the rights to access images on a registry. For more information, see [Using certificates for repository client verification](certificates.md).
21
+
18 22
 * You can configure secure computing mode (Seccomp) policies to secure system calls in a container. For more information, see [Seccomp security profiles for Docker](seccomp.md).
19 23
 
20 24
 * An AppArmor profile for Docker is installed with the official *.deb* packages. For information about this profile and overriding it, see [AppArmor security profiles for Docker](apparmor.md).
... ...
@@ -5,6 +5,7 @@ description = "Enabling seccomp in Docker"
5 5
 keywords = ["seccomp, security, docker, documentation"]
6 6
 [menu.main]
7 7
 parent= "smn_secure_docker"
8
+weight=90
8 9
 +++
9 10
 <![end-metadata]-->
10 11
 
... ...
@@ -116,7 +116,7 @@ However, if you do that, being aware of the above mentioned security
116 116
 implication, you should ensure that it will be reachable only from a
117 117
 trusted network or VPN; or protected with e.g., `stunnel` and client SSL
118 118
 certificates. You can also secure them with [HTTPS and
119
-certificates](../articles/https/).
119
+certificates](https.md).
120 120
 
121 121
 The daemon is also potentially vulnerable to other inputs, such as image
122 122
 loading from either disk with 'docker load', or from the network with
... ...
@@ -5,7 +5,7 @@ description = "Use trusted images"
5 5
 keywords = ["trust, security, docker,  index"]
6 6
 [menu.main]
7 7
 identifier="smn_content_trust"
8
-parent= "mn_docker_hub"
8
+parent= "smn_secure_docker"
9 9
 weight=4
10 10
 +++
11 11
 <![end-metadata]-->
... ...
@@ -14,8 +14,7 @@ weight=4
14 14
 
15 15
 The following topics are available:
16 16
 
17
-* [Content trust in Docker](content_trust.md) 
17
+* [Content trust in Docker](content_trust.md)
18 18
 * [Manage keys for content trust](trust_key_mng.md)
19 19
 * [Automation with content trust](trust_automation.md)
20 20
 * [Play in a content trust sandbox](trust_sandbox.md)
21
-