testing docker images security -ncn edition

84
WhoamI Testing Docker Images Security José Manuel Ortega Noviembre 2017

Upload: jose-manuel-ortega-candel

Post on 22-Jan-2018

141 views

Category:

Software


4 download

TRANSCRIPT

Page 1: Testing Docker Images Security -NcN edition

WhoamI

Testing Docker Images Security

José Manuel OrtegaNoviembre 2017

Page 2: Testing Docker Images Security -NcN edition

WhoamI

@jmortegac

jmortega.github.io

about.me/jmortegac

Page 3: Testing Docker Images Security -NcN edition

WhoamI

Introduction to docker securitySecurity best practices

3. Tools for auditing docker hostTools for auditing docker imagesDemo

Page 4: Testing Docker Images Security -NcN edition

WhoamI

Page 5: Testing Docker Images Security -NcN edition

WhoamI

Page 6: Testing Docker Images Security -NcN edition

WhoamI

● Docker uses several mechanisms:○ Linux kernel namespaces○ Linux Control Groups (cgroups)○ The Docker daemon○ Linux capabilities (libcap)○ Linux security mechanisms like○ AppArmor,SELinux,Seccomp

Page 7: Testing Docker Images Security -NcN edition

WhoamI

● 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 8: Testing Docker Images Security -NcN edition

WhoamI

● 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 9: Testing Docker Images Security -NcN edition

WhoamI

Page 10: Testing Docker Images Security -NcN edition

WhoamI

Page 11: Testing Docker Images Security -NcN edition

WhoamI

Page 12: Testing Docker Images Security -NcN edition

WhoamI

Page 13: Testing Docker Images Security -NcN edition

WhoamI

Page 14: Testing Docker Images Security -NcN edition

WhoamI

Page 15: Testing Docker Images Security -NcN edition

WhoamI

Page 16: Testing Docker Images Security -NcN edition

WhoamI

Page 17: Testing Docker Images Security -NcN edition

WhoamI

Page 18: Testing Docker Images Security -NcN edition

WhoamI

Page 19: Testing Docker Images Security -NcN edition

WhoamI

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

from docker hub● Pulling by digest to enforce consistent

Page 20: Testing Docker Images Security -NcN edition

WhoamI

Page 21: Testing Docker Images Security -NcN edition

WhoamI

Page 22: Testing Docker Images Security -NcN edition

WhoamI

Page 23: Testing Docker Images Security -NcN edition

WhoamI

● A capability is a unix action a user can perform● Goal is to restrict “capabilities”● Privileged process = all the capabilities!● Unprivileged process = check individual user

capabilities● Example Capabilities:

○ CAP_CHOWN○ CAP_SETUID○ CAP_NET_RAW○ CAP_SYS_ADMIN

Page 24: Testing Docker Images Security -NcN edition

WhoamI

Page 25: Testing Docker Images Security -NcN edition

WhoamI

Page 26: Testing Docker Images Security -NcN edition

WhoamI

Page 27: Testing Docker Images Security -NcN edition

WhoamI

Page 28: Testing Docker Images Security -NcN edition

WhoamI

Page 29: Testing Docker Images Security -NcN edition

WhoamI

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

Page 30: Testing Docker Images Security -NcN edition

WhoamI

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

Page 31: Testing Docker Images Security -NcN edition

WhoamI

● Do not run processes in a container as root to avoid root access from attackers.

● Enable User-namespace (disabled by default.)● Run filesystems as read-only so that attackers can

not overwrite data or save malicious scripts to file.● Cut down the kernel calls that a container can make

to reduce the potential attack surface.● Limit the resources that a container can use

(SELinux/AppArmor)

Page 32: Testing Docker Images Security -NcN edition

WhoamI

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

containers.

Page 33: Testing Docker Images Security -NcN edition

WhoamI

Page 34: Testing Docker Images Security -NcN edition

WhoamI

Page 35: Testing Docker Images Security -NcN edition

WhoamI

● AppArmor is a Mandatory Access Control (MAC) system which is a kernel (LSM) enhancement to confine programs to a limited set of resources. AppArmor's security model is to bind access control attributes to programs rather than to users.

● Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides a mechanism for supporting access control security policies, including United States Department of Defense

Page 36: Testing Docker Images Security -NcN edition

WhoamI

● Restricts system calls based on a policy● Block things like

○ Kernel manipulation (init_module, finit_module, delete_module)

○ Executing mount options○ Change permissions○ Change owner and groups

Page 37: Testing Docker Images Security -NcN edition

WhoamI

Page 38: Testing Docker Images Security -NcN edition

WhoamI

