79

Testing Docker Images Security -All day dev ops 2017

Embed Size (px)

Citation preview

Page 1: Testing Docker Images Security -All day dev ops 2017
Page 2: Testing Docker Images Security -All day dev ops 2017

jmortega.github.io

about.me/jmortegac

Software Engineer & Security Researcher

Page 3: Testing Docker Images Security -All day dev ops 2017

Introduction to docker securitySecurity best practicesTools for auditing docker images

Three Takeaways

Page 4: Testing Docker Images Security -All day dev ops 2017

● “Docker containers wrap up a piece of

software in a complete filesystem

that contains everything it needs to

run: code,runtime, system tools,

system libraries –anything you can

install on a server. This guarantees

that it will always run the

same,regardless of the environment it

is running in.”

Page 5: Testing Docker Images Security -All day dev ops 2017
Page 6: Testing Docker Images Security -All day dev ops 2017

● Docker provides an additional layer of isolation,

making your infrastructure safer by default.

● Makes the application lifecycle fast and easier,

reducing risks in your applications

Page 7: Testing Docker Images Security -All day dev ops 2017

● Docker uses several mechanisms for security:

○ Linux kernel namespaces

○ Linux Control Groups (cgroups)

○ The Docker daemon

○ Linux capabilities (libcap)

○ Linux security mechanisms like AppArmor or

SELinux

Page 8: Testing Docker Images Security -All day dev ops 2017

● Namespaces:provides an isolated view of the

system where processes cannot see other

processes in other containers

● Each container also gets its own network stack.

● A container doesn’t get privileged access to the sockets or interfaces of another container.

Page 9: Testing Docker Images Security -All day dev ops 2017

● Cgroups: kernel feature that limits and isolates

the resource usage(CPU,memory,network) of a

collection of processes.

● Linux Capabilities: divides the privileges of root

into distinct units and smaller groups of privileges.

Page 10: Testing Docker Images Security -All day dev ops 2017

● The docker daemon (/usr/bin/docker) is responsible for managing the control groups, orchestrating the namespaces, and so on so that docker images can be run and secured.

● Because of the need to manage kernel functions, Docker runs with root privileges.

● Limit the users who have control of the Docker Daemon

Page 11: Testing Docker Images Security -All day dev ops 2017

● Restrict access to the daemon only to the ones really needing it (users, processes)

● Don’t expose the daemon to the outside your network ● If you do so, make sure you have put this behind a secure

proxy, like NGINX

Page 12: Testing Docker Images Security -All day dev ops 2017
Page 13: Testing Docker Images Security -All day dev ops 2017
Page 14: Testing Docker Images Security -All day dev ops 2017
Page 15: Testing Docker Images Security -All day dev ops 2017
Page 16: Testing Docker Images Security -All day dev ops 2017

https://github.com/CenturyLinkLabs/dockerfile-from-image

Page 17: Testing Docker Images Security -All day dev ops 2017
Page 18: Testing Docker Images Security -All day dev ops 2017

● Images are extracted in a chrooted sub process, being the

first-step in a wider effort toward privilege separation.

● From Docker 1.10, all images are stored and accessed by

the cryptographic checksums of their contents, limiting the possibility of an attacker causing a collision with an existing image Docker Content Trust.

Page 19: Testing Docker Images Security -All day dev ops 2017
Page 20: Testing Docker Images Security -All day dev ops 2017

● Protects against untrusted images

● Can enable signing checks on every managed host

● Signature verification transparent to users

● Guarantee integrity of your images when pulled

● Provides trust from publisher to consumer

● export DOCKER_CONTENT_TRUST=1

● ~/.docker/trust/trusted-certificates/

Page 21: Testing Docker Images Security -All day dev ops 2017

● Do not write secrets(users and passwords).● Remove unnecessary setuid, setgid permissions

(Privilege escalation)● Download packages securely using GPG and certificates● Try to restrict an image or container to one service

Page 22: Testing Docker Images Security -All day dev ops 2017

● To disable setuid rights, add the following to the Dockerfile of your image

Page 23: Testing Docker Images Security -All day dev ops 2017

● Set a specific user.● Don’t run your applications as root in containers.

Page 24: Testing Docker Images Security -All day dev ops 2017

● Don’t run containers with --privileged flag

● The --privileged flag gives all capabilities to the

container.

● docker run --privileged …

● docker run --cap-drop=ALL --cap-add=

CAP_NET_ADMIN ...

Page 25: Testing Docker Images Security -All day dev ops 2017

● Manual management within the container:docker run --cap-add ALL

● Restricted capabilities with root:docker run --cap-drop ALL --cap-add $CAP

● No capabilities:docker run --user

Page 26: Testing Docker Images Security -All day dev ops 2017
Page 27: Testing Docker Images Security -All day dev ops 2017
Page 28: Testing Docker Images Security -All day dev ops 2017

● We can verify the integrity of the image● Checksum validation when pulling image from

docker hub● Pulling by digest to enforce consistent

Page 29: Testing Docker Images Security -All day dev ops 2017

● Pulling by Docker content trust

● $ export DOCKER_CONTENT_TRUST=1$ docker pull debian:latestPull (1 of 1): debian:latest@sha256:a25306f38…

Page 30: Testing Docker Images Security -All day dev ops 2017

● Check packages installed in the container

Page 31: Testing Docker Images Security -All day dev ops 2017

Docker security is about limiting and controlling the attack surface on the kernel.

Page 32: Testing Docker Images Security -All day dev ops 2017

Run filesystems as read-only so that attackers can not overwrite data or save malicious scripts to the image.

Page 33: Testing Docker Images Security -All day dev ops 2017
Page 34: Testing Docker Images Security -All day dev ops 2017
Page 35: Testing Docker Images Security -All day dev ops 2017
Page 36: Testing Docker Images Security -All day dev ops 2017

