68
CONTAINER AND MICROSERVICE SECURITY ADRIAN MOUAT

CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

  • Upload
    builiem

  • View
    219

  • Download
    1

Embed Size (px)

Citation preview

Page 1: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

CONTAINERANDMICROSERVICESECURITY

ADRIANMOUAT

Page 2: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

ChiefScientist@ContainerSolutions

Wrote"UsingDocker"forO'Reilly

40%DiscountwithAUTHDcode

FreeDockerSecurityminibook

@adrianmouat

http://www.oreilly.com/webops-perf/free/docker-security.csp

Page 3: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

OVERVIEWTheBenefitsofSecurityContainerAttackVectorsSecurityPhilosophyDemoTips&Techniques

Page 4: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

THEBENEFITSOFSECURITY

Page 5: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu
Page 6: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu
Page 7: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu
Page 8: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu
Page 9: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu
Page 10: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

CONTAINERATTACKVECTORS

Page 11: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

KERNELATTACKS

Page 12: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

DENIALOFSERVICE

Page 13: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

CONTAINERBREAKOUTS

Page 14: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

POISONEDIMAGES

Page 15: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SNIFFINGSECRETS

Page 16: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SECURITYPARADIGMS

Page 17: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

DEFENCE-IN-DEPTHMultiplelayersofsecurity

Page 18: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

LEASTPRIVILEGE

Onlyaccessdataandresourcesessentialtofunction"LeastPrivilegeMicroservices"byNathanMcCauleyandDiogoMónica

Page 19: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

DEMO

Page 20: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SOWHATNOW?IdeallyhaveguidelinesforprocedureNeedtoisolatecontainer(andprobablyhost)dockernetworkdisconnect

Don'tdelete,preferablydon'tstopifsafedockerdiff

Page 21: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

HOWTOMITIGATERuncontainerwithlessprivileges

--read-onlyUsenon-privilegeduser...

Page 22: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

NOTASOLUTION!StillallowsremoteexecutionofarbitraryJSRealsolutionistoreplacevulnerablelibraryImageshouldbescannedforknownvulns

Page 23: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

IMAGESCANNINGDockerSecurityScanningOthersolutionsClairfromCoreOSPeekrfromAquaSecurityTwistlockAtomicScanfromRedHat

Page 24: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

DEPENDENCYCHECKERSOWASPDependencyCheckerNodeSecurityProject(NSP)

Page 25: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

TIPS&TECHNIQUES

Page 26: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

USECONTAINERSANDVMSUseVMstosegregategroupsofcontainersFormultitenancyEachuser'scontainersinseparateVM

FordifferentsecuritylevelsContainersprocessingCCdetailsinownVM

Page 27: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

ASIDE:DIRTYCOW(CVE-2016-5195)RecentvulnerabilityfoundinthekernelAllows“privilegeescalation”CanbeusedtobreakoutofcontainersAlsobreaksread-onlyfilesystemshttps://dirtycow.ninja/https://blog.paranoidsoftware.com/dirty-cow-cve-2016-5195-docker-container-escape/

dockerrun--rmamouat/dirty-cow-test

Page 28: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SEGREGATEBYNETWORKUsemultiple"logical"networkse.g.backend,frontend

frontendshouldnotbeabletobackendnetwork"link"containerwillbeinboth

dockernetworkcreatefrontend

Page 29: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

DOCKERPRIVILEGES==

ROOTPRIVILEGES

Page 30: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

CanmountanydirectoryCancreateandcopyout"backdoors"

dockerrun-v$PWD:/datadebian/bin/sh-c\'cp/bin/sh/data/&&chownroot.root/data/sh&&chmoda+s/data/sh'

Page 31: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

USERNAMESPACING

Bydefault,thereisnousernamespacingRootincontainerisrootonhostDon'trunappsinaVMasrootSamegoesforcontainers

Page 32: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

USERNAMESPACINGCanbeturnedonsince1.10Mapsusersincontainerstohigh-numberedusersonhostSetondaemon,notpercontainerDuetocomplicationswithownershipofimagelayers

Page 33: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

GOTCHASProblemswithvolumesandpluginsCan'tuse--pid=hostor--net=hostCan'tuseread-onlyRestrictionsonsomeoperations(e.g.mknod)

Page 34: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SETAUSERCreateauserinyourDockerfileChangetotheuserviaUSERorsu/sudo/gosu

RUNgroupadd-ruser&&useradd-r-guseruserUSERuser

Page 35: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

BECAREFULWHENDELETINGDATAINDOCKERFILES

Page 36: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

THISDOESN'TWORKFROMdebianRUNapt-getupdate&&apt-getinstall-ycurlRUNcurlhttp://sourcecode.com/file.tgz-o/file.tgzRUNtarxzf/file.tgz&&makeRUNrm/file.tgz

Page 37: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

THISDOESFROMdebianRUNapt-getupdate&&apt-getinstall-ycurlRUNcurlhttp://sourcecode.com/file.tgz-o/file.tgz&&tarxzf/file.tgz&&make&&rm/file.tgz

Page 38: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

ANDTHISISREALLYBAD#CopygithubsshkeyCOPYgithub_rsa/root/.ssh/id_rsa...#RemovesshkeyRUNrm/root/.ssh/id_rsa

