Join our Newsletter — 33% off our NHI Course
Home› Guides› Kubernetes Pod Security Context Reference: Every Field, Safe…
Guide Cloud Security

Kubernetes Pod Security Context Reference: Every Field, Safe Value and Risk

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 12 min read
On this page

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.

FieldLevelDocumented default if unsetSafe valueRisk if unset or unsafe
runAsNonRootPod, containerNo validationtrueAn image whose user is UID 0 starts as root; with true the kubelet refuses to start it
runAsUserPod, containerUser from image metadataA fixed non-zero UID, for example 10001Image changes silently change the runtime identity; Restricted forbids 0
runAsGroupPod, containerRuntime default (primary GID 0 per the task docs)A fixed non-zero GIDFiles written by the process are group-owned by root
supplementalGroupsPodNo extra groupsOnly the groups the workload needsUnneeded group access to shared volumes
supplementalGroupsPolicyPodMergeStrict where supportedMerge adds group memberships from the image's /etc/group, which the manifest does not show
fsGroupPodVolume ownership not changedThe workload's GID when it writes to volumesWorkloads fail on volumes, then teams fall back to running as root
fsGroupChangePolicyPodAlwaysOnRootMismatch for large volumesSlow starts on large volumes from recursive ownership changes (performance rather than security)
sysctlsPodNoneOnly names on the Baseline safe listUnsafe sysctls can affect other pods on the node
seccompProfilePod, containerUnconfined, unless kubelet seccompDefault is enabledtype: RuntimeDefault, or Localhost with a tested profileFull kernel syscall surface available to a compromised process
appArmorProfilePod, containerApplied only if AppArmor is enabled on the nodetype: RuntimeDefault or LocalhostUnconfined removes mandatory access control on file and capability use
seLinuxOptionsPod, containerRuntime allocates a random SELinux context per containerLeave unset, or a type allowed by Baseline (container_t and related)Custom user, role or type values (for example spc_t) bypass container confinement
seLinuxChangePolicyPodMountOptionMountOption unless pods with different labels share a volumeMixed policies on a shared volume can leave pods stuck in ContainerCreating
privilegedContainerfalsefalse (omit)Essentially root on the host
allowPrivilegeEscalationContainerno_new_privs not setfalsesetuid binaries and file capabilities can raise privileges inside the container
capabilitiesContainerRuntime's default capability setdrop: ["ALL"], add only NET_BIND_SERVICE if neededThe runtime default set grants capabilities most applications never use, widening what a compromised process can do
readOnlyRootFilesystemContainerfalsetrue, with emptyDir mounts for writable pathsAn attacker can write tools or modify binaries in the container filesystem
procMountContainerDefault (runtime masked and read-only paths)DefaultUnmasked exposes /proc and /sys/firmware read-write; requires hostUsers: false
windowsOptionsPod, containerContainer value, else pod valuehostProcess unset or falseSee 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.

Sample 1
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

FieldTypes and valuesVersion notes (as documented)Operational note
seccompProfile.typeRuntimeDefault, Localhost (with localhostProfile), UnconfinedField stable since v1.19; kubelet seccompDefault stable since v1.27Localhost paths are relative to the kubelet's seccomp directory. Privileged containers always run Unconfined
appArmorProfile.typeRuntimeDefault, Localhost (with localhostProfile), UnconfinedField introduced in v1.30, replacing the beta annotations; stable since v1.31An explicitly set profile that is not loaded on the node leaves the pod Pending; Kubernetes does not load profiles onto nodes
seLinuxOptionsuser, role, type, levelBaseline allows type container_t, container_init_t, container_kvm_t, container_engine_t (since v1.31); user and role must be emptyOnly effective on SELinux-enabled nodes
seLinuxChangePolicyMountOption (default), RecursiveSELinuxChangePolicy feature gate GA in v1.36Use 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.

FieldBaselineRestricted
windowsOptions.hostProcessUnset or falseUnset or false
privilegedUnset or falseUnset or false
capabilities.addBaseline list onlyUnset or NET_BIND_SERVICE
capabilities.dropNot checkedMust include ALL
appArmorProfile.typeUnset, RuntimeDefault or LocalhostSame as Baseline
seLinuxOptionsAllowed types only; no user or roleSame as Baseline
procMountUnset or DefaultUnset or Default
seccompProfile.typeMust not be UnconfinedMust be RuntimeDefault or Localhost (unset is rejected)
sysctlsSafe list onlySafe list only
allowPrivilegeEscalationNot checkedfalse
runAsNonRootNot checkedtrue (pod or every container)
runAsUserNot checkedMust not be 0
readOnlyRootFilesystem, runAsGroup, fsGroupNot checkedNot 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

  1. 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.
  2. Fix images first: build images with a numeric non-root USER and writable paths under a known directory; this removes most runAsNonRoot failures.
  3. Set defaults in templates: add the pod and container securityContext block to Helm charts and base manifests, including init containers.
  4. Enable seccompDefault on kubelets in a canary node pool, watch for syscall-related crashes, then roll out.
  5. Add readOnlyRootFilesystem per workload with emptyDir mounts, tested in staging.
  6. 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.
  7. 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.

FrameworkReferenceHow securityContext supports it
NIST SP 800-53 Rev 5AC-6 Least Privilege; CM-6 Configuration Settings; CM-7 Least Functionality; SC-39 Process IsolationNon-root, dropped capabilities, seccomp and enforced baselines
NIST CSF 2.0PR.PS-01 Configuration management practices are established and appliedTemplated and enforced pod settings
MITRE ATT&CK v20T1611 Escape to Host; T1610 Deploy Container; T1068 Exploitation for Privilege EscalationRestricted contexts block privileged deployment and reduce escape paths
NIST SP 800-190Application Container Security GuideRuntime 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

Related NHI Mgmt Group resources: Kubernetes Security Guide · Kubernetes Pod Security Standards and Pod Security Admission Guide · Container Security Guide · Kubernetes Security Checklist

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.