Slide 1

Slide 1 text

WhoamI Testing Docker Images Security José Manuel Ortega Noviembre 2017

Slide 2

Slide 2 text

WhoamI @jmortegac jmortega.github.io about.me/jmortegac

Slide 3

Slide 3 text

WhoamI Introduction to docker security Security best practices 3. Tools for auditing docker host Tools for auditing docker images Demo

Slide 4

Slide 4 text

WhoamI

Slide 5

Slide 5 text

WhoamI

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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.

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

WhoamI

Slide 10

Slide 10 text

WhoamI

Slide 11

Slide 11 text

WhoamI

Slide 12

Slide 12 text

WhoamI

Slide 13

Slide 13 text

WhoamI

Slide 14

Slide 14 text

WhoamI

Slide 15

Slide 15 text

WhoamI

Slide 16

Slide 16 text

WhoamI

Slide 17

Slide 17 text

WhoamI

Slide 18

Slide 18 text

WhoamI

Slide 19

Slide 19 text

WhoamI ● We can verify the integrity of the image ● Checksum validation when pulling image from docker hub ● Pulling by digest to enforce consistent

Slide 20

Slide 20 text

WhoamI

Slide 21

Slide 21 text

WhoamI

Slide 22

Slide 22 text

WhoamI

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

WhoamI

Slide 25

Slide 25 text

WhoamI

Slide 26

Slide 26 text

WhoamI

Slide 27

Slide 27 text

WhoamI

Slide 28

Slide 28 text

WhoamI

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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)

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

WhoamI

Slide 34

Slide 34 text

WhoamI

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

WhoamI

Slide 38

Slide 38 text

WhoamI

Slide 39

Slide 39 text

WhoamI

Slide 40

Slide 40 text

WhoamI

Slide 41

Slide 41 text

WhoamI

Slide 42

Slide 42 text

WhoamI Auditing Docker Host

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

WhoamI

Slide 45

Slide 45 text

WhoamI ● The host configuration ● The Docker daemon configuration ● The Docker daemon configuration files ● Container images and build files ● Container runtime ● Docker security operations

Slide 46

Slide 46 text

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:

Slide 47

Slide 47 text

WhoamI

Slide 48

Slide 48 text

WhoamI

Slide 49

Slide 49 text

WhoamI

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

WhoamI

Slide 52

Slide 52 text

WhoamI

Slide 53

Slide 53 text

WhoamI

Slide 54

Slide 54 text

WhoamI

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

WhoamI

Slide 57

Slide 57 text

WhoamI

Slide 58

Slide 58 text

WhoamI

Slide 59

Slide 59 text

WhoamI Demo time

Slide 60

Slide 60 text

WhoamI Auditing Docker Images

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

WhoamI

Slide 63

Slide 63 text

WhoamI

Slide 64

Slide 64 text

WhoamI

Slide 65

Slide 65 text

WhoamI

Slide 66

Slide 66 text

WhoamI https://hub.docker.com/r/deepfenceio/deepfence_depcheck/

Slide 67

Slide 67 text

WhoamI

Slide 68

Slide 68 text

WhoamI

Slide 69

Slide 69 text

WhoamI

Slide 70

Slide 70 text

WhoamI

Slide 71

Slide 71 text

WhoamI

Slide 72

Slide 72 text

WhoamI

Slide 73

Slide 73 text

WhoamI https://github.com/eliasgranderubio/dagda

Slide 74

Slide 74 text

WhoamI Python 3 MongoDB PyMongo Requests Python-dateutil Joblib Docker-py Flask Flask-cors PyYAML

Slide 75

Slide 75 text

WhoamI

Slide 76

Slide 76 text

WhoamI

Slide 77

Slide 77 text

WhoamI

Slide 78

Slide 78 text

WhoamI

Slide 79

Slide 79 text

WhoamI Docker Images for Malware Analysis

Slide 80

Slide 80 text

WhoamI Demo time

Slide 81

Slide 81 text

WhoamI Signing ● Secure & sign your source Dependences ● Pin & verify your dependencies Content Trust ● Sign your artifacts with Docker Content Trust Privileges ● Least Privilege configurations

Slide 82

Slide 82 text

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 Trust https://docs.docker.com/engine/security/trust/content_trust ● Docker Security Scanning https://docs.docker.com/docker-cloud/builds/image-scan https://blog.docker.com/2016/04/docker-security http://softwaretester.info/docker-audit

Slide 83

Slide 83 text

WhoamI

Slide 84

Slide 84 text

WhoamI jmortega.github.io @jmortegac