Page 39: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SETCONTAINERFSTOREAD-ONLY$dockerrun--read-onlydebiantouchxtouch:cannottouch'x':Read-onlyfilesystem

Page 40: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SETVOLUMESTOREAD-ONLY$dockerrun-v$(pwd)/secrets:/secrets:ro\debiantouch/secrets/xtouch:cannottouch'/secrets/x':Read-onlyfilesystem

Page 41: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

DROPCAPABILITIES$dockerrun--cap-dropSETUID--cap-dropSETGIDmyimage$dockerrun--cap-dropALL--cap-add...

Page 42: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SETCPUSHARES$dockerrun-dmyimage$dockerrun-d-c512myimage$dockerrun-d-c512myimage

Page 43: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SETMEMORYLIMITS$dockerrun-m512mmyimage

Page 44: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

DEFANGSETUID/SETGIDBINARIESApplicationsprobablydon'tneedthemSodon'truntheminproduction

Page 45: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

TOFINDTHEM$dockerrundebian\find/-perm+6000-typef-execls-ld{}\;2>/dev/null-rwsr-xr-x1rootroot10248Apr1500:02/usr/lib/pt_chown-rwxr-sr-x1rootshadow62272Nov202014/usr/bin/chage-rwsr-xr-x1rootroot75376Nov202014/usr/bin/gpasswd-rwsr-xr-x1rootroot53616Nov202014/usr/bin/chfn...

Page 46: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

TODEFANGTHEMFROMdebian:wheezyRUNfind/-perm+6000-typef-execchmoda-s{}\;\||true

Page 47: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

RESULT$dockerbuild-tdefanged-debian....Successfullybuilt526744cf1bc1$dockerrun--rmdefanged-debian\find/-perm+6000-typef-execls-ld{}\;\2>/dev/null|wc-l0$

Page 48: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

USEMINIMALIMAGES

LesssoftwareLessattacksurface

Page 49: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

AlpineLinux

StaticbinariesGomakesthiseasy

https://hub.docker.com/_/alpine/

https://medium.com/iron-io-blog/an-easier-way-to-create-tiny-golang-docker-images-7ba2893b160

Page 50: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

USELINUXSECURITYMODULES

Page 51: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SELINUXByNSA!PolicybasedMACnotDACFileaccess,sockets,interfaces

Page 52: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

PITAHardtodefineownpoliciesHavetousedevicemapperExtraworktousevolumes

Page 53: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

$sestatus|grepmodeCurrentmode:enforcing$mkdirdata$echo"hello">data/file$dockerrun-v$(pwd)/data:/datadebiancat/data/filecat:/data/file:Permissiondenied

Page 54: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

$ls--scontextdataunconfined_u:object_r:user_home_t:s0file$chcon-Rtsvirt_sandbox_file_tdata$dockerrun-v$(pwd)/data:/datadebiancat/data/filehello

Page 55: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

APPARMORUsedbyDebian&UbuntuOnbydefaultLimitscontaineraccesstohostfilesandkernelcapabilitiesCanpassinownpolicyforacontainerProcessbased;notasfine-grainedasSELinux

Page 56: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

ALSOAPITA,BUT...

Page 57: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

BANEProjectbyJessieFrazelleSimplifiescreatingAppArmorprofiles

Page 58: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SECURITYHARDENEDKERNELPatchedkernelwithsecurityenhancementsgrsecurityPaXLagbehindlatestkernelversion

Page 59: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

VERIFYIMAGESKnowwhatyou'rerunningAndwhereitcamefromOnlyuseautomatedbuilds,checkDockerfileDockerContentTrustPullbydigest

Page 60: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

AUDITINGImmutableinfrastructureAuditimages,notcontainersDockerdiffScanningtoolsscalock,twistlock,clair

Page 61: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SHARINGSECRETS

Page 62: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

BAKEITINTOTHEIMAGE

Page 63: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

ENVIRONMENTVARIABLES

Suggestedby12factorappsCanbeseentoomanyplaceslinkedcontainers,inspect

Can'tbedeletedGetincludedinreports

$dockerrun-eAPI_TOKEN=MY_SECRETmyimage

Page 64: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

MOUNTEDVOLUMESORDATAVOLUMECONTAINERS

Works,butickyFilescangetcheckedinbyaccident

$dockerrun-v/secretdir/keyfile:/keyfile:romyimage$dockerrun--volumes-frommy-secret-containermyimage

Page 65: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

SECUREKEY-VALUESTOREDocker1.13inSwarmMode

KubernetesSecrets

Vault

Cancontrolleases,storeencrypted

https://github.com/docker/docker/pull/27794

https://hashicorp.com/blog/vault.html

Page 66: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

CONCLUSIONContainersAddisolationProvidetoolsforrestrictingattackers

UsewithVMsifconcernedThinkDefence-In-Depth&LeastPrivilege

Page 67: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

THANKYOU!

Page 68: CONTAINER AND MICROSERVICE SECURITY - GOTO … · security.csp. OVERVIEW The Benefits of Security ... RUN apt-get update && apt-get install -y curl ... Used by Debian & Ubuntu

ChiefScientist@ContainerSolutions

Wrote"UsingDocker"forO'Reilly

FreeDockerSecurityminibook

@adrianmouat

https://www.openshift.com/promotions/docker-security.html