container and microservice security
play

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-


  1. CONTAINER AND MICROSERVICE SECURITY ADRIAN MOUAT

  2. 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- security.csp @adrianmouat

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

  4. THE BENEFITS OF SECURITY

  5. CONTAINER ATTACK VECTORS

  6. KERNEL ATTACKS

  7. DENIAL OF SERVICE

  8. CONTAINER BREAKOUTS

  9. POISONED IMAGES

  10. SNIFFING SECRETS

  11. SECURITY PARADIGMS

  12. DEFENCE-IN-DEPTH Multiple layers of security

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

  14. DEMO

  15. 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

  16. HOW TO MITIGATE Run container with less privileges --read-only Use non-privileged user ...

  17. NOT A SOLUTION! Still allows remote execution of arbitrary JS Real solution is to replace vulnerable library Image should be scanned for known vulns

  18. IMAGE SCANNING Docker Security Scanning Other solutions Clair from CoreOS Peekr from Aqua Security Twistlock Atomic Scan from Red Hat

  19. DEPENDENCY CHECKERS OWASP Dependency Checker Node Security Project (NSP)

  20. TIPS & TECHNIQUES

  21. 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

  22. 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

  23. 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

  24. DOCKER PRIVILEGES == ROOT PRIVILEGES

  25. 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'

  26. 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

  27. 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

  28. 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)

  29. 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

  30. BE CAREFUL WHEN DELETING DATA IN DOCKERFILES

  31. 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

  32. 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

  33. 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

  34. SET CONTAINER FS TO READ-ONLY $ docker run --read-only debian touch x touch: cannot touch 'x': Read-only file system

  35. 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

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

  37. SET CPUSHARES $ docker run -d myimage $ docker run -d -c 512 myimage $ docker run -d -c 512 myimage

  38. SET MEMORY LIMITS $ docker run -m 512m myimage

  39. DEFANG SETUID/SETGID BINARIES Applications probably don't need them So don't run them in production

  40. 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 ...

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

  42. 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 0 $

  43. USE MINIMAL IMAGES Less software Less attack surface

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

  45. USE LINUX SECURITY MODULES

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

  47. PITA Hard to define own policies Have to use devicemapper Extra work to use volumes

  48. $ 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

  49. $ 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

  50. 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

  51. ALSO A PITA, BUT...

  52. BANE Project by Jessie Frazelle Simplifies creating AppArmor profiles

  53. SECURITY HARDENED KERNEL Patched kernel with security enhancements grsecurity PaX Lag behind latest kernel version

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

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

  56. SHARING SECRETS

  57. BAKE IT INTO THE IMAGE

  58. ENVIRONMENT VARIABLES $ docker run -e API_TOKEN=MY_SECRET myimage Suggested by 12 factor apps Can be seen too many places linked containers, inspect Can't be deleted Get included in reports

  59. MOUNTED VOLUMES OR DATA VOLUME CONTAINERS $ docker run -v /secretdir/keyfile:/keyfile:ro myimage $ docker run --volumes-from my-secret-container myimage Works, but icky Files can get checked in by accident

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

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

  62. THANK YOU!

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

Recommend


More recommend