# Error: container has runAsNonRoot and image will run as root. PodSecurityPolicy: Privileged containers are not allowed. PodSecurityPolicy: allowedCapabilities is empty: drop all capabilities

- **ID:** `policy/kubernetes-psp-privileged-container-blocked`
- **Domain:** policy
- **Category:** auth_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

A PodSecurityPolicy (or OPA/Gatekeeper constraint) denies the pod because the container image requires root or privileged capabilities, conflicting with the policy's runAsNonRoot requirement and empty allowedCapabilities.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Kubernetes v1.24 (PSP deprecated, replaced by Pod Security Admission) | active | — | — |
| PodSecurityPolicy API v1beta1 | active | — | — |
| Open Policy Agent v3.0.0 | active | — | — |

## Workarounds

1. **Modify the container image to run as a non-root user by adding a USER directive in the Dockerfile:

FROM ubuntu:22.04
RUN useradd -m appuser
USER appuser
CMD ["/bin/bash"]** (90% success)
   ```
   Modify the container image to run as a non-root user by adding a USER directive in the Dockerfile:

FROM ubuntu:22.04
RUN useradd -m appuser
USER appuser
CMD ["/bin/bash"]
   ```
2. **Update the PodSecurityPolicy to allow the required capabilities or set runAsNonRoot: false if the workload truly needs root, but evaluate security implications first.** (75% success)
   ```
   Update the PodSecurityPolicy to allow the required capabilities or set runAsNonRoot: false if the workload truly needs root, but evaluate security implications first.
   ```

## Dead Ends

- **Setting 'runAsNonRoot: false' in the pod spec** — The PSP still requires runAsNonRoot: true, so the pod will be rejected again; also weakens security. (60% fail)
- **Adding 'CAP_SYS_ADMIN' to the container's capabilities** — The PSP's allowedCapabilities is empty, so any capability addition is denied. (80% fail)
- **Deleting the PodSecurityPolicy resource entirely** — In many clusters, PSP is enforced by an admission controller; deleting the policy may cause other security gaps or the cluster to reject all pods. (50% fail)
