A container is a process with some walls around it. Kubernetes manifests decide how thick those walls are, and a handful of fields can remove them entirely: one line of YAML turns "an attacker has code execution in a web pod" into "an attacker has root on the node" or "an attacker can talk to the API server as a privileged identity".
Those fields are easy to find in review because they are explicit. This post goes through them in order of blast radius, shows what the Kubernetes Pod Security Standards say about each, and ends with a manifest you can copy.
The settings that matter most
| Field | What it gives a compromised container | Pod Security Standards level that forbids it |
|---|---|---|
privileged: true |
Effectively the host's root: all devices, all capabilities | Baseline |
hostPID, hostIPC, hostNetwork: true |
The node's process list, shared memory or network stack | Baseline |
hostPath volume |
Read or write access to node files (/, /etc, the container runtime socket) |
Baseline |
capabilities.add beyond the default set (for example SYS_ADMIN) |
Kernel features that enable escapes without privileged |
Baseline |
hostPort |
A port on the node's network, bypassing Services | Baseline (unless on a known list) |
seccompProfile.type: Unconfined |
No system call filter | Baseline |
allowPrivilegeEscalation not false |
setuid binaries can raise privileges | Restricted |
runAsUser: 0 or no runAsNonRoot: true |
Root inside the container | Restricted |
| Default service account token mounted | A token to call the API server with whatever RBAC the account has | Not covered: an RBAC and automount decision |
The levels come from the Pod Security Standards: Privileged (no restrictions), Baseline (blocks known privilege escalations) and Restricted (current hardening practice).
Privileged containers and host namespaces
privileged: true removes most of the isolation a container has. It is the setting that makes "container escape" a matter of mounting the host disk. The host namespace flags are narrower but serious: hostPID lets a container see and signal every process on the node, and hostNetwork puts it on the node's network interfaces, outside NetworkPolicy.
Legitimate uses exist: CNI plugins, storage drivers, node monitoring agents. They belong in their own namespace with the Privileged policy level, an owner and a reason. An application Deployment never needs them.
hostPath volumes
A hostPath volume mounts a directory from the node into the pod. Baseline forbids it outright. The paths that matter most:
/or/etc: read node secrets, write cron jobs or SSH keys.- The container runtime socket (for example
/var/run/docker.sockor the containerd socket): start a new privileged container, which is root on the node. /var/lib/kubelet: other pods' mounted secrets and tokens./var/log: often requested by log shippers, and can still expose tokens printed in logs.
If a workload needs node data, prefer a CSI driver or a narrowly scoped read-only mount in a dedicated agent namespace.
Capabilities, seccomp and privilege escalation
Linux capabilities split root's powers into pieces. The Baseline level allows adding only a fixed list (AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID, SETPCAP, SETUID, SYS_CHROOT). Restricted goes further: drop must include ALL, and add may contain only NET_BIND_SERVICE. Capabilities such as SYS_ADMIN, SYS_PTRACE or NET_ADMIN grant near-privileged access without the word "privileged" appearing anywhere.
Restricted also requires allowPrivilegeEscalation: false, runAsNonRoot: true, no runAsUser: 0, and an explicit seccomp profile of RuntimeDefault or Localhost. Each one closes a step that escape chains commonly use.
The default service account
Every namespace has a service account named default, and the service account documentation notes that a pod with no serviceAccountName is assigned it automatically. Unless you opt out, the kubelet mounts that account's API token into the pod. Code execution in the pod then means API access with whatever RBAC that account holds.
Most application pods never call the Kubernetes API. For those, opt out:
apiVersion: v1
kind: ServiceAccount
metadata:
name: web
automountServiceAccountToken: falseThe setting can also go on the pod spec, and "if both the ServiceAccount and the Pod's .spec specify a value for automountServiceAccountToken, the Pod spec takes precedence". For pods that do call the API, give each workload its own service account bound by a namespaced Role with the exact verbs it needs. Never bind cluster-admin to an application account, and avoid verbs: ["*"] in any role.
Image references
The Kubernetes images documentation says to avoid :latest in production because "it is harder to track which version of the image is running and more difficult to roll back properly". A tag can also be republished to point at different content. Pin by digest (image@sha256:...) for anything you deploy, with the tag kept in a comment or alongside it for readability. When both are given, only the digest is used for the pull.
A manifest that passes Restricted
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
selector:
matchLabels: { app: web }
template:
metadata:
labels: { app: web }
spec:
serviceAccountName: web
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 10001
seccompProfile:
type: RuntimeDefault
containers:
- name: web
image: registry.example.com/web@sha256:<digest> # v2.4.1
ports:
- containerPort: 8080
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
resources:
requests: { cpu: 100m, memory: 128Mi }
limits: { memory: 256Mi }
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir: {}readOnlyRootFilesystem and resource limits are not part of the Restricted level, but they cost little and limit what an attacker can write or consume.
Enforce it at the namespace
Review catches mistakes; admission control stops them reaching the cluster. Pod Security Admission, stable since Kubernetes v1.25, applies a level per namespace through labels:
metadata:
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/warn: restrictedThe modes are enforce (reject the pod), audit (record it) and warn (show a warning). A common rollout is warn and audit first, then enforce once the warnings are gone. Pin the policy version with pod-security.kubernetes.io/enforce-version if you want upgrades to change nothing until you choose.
What Vulkro checks
Vulkro Core reads Kubernetes YAML and Helm charts in a normal scan and flags the explicit settings above:
| Rule | What it flags |
|---|---|
k8s:privileged |
privileged: true |
k8s:host-network, k8s:host-pid, k8s:host-ipc |
Host namespace sharing |
k8s:host-path |
A hostPath volume, graded by the host path |
k8s:dangerous-capability |
An added capability that grants near-privileged access |
k8s:privilege-escalation |
allowPrivilegeEscalation: true |
k8s:root-user |
runAsUser: 0 |
k8s:seccomp-unconfined, k8s:host-port |
An Unconfined profile, a mapped hostPort |
k8s:latest-image |
An image on the :latest tag |
k8s:rbac-wildcard-verbs |
A Role or ClusterRole with verbs: ["*"] |
k8s:secret-in-env |
A literal credential in a container env value |
K8S-NETPOL-001 |
cluster-admin bound to an application service account, or tenant workloads without a NetworkPolicy |
R2-IAC-001 |
A binding that grants an authenticated-users or anonymous group |
vulkro scan ./deployIt flags what is written in the file. It does not yet report a missing runAsNonRoot or an automounted default token, and it cannot see what an admission controller or a Helm value override changes at deploy time, so keep Pod Security Admission on the namespace as the enforcement layer.
FAQ
What are the Kubernetes Pod Security Standards levels?
There are three: Privileged (unrestricted), Baseline (prevents known privilege escalations such as privileged containers, host namespaces and hostPath) and Restricted (adds non-root, no privilege escalation, dropped capabilities and a required seccomp profile). Pod Security Admission enforces them per namespace.
Should I set automountServiceAccountToken to false?
For any pod that does not call the Kubernetes API, yes. It removes the API token from the pod's file system, so code execution in the pod does not come with API access. Pods that need the API should use their own service account with a narrow Role.
Is hostPath ever safe to use?
It is forbidden at the Baseline level for good reason. If a node agent truly needs host files, mount the narrowest path read-only, run the agent in a dedicated namespace with the Privileged level, and never mount /, /etc or the container runtime socket into an application pod.
See the supply chain use case and the supported detection list, or start a 14-day trial. Related: Dockerfile security best practices and Terraform security misconfigurations.