← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Uses an Unmasked /proc Mount

ephemeralcontainer-procmount

severityHigh resourceEphemeralContainers productKubernetes bundles2

An unmasked /proc strips the default masks and read-only paths the runtime applies, exposing kernel memory and tunables such as /proc/kcore and /proc/sys to the ephemeral container and easing container escape.

Rejects unless

!has(object.spec.ephemeralContainers) || object.spec.ephemeralContainers.all(ec,
  !has(ec.securityContext) ||
  !has(ec.securityContext.procMount) ||
  ec.securityContext.procMount == "Default"
)

spec.ephemeralContainers[*].securityContext.procMount must be undefined or "Default".

Remediation

Remove securityContext.procMount from every ephemeral container or set it back to Default instead of Unmasked. Field: spec.ephemeralContainers[*].securityContext.procMount.

Applies to

  • pods/ephemeralcontainers · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: ephemeralcontainer-procmount
  annotations:
    kubeapt.io/uuid: "eb9b7ab0-8488-46a7-83d6-7ad706ec9901"
    security.kubeapt.io/displayName: "Uses an Unmasked /proc Mount"
    security.kubeapt.io/description: "An unmasked /proc strips the default masks and read-only paths the runtime applies, exposing kernel memory and tunables such as /proc/kcore and /proc/sys to the ephemeral container and easing container escape."
    security.kubeapt.io/resource: "EphemeralContainers"
    security.kubeapt.io/severity: "High"
    security.kubeapt.io/remediation: "Remove securityContext.procMount from every ephemeral container or set it back to Default instead of Unmasked. Field: spec.ephemeralContainers[*].securityContext.procMount."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods/ephemeralcontainers
  validations:
  - expression: |
      !has(object.spec.ephemeralContainers) || object.spec.ephemeralContainers.all(ec,
        !has(ec.securityContext) ||
        !has(ec.securityContext.procMount) ||
        ec.securityContext.procMount == "Default"
      )
    message: |
      spec.ephemeralContainers[*].securityContext.procMount must be undefined or "Default".

Save it as ephemeralcontainer-procmount.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 ./ephemeralcontainer-procmount.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 ephemeralcontainer-procmount -r ./manifests

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

$ kubeapt validate --policy-name ephemeralcontainer-procmount -A