Sub topic 5
What the Restricted profile requires
This chapter assumes you know the Baseline profile from the previous chapter and can read a Pod securityContext. The Restricted profile is the strictest of the three Pod Security Standards. It follows current hardening practice for pods, at the cost of some compatibility with older images.
How Restricted relates to Baseline
Restricted includes every Baseline rule. A pod that uses hostNetwork or a privileged container fails Restricted for the same reasons it fails Baseline. Restricted then adds rules in five areas: volume types, privilege escalation, running as non-root, seccomp, and capabilities.
The added requirements
| Area | Field | Required value |
|---|---|---|
| Volume types | `spec.volumes[*]` | Only `configMap`, `csi`, `downwardAPI`, `emptyDir`, `ephemeral`, `persistentVolumeClaim`, `projected`, `secret` |
| Privilege escalation | `allowPrivilegeEscalation` (each container) | `false` |
| Non-root | `runAsNonRoot` (pod or each container) | `true` |
| Non-root user | `runAsUser` | Unset, or any value other than `0` |
| Seccomp | `seccompProfile.type` (pod or each container) | `RuntimeDefault` or `Localhost` |
| Capabilities | `capabilities.drop` (each container) | Must include `ALL` |
| Capabilities | `capabilities.add` | Only `NET_BIND_SERVICE` is allowed |
Volume types exclude hostPath, which Baseline already restricts for host paths, and also other types such as nfs.
Some details trip people up:
allowPrivilegeEscalationmust be set explicitly tofalse. Leaving it unset fails the check, because Kubernetes defaults it totrue.- Baseline allows an unset seccomp profile. Restricted does not, and
Unconfinedalso fails. You must set the profile yourself. runAsNonRoot: truealone is not enough if the image's user is root. The kubelet then refuses to start the container. SetrunAsUseror build the image with a numeric non-rootUSER.- Dropping
ALLand addingNET_BIND_SERVICEback is the only permitted way to bind ports below 1024.
A compliant pod
This is the pod from the topic's examples. Each field maps to a row in the table.
apiVersion: v1
kind: Pod
metadata:
name: restricted-demo
namespace: payments
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: app
image: busybox:1.36
command: ["sleep", "3600"]
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]runAsNonRoot, runAsUser, and seccompProfile sit at pod level, so every container inherits them. allowPrivilegeEscalation and capabilities exist only at container level, so each container, including init containers, needs them. A missing field in one sidecar is the most common reason a multi-container pod is rejected.
Testing a pod against Restricted
Before enforcing the profile, label a test namespace with warn and apply your manifest. The API server returns a warning that lists each failing field, for example allowPrivilegeEscalation != false or unrestricted capabilities. Fix the fields one by one until the warnings stop.
Exercise
A pod sets runAsNonRoot: true and seccompProfile.type: RuntimeDefault at pod level. Its only container sets capabilities.drop: ["ALL"] but nothing else. Does it meet Restricted? If not, what is missing?
Show answer
No. The container does not set allowPrivilegeEscalation: false. Kubernetes defaults that field to true, so the Restricted check fails. Adding allowPrivilegeEscalation: false to the container's securityContext fixes it.