Skip to content

Commit 27abf63

Browse files
committed
Clarify Docker Security considerations -- with added emphasis on securing the underlying host and controlling access to the docker daemon
1 parent ebf8ca9 commit 27abf63

File tree

1 file changed

+81
-71
lines changed

1 file changed

+81
-71
lines changed

docs/articles/security.md

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,89 @@ weight = 2
1313

1414
There are three major areas to consider when reviewing Docker security:
1515

16-
- the intrinsic security of the kernel and its support for
17-
namespaces and cgroups;
18-
- the attack surface of the Docker daemon itself;
19-
- loopholes in the container configuration profile, either by default,
20-
or when customized by users.
21-
- the "hardening" security features of the kernel and how they
22-
interact with containers.
16+
- **Host Security** -- the attack surface of the underlying host and the
17+
Docker daemon itself;
18+
- **Container Security** -- and how it interacts with namespaces, cgroups,
19+
and "hardening" features of the kernel
20+
- **Configuring Containers for Least Privilege**
21+
22+
## Host Security
23+
The overall purpose and design of Docker Security is to protect against
24+
**external attack vectors**, with a focus on keeping containers isolated and
25+
operating with least privilege. First, it is essential that you control access
26+
to the host and keep it securely configured. Secondly, the Docker daemon
27+
currently requires `root` privileges, and you should therefore be aware of
28+
some important details:
29+
30+
###Docker Daemon Security Details
31+
32+
**Only trusted users should be allowed to control your Docker daemon**.
33+
Running containers (and applications) with Docker implies running the
34+
Docker daemon.
35+
36+
This is a direct consequence of some powerful Docker
37+
features. Specifically, Docker allows you to share a directory between
38+
the Docker host and a guest container; and it allows you to do so
39+
without limiting the access rights of the container. This means that you
40+
can start a container where the `/host` directory will be the `/` directory
41+
on your host; and the container will be able to alter your host filesystem
42+
without any restriction. This is similar to how virtualization systems
43+
allow filesystem resource sharing. Nothing prevents you from sharing your
44+
root filesystem (or even your root block device) with a virtual machine.
45+
46+
This has a strong security implication: for example, if you instrument Docker
47+
from a web server to provision containers through an API, you should be
48+
even more careful than usual with parameter checking, to make sure that
49+
a malicious user cannot pass crafted parameters causing Docker to create
50+
arbitrary containers.
51+
52+
For this reason, the REST API endpoint (used by the Docker CLI to
53+
communicate with the Docker daemon) changed in Docker 0.5.2, and now
54+
uses a UNIX socket instead of a TCP socket bound on 127.0.0.1 (the
55+
latter being prone to cross-site-scripting attacks if you happen to run
56+
Docker directly on your local machine, outside of a VM). You can then
57+
use traditional UNIX permission checks to limit access to the control
58+
socket.
59+
60+
You can also expose the REST API over HTTP if you explicitly decide to do so.
61+
However, if you do that, being aware of the above mentioned security
62+
implication, you should ensure that it will be reachable only from a
63+
trusted network or VPN; or protected with e.g., `stunnel` and client SSL
64+
certificates. You can also secure them with [HTTPS and
65+
certificates](../articles/https/).
2366

24-
## Kernel namespaces
67+
The daemon is also potentially vulnerable to other inputs, such as image
68+
loading from either disk with 'docker load', or from the network with
69+
'docker pull'. This has been a focus of improvement in the community,
70+
especially for 'pull' security. While these overlap, it should be noted
71+
that 'docker load' is a mechanism for backup and restore and is not
72+
currently considered a secure mechanism for loading images. As of
73+
Docker 1.3.2, images are now extracted in a chrooted subprocess on
74+
Linux/Unix platforms, being the first-step in a wider effort toward
75+
privilege separation.
76+
77+
Eventually, it is expected that the Docker daemon will run restricted
78+
privileges, delegating operations well-audited sub-processes,
79+
each with its own (very limited) scope of Linux capabilities,
80+
virtual network setup, filesystem management, etc. That is, most likely,
81+
pieces of the Docker engine itself will run inside of containers.
82+
83+
Finally, if you run Docker on a server, it is recommended to run
84+
exclusively Docker in the server, and move all other services within
85+
containers controlled by Docker. Of course, it is fine to keep your
86+
favorite admin tools (probably at least an SSH server), as well as
87+
existing monitoring/supervision processes (e.g., NRPE, collectd, etc).
88+
89+
90+
## Container Security
2591

2692
Docker containers are very similar to LXC containers, and they have
2793
similar security features. When you start a container with
2894
`docker run`, behind the scenes Docker creates a set of namespaces and control
2995
groups for the container.
3096

