Skip to content

Commit 8f491ad

Browse files
committed
docker: remove insecure tcp://0.0.0.0:2375 configuration
TCP connection without TLS is completely insecure and can easily result in container breakout. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
1 parent 9c3abb3 commit 8f491ad

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

docker/content.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,26 @@ If you are still convinced that you need Docker-in-Docker and not just access to
1919
## Start a daemon instance
2020

2121
```console
22-
$ docker run --privileged --name some-docker -d %%IMAGE%%:dind
22+
$ docker run --privileged --name some-docker -d -v /daemon-secret:/secret %%IMAGE%%:dind \
23+
dockerd -H tcp://0.0.0.0:2376 --tlsverify --tlscacert /secret/ca.pem --tlscert /secret/cert.pem --tlskey /secret/key.pem
2324
```
2425

2526
**Note:** `--privileged` is required for Docker-in-Docker to function properly, but it should be used with care as it provides full access to the host environment, as explained [in the relevant section of the Docker documentation](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).
2627

27-
By default, the `dind` variants of this image add `--host=tcp://0.0.0.0:2375` (on top of the explicit default of `--host=unix:///var/run/docker.sock`) in order to allow external containers to access `dockerd` appropriately (as the following examples illustrate). If you use `--network=host` or other methods of sharing network namespaces (such as Kubernetes pods, for example), this might be a security issue. To disable this image behavior, simply override the container command or entrypoint to run `dockerd` directly (`... docker:dind dockerd ...` or `... --entrypoint dockerd docker:dind ...`).
28+
By default, the `dind` variants of this image add `--host=tcp://0.0.0.0:2375` (on top of the explicit default of `--host=unix:///var/run/docker.sock`) via the `ENTRYPOINT` script (`/usr/local/bin/dockerd-entrypoint.sh`) in order to allow external containers to access `dockerd` without TLS.
29+
30+
This default `ENTRYPOINT` configuration is *INSECURE* and can easily result in *"container breakout"*, because any container inside the `dind` with network connectivity can connect to the `dind` daemon via the gateway IP and gain the root privileges on the host, not just the root privileges in the `dind` daemon container. Any process in the host, and any container in the parent Docker with network connectivy can gain the root privileges as well.
31+
32+
To disable this image behavior, simply override the container command or entrypoint to run `dockerd` directly (`... docker:dind dockerd ...` as shown in this document or `... --entrypoint dockerd docker:dind ...`).
2833

2934
## Connect to it from a second container
3035

36+
`/client-secret` is assumed to contain `ca.pem`, `cert.pem`, and `key.pem` here.
37+
3138
```console
32-
$ docker run --rm --link some-docker:docker %%IMAGE%%:edge version
39+
$ docker run --rm --link some-docker:docker -v /client-secret:/root/.docker \
40+
-e DOCKER_HOST=tcp://docker:2376 -e DOCKER_TLS_VERIFY=1 \
41+
%%IMAGE%%:edge version
3342
Client:
3443
Version: 17.05.0-ce
3544
API version: 1.27 (downgraded from 1.29)
@@ -49,7 +58,9 @@ Server:
4958
```
5059

5160
```console
52-
$ docker run -it --rm --link some-docker:docker %%IMAGE%%:edge sh
61+
$ docker run -it --rm --link some-docker:docker -v /client-secret:/root/.docker %%IMAGE%%:edge sh
62+
/ # export DOCKER_HOST=tcp://docker:2376
63+
/ # export DOCKER_TLS_VERIFY=1
5364
/ # docker version
5465
Client:
5566
Version: 17.05.0-ce
@@ -70,7 +81,9 @@ Server:
7081
```
7182

7283
```console
73-
$ docker run --rm --link some-docker:docker %%IMAGE%% info
84+
$ docker run --rm --link some-docker:docker -v /client-secret:/root/.docker \
85+
-e DOCKER_HOST=tcp://docker:2376 -e DOCKER_TLS_VERIFY=1 \
86+
%%IMAGE%%:edge info
7487
Containers: 0
7588
Running: 0
7689
Paused: 0
@@ -113,6 +126,37 @@ Insecure Registries:
113126
Live Restore Enabled: false
114127
```
115128

129+
## Connect via UNIX socket
130+
131+
If the client and the daemon are running on the same host and you don't want to configure TLS, you can use UNIX socket instead.
132+
133+
```console
134+
$ mkdir /tmp/foo
135+
$ docker run --privileged --name some-docker -d -v /tmp/foo:/var/run %%IMAGE%%:dind dockerd
136+
```
137+
138+
```console
139+
$ docker run --rm -v /tmp/foo:/var/run %%IMAGE%% version
140+
Client:
141+
Version: 17.05.0-ce
142+
API version: 1.28 (downgraded from 1.29)
143+
Go version: go1.7.5
144+
Git commit: 89658be
145+
Built: Fri May 5 15:36:11 2017
146+
OS/Arch: linux/amd64
147+
148+
Server:
149+
Version: 17.04.0-ce
150+
API version: 1.28 (minimum version 1.12)
151+
Go version: go1.8
152+
Git commit: 4845c56
153+
Built: Thu Apr 27 07:51:43 2017
154+
OS/Arch: linux/amd64
155+
Experimental: false
156+
```
157+
158+
To connect to the host daemon:
159+
116160
```console
117161
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock %%IMAGE%% version
118162
Client:

0 commit comments

Comments
 (0)