Kubernetes Security Reference
Pod security, RBAC misconfigurations, container escape techniques, admission controllers, and kubectl security audit commands for cloud security teams.
π RBAC Misconfigurations
Kubernetes RBAC (Role-Based Access Control) misconfigurations are the most common path to cluster compromise. These are the most dangerous patterns.
Dangerous Permissions Reference
| Permission | Why Dangerous | Escalation Path | Severity |
|---|---|---|---|
* / * / * (wildcard all) | Full cluster admin β complete control | Direct cluster takeover | Critical |
pods/exec | Execute commands in any pod | Container escape β node access | Critical |
create pods (with hostPID/hostNetwork/hostPath) | Create privileged pods on any node | Node escape β full cluster | Critical |
secrets get/list (cluster-wide) | Read all secrets including service account tokens | Impersonate any SA in cluster | Critical |
clusterroles/clusterrolebindings create | Create new cluster admin bindings | Direct privilege escalation | Critical |
nodes/proxy or pods/proxy | Proxy to any pod/node β bypasses network policies | Access internal services | High |
impersonate users/groups/serviceaccounts | Act as any user or SA in the cluster | Lateral movement to any identity | High |
daemonsets create | Run privileged container on every node simultaneously | Full cluster node compromise | High |
validatingwebhookconfigurations create | Intercept all API requests β man-in-the-middle | Data theft, policy bypass | High |
roles/rolebindings create (same namespace) | Grant yourself any permissions within namespace | Namespace privilege escalation | Medium |
Find dangerous RBAC bindings in your cluster
Secure RBAC β Least Privilege Example
π‘ Pod Security
Pod security controls whether a container can access host resources. A misconfigured pod is the most common container escape vector.
Dangerous Pod Security Settings
| Setting | Risk | Escape Path |
|---|---|---|
privileged: true | Critical | Container has full host capabilities β trivial escape to node |
hostPID: true | Critical | See all host processes β can inject into host process namespaces |
hostNetwork: true | High | Container on host network β bypass network policies, access cloud metadata |
hostPath volume mounts | Critical | Mount host filesystem β read /etc/shadow, write cron, access node credentials |
allowPrivilegeEscalation: true (default) | High | setuid binaries can escalate to root |
runAsUser: 0 or no runAsNonRoot | Medium | Running as root β combined with other settings enables escape |
capabilities: add: [SYS_ADMIN] | Critical | SYS_ADMIN capability allows mount operations β enables escape |
capabilities: add: [NET_ADMIN] | Medium | Can modify network interfaces and routing |
serviceAccountToken: true (default) + cluster-admin SA | Critical | Compromised container gets cluster-admin token |
Secure pod template β hardened baseline
Pod Security Standards (PSS) β Kubernetes built-in
| Level | What it restricts | Use for |
|---|---|---|
privileged | No restrictions | System components only (kube-system) |
baseline | Blocks most dangerous settings (privileged, hostPID, hostNetwork, hostPath) | Default for all application namespaces |
restricted | All of baseline + requires non-root, drops capabilities, requires seccomp | Sensitive workloads, PCI/PII processing |
π¨ Container Escape Techniques
1. Privileged Container Escape via /proc T1611
2. hostPath Volume Mount β Node Filesystem Access T1611
3. Docker Socket Mount β Container Management T1610
4. Service Account Token Abuse β API Server Access T1528
5. IMDS Access from Container with hostNetwork T1552.005
π¦ Admission Controllers
Admission controllers intercept API requests before objects are persisted. They are the primary enforcement mechanism for security policies in Kubernetes.
| Controller | What It Does | Security Value |
|---|---|---|
| OPA Gatekeeper | Policy enforcement via Open Policy Agent. Rego-based policies evaluated for every API request. | Essential β block privileged pods, enforce image registries, require labels |
| Kyverno | Kubernetes-native policy engine. YAML-based policies (easier than Rego). Validate, mutate, generate. | Essential β simpler than Gatekeeper for most teams |
| PodSecurity (built-in) | Enforces Pod Security Standards (privileged/baseline/restricted) at namespace level. | High β built-in, no additional install needed |
| ImagePolicyWebhook | Validate container images against an external policy server before allowing pod creation. | High β enforce image scanning, registry allowlist |
| NodeRestriction | Limits what kubelet can modify β prevents nodes from elevating their own privileges. | High β should always be enabled |
| AlwaysPullImages | Forces container images to always be pulled from registry β prevents using cached malicious images. | Medium β useful with private registry |
Kyverno β Enforce no privileged containers (policy example)
π Kubernetes Security Audit β kubectl Commands
One-liner cluster security assessment
Automated scanners
βοΈ MITRE ATT&CK for Containers
| Tactic | Technique | ID | K8s Context |
|---|---|---|---|
| Initial Access | Valid Accounts β Cloud Accounts | T1078.004 | Stolen kubeconfig, RBAC misconfiguration, exposed API server |
| Initial Access | Exploit Public-Facing Application | T1190 | Kubernetes API server exposed without auth, exposed dashboard |
| Execution | Deploy Container | T1610 | Attacker deploys malicious container via Docker socket or API |
| Execution | Container Administration Command | T1609 | kubectl exec, docker exec to run commands in existing container |
| Persistence | Account Manipulation | T1098 | Create new ClusterRoleBinding, new ServiceAccount with cluster-admin |
| Persistence | Create Account | T1136 | Create new ServiceAccount, new kubeconfig credential |
| Privilege Escalation | Escape to Host | T1611 | Privileged container, hostPath mount, hostPID, Docker socket |
| Privilege Escalation | Abuse Elevation Control Mechanism | T1548 | Create ClusterRoleBinding to cluster-admin from lesser-privileged SA |
| Defence Evasion | Impair Defences | T1562 | Delete audit logs, disable admission controllers, remove DaemonSet agents |
| Credential Access | Steal Application Access Token | T1528 | Read SA tokens from /var/run/secrets/kubernetes.io/serviceaccount/ |
| Credential Access | Unsecured Credentials: Cloud Instance Metadata | T1552.005 | Access IMDS via hostNetwork pod or compromised node |
| Discovery | Network Service Discovery | T1046 | Scan cluster network from compromised pod |
| Discovery | Cloud Infrastructure Discovery | T1580 | kubectl get all --all-namespaces to enumerate cluster |
| Lateral Movement | Use Alternate Authentication Material | T1550 | Use stolen SA token to access other namespaces or services |
| Exfiltration | Transfer Data to Cloud Account | T1537 | Exfiltrate PVC data, secrets, or config to external storage |
| Impact | Resource Hijacking | T1496 | Crypto mining via deployed pods on cluster nodes |
| Impact | Data Destruction | T1485 | Delete namespaces, PVCs, deployments β cluster destruction |