The State of Kubernetes Security
Hello! I’m Jimmy.
- What are Containers?
- What is Kubernetes?
- Kubernetes Security Considerations
- Kubernetes: Self Assessment
- The Future of K8S Security
Containers
Containers are an application-
layer construct which rely on
a shared kernel.
Containers are not
“lightweight VMs.”
Containers rely on Linux kernel
features such as namespaces
and cgroups to isolate a given
process (AKA container).
Container Breakout occurs when the
container isolation mechanisms have
been bypassed and additional privileges
have been obtained on the host.
Containers can do bad things:
- Mount volumes & directories
- Disable security features
- Run as root
- Share the host namespace
Exploits
Dangerous Mountpoints
Containers typically restrict the
number of powerful Linux capabilities
granted to it.
Privileged containers bypass those
controls, granting dangerous
capabilities to the container.
Demo: Privileged vs. Non-Privileged
Image Integrity
Kubernetes
Kubernetes is an open-source
platform built to automate
deployment, scaling, and
orchestration of containers.
”Kubernetes is a
pile of Linux goop.”
I thought Kubernetes
was secure by default?
Kubernetes optimizes for
flexibility over security.
…And that’s ok!
Kubernetes is a living, breathing
system. Security is never “done”.
https://medium.com/jw-player-engineering/how-a-cryptocurrency-miner-made-its-way-onto-our-internal-kubernetes-clusters-9b09c4704205
Kubernetes Threat Model
28
User Compromise and Insider Threats
• Cluster admin account compromise
• Rogue Employee
• Build system compromised
Application Vulnerabilities
• Lack of authentication and authorization, both k8s internal and external
• Weak or incorrect usage of cryptography
• Application and API vulnerabilities - remote code execution (RCE), web
vulnerabilities (XSS, CSRF, SSRF, SQL Injection etc.)
• Insecure third-party components
Kubernetes Threat Model
29
Network and Infrastructure
• Network snooping, ARP spoof attacks
• Compromising infrastructure services (etc. NTP, DNS, SSH)
• Kernel and other operating system vulnerabilities
Application Containers
• Container breakout and unauthorized access control plane and other
containers
• Denial of Service - resource hogging, eating up CPU/Mem/Disk/IO to
impact or even crash other containers
• Compromised or malicious image or pipeline
Kubernetes Threat Model
30
Misconfiguration
• Insecure default configurations - unused open ports,
services, not enforcing system/application limits, failing to
implement security features
• Misuse of passwords, passphrases, TLS private keys
(*cough* checking them into git *cough*. Bad handling
include key reuse, insecure handling of keys, no key
rotation, weak passwords, not using MFA etc.
• Lack of network segmentation - exposing critical systems to
various network attacks
31
Source: Kubernetes Security - Operating Kubernetes Clusters and Applications Safely
Access via Kubelet API
Defenses
RBAC
Container and Pod Permissions
Pod Security Policies
Dynamic Admission Control
OPA
Sandboxing
Node Protection
Role-Based Access Control
(RBAC) is how we regulate
access to Kubernetes resources.
Users
you@email.com
Service account
API Resources
Namespaces
Pod
Service
Secrets
…
Operations
Get
List
Delete
Patch
role.yaml
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: development
name: pod-reader
rules:
- apiGroups: [""]
resources: [”pods"]
verbs: ["get", "list"]
Containers may request elevated
privileges such as running as root,
mounting sensitive volumes, or
requesting access to specific ports.
Pod specifications may declare to
access devices on the host using
privileged mode.
Pod Security Policies give
administrators the ability to
validate requests to the cluster
based on security requirements.
psp.yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: my-psp
spec:
privileged: false
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
runAsUser:
rule: MustRunAsNonRoot
volumes:
- 'configMap'
- 'emptyDir’
- 'secret’
- 'persistentVolumeClaim'
Dynamic Admission Control allows
teams to build custom security
checks by intercepting requests to
the Kubernetes API server prior to
scheduling the object.
https://github.com/kelseyhightower/denyenv-validating-admission-webhook
Open Policy Agent (OPA) acts as
a middleware to help enforce
cluster-wide security policies.
https://github.com/open-policy-agent/gatekeeper
Gatekeeper Examples
46
Require Specific Labels upon object creation
Audit Cluster for violations of policy
Namespace must have “Owner” label
Containers must have resource limits defined
Always ensure images come
from a known-good source
and the integrity has been
verified.
Tools such as gVisor and Kata
Containers can help further isolate
and sandbox containers that are
running untrusted workloads
inside of Kubernetes.
Remember, Kubernetes is just
running servers under the hood.
Our regular old OS hardening and
network protections apply.
Kubernetes can be secure,
but it is far from default.
Take Home Assignment
52
• Can containers run as root?
• Can containers mount sensitive volumes / directories? Read or Read / Write?
• Can Pods run in “Privileged” mode?
• What policies (PSP, custom, OPA) are in place and for who?
• How is authentication handled?
• Is RBAC enforcing the principle of least privilege?
• How are secrets being stored and retrieved? Rotated? Revoked?
• Where do container images come from? Are images being validated?
• How is network security being enforced? Can you audit these rules?
• Are your hosts hardened? Monitoring in place?
• Are you using Kubernetes Audit? Where are logs sent?
• Ingress / LB inventory in place? What external IP addresses are available?
• What happens if / when your application has an SSRF bug?
• Have you performed a proper threat model of Kubernetes environments?
• Third party products, tools, helpers? Are they secure?
Beware of blind spots
Embrace a beginners mindset mindset
Adapt and evolve
Give back to the community
58
• Flexibility > Security will be our reality
• Choose your Own Security Adventure
• More tooling
• Tighter Cloud integrations
• Overall Kubernetes maturity
• Increasing target for attack
The Future?
https://github.com/RhinoSecurityLabs/cloudgoathttps://github.com/ksoclabs/kube-goat
https://www.owasp.org/index.php/OWASP_Serverless_Goat
Practice
@jimmesta
jimmy[at]ksoc.com

The State of Kubernetes Security

Editor's Notes

  • #32 From the fallout 4 video game This game is published by the Don't Be Bored Games Company in the years before the Great War and is for ages 5 to 29. A text blurb describes the game as "an exciting new board game that brings friends, family, and nuclear explosions together. The first player to make it to a safe distance will survive. The rest will perish. Do you have what it takes?"