Auditing Docker Images

Page 37: Testing Docker Images Security -All day dev ops 2017

● You can scan your images for known vulnerabilities● There are tools for that, like Docker Security Scanning,

Docker Bench Security and CoreOS Clair● Find known vulnerable binaries

Page 38: Testing Docker Images Security -All day dev ops 2017

● Checks based on best practices for hosts and containers

● Find Common Vulnerabilities and Exposures (CVEs)

https://docs.docker.com/docker-cloud/builds/image-scan/

Page 39: Testing Docker Images Security -All day dev ops 2017

● Checks against CVE database for image layers● Binary scanning of all components in the image● Performs binary scan to pick up on statically linked

binaries● Analyses libraries statically compiled in the image● Generates a reports that shows if there are CVE in the

libraries inside the image

Page 40: Testing Docker Images Security -All day dev ops 2017
Page 41: Testing Docker Images Security -All day dev ops 2017
Page 42: Testing Docker Images Security -All day dev ops 2017

https://www.docker.com/docker-cve-database

Page 43: Testing Docker Images Security -All day dev ops 2017
Page 44: Testing Docker Images Security -All day dev ops 2017
Page 45: Testing Docker Images Security -All day dev ops 2017

● Vulnerability Static Analysis for Containers

● https://github.com/coreos/clair

Page 46: Testing Docker Images Security -All day dev ops 2017

● You've found an image by searching the internet and want to determine if it's safe enough for you to use in production.

● You're regularly deploying into a containerized production environment and want operations to alert or block deployments on insecure software.

Page 47: Testing Docker Images Security -All day dev ops 2017
Page 48: Testing Docker Images Security -All day dev ops 2017
Page 49: Testing Docker Images Security -All day dev ops 2017

● Checks based on best practices for hosts and containers● https://github.com/docker/docker-bench-security● Open-source tool for running automated tests ● Inspired by the CIS Docker 1.11 benchmark● Runs against containers currently running on same host● Checks for AppArmor, read-only volumes, etc...

Page 50: Testing Docker Images Security -All day dev ops 2017
Page 51: Testing Docker Images Security -All day dev ops 2017

● The host configuration

● The Docker daemon configuration

● The Docker daemon configuration files

● Container images and build files

● Container runtime

● Docker security operations

Page 52: Testing Docker Images Security -All day dev ops 2017

● The Docker daemon configuration● [WARN] 2.1- Restrict network traffic between containers● [WARN] 4.1 - Create a user for the container● [WARN] * Running as root:● [WARN] 5.4 - Restrict Linux Kernel Capabilities within

containers● [WARN] * Capabilities added: CapAdd=[audit_control]● [WARN] 5.13 - Mount container's root filesystem as readonly● [WARN] * Container running with root FS mounted R/W:

Page 53: Testing Docker Images Security -All day dev ops 2017
Page 54: Testing Docker Images Security -All day dev ops 2017

● Lynis● Dagda● Anchore

Page 55: Testing Docker Images Security -All day dev ops 2017

● https://github.com/CISOfy/lynis-docker● Lynis is a Linux, Mac and Unix security auditing and

system hardening tool that includes a module to audit

Dockerfiles.

● lynis audit dockerfile <file>

Page 56: Testing Docker Images Security -All day dev ops 2017
Page 57: Testing Docker Images Security -All day dev ops 2017

● https://github.com/eliasgranderubio/dagda● Static analysis of known vulnerabilities on

Docker containers● Allows monitoring Docker containers for

detecting anomalous activities

Page 58: Testing Docker Images Security -All day dev ops 2017

Python 3

MongoDB

PyMongo

Requests

Python-dateutil

Joblib

Docker-py

Flask

Flask-cors

PyYAML

Page 59: Testing Docker Images Security -All day dev ops 2017

● python3 dagda.py check --docker_image <image_name>● python3 dagda.py history <image_name> --id <Id_Scan>

Page 60: Testing Docker Images Security -All day dev ops 2017
Page 61: Testing Docker Images Security -All day dev ops 2017
Page 62: Testing Docker Images Security -All day dev ops 2017
Page 63: Testing Docker Images Security -All day dev ops 2017
Page 64: Testing Docker Images Security -All day dev ops 2017
Page 65: Testing Docker Images Security -All day dev ops 2017
Page 66: Testing Docker Images Security -All day dev ops 2017
Page 67: Testing Docker Images Security -All day dev ops 2017
Page 68: Testing Docker Images Security -All day dev ops 2017
Page 69: Testing Docker Images Security -All day dev ops 2017
Page 70: Testing Docker Images Security -All day dev ops 2017
Page 71: Testing Docker Images Security -All day dev ops 2017

Signing ● Secure & sign your source

Dependences ● Pin & verify your dependencies

Content Trust● Sign your artifacts with Docker

Content Trust

Privileges ● Least Privilege configurations

Page 73: Testing Docker Images Security -All day dev ops 2017

● Docker Content Trusthttps://docs.docker.com/engine/security/trust/content_trust

● Docker Security Scanninghttps://docs.docker.com/docker-cloud/builds/image-scanhttps://blog.docker.com/2016/04/docker-securityhttp://softwaretester.info/docker-audit

Page 74: Testing Docker Images Security -All day dev ops 2017
Page 75: Testing Docker Images Security -All day dev ops 2017
Page 76: Testing Docker Images Security -All day dev ops 2017

jmortega.github.io@jmortegac

Thanks!

Page 77: Testing Docker Images Security -All day dev ops 2017
Page 78: Testing Docker Images Security -All day dev ops 2017
Page 79: Testing Docker Images Security -All day dev ops 2017

bit.ly/addo-slackFind me on slack, right now!