CONTAINER AND MICROSERVICE SECURITY ADRIAN MOUAT Chief Scientist @ - - PowerPoint PPT Presentation

container and microservice security
SMART_READER_LITE
LIVE PREVIEW

CONTAINER AND MICROSERVICE SECURITY ADRIAN MOUAT Chief Scientist @ - - PowerPoint PPT Presentation

CONTAINER AND MICROSERVICE SECURITY ADRIAN MOUAT Chief Scientist @ Container Solutions Wrote "Using Docker" for O'Reilly 40% Discount with AUTHD code Free Docker Security minibook http://www.oreilly.com/webops-perf/free/docker-


slide-1
SLIDE 1

CONTAINER AND MICROSERVICE SECURITY

ADRIAN MOUAT

slide-2
SLIDE 2

Chief Scientist @ Container Solutions Wrote "Using Docker" for O'Reilly 40% Discount with AUTHD code Free Docker Security minibook @adrianmouat http://www.oreilly.com/webops-perf/free/docker- security.csp

slide-3
SLIDE 3

OVERVIEW

The Benefits of Security Container Attack Vectors Security Philosophy Demo Tips & Techniques

slide-4
SLIDE 4

THE BENEFITS OF SECURITY

slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10

CONTAINER ATTACK VECTORS

slide-11
SLIDE 11

KERNEL ATTACKS

slide-12
SLIDE 12

DENIAL OF SERVICE

slide-13
SLIDE 13

CONTAINER BREAKOUTS

slide-14
SLIDE 14

POISONED IMAGES

slide-15
SLIDE 15

SNIFFING SECRETS

slide-16
SLIDE 16

SECURITY PARADIGMS

slide-17
SLIDE 17

DEFENCE-IN-DEPTH

Multiple layers of security

slide-18
SLIDE 18

LEAST PRIVILEGE

Only access data and resources essential to function "Least Privilege Microservices" by Nathan McCauley and Diogo Mónica

slide-19
SLIDE 19

DEMO

slide-20
SLIDE 20

SO WHAT NOW?

Ideally have guidelines for procedure Need to isolate container (and probably host) docker network disconnect Don't delete, preferably don't stop if safe docker diff

slide-21
SLIDE 21

HOW TO MITIGATE

Run container with less privileges

  • -read-only

Use non-privileged user ...

slide-22
SLIDE 22

NOT A SOLUTION!

Still allows remote execution of arbitrary JS Real solution is to replace vulnerable library Image should be scanned for known vulns

slide-23
SLIDE 23

IMAGE SCANNING

Docker Security Scanning Other solutions Clair from CoreOS Peekr from Aqua Security Twistlock Atomic Scan from Red Hat

slide-24
SLIDE 24

DEPENDENCY CHECKERS

OWASP Dependency Checker Node Security Project (NSP)

slide-25
SLIDE 25

TIPS & TECHNIQUES

slide-26
SLIDE 26

USE CONTAINERS AND VMS

Use VMs to segregate groups of containers For multitenancy Each user's containers in separate VM For different security levels Containers processing CC details in own VM

slide-27
SLIDE 27

ASIDE: DIRTY COW (CVE-2016-5195)

Recent vulnerability found in the kernel Allows “privilege escalation” Can be used to break out of containers Also breaks read-only filesystems https://dirtycow.ninja/ https://blog.paranoidsoftware.com/dirty-cow-cve-2016- 5195-docker-container-escape/

docker run --rm amouat/dirty-cow-test

slide-28
SLIDE 28

SEGREGATE BY NETWORK

Use multiple "logical" networks e.g. backend, frontend frontend should not be able to backend network "link" container will be in both

docker network create frontend

slide-29
SLIDE 29

DOCKER PRIVILEGES == ROOT PRIVILEGES

slide-30
SLIDE 30

Can mount any directory Can create and copy out "backdoors"

docker run -v $PWD:/data debian /bin/sh -c \ 'cp /bin/sh /data/ && chown root.root /data/sh && chmod a+s /data/sh'

slide-31
SLIDE 31

USER NAMESPACING

By default, there is no user namespacing Root in container is root on host Don't run apps in a VM as root Same goes for containers

slide-32
SLIDE 32

USER NAMESPACING

Can be turned on since 1.10 Maps users in containers to high-numbered users on host Set on daemon, not per container Due to complications with ownership of image layers

slide-33
SLIDE 33

GOTCHAS

Problems with volumes and plugins Can't use --pid=host or --net=host Can't use read-only Restrictions on some operations (e.g. mknod)

slide-34
SLIDE 34

SET A USER

Create a user in your Dockerfile Change to the user via USER or su/sudo/gosu

RUN groupadd -r user && useradd -r -g user user USER user

slide-35
SLIDE 35

BE CAREFUL WHEN DELETING DATA IN DOCKERFILES

slide-36
SLIDE 36

THIS DOESN'T WORK

FROM debian RUN apt-get update && apt-get install -y curl RUN curl http://sourcecode.com/file.tgz -o /file.tgz RUN tar xzf /file.tgz && make RUN rm /file.tgz

slide-37
SLIDE 37

THIS DOES

FROM debian RUN apt-get update && apt-get install -y curl RUN curl http://sourcecode.com/file.tgz -o /file.tgz && tar xzf /file.tgz && make && rm /file.tgz

slide-38
SLIDE 38

AND THIS IS REALLY BAD