Page 39: Testing Docker Images Security -NcN edition

WhoamI

Page 40: Testing Docker Images Security -NcN edition

WhoamI

Page 41: Testing Docker Images Security -NcN edition

WhoamI

Page 42: Testing Docker Images Security -NcN edition

WhoamI

Auditing Docker Host

Page 43: Testing Docker Images Security -NcN edition

WhoamI

● Auditing docker environment and containers● 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...

● https://github.com/docker/docker-bench-security

Page 44: Testing Docker Images Security -NcN edition

WhoamI

Page 45: Testing Docker Images Security -NcN edition

WhoamI

● The host configuration

● The Docker daemon configuration

● The Docker daemon configuration

files

● Container images and build files

● Container runtime

● Docker security operations

Page 46: Testing Docker Images Security -NcN edition

WhoamI

● 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 47: Testing Docker Images Security -NcN edition

WhoamI

Page 48: Testing Docker Images Security -NcN edition

WhoamI

Page 49: Testing Docker Images Security -NcN edition

WhoamI

Page 50: Testing Docker Images Security -NcN edition

WhoamI

● 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 system● lynis audit dockerfile <file>

Page 51: Testing Docker Images Security -NcN edition

WhoamI

Page 52: Testing Docker Images Security -NcN edition

WhoamI

Page 53: Testing Docker Images Security -NcN edition

WhoamI

Page 54: Testing Docker Images Security -NcN edition

WhoamI

Page 55: Testing Docker Images Security -NcN edition

WhoamI

https://github.com/CISOfy/lynis/blob/master/include/helper_audit_dockerfile

Page 56: Testing Docker Images Security -NcN edition

WhoamI

Page 57: Testing Docker Images Security -NcN edition

WhoamI

Page 58: Testing Docker Images Security -NcN edition

WhoamI

Page 59: Testing Docker Images Security -NcN edition

WhoamI

Demo time

Page 60: Testing Docker Images Security -NcN edition

WhoamI

Auditing Docker Images

Page 61: Testing Docker Images Security -NcN edition

WhoamI● You can scan your images for known

vulnerabilities● Find known vulnerable binaries● Docker Security Scanning● OWASP Dependency checker● Anchore Cloud● Tenable.io Container Security● Dagda

Page 62: Testing Docker Images Security -NcN edition

WhoamI

Page 63: Testing Docker Images Security -NcN edition

WhoamI

Page 64: Testing Docker Images Security -NcN edition

WhoamI

Page 65: Testing Docker Images Security -NcN edition

WhoamI

Page 66: Testing Docker Images Security -NcN edition

WhoamIhttps://hub.docker.com/r/deepfenceio/deepfence_depcheck/

Page 67: Testing Docker Images Security -NcN edition

WhoamI

Page 68: Testing Docker Images Security -NcN edition

WhoamI

Page 69: Testing Docker Images Security -NcN edition

WhoamI

Page 70: Testing Docker Images Security -NcN edition

WhoamI

Page 71: Testing Docker Images Security -NcN edition

WhoamI

Page 72: Testing Docker Images Security -NcN edition

WhoamI

Page 73: Testing Docker Images Security -NcN edition

WhoamI

https://github.com/eliasgranderubio/dagda

Page 74: Testing Docker Images Security -NcN edition

WhoamI

Python 3MongoDB

PyMongoRequests

Python-dateutil

Joblib

Docker-pyFlaskFlask-cors

PyYAML

Page 75: Testing Docker Images Security -NcN edition

WhoamI

Page 76: Testing Docker Images Security -NcN edition

WhoamI

Page 77: Testing Docker Images Security -NcN edition

WhoamI

Page 78: Testing Docker Images Security -NcN edition

WhoamI

Page 79: Testing Docker Images Security -NcN edition

WhoamIDocker Images for Malware Analysis

Page 80: Testing Docker Images Security -NcN edition

WhoamI

Demo time

Page 81: Testing Docker Images Security -NcN edition

WhoamI

Signing ● Secure & sign your source

Dependences ● Pin & verify your dependencies

Content Trust● Sign your artifacts with Docker

Content Trust

Privileges ● Least Privilege configurations

Page 82: Testing Docker Images Security -NcN edition

WhoamI

● https://docs.docker.com/engine/security● http://www.oreilly.com/webops-perf/free/files/docker-securit

y.pdf● http://container-solutions.com/content/uploads/2015/06/15.

06.15_DockerCheatSheet_A2.pdf

● 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 83: Testing Docker Images Security -NcN edition

WhoamI

Page 84: Testing Docker Images Security -NcN edition

WhoamI jmortega.github.io@jmortegac