← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Permits Privilege Escalation

container-privilege-escalation

severityHigh resourceContainers productKubernetes bundles2

Leaving privilege escalation enabled lets a process in the container gain more privileges than its parent through setuid binaries or file capabilities, turning a compromised unprivileged process into root inside the container.

Rejects unless

(has(object.spec.os) &&
 has(object.spec.os.name) &&
 object.spec.os.name.lowerAscii() == "windows") ||
object.spec.containers.all(c,
  has(c.securityContext) &&
  has(c.securityContext.allowPrivilegeEscalation) &&
  c.securityContext.allowPrivilegeEscalation == false
)

spec.containers[*].securityContext.allowPrivilegeEscalation must be set to false.

Remediation

Set allowPrivilegeEscalation to false in the security context of every container. The field must be present explicitly, since omitting it also fails. Field: spec.containers[*].securityContext.allowPrivilegeEscalation.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: container-privilege-escalation
  annotations:
    kubeapt.io/uuid: "e7d47f8e-5007-45a8-b664-f21877f31e74"
    security.kubeapt.io/displayName: "Permits Privilege Escalation"
    security.kubeapt.io/description: "Leaving privilege escalation enabled lets a process in the container gain more privileges than its parent through setuid binaries or file capabilities, turning a compromised unprivileged process into root inside the container."
    security.kubeapt.io/resource: "Containers"
    security.kubeapt.io/severity: "High"
    security.kubeapt.io/remediation: "Set allowPrivilegeEscalation to false in the security context of every container. The field must be present explicitly, since omitting it also fails. Field: spec.containers[*].securityContext.allowPrivilegeEscalation."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods
  validations:
  - expression: |
      (has(object.spec.os) &&
       has(object.spec.os.name) &&
       object.spec.os.name.lowerAscii() == "windows") ||
      object.spec.containers.all(c,
        has(c.securityContext) &&
        has(c.securityContext.allowPrivilegeEscalation) &&
        c.securityContext.allowPrivilegeEscalation == false
      )
    message: |
      spec.containers[*].securityContext.allowPrivilegeEscalation must be set to false.

Save it as container-privilege-escalation.yaml — the commands below assume that name.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./container-privilege-escalation.yaml -r ./workload.yaml

Or without the file, from the published policy set — -r takes a directory too:

$ kubeapt policies download && kubeapt validate --policy-name container-privilege-escalation -r ./manifests

Or against every namespace in the cluster your kubeconfig points at:

$ kubeapt validate --policy-name container-privilege-escalation -A