Docker Security
Docker is the most popular containerisation technology. Upon proper use, it can increase the level of security (in comparison to running applications directly on the host). On the other hand, some misconfigurations can lead to downgrade the level of security or even introduce new vulnerabilities.There are common container security risks and vulnerabilities during a development cycle that can be exploited be attackers.
Using insecure images
Containers running with the privileged flag
Unrestricted communication between containers
Containers running rogue or malicious processes
- Containers that are not properly isolated from the host
Using insecure images:
You should always try to use images from trusted sources. What i mean by that is if I am going to download mssql image from docker hub then it should be from microsoft only. Others images also could be used for downloading mssql but you don't know which image could be containing vulnerabilities.
Containers running with the privileged flag
docker run --privileged -t -i --rm ubuntu:latest bash
Unrestricted communication between containers
Docker containers are very similar to LXC containers, and they have similar security features. When you start a container with docker run
, behind the scenes Docker creates a set of namespaces and control groups for the container.
Namespaces provide the first and most straightforward form of isolation: processes running within a container cannot see, and even less affect, processes running in another container, or in the host system.
Each container also gets its own network stack, meaning that a container doesn’t get privileged access to the sockets or interfaces of another container.
root
privileges unless you opt-in to Rootless Mode, and you should therefore be aware of some important details. First of all, only trusted users should be allowed to control your Docker daemon. This is a direct consequence of some powerful Docker features. Specifically, Docker allows you to share a directory between the Docker host and a guest container; and it allows you to do so without limiting the access rights of the container. This means that you can start a container where the /host
directory is the /
directory on your host; and the container can alter your host filesystem without any restriction. Containers running rogue or malicious processes
Containers that are not properly isolated from the host
down the Docker host.
Don’t share the host’s process namespaces. Doing so would allow a container to see all of the processes running on a host system, which leaves the processes on the host at risk of being manipulated or shut down.
There are few things could be followed
- Always Keep Host and Docker up to date.
To prevent from known, container escapes vulnerabilities, which typically end in escalating to root/administrator privileges, patching Docker Engine and Docker Machine is crucial.
- Do not expose the Docker daemon socket (even to the containers)
Docker socket /var/run/docker.sock is the UNIX socket that Docker is listening to. This is the primary entry point for the Docker API. The owner of this socket is root. Giving someone access to it is equivalent to giving unrestricted root access to your host.
Do not enable tcp Docker daemon socket. If you are running docker daemon with -H tcp://0.0.0.0:XXX or similar you are exposing un-encrypted and unauthenticated direct access to the Docker daemon, if the host is internet connected this means the docker daemon on your computer can be used by anyone from the public internet.
- Set User
Configuring the container to use an unprivileged user is the best way to prevent privilege escalation attacks. This can be accomplished in few different ways as follows:
During runtime using -u option of docker run:
docker run -u 4000 alpine
During build time. Simple add user in Dockerfile and use it. For example:FROM alpineRUN groupadd -r myuser && useradd -r -g myuser myuser
- Add –no-new-privileges flag
Always run you docker images with --security-opt=no-new-privileges in order to prevent escalate privileges using setuid or setqid binaries.
In kubernetes, this can be configured in security context using allowPrivilegeEscalation field.
- Disable inter-container communication (--icc=false)
By default inter-container communication(icc) is enabled - it means that all containers can talk with each other using (docker0 bridged network). This can be disabled by running docker daemon with --icc=false flag. If icc is disabled (icc=false) it is required to tell which container can communicate using --link=container_name or id:ALIAS option.
No comments:
Post a Comment