Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
A security context is the block of a Kubernetes manifest that decides which user a container runs as, which Linux capabilities it keeps, and whether it can gain privileges at runtime.

What Is a Pod Security Context?
A security context is the part of a Kubernetes manifest that tells the container runtime how much privilege a workload gets: which user and group it runs as, which Linux capabilities it keeps, whether its root filesystem is writable, and whether a process inside it can acquire more rights than it started with. It appears as securityContext at two levels — once under spec for the whole pod, and once under each container — and the container-level block wins wherever both set the same field.
A handful of fields account for almost all of the security value.
runAsNonRoot: true instructs the kubelet to refuse to start the container if the image would run as UID 0. Combined with an explicit runAsUser, it removes the default that still ships with a surprising number of public images.allowPrivilegeEscalation: false sets the no_new_privs flag, so setuid binaries and file capabilities cannot raise privileges after the process starts. This is a container-level field only.privileged: true is the opposite extreme: it disables most isolation and gives the container access to host devices. Outside a handful of CNI and storage agents, it should never appear.capabilities.drop: ["ALL"] removes the default capability set the runtime grants. Add back only what the workload genuinely needs — typically nothing, occasionally NET_BIND_SERVICE for a process binding below port 1024.readOnlyRootFilesystem: true forces an attacker who lands in the container to write somewhere you chose, which is usually an emptyDir mounted at /tmp.seccompProfile.type: RuntimeDefault applies the runtime’s filter over the system call interface, blocking a large set of calls that application workloads never make and that kernel exploits often need.fsGroup and fsGroupChangePolicy control group ownership of mounted volumes, which is how you avoid the temptation to run as root purely to write to a persistent volume.Platform-specific fields sit alongside these: seLinuxOptions on clusters that enforce SELinux, and the appArmorProfile field that became generally available in Kubernetes 1.31, replacing the older annotation syntax.
apiVersion: v1
kind: Pod
metadata:
name: invoice-api
spec:
securityContext:
runAsNonRoot: true
runAsUser: 10001
fsGroup: 10001
seccompProfile:
type: RuntimeDefault
containers:
- name: api
image: registry.internal/invoice-api@sha256:9f2c...
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
volumeMounts:
- name: scratch
mountPath: /tmp
volumes:
- name: scratch
emptyDir: {}
That manifest satisfies the restricted profile of the Pod Security Standards, and the relationship between the two concepts is worth being precise about: the security context is what you write, and the standards are what the cluster checks it against.
A security context constrains a process within the isolation the kernel already provides. It does not create a new boundary. A kernel vulnerability, a dangerous host path mount, or a shared namespace can still produce an escape — MITRE ATT&CK tracks that outcome as Escape to Host (T1611), and runc flaws such as CVE-2019-5736 and the Leaky Vessels issues disclosed in January 2024, including CVE-2024-21626, are reminders that the runtime itself is in scope. Where a workload is genuinely untrusted, a sandboxed runtime such as gVisor or Kata Containers gives you the boundary that a security context cannot.
Equally, it says nothing about what the pod may talk to, what cloud permissions it inherits, or what secrets it can mount. Those belong to NetworkPolicy, workload identity, and role-based access control respectively, and a hardened security context alongside a service account holding administrator rights over your cloud account is not a secure pod.
Retrofitting these settings onto an existing estate usually surfaces three problems: images built to run as root, applications that write to their own installation directory, and agents that need a capability nobody documented. Work through it in order. Label namespaces with the restricted standard in warn and audit mode first to produce a list of offenders without blocking anything. Fix images by adding a non-root user in the Dockerfile and setting file ownership at build time rather than patching at runtime. For the few workloads that genuinely require elevated settings, isolate them in their own namespace with a documented exception and tighter monitoring.
If you would like evidence of what a compromised pod could actually reach in your cluster, that is the starting point we use in our cloud security services.
The security context is the configuration you write in a pod or container specification. The Pod Security Standards are three named profiles — privileged, baseline, and restricted — that describe acceptable combinations of those settings. Pod Security Admission enforces a profile at namespace level and rejects pods whose security context does not comply. One is the setting; the other is the policy that checks it.
Usually because the image has no numeric user configured. If the Dockerfile sets no USER, or sets it by name rather than UID, the kubelet cannot confirm the user is non-root and refuses to start the pod. Fix it by creating a user in the image and setting USER to its numeric ID, or set runAsUser explicitly in the manifest and ensure the application can write to the paths it needs.
Yes. Running as a non-root user and holding Linux capabilities are separate things, and the default container runtime grants a set of capabilities regardless of the user. Capabilities such as CAP_NET_RAW enable useful attacker behaviour like ARP spoofing from inside the pod. Dropping ALL and adding back only what is needed costs nothing and closes that gap.
More often than teams expect. Most applications write only to temporary directories, logs, and caches, all of which can be mounted as emptyDir volumes at the specific paths required. The exceptions are legacy software that writes into its own installation directory and some language runtimes that compile on first use. Start with it enabled and add mounts as failures appear, rather than the reverse.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.