container security and sandboxingyiying/cse291j-winter20/reading/container-security.pdflec6: threats...

40
Container Security and Sandboxing Yiying Zhang

Upload: others

Post on 20-May-2020

10 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Container Security and Sandboxing

Yiying Zhang

Page 2: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Lec6: Security Implications of Containers

Source: S. Sultan et al.: Container Security: Issues, Challenges, and the Road Ahead

Page 3: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Lec6: Threats of Containers

• Unlike VMs whose interface is hardware instructions, containers’ interface is OS system calls

• More difficult to protect syscalls

• Involve large amount of code in the OS

• And there are many syscalls

Page 4: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Lec6: Threats of Container Images• Difficult to understand the source/provenance of images

Source: B. Tak et al.: Understanding Security Implications of Using Containers in the Cloud

Page 5: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Secure PodsSandboxing workloads in Kubernetes

Tim Allclair < [email protected] >

Software Engineer, Google

@tallclair

Page 6: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

What is a secure pod?

Page 7: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Threats from the outside

Keeping the attackers out:

➢ Application Security➢ Firewall➢ Integrity Checks➢ Intrusion Detection➢ ...

Page 8: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Threats from the inside

Keeping the attackers in.

Page 9: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

How do we protectfrom internal threats?

Page 10: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Lec7: Sandboxing

• Rule-based sandboxing: reduce the attack surface by restricting what applications can access

• e.g., AppArmor, SELinux, Seccomp-bpf

• Rules can be fragile (not properly capture threats) and can’t prevent side channel attacks

Page 11: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Sandbox Use Cases• Sandbox vulnerable code

• Sandbox untrusted code

• Provide max defense in depth

• Sandbox multitenant code

• Sandbox multitenant services

• Mutually untrusted users want to share a cluster

• Sidecar container ha distinct privileges

Page 12: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Sandbox Layer• Container

• A subset of containers in a pod

• Both container and pod isolation

• Pod

• A set of pots in a sandbox

• Node

• Pros and cons?

Page 13: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attack Surfaces

➢ Kernel➢ Storage➢ Network➢ Daemons

Logging, monitoring, ...

➢ Hardware➢ ...

Page 14: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attack Surfaces

➢ Kernel➢ Storage➢ Network➢ Daemons

Logging, monitoring, ...

➢ Hardware➢ ...

Page 15: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attacks via the Kernel

Node Host

Kernel

Pod

Container

Escape!

Page 16: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

source: https://www.cvedetails.com/product/47/Linux-Linux-Kernel.html?vendor_id=33

Page 17: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Google confidential │ Do not distribute Source: https://www.cvedetails.com/vulnerability-list/vendor_id-33/product_id-47/year-2017/opec-1/Linux-Linux-Kernel.html

Page 18: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Today: kernel isolation features

apiVersion: v1kind: Podmetadata: name: restricted-pod annotations: seccomp.security.alpha.kubernetes.io/pod: docker/default apparmor.security.beta.kubernetes.io/pod: runtime/defaultspec: securityContext: runAsUser: 1234 runAsNonRoot: true containers: - name: untrusted-container image: sketchy:v1 securityContext: allowPrivilegeEscalation: false

Page 19: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Today: kernel isolation features

apiVersion: v1kind: Podmetadata: name: restricted-pod annotations: seccomp.security.alpha.kubernetes.io/pod: docker/default apparmor.security.beta.kubernetes.io/pod: runtime/defaultspec: securityContext: runAsUser: 1234 runAsNonRoot: true containers: - name: untrusted-container image: sketchy:v1 securityContext: allowPrivilegeEscalation: false

Page 20: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Today: kernel isolation features

apiVersion: v1kind: Podmetadata: name: restricted-pod annotations: seccomp.security.alpha.kubernetes.io/pod: docker/default apparmor.security.beta.kubernetes.io/pod: runtime/defaultspec: securityContext: runAsUser: 1234 runAsNonRoot: true containers: - name: untrusted-container image: sketchy:v1 securityContext: allowPrivilegeEscalation: false

Page 21: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Today: kernel isolation features