97+
### Kernel namespaces
98+
3199
**Namespaces provide the first and most straightforward form of
32100
isolation**: processes running within a container cannot see, and even
33101
less affect, processes running in another container, or in the host
@@ -60,7 +128,7 @@ http://en.wikipedia.org/wiki/OpenVZ) in such a way that they could be
60128
merged within the mainstream kernel. And OpenVZ was initially released
61129
in 2005, so both the design and the implementation are pretty mature.
62130

63-
## Control groups
131+
### Control groups
64132

65133
Control Groups are another key component of Linux Containers. They
66134
implement resource accounting and limiting. They provide many
@@ -79,67 +147,8 @@ when some applications start to misbehave.
79147
Control Groups have been around for a while as well: the code was
80148
started in 2006, and initially merged in kernel 2.6.24.
81149

82-
## Docker daemon attack surface
83-
84-
Running containers (and applications) with Docker implies running the
85-
Docker daemon. This daemon currently requires `root` privileges, and you
86-
should therefore be aware of some important details.
87-
88-
First of all, **only trusted users should be allowed to control your
89-
Docker daemon**. This is a direct consequence of some powerful Docker
90-
features. Specifically, Docker allows you to share a directory between
91-
the Docker host and a guest container; and it allows you to do so
92-
without limiting the access rights of the container. This means that you
93-
can start a container where the `/host` directory will be the `/` directory
94-
on your host; and the container will be able to alter your host filesystem
95-
without any restriction. This is similar to how virtualization systems
96-
allow filesystem resource sharing. Nothing prevents you from sharing your
97-
root filesystem (or even your root block device) with a virtual machine.
98-
99-
This has a strong security implication: for example, if you instrument Docker
100-
from a web server to provision containers through an API, you should be
101-
even more careful than usual with parameter checking, to make sure that
102-
a malicious user cannot pass crafted parameters causing Docker to create
103-
arbitrary containers.
104-
105-
For this reason, the REST API endpoint (used by the Docker CLI to
106-
communicate with the Docker daemon) changed in Docker 0.5.2, and now
107-
uses a UNIX socket instead of a TCP socket bound on 127.0.0.1 (the
108-
latter being prone to cross-site-scripting attacks if you happen to run
109-
Docker directly on your local machine, outside of a VM). You can then
110-
use traditional UNIX permission checks to limit access to the control
111-
socket.
112-
113-
You can also expose the REST API over HTTP if you explicitly decide to do so.
114-
However, if you do that, being aware of the above mentioned security
115-
implication, you should ensure that it will be reachable only from a
116-
trusted network or VPN; or protected with e.g., `stunnel` and client SSL
117-
certificates. You can also secure them with [HTTPS and
118-
certificates](../articles/https/).
119-
120-
The daemon is also potentially vulnerable to other inputs, such as image
121-
loading from either disk with 'docker load', or from the network with
122-
'docker pull'. This has been a focus of improvement in the community,
123-
especially for 'pull' security. While these overlap, it should be noted
124-
that 'docker load' is a mechanism for backup and restore and is not
125-
currently considered a secure mechanism for loading images. As of
126-
Docker 1.3.2, images are now extracted in a chrooted subprocess on
127-
Linux/Unix platforms, being the first-step in a wider effort toward
128-
privilege separation.
129-
130-
Eventually, it is expected that the Docker daemon will run restricted
131-
privileges, delegating operations well-audited sub-processes,
132-
each with its own (very limited) scope of Linux capabilities,
133-
virtual network setup, filesystem management, etc. That is, most likely,
134-
pieces of the Docker engine itself will run inside of containers.
135-
136-
Finally, if you run Docker on a server, it is recommended to run
137-
exclusively Docker in the server, and move all other services within
138-
containers controlled by Docker. Of course, it is fine to keep your
139-
favorite admin tools (probably at least an SSH server), as well as
140-
existing monitoring/supervision processes (e.g., NRPE, collectd, etc).
141150

142-
## Linux kernel capabilities
151+
### Linux kernel capabilities
143152

144153
By default, Docker starts containers with a restricted set of
145154
capabilities. What does that mean?
@@ -177,7 +186,8 @@ infrastructure around the container:
177186
is specifically engineered to behave like a router or firewall, of
178187
course).
179188

180-
This means that in most cases, containers will not need "real" root
189+
## Configuring Containers for Least Privilege
190+
In most cases, containers will not need "real" root
181191
privileges *at all*. And therefore, containers can run with a reduced
182192
capability set; meaning that "root" within a container has much less
183193
privileges than the real "root". For instance, it is possible to:
@@ -213,7 +223,7 @@ capability removal, or less secure through the addition of capabilities.
213223
The best practice for users would be to remove all capabilities except
214224
those explicitly required for their processes.
215225

216-
## Other kernel security features
226+
### Other kernel security features
217227

218228
Capabilities are just one of the many security features provided by
219229
modern Linux kernels. It is also possible to leverage existing,

0 commit comments

Comments
 (0)