Security context and runtime controls
Security context is a runtime contract
Security context describes constraints for a Pod or individual container. A Pod-level identity can supply defaults, while a container-level value can override applicable defaults. Some settings, such as a read-only root filesystem, belong to the container. A configuration that passes admission can still fail to start when the image or runtime cannot satisfy it.
runAsNonRoot: truerunAsUser: 10001runAsGroup: 10001fsGroup: 10001seccompProfile: type: RuntimeDefaultRun as a known non-root identity
runAsNonRoot asks kubelet to reject root execution; runAsUser selects a numeric UID. The fixture chooses 10001, which must be compatible with the image and files. runAsGroup selects the primary GID, and fsGroup can help supported volume types expose group-writable files. Ownership handling depends on the volume and CSI implementation; do not assume fsGroup rewrites every mount.
runAsNonRoot: truerunAsUser: 10001runAsGroup: 10001fsGroup: 10001Capabilities, escalation and seccomp
Capabilities divide certain Linux privileges into smaller pieces. Drop unnecessary privileges; this catalog needs none. allowPrivilegeEscalation false limits acquiring additional privilege via execution. Seccomp restricts system calls, and RuntimeDefault selects a runtime-supplied profile whose details can vary. These controls are complementary rather than interchangeable. The Linux-specific assumptions here do not automatically apply to Windows.
allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truecapabilities: drop: - ALLRead-only root with explicit writable scratch
A catalog that writes temporary files should not require an entirely writable image filesystem. Mount a bounded emptyDir at /tmp, keep the root filesystem read-only, and check that the runtime UID can write the mount. The data disappears when the Pod is removed. Read-only root is an additional hardening choice, not a universal Restricted PSS requirement. The size limit does not promise reserved disk capacity.
volumeMounts:- name: scratch mountPath: /tmpvolumes:- name: scratch emptyDir: sizeLimit: 16MiAppArmor and SELinux
These Linux mechanisms add mandatory access constraints beyond ordinary ownership permissions. AppArmor profiles restrict program access using policy rules; SELinux uses labels and policy decisions. Confirm node OS, kernel support, runtime and installed profiles before specifying them. A missing profile or incompatible volume label can prevent startup. Investigate logs and correct the intended profile or application behavior rather than disabling protection.
node/runtime support → profile availability → admitted specification → runtime evidenceVerify actual behavior
For the optional authorized lab, first review the image and its UID contract. Verify the approved application can write only its intended scratch directory and can read required configuration. Inspect runtime status and bounded application diagnostics. Do not execute arbitrary commands in real workloads. Offline fixtures only reason about expected writes; they cannot confirm kernel enforcement.
expected: /tmp/cache writableexpected: /app/config read-onlyactual: unknown until tested in approved runtimeCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Security context and runtime controls — knowledge check
Interpret synthetic workload security evidence.
Which field makes the root filesystem read-only?
What does RuntimeDefault select?
What is a suitable writable scratch mount for this fixture?
Does Restricted require a read-only root filesystem?
What proves actual runtime enforcement?