# Copy github ssh key COPY github_rsa /root/.ssh/id_rsa ... # Remove ssh key RUN rm /root/.ssh/id_rsa

slide-39
SLIDE 39

SET CONTAINER FS TO READ-ONLY

$ docker run --read-only debian touch x touch: cannot touch 'x': Read-only file system

slide-40
SLIDE 40

SET VOLUMES TO READ-ONLY

$ docker run -v $(pwd)/secrets:/secrets:ro \ debian touch /secrets/x touch: cannot touch '/secrets/x': Read-only file system

slide-41
SLIDE 41

DROP CAPABILITIES

$ docker run --cap-drop SETUID --cap-drop SETGID myimage $ docker run --cap-drop ALL --cap-add ...

slide-42
SLIDE 42

SET CPUSHARES

$ docker run -d myimage $ docker run -d -c 512 myimage $ docker run -d -c 512 myimage

slide-43
SLIDE 43

SET MEMORY LIMITS

$ docker run -m 512m myimage

slide-44
SLIDE 44

DEFANG SETUID/SETGID BINARIES

Applications probably don't need them So don't run them in production

slide-45
SLIDE 45

TO FIND THEM

$ docker run debian \ find / -perm +6000 -type f -exec ls -ld {} \; 2> /dev/null

  • rwsr-xr-x 1 root root 10248 Apr 15 00:02 /usr/lib/pt_chown
  • rwxr-sr-x 1 root shadow 62272 Nov 20 2014 /usr/bin/chage
  • rwsr-xr-x 1 root root 75376 Nov 20 2014 /usr/bin/gpasswd
  • rwsr-xr-x 1 root root 53616 Nov 20 2014 /usr/bin/chfn

...

slide-46
SLIDE 46

TO DEFANG THEM

FROM debian:wheezy RUN find / -perm +6000 -type f -exec chmod a-s {} \; \ || true

slide-47
SLIDE 47

RESULT

$ docker build -t defanged-debian . ... Successfully built 526744cf1bc1 $ docker run --rm defanged-debian \ find / -perm +6000 -type f -exec ls -ld {} \; \ 2> /dev/null | wc -l $

slide-48
SLIDE 48

USE MINIMAL IMAGES

Less software Less attack surface

slide-49
SLIDE 49

Alpine Linux Static binaries Go makes this easy https://hub.docker.com/_/alpine/ https://medium.com/iron-io-blog/an-easier-way-to- create-tiny-golang-docker-images-7ba2893b160

slide-50
SLIDE 50

USE LINUX SECURITY MODULES

slide-51
SLIDE 51

SELINUX

By NSA! Policy based MAC not DAC File access, sockets, interfaces

slide-52
SLIDE 52

PITA

Hard to define own policies Have to use devicemapper Extra work to use volumes

slide-53
SLIDE 53

$ sestatus | grep mode Current mode: enforcing $ mkdir data $ echo "hello" > data/file $ docker run -v $(pwd)/data:/data debian cat /data/file cat: /data/file: Permission denied

slide-54
SLIDE 54

$ ls --scontext data unconfined_u:object_r:user_home_t:s0 file $ chcon -Rt svirt_sandbox_file_t data $ docker run -v $(pwd)/data:/data debian cat /data/file hello

slide-55
SLIDE 55

APPARMOR

Used by Debian & Ubuntu On by default Limits container access to host files and kernel capabilities Can pass in own policy for a container Process based; not as fine-grained as SELinux

slide-56
SLIDE 56

ALSO A PITA, BUT...

slide-57
SLIDE 57

BANE

Project by Jessie Frazelle Simplifies creating AppArmor profiles

slide-58
SLIDE 58

SECURITY HARDENED KERNEL

Patched kernel with security enhancements grsecurity PaX Lag behind latest kernel version

slide-59
SLIDE 59

VERIFY IMAGES

Know what you're running And where it came from Only use automated builds, check Dockerfile Docker Content Trust Pull by digest

slide-60
SLIDE 60

AUDITING

Immutable infrastructure Audit images, not containers Docker diff Scanning tools scalock, twistlock, clair

slide-61
SLIDE 61

SHARING SECRETS

slide-62
SLIDE 62

BAKE IT INTO THE IMAGE

slide-63
SLIDE 63

ENVIRONMENT VARIABLES

Suggested by 12 factor apps Can be seen too many places linked containers, inspect Can't be deleted Get included in reports

$ docker run -e API_TOKEN=MY_SECRET myimage

slide-64
SLIDE 64

MOUNTED VOLUMES OR DATA VOLUME CONTAINERS

Works, but icky Files can get checked in by accident

$ docker run -v /secretdir/keyfile:/keyfile:ro myimage $ docker run --volumes-from my-secret-container myimage

slide-65
SLIDE 65

SECURE KEY-VALUE STORE

Docker 1.13 in Swarm Mode Kubernetes Secrets Vault Can control leases, store encrypted https://github.com/docker/docker/pull/27794 https://hashicorp.com/blog/vault.html

slide-66
SLIDE 66

CONCLUSION

Containers Add isolation Provide tools for restricting attackers Use with VMs if concerned Think Defence-In-Depth & Least Privilege

slide-67
SLIDE 67

THANK YOU!

slide-68
SLIDE 68

Chief Scientist @ Container Solutions Wrote "Using Docker" for O'Reilly Free Docker Security minibook @adrianmouat https://www.openshift.com/promotions/docker- security.html