PodSecurityPolicy permits privilege escalation

A PodSecurityPolicy that permits privilege escalation does not restrict gaining additional permissions through executable files.

Description

A legacy PSP with allowPrivilegeEscalation: true permits a Linux container to gain privileges when executing a program with setuid, setgid or file capabilities.

Potential impact

The permissions attached to an executable can let a process exceed its original privileges.

Remediation

Set allowPrivilegeEscalation: false in the PSP and workload. Remove privileged mode and SYS_ADMIN, and minimize permissions already granted. Kubernetes deprecated PSP in 1.21 and removed it in 1.25. On current clusters, enforce the Restricted Pod Security Standard or an equivalent admission policy.

Examples

The excerpts switch off both privileged and allowPrivilegeEscalation. Check that another applicable policy cannot allow them, and test applications that previously relied on setuid behavior.

Before

yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: privileged
spec:
  privileged: true
  allowPrivilegeEscalation: true

After

yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: privileged
spec:
  privileged: false
  allowPrivilegeEscalation: false

References