security best practices operationalizing kubernetes cncf ... · what will run? any guardrails? with...

34
CNCF Webinar: Operationalizing Kubernetes Security Best Practices Connor Gilbert 26 March 2019

Upload: others

Post on 31-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

CNCF Webinar:

Operationalizing Kubernetes Security Best PracticesConnor Gilbert26 March 2019

Page 2: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

● How does Kubernetes change security?● How does cooperation work in a Kubernetes

stack?● What can I do to improve the security of:

○ My infrastructure?○ My applications?

● What are some Kubernetes controls I could consider adopting?

What we’ll cover

Page 3: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

How does Kuberneteschange security?

Page 4: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“Move fast,” they said

http://www.newseum.org/exhibits/current/conus-1-satellite-truck/

Page 5: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“Move fast,” they said

Personal photo

Page 6: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“Move fast,” they said

Personal photo

Page 7: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Most people use defaults —but you don’t have to.

Page 8: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

apiVersion: apps/v1 kind: Deployment spec: replicas: 1 template: spec: containers: - name: server image: my-app:1.0.0-1-g123456+ securityContext:+ capabilities:+ drop: ["NET_RAW"]+ readOnlyRootFilesystem: true+---+apiVersion: networking.k8s.io/v1+kind: NetworkPolicy+metadata:+ name: allow-server-https+spec:+ ingress:+ - ports:+ - port: 443+ protocol: TCP

apiVersion: apps/v1kind: Deploymentspec:replicas: 1template: spec: containers: - name: server image: my-app:1.0.0-1-g123456

Test your security like your app

Page 9: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

How does cooperation workin a Kubernetes stack?

Page 10: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“Things move too fast for my security team to keep up!”

Page 11: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“Things move too fast for my security team to keep up!I’m afraid we’ll miss something.”

Page 12: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“I don’t want this security feature deployed in my cluster!”

Page 13: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“I don’t want this security feature deployed in my cluster!I’m afraid it will stop me from recovering from an outage.”

Page 14: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

What can I do to improve thesecurity of my infrastructure?

Page 15: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Caveat: There’s a lot out there

https://landscape.cncf.io

Page 16: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Good infrastructure habits● Be ready to upgrade

○ You may need to do this on short notice!● Automate, automate, automate● Keep the abstractions tight — no leaks● Think carefully about API access control

Page 17: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

What can I do to improve thesecurity of my applications?

Page 18: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Workload dataWho runs this?What is it?

What code is it?What can it access?

How is it exposed?

Page 19: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Workload data, zooming in

What will run?Any guardrails?

With which privileges?With a writable FS?What’s the env like?Any disk or secrets?

Page 20: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

“Not pictured”A complete spec may also include:

● Network Policies● Storage● Configuration Maps● Health Check Procedures● Custom Resources● More?

Page 21: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Kubernetes context

Page 22: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

● Have a “style guide”● Apply metadata consistently● Know your images● Plan for replicas to be killed in case of

compromise● Establish secure practices early

○ Workload configurations○ Network policies

Good application habits

Page 23: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Options include:

● Pod Security Policies● Custom admission controllers● Ongoing monitoring and analysis

But, remember the user experience when choosing what to enforce, and where.

...and how to enforce them

Page 24: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

What are some specificsecurity controls I might consider?

Page 25: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

● Read-only root file system● Linux capabilities● Network policies● Host mounts● Disable service account auto-mount● Environment● Resource requirements

Configurations to explore

Page 26: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Demo: Stopping a Struts exploitDeploying a vulnerable container (with R/W root FS)

Page 27: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Demo: Stopping a Struts exploitThe exploit works — we can download and run minerd.

Page 28: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Can my app be read-only?

Page 29: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Demo: Stopping a Struts exploitAfter declaring a VOLUME for /usr/local/tomcat,and opting-in for a read-only root FS:

Page 30: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Linux capabilities

Page 31: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

securityContext: capabilities: drop: - all

minerdtar: minerd: Cannot change ownership to uid 1000, gid 1000: Operation not permittedtar: Exiting with failure status due to previous errors

Demo: Capabilities dropped

Page 32: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

Network policies

Page 33: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

● Read-only root file system● Linux capabilities● Network policies● Host mounts● Disable service account auto-mount● Environment● Resource requirements

Configurations to explore

Page 34: Security Best Practices Operationalizing Kubernetes CNCF ... · What will run? Any guardrails? With which privileges? With a writable FS? What’s the env like? Any disk or secrets?

What next?Have a question now?Ask in Zoom!

Think of one [email protected]@connorgilbert

Want to learn more?https://stackrox.com/cncf/