Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Secure your Kubernetes Containers - NDC Sydney ...

Secure your Kubernetes Containers - NDC Sydney 2019

Hossam Barakat

October 18, 2019
Tweet

More Decks by Hossam Barakat

Other Decks in Technology

Transcript

  1. @hossambarakat_ Attack Vectors 4 OS Kubernetes Container Image Container Application

    - Container escape - Intercept & modify traffic - Base image vulnerability - OSS Lib Vulnerability - Privilege Escalation - API Compromise
  2. @hossambarakat_ Kubernetes Architecture Master API Server Worker Kubelet Container Runtime

    UI (Dashboard) CLI (Kubectl) Other Client(s) Pod Pod Cluster Scheduler TLS TLS
  3. @hossambarakat_ Attack Insecure API Server 10 Pod Worker Master Cluster

    Container API Server {Access Token} Get Pods Create Pods … Hacker icon by karina from the Noun Project
  4. @hossambarakat_ Role Based Access Control (RBAC) 12 Role Binding Role

    Resource User Group Service Account Verb Verb Subject
  5. @hossambarakat_ Role 14 Role Based Access Control (RBAC) Role Binding

    kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: my-role namespace: default rules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "list"] kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: my-role-binding namespace: default subjects: - kind: ServiceAccount name: webapp-service-account namespace: default roleRef: kind: Role name: my-role apiGroup: rbac.authorization.k8s.io
  6. @hossambarakat_ Get Pods Using RBAC 16 Pod Worker Master Cluster

    Container API Server {Access Token} Get Pods Create Pods Create Deployment …
  7. @hossambarakat_ CIS Kubernetes Benchmark » Document that provide guidance for

    establishing a secure configuration posture for Kubernetes » Specific recommendations with a description, rationale, method of audit and remediation » Can be automated with kube-bench 18
  8. @hossambarakat_ Images Security » Never run as root • Set

    USER in Dockerfile » Minimal base image • Alpine 2 MB • Ubuntu 60 MB » Trusted base image » Private image registry » Do NOT use latest tag » Vulnerability scans 20
  9. @hossambarakat_ Image Scanning Tools » aquasecurity/trivy » coreos/clair » optiopay/klar

    » aquasecurity/microscanner » Aqua Security » Twistlock 21
  10. @hossambarakat_ Vulnerability Scanning CI Pipeline Integration 24 Code CI Vulnerability

    Scanning Image Registry Schedule Container Publish Scanning Results Is Scanned Image? Admission Webhook
  11. @hossambarakat_ Privilege Escalation 27 Pod Worker Container Modify container file

    system Modify host file system Crypto Miner Hacker icon by karina from the Noun Project
  12. @hossambarakat_ » RunAsUser » RunAsGroup » AllowPrivilegdeEscalation » ReadOnlyRootFilesystem 32

    Security Context apiVersion: v1 kind: Pod metadata: name: my-app spec: securityContext: runAsUser: 1000 RunAsGroup: 2000 containers: - name: my-app image: my-app securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true
  13. @hossambarakat_ Pod Security Policy » A Pod Security Policy is

    a cluster-level resource that controls the actions that a pod can perform and what it has the ability to access. » The PodSecurityPolicy objects define a set of conditions that a pod must run with in order to be accepted into the system. 34
  14. @hossambarakat_ Pod Security Policy » privileged » volumes » fsGroup

    » runAsUser, runAsGroup » readOnlyRootFilesystem » allowedHostPaths » hostNetwork » Linux capabilities 35
  15. @hossambarakat_ Stop Privileged Pods with PSP 38 Master API Server

    securityContext: privileged: true Pod Security Policy Controller Schedule Pod Pod Security Policy Policy spec: privileged: false
  16. @hossambarakat_ App 1 42 Network Policies Frontend DB Pod apiVersion:

    networking.k8s.io/v1 kind: NetworkPolicy metadata: name: my-frontend-policy spec: podSelector: matchLabels: app: db ingress: - from: - podSelector: matchLabels: app: frontend
  17. @hossambarakat_ Summary 48 Kubernetes Cluster Bootstrap TLS Authentication Enable RBAC

    CIS Benchmark Container Images No root user Small images Do NOT use latest Private Image Registry Containers Pod Security Context Pod Security Policy Network Policy Service Mesh Vulnerability Scans