← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Retains Default Linux Capabilities

initcontainer-capabilities-drop-all

severityModerate resourceInitContainers productKubernetes bundles2

An init container that never drops ALL keeps the default runtime capability set, so code execution inside it inherits DAC_OVERRIDE, SETUID and NET_RAW for bypassing file permissions, regaining root and spoofing traffic.

Rejects unless

(has(object.spec.os) &&
 has(object.spec.os.name) &&
 object.spec.os.name.lowerAscii() == "windows") ||
!has(object.spec.initContainers) || object.spec.initContainers.all(ic,
  has(ic.securityContext) &&
  has(ic.securityContext.capabilities) &&
  has(ic.securityContext.capabilities.drop) &&
  ic.securityContext.capabilities.drop.exists(d, d == "ALL")
)

spec.initContainers[*].securityContext.capabilities.drop must exist and include "ALL".

Remediation

Add ALL to the dropped capability list and re-add only the specific capabilities the workload actually needs. Field: spec.initContainers[*].securityContext.capabilities.drop.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: initcontainer-capabilities-drop-all
  annotations:
    kubeapt.io/uuid: "53066e98-fe0f-4f71-8011-f14d6bf2aefe"
    security.kubeapt.io/displayName: "Retains Default Linux Capabilities"
    security.kubeapt.io/description: "An init container that never drops ALL keeps the default runtime capability set, so code execution inside it inherits DAC_OVERRIDE, SETUID and NET_RAW for bypassing file permissions, regaining root and spoofing traffic."
    security.kubeapt.io/resource: "InitContainers"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Add ALL to the dropped capability list and re-add only the specific capabilities the workload actually needs. Field: spec.initContainers[*].securityContext.capabilities.drop."
    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") ||
      !has(object.spec.initContainers) || object.spec.initContainers.all(ic,
        has(ic.securityContext) &&
        has(ic.securityContext.capabilities) &&
        has(ic.securityContext.capabilities.drop) &&
        ic.securityContext.capabilities.drop.exists(d, d == "ALL")
      )
    message: |
      spec.initContainers[*].securityContext.capabilities.drop must exist and include "ALL".

Save it as initcontainer-capabilities-drop-all.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 ./initcontainer-capabilities-drop-all.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 initcontainer-capabilities-drop-all -r ./manifests

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

$ kubeapt validate --policy-name initcontainer-capabilities-drop-all -A