apiVersion: v1kind: Podmetadata: name: restricted-pod annotations: seccomp.security.alpha.kubernetes.io/pod: docker/default apparmor.security.beta.kubernetes.io/pod: runtime/defaultspec: securityContext: runAsUser: 1234 runAsNonRoot: true containers: - name: untrusted-container image: sketchy:v1 securityContext: allowPrivilegeEscalation: false

Page 22: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Sandboxes

Node Host

Kernel

Container

Sandboxed Pod

Kubelet

Runtime Container

Page 23: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Sandboxes -

Node Host

Kernel

Container

Guest Kernel

KVM

Agent

Sandboxed Pod (VM)

Kubelet

Runtime

Page 24: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Sandboxes - gVisor

Node Host

Kernel

Platform

Container EmulatedKernel

KVM

Sandboxed Pod (runsc)

Kubelet

Runtime

Page 25: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Future: sandboxed

apiVersion: v1kind: Podmetadata: name: sandboxed-podspec: securityContext: sandboxed: true containers: - name: untrusted-container image: sketchy:v1

API still under discussion

Page 26: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Sandboxes

Node Host

Kernel

Container

KVM

Thwarte

d!Sandboxed Pod

Kubelet

Runtime

Page 27: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

What's the catch?

1. Cost & PerformanceBut getting better!

2. Not 100% compatibleClose though

3. Incomplete solutionRequires network hardening

Page 28: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attack Surfaces

➢ Kernel➢ Storage➢ Network➢ Daemons

Logging, monitoring, ...

➢ Hardware➢ ...

Page 29: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

CVE-2017-1002101: Host-resolved symlinks

Node Host

Kernel

Pod

ContainerEscape!

VolumeVolume

Page 30: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

CVE-2017-1002101: Host-resolved symlinks

Node Host

Kernel

Sandbox Pod

ContainerEscape!

VolumeVolume

Page 31: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

TODO: Sandboxed storage

1. Readonly storage via readonly protocols

2. Ephemeral storage opaque to host

3. Direct access block volumes

4. Sandboxed persistent filesystems ???

Image credit: Charles J Sharp

Page 32: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attack Surfaces

➢ Kernel➢ Storage➢ Network➢ Daemons

Logging, monitoring, ...

➢ Hardware➢ ...

Image credit: Albarubescens

Page 33: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attacks over the network

Node

Kubelet

API Server

Cluster Service

Pod

Metadata Service

Cluster DNS

Unauthenticated Port :10255

Kubelet Credentials169.254.169.254

Kubernetes API

InformationLeak

UnauthenticatedService

Possible solution: enforce iptables rules at host

Page 34: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Network Policy

apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: { ... }spec: podSelector: matchLabels: sandboxed: true policyTypes: - Egress egress: - to: - ipBlock: cidr: 0.0.0.0/0 except: - 10.0.0.0/8 - 172.16.0.0/12 - 192.168.0.0/16

Page 35: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attack Surfaces

➢ Kernel➢ Storage➢ Network➢ Daemons

Logging, monitoring, ...

➢ Hardware➢ ...

Page 36: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attacks via system logsNode

Pod (Sandboxed)Pod (Native)

Container

Runtime

log file Kubelet

API server

fluentd

Log aggregator

Container

Agent

stdio/stderr

stdio/stderr

vsockkubectl logs

logs request

Page 37: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Threats Related to Other Daemons• Kubelet

• CVE-2018-1002100: Kubectl copy doesn’t check for paths outside of its destination directory

• Container runtime

• Spoofed container status, fake container stats

• Processes not specified by the user that run in sandbox

• Kube-proxy

Page 38: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attack Surfaces

➢ Kernel➢ Storage➢ Network➢ Daemons

Logging, monitoring, ...

➢ Hardware➢ ...

Image credit: Jonas Löwgren

Page 39: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Attacks via the Hardware

Page 40: Container Security and Sandboxingyiying/cse291j-winter20/reading/Container-Security.pdfLec6: Threats of Containers • Unlike VMs whose interface is hardware instructions, containers’

Summary

➢ Kubernetes is a complex system with many layers of attack surfaces exposed to internal threats

➢ Sandboxes is an upcoming feature to mitigate many of those threats

i. Leverage hypervisor isolation

ii. Deeper Kubernetes integration for enhanced protection

Image credit: William Warby