Overview
Pod Security Policy (PSP) was a cluster-level admission controller that allowed you to define conditions a pod must meet in order to run in the cluster. It not only blocked non-compliant pods from being created but also could mutate pod configurations usingdefaultAddCapabilities.
To enable PSP, add PodSecurityPolicy to the --enable-admission-plugins flag on the kube-apiserver:
kube-apiserver.yaml
Usage and concept
Consider the following insecure pod configuration:sample-pod.yaml
CAP_SYS_BOOT capability (which allows rebooting the host), and mounts the host filesystem — all of which are insecure configurations.
Create a Pod Security Policy
Define a PSP to block the insecure configurations above:This policy:
pod-security-policy.yaml
- Rejects pods with
privileged: true - Rejects pods running as
runAsUser: 0(root) - Rejects pods using
hostPathvolumes (onlypersistentVolumeClaimis permitted) - Rejects pods with the
CAP_SYS_BOOTcapability - Adds
CAP_SYS_TIMEto all pods by default, even if not specified
Authorize the Pod Security Policy with RBAC
Enabling the PSP admission controller alone is not enough. Without authorizing service accounts to use a PSP, the admission controller cannot communicate with the security policies API and will reject all pod creation requests.Every pod has a service account (defaulting to
default in the namespace). Create a Role and RoleBinding to let the default service account use the PSP:- Role
- RoleBinding
role.yaml