Skip to content

Commit 9fb45d6

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 9fb45d6

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

docker/content.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,27 @@ 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 --tls /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.
31+
Any process in the host, and any container in the parent Docker with network connectivy can gain the root privileges as well.
32+
33+
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 ...`).
2834

2935
## Connect to it from a second container
3036

37+
`/client-secret` is assumed to contain `ca.pem`, `cert.pem`, and `key.pem` here.
38+
3139
```console
32-
$ docker run --rm --link some-docker:docker %%IMAGE%%:edge version
40+
$ docker run --rm --link some-docker:docker -v /client-secret:/root/.docker \
41+
-e DOCKER_HOST=tcp://docker:2376 -e DOCKER_TLS_VERIFY=1 \
42+
%%IMAGE%%:edge version
3343
Client:
3444
Version: 17.05.0-ce
3545
API version: 1.27 (downgraded from 1.29)
@@ -49,7 +59,9 @@ Server:
4959
```
5060

5161
```console
52-
$ docker run -it --rm --link some-docker:docker %%IMAGE%%:edge sh
62+
$ docker run -it --rm --link some-docker:docker -v /client-secret:/root/.docker %%IMAGE%%:edge sh
63+
/ # export DOCKER_HOST=tcp://docker:2376
64+
/ # export DOCKER_TLS_VERIFY=1
5365
/ # docker version
5466
Client:
5567
Version: 17.05.0-ce
@@ -70,7 +82,9 @@ Server:
7082
```
7183

7284
```console
73-
$ docker run --rm --link some-docker:docker %%IMAGE%% info
85+
$ docker run --rm --link some-docker:docker -v /client-secret:/root/.docker \
86+
-e DOCKER_HOST=tcp://docker:2376 -e DOCKER_TLS_VERIFY=1 \
87+
%%IMAGE%%:edge info
7488
Containers: 0
7589
Running: 0
7690
Paused: 0
@@ -113,6 +127,38 @@ Insecure Registries:
113127
Live Restore Enabled: false
114128
```
115129

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

0 commit comments

Comments
 (0)