A Kubernetes pod with no securityContext runs with whatever the image and the container runtime decide, which often means root, the runtime's default capability set, no seccomp filter and a writable root filesystem. The securityContext fields are where you take those decisions back. This page is a field-by-field lookup: every field in the pod-level PodSecurityContext and the container-level SecurityContext, the level it lives at, a safe value and the risk if it is left unset. Field names, defaults and feature states were checked against the Kubernetes v1.37 API types and the kubernetes.io documentation in November 2026; fields change between releases, so confirm against your cluster version. It is written for platform engineers and reviewers of Kubernetes manifests.
Key takeaways
- Container settings win. Where a field exists at both levels, the container value overrides the pod value for that container; volume effects such as fsGroup come only from the pod level.
- Four fields do most of the work. runAsNonRoot: true, allowPrivilegeEscalation: false, capabilities.drop: ["ALL"] and seccompProfile.type: RuntimeDefault are the Restricted profile's core, and readOnlyRootFilesystem: true is the best addition beyond it.
- Unset is not safe. Without seccompDefault on the kubelet, an unset seccomp profile means Unconfined; an unset runAsUser means the image's user; an unset runAsGroup means GID 0.
- privileged: true cancels the rest. Privileged containers are essentially root on the host, always run seccomp Unconfined and always allow privilege escalation.
- Enforce, do not hope. Set the fields in templates, then enforce them with Pod Security Admission at the Restricted level so a missing field is rejected, not deployed.
How pod and container securityContext interact
There are two structures. spec.securityContext (PodSecurityContext) applies to every container in the pod, including init, sidecar and ephemeral containers. spec.containers[*].securityContext (SecurityContext) applies to one container. Fields that exist in both (runAsUser, runAsGroup, runAsNonRoot, seLinuxOptions, seccompProfile, appArmorProfile, windowsOptions) follow one rule: the container value takes precedence for that container. A pod-level runAsUser: 1000 with a container-level runAsUser: 2000 runs that container as 2000.
Some fields exist only at one level. Group and volume settings (fsGroup, fsGroupChangePolicy, supplementalGroups, supplementalGroupsPolicy, sysctls, seLinuxChangePolicy) are pod-only, because they affect shared volumes or the pod's kernel namespaces. Process privilege settings (privileged, capabilities, allowPrivilegeEscalation, readOnlyRootFilesystem, procMount) are container-only. The practical pattern is to set identity and profiles once at pod level, then set the privilege fields on every container, including init containers, which reviewers often skip.
Two neighbouring fields are not in securityContext but belong in the same review: spec.hostNetwork, spec.hostPID and spec.hostIPC (host namespaces, blocked by Baseline) and spec.hostUsers, which when false runs the pod in a user namespace so that root in the container maps to an unprivileged user on the node. See the Kubernetes User Namespaces Guide. spec.os.name matters too: most Linux fields cannot be set when it is windows, and windowsOptions cannot be set when it is linux.
Field reference table
Defaults are stated only where the Kubernetes API documentation states them. "Runtime" means the container runtime decides.
| Field | Level | Documented default if unset | Safe value | Risk if unset or unsafe |
|---|---|---|---|---|
| runAsNonRoot | Pod, container | No validation | true | An image whose user is UID 0 starts as root; with true the kubelet refuses to start it |
| runAsUser | Pod, container | User from image metadata | A fixed non-zero UID, for example 10001 | Image changes silently change the runtime identity; Restricted forbids 0 |
| runAsGroup | Pod, container | Runtime default (primary GID 0 per the task docs) | A fixed non-zero GID | Files written by the process are group-owned by root |
| supplementalGroups | Pod | No extra groups | Only the groups the workload needs | Unneeded group access to shared volumes |
| supplementalGroupsPolicy | Pod | Merge | Strict where supported | Merge adds group memberships from the image's /etc/group, which the manifest does not show |
| fsGroup | Pod | Volume ownership not changed | The workload's GID when it writes to volumes | Workloads fail on volumes, then teams fall back to running as root |
| fsGroupChangePolicy | Pod | Always | OnRootMismatch for large volumes | Slow starts on large volumes from recursive ownership changes (performance rather than security) |
| sysctls | Pod | None | Only names on the Baseline safe list | Unsafe sysctls can affect other pods on the node |
| seccompProfile | Pod, container | Unconfined, unless kubelet seccompDefault is enabled | type: RuntimeDefault, or Localhost with a tested profile | Full kernel syscall surface available to a compromised process |
| appArmorProfile | Pod, container | Applied only if AppArmor is enabled on the node | type: RuntimeDefault or Localhost | Unconfined removes mandatory access control on file and capability use |
| seLinuxOptions | Pod, container | Runtime allocates a random SELinux context per container | Leave unset, or a type allowed by Baseline (container_t and related) | Custom user, role or type values (for example spc_t) bypass container confinement |
| seLinuxChangePolicy | Pod | MountOption | MountOption unless pods with different labels share a volume | Mixed policies on a shared volume can leave pods stuck in ContainerCreating |
| privileged | Container | false | false (omit) | Essentially root on the host |
| allowPrivilegeEscalation | Container | no_new_privs not set | false | setuid binaries and file capabilities can raise privileges inside the container |
| capabilities | Container | Runtime's default capability set | drop: ["ALL"], add only NET_BIND_SERVICE if needed | The runtime default set grants capabilities most applications never use, widening what a compromised process can do |
| readOnlyRootFilesystem | Container | false | true, with emptyDir mounts for writable paths | An attacker can write tools or modify binaries in the container filesystem |
| procMount | Container | Default (runtime masked and read-only paths) | Default | Unmasked exposes /proc and /sys/firmware read-write; requires hostUsers: false |
| windowsOptions | Pod, container | Container value, else pod value | hostProcess unset or false | See the Windows section |
The Restricted example pattern is short:
1 Sample only, based on the public documentation cited. Assess it independently against the current official documentation, test outside production and back up first.
spec:
securityContext:
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
seccompProfile:
type: RuntimeDefault
containers:
- name: app
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]Linux capabilities and privilege escalation fields
- runAsNonRoot: the kubelet checks the image at start and refuses to run a container that would run as UID 0. Pair it with a numeric runAsUser: if the image declares a non-numeric user name, the kubelet cannot verify it is not root and the container fails to start. The fix is a numeric UID in the image or the manifest, not removing the check.
- allowPrivilegeEscalation: directly controls the Linux no_new_privs flag on the container process. With false, a setuid binary or file capability inside the image cannot give the process more privilege than its parent. The API states it is always true when the container is privileged or has CAP_SYS_ADMIN, so setting false while adding SYS_ADMIN is contradictory.
- capabilities: names omit the CAP_ prefix (SYS_TIME for CAP_SYS_TIME). Drop ALL, then add back only what is proven necessary. Restricted allows only NET_BIND_SERVICE in add; Baseline allows a wider list (AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID, SETPCAP, SETUID, SYS_CHROOT). Binding to a port below 1024 is the usual reason for NET_BIND_SERVICE; listening on 8080 avoids it.
- privileged: disables most container isolation. Reserve it for node-level agents (some CNI and storage drivers) in dedicated namespaces with documented exemptions.
- readOnlyRootFilesystem: not required by any Pod Security Standards level, which is why it is often missing. Mount emptyDir volumes at /tmp and any cache paths; test with the application's real workload, because write failures may appear only on rare code paths.
These fields map to container escape and privilege techniques: ATT&CK T1611 (Escape to Host) and T1068 (Exploitation for Privilege Escalation) are much harder from a non-root, no-new-privileges, capability-less container. For runtime detection see the Container Runtime Security Guide.
seccomp, AppArmor and SELinux fields
| Field | Types and values | Version notes (as documented) | Operational note |
|---|---|---|---|
| seccompProfile.type | RuntimeDefault, Localhost (with localhostProfile), Unconfined | Field stable since v1.19; kubelet seccompDefault stable since v1.27 | Localhost paths are relative to the kubelet's seccomp directory. Privileged containers always run Unconfined |
| appArmorProfile.type | RuntimeDefault, Localhost (with localhostProfile), Unconfined | Field introduced in v1.30, replacing the beta annotations; stable since v1.31 | An explicitly set profile that is not loaded on the node leaves the pod Pending; Kubernetes does not load profiles onto nodes |
| seLinuxOptions | user, role, type, level | Baseline allows type container_t, container_init_t, container_kvm_t, container_engine_t (since v1.31); user and role must be empty | Only effective on SELinux-enabled nodes |
| seLinuxChangePolicy | MountOption (default), Recursive | SELinuxChangePolicy feature gate GA in v1.36 | Use Recursive when privileged and unprivileged pods share a volume on one node |
The cheapest high-value step is enabling seccompDefault on every kubelet, so unset profiles become RuntimeDefault, and still setting seccompProfile explicitly in manifests, because Pod Security Admission evaluates the manifest, not the kubelet configuration. Per-workload Localhost profiles are worth the effort only for high-risk workloads. See the seccomp Guide and the AppArmor Guide for profile authoring.
Windows-specific fields
Most securityContext fields have no effect on Windows and cannot be set when spec.os.name is windows. Windows pods use windowsOptions, at pod or container level:
- runAsUserName: the Windows user that runs the entrypoint; defaults to the image's user.
- gmsaCredentialSpecName and gmsaCredentialSpec: select a Group Managed Service Account credential spec; the GMSA admission webhook inlines the spec contents. Treat access to credential specs as access to a domain identity. See the Kubernetes NHI Security Guide.
- hostProcess: runs the container as a process directly on the Windows host. All containers in the pod must share the same value and hostNetwork must be true. Baseline forbids it, so it needs an explicit exemption.
From v1.25, the Restricted controls for privilege escalation, seccomp and capabilities apply only when spec.os.name is not windows.
Mapping to Pod Security Standards levels
The Kubernetes Pod Security Standards and Pod Security Admission Guide covers the profiles and enforcement in depth; this table shows which securityContext fields each level checks.
| Field | Baseline | Restricted |
|---|---|---|
| windowsOptions.hostProcess | Unset or false | Unset or false |
| privileged | Unset or false | Unset or false |
| capabilities.add | Baseline list only | Unset or NET_BIND_SERVICE |
| capabilities.drop | Not checked | Must include ALL |
| appArmorProfile.type | Unset, RuntimeDefault or Localhost | Same as Baseline |
| seLinuxOptions | Allowed types only; no user or role | Same as Baseline |
| procMount | Unset or Default | Unset or Default |
| seccompProfile.type | Must not be Unconfined | Must be RuntimeDefault or Localhost (unset is rejected) |
| sysctls | Safe list only | Safe list only |
| allowPrivilegeEscalation | Not checked | false |
| runAsNonRoot | Not checked | true (pod or every container) |
| runAsUser | Not checked | Must not be 0 |
| readOnlyRootFilesystem, runAsGroup, fsGroup | Not checked | Not checked |
The last row is the gap: a pod can pass Restricted with a writable root filesystem and GID 0. Close it with an admission policy (ValidatingAdmissionPolicy, Kyverno or Gatekeeper). See the Kubernetes Admission Control Guide.
Rolling out hardened security contexts
- Inventory: export pod specs and list workloads that run as UID 0, are privileged, add capabilities, or lack seccomp. Label namespaces with pod-security.kubernetes.io/audit=restricted and warn=restricted to see violations without blocking.
- Fix images first: build images with a numeric non-root USER and writable paths under a known directory; this removes most runAsNonRoot failures.
- Set defaults in templates: add the pod and container securityContext block to Helm charts and base manifests, including init containers.
- Enable seccompDefault on kubelets in a canary node pool, watch for syscall-related crashes, then roll out.
- Add readOnlyRootFilesystem per workload with emptyDir mounts, tested in staging.
- Enforce: move namespaces to enforce=restricted, pinning enforce-version to your cluster version. Roll back by relabelling the namespace to baseline; workloads already running are not evicted.
- Exemptions: document each privileged workload, its owner and review date in a dedicated namespace.
Common misconfigurations
- Hardening only the main container: init and sidecar containers left with defaults, often running as root with full runtime capabilities.
- runAsNonRoot without a numeric user: the pod fails, and the "fix" is to delete runAsNonRoot rather than add a UID.
- Relying on kubelet seccompDefault alone: manifests still fail Restricted and nodes without the setting run Unconfined.
- Adding SYS_ADMIN "to make it work": this makes allowPrivilegeEscalation effectively true and grants broad host-affecting power.
- Using the old AppArmor annotations: new manifests should use the appArmorProfile field.
- Treating Restricted as complete: it does not require readOnlyRootFilesystem, and it says nothing about the service account token mounted into the pod. See the Kubernetes Service Account Token Guide.
Measurement and framework mapping
Track: percentage of running pods passing Restricted; containers running as UID 0; privileged containers outside exempt namespaces; containers with readOnlyRootFilesystem true; nodes with seccompDefault enabled; and age of open exemptions. Audit-mode PSA warnings and Kubernetes audit logs give the data; see the Kubernetes Audit Log Detection Guide.
| Framework | Reference | How securityContext supports it |
|---|---|---|
| NIST SP 800-53 Rev 5 | AC-6 Least Privilege; CM-6 Configuration Settings; CM-7 Least Functionality; SC-39 Process Isolation | Non-root, dropped capabilities, seccomp and enforced baselines |
| NIST CSF 2.0 | PR.PS-01 Configuration management practices are established and applied | Templated and enforced pod settings |
| MITRE ATT&CK v20 | T1611 Escape to Host; T1610 Deploy Container; T1068 Exploitation for Privilege Escalation | Restricted contexts block privileged deployment and reduce escape paths |
| NIST SP 800-190 | Application Container Security Guide | Runtime privilege and host protection recommendations |
Practitioner checklist
- Set runAsNonRoot: true with a numeric non-zero runAsUser and runAsGroup at pod level.
- Set allowPrivilegeEscalation: false and capabilities.drop: ["ALL"] on every container, including init and sidecar containers.
- Set seccompProfile.type: RuntimeDefault explicitly, and enable seccompDefault on kubelets as a backstop.
- Set readOnlyRootFilesystem: true with emptyDir mounts for writable paths.
- Use the appArmorProfile field, not annotations, and load Localhost profiles on every eligible node.
- Keep privileged and hostProcess workloads in documented, exempt namespaces only.
- Enforce Restricted with Pod Security Admission, pinned to your Kubernetes version, and add policy for readOnlyRootFilesystem.
- Re-check field names and feature states against the API reference at every cluster upgrade.
Standards and references
- Kubernetes: Configure a Security Context for a Pod or Container
- Kubernetes: core/v1 API types (release-1.37)
- Kubernetes: Pod Security Standards
- Kubernetes: Restrict a Container's Syscalls with seccomp
- Kubernetes: Restrict a Container's Access to Resources with AppArmor
- NIST: SP 800-190 Application Container Security Guide
Related NHI Mgmt Group resources: Kubernetes Security Guide · Kubernetes Pod Security Standards and Pod Security Admission Guide · Container Security Guide · Kubernetes Security Checklist