Exercise: restricted PSA, and why one Pod is rejected
Host: controlplane · Time: 9 min · Domain: Minimize Microservice Vulnerabilities
Task
- Namespace
lockedmust enforce therestrictedPod Security Standard. - Deployments
goodandbadare provided.badis rejected; make it compliant without deleting the Deployment.
Acceptance criteria
kubectl get ns locked --show-labelsshowspod-security.kubernetes.io/enforce=restricted.kubectl run nginx --image=nginx -n lockedis refused.- Deployment
badhas 1 ready replica.
Solution
kubectl label ns locked pod-security.kubernetes.io/enforce=restricted --overwrite
kubectl apply -f bad.yaml --dry-run=server # read the exact violations
spec:
template:
spec:
securityContext:
runAsNonRoot: true
runAsUser: 2000
runAsGroup: 3000
seccompProfile: {type: RuntimeDefault}
containers:
- name: bad
image: nginxinc/nginx-unprivileged:1.27
securityContext:
allowPrivilegeEscalation: false
capabilities: {drop: ["ALL"]}
volumeMounts:
- {name: cache, mountPath: /var/cache/nginx}
- {name: run, mountPath: /var/run}
- {name: tmp, mountPath: /tmp}
volumes:
- {name: cache, emptyDir: {}}
- {name: run, emptyDir: {}}
- {name: tmp, emptyDir: {}}
--dry-run=server gives you the four violation lines: those four lines are
the answer.