Deny Privilege Escalation

Privilege escalation, such as via set-user-ID or set-group-ID file mode, should not be allowed.

Policy Definition

/pod-security/restricted/deny-privilege-escalation.yaml

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: deny-privilege-escalation
  annotations:
    policies.kyverno.io/category: Pod Security Standards (Restricted)
    policies.kyverno.io/description: >-
      Privilege escalation, such as via set-user-ID or set-group-ID file mode, should not be allowed.
spec:
  background: true
  validationFailureAction: audit
  rules:
  - name: deny-privilege-escalation
    match:
      resources:
        kinds:
        - Pod
    validate:
      message: >-
        Privilege escalation is disallowed. The fields
        spec.containers[*].securityContext.allowPrivilegeEscalation, and
        spec.initContainers[*].securityContext.allowPrivilegeEscalation must
        be undefined or set to `false`.
      pattern:
        spec:
          =(initContainers):
          - =(securityContext):
              =(allowPrivilegeEscalation): "false"
          containers:
          - =(securityContext):
              =(allowPrivilegeEscalation): "false"

Last modified January 2, 2021: fix titles (9a0d72f)