container-capabilities-drop-all
A 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.
(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.capabilities) &&
has(c.securityContext.capabilities.drop) &&
c.securityContext.capabilities.drop.exists(d, d == "ALL")
)
spec.containers[*].securityContext.capabilities.drop must exist and include "ALL".
Add ALL to the dropped capability list and re-add only the specific capabilities the workload actually needs. Field: spec.containers[*].securityContext.capabilities.drop.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: container-capabilities-drop-all
annotations:
kubeapt.io/uuid: "744e7415-e0dd-4f4c-89ad-4594f734b8b9"
security.kubeapt.io/displayName: "Retains Default Linux Capabilities"
security.kubeapt.io/description: "A 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: "Containers"
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.containers[*].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") ||
object.spec.containers.all(c,
has(c.securityContext) &&
has(c.securityContext.capabilities) &&
has(c.securityContext.capabilities.drop) &&
c.securityContext.capabilities.drop.exists(d, d == "ALL")
)
message: |
spec.containers[*].securityContext.capabilities.drop must exist and include "ALL".Save it as container-capabilities-drop-all.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./container-capabilities-drop-all.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name container-capabilities-drop-all -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name container-capabilities-drop-all -A