Skip to content
Pwnversity
DSO-K8SSECadvanced · 7 min · upd. 2026-10

Kubernetes hardening

OWASP A02:2025

Kubernetes orchestrates containers at scale and its attack surface is huge: API server, RBAC, pod networking, secrets, and the runtime. A misconfigured cluster lets you escalate from a compromised pod to full control. This card covers hardening the critical points. (For K8s cloud fundamentals see Kubernetes.)

The attacker’s goal is usually the same: from execution in a pod to cluster control. The path runs through the classic weak points:

  • Exposed API server: the control plane; if reachable without strong auth, it’s game over.
  • Lax RBAC: service accounts with cluster-admin permissions or dangerous verbs (create pods, get secrets, escalate).
  • Flat network: without NetworkPolicies, any pod talks to any other and to internal services.
  • Weak secrets: K8s Secrets are only base64, not encryption; without etcd encryption, anyone with store access reads them.
  • Over-privileged pods: privileged, hostPID, hostNetwork, hostPath mounts → node escape.
flowchart TD
    POD["Compromised pod (RCE in the app)"] --> SA["Mounted ServiceAccount token"]
    SA -->|lax RBAC| API["API server"]
    API -->|get secrets| SEC["Namespace secrets"]
    API -->|create privileged pod| ESC["Pod with hostPath / privileged"]
    ESC --> NODE["Node (kubelet, host)"]
    NODE --> CLUSTER["Cluster control"]
    POD -. flat network .-> OTHER["Other pods / internal services"]
    style CLUSTER fill:#c0392b,color:#fff

The most important control. Each service account should have only the permissions it needs; avoid wildcards and escalation verbs.

# Read-only Role over a specific resource, in a namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: app
name: configmap-reader
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list"] # no create/update/delete, no "*"

Rules: no cluster-admin for workloads; beware get/list secrets, create pods, bind, escalate, and impersonate; unmount the SA token (automountServiceAccountToken: false) in pods that don’t call the API.

The Pod Security Standards (replacing the old PodSecurityPolicies) define three levels: privileged, baseline, and restricted. Apply restricted per namespace via Pod Security Admission:

apiVersion: v1
kind: Namespace
metadata:
name: app
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/enforce-version: latest

And harden each pod’s securityContext, consistent with container hardening:

securityContext:
runAsNonRoot: true
runAsUser: 65532
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault

By default, in K8s all pods can talk to each other. A deny-all NetworkPolicy as the baseline, then allowing only what’s needed, cuts lateral movement:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: app
spec:
podSelector: {} # all pods in the namespace
policyTypes: ["Ingress", "Egress"]
# no ingress/egress rules = everything denied

From there you add policies that allow, for example, only the frontend to talk to the API and only the API to the database.

  • etcd encryption at rest: Secrets are base64, not encryption. You must enable encryption at rest in the API server and, better, integrate an external KMS or a secrets operator (Vault, External Secrets).
  • Admission control: an admission controller (OPA Gatekeeper, Kyverno) rejects at ingress whatever breaks policy — unsigned images, privileged pods, missing limits. It’s the cluster’s runtime gate.
  • Image signature verification at admission, linking to the CI/CD chain.
  • Enumerate the token’s permissions: from a pod, kubectl auth can-i --list (or the API directly with the token mounted at /var/run/secrets/...) reveals what the compromised SA can do.
  • Hunt RBAC escalations: an SA with create pods lets you launch a privileged pod mounting the host; with get secrets, steal credentials; with escalate, grant yourself more permissions.
  • Node escape: pods with hostPath, hostPID, hostNetwork, or privileged grant access to the node and the kubelet, and from there to other pods’ tokens.
  • Node metadata: from a pod, reach the node’s cloud metadata endpoint to steal the worker’s IAM role.
  • Exposed API/dashboard: an API server or dashboard reachable without strong auth is a direct cluster takeover.
  • Least-privilege RBAC, audited; no cluster-admin for workloads; unmount unused tokens.
  • Pod Security Admission at restricted by default and a hardened securityContext.
  • Deny-all NetworkPolicies + allow what’s needed (microsegmentation).
  • etcd encryption at rest and an external secrets manager.
  • Admission control (Kyverno/Gatekeeper) blocking unsigned images and insecure pods.
  • API server not exposed to the internet; access via bastion/VPN and strong authn.
  • Auditing and runtime detection (API server audit log + Falco).
  • CIS Kubernetes Benchmark (kube-bench) as a baseline.
  • Least-privilege RBAC; no cluster-admin on workloads.
  • automountServiceAccountToken: false where the API isn’t used.
  • Pod Security Admission at restricted per namespace.
  • Hardened securityContext (non-root, drop ALL, read-only FS, seccomp).
  • Deny-all NetworkPolicy baseline + explicit rules.
  • etcd encryption at rest / KMS for secrets.
  • Admission controller verifying signature and pod policy.
  • API server and dashboard not exposed to the internet.
  • API server audit log enabled and monitored.
  • kube-bench (CIS) run periodically.