ephemeralcontainer-capabilities-add-netbindservice
Added capabilities other than NET_BIND_SERVICE give an ephemeral debug container kernel privileges such as raw socket access, process tracing and filesystem mounting, extending its reach past its namespace onto the node.
(has(object.spec.os) &&
has(object.spec.os.name) &&
object.spec.os.name.lowerAscii() == "windows") ||
!has(object.spec.ephemeralContainers) || object.spec.ephemeralContainers.all(ec,
!has(ec.securityContext) ||
!has(ec.securityContext.capabilities) ||
!has(ec.securityContext.capabilities.add) ||
ec.securityContext.capabilities.add.all(cap,
variables.allowedCaps.exists(a, a == cap)
)
)
spec.ephemeralContainers[*].securityContext.capabilities.add must be undefined/nil or contain only "NET_BIND_SERVICE".
allowedCaps
["NET_BIND_SERVICE"]
Remove every entry from the added capability list except NET_BIND_SERVICE, or drop the list entirely. Field: spec.ephemeralContainers[*].securityContext.capabilities.add.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: ephemeralcontainer-capabilities-add-netbindservice
annotations:
kubeapt.io/uuid: "d8cfe5f0-c5f9-4bb8-87e0-327213d313ec"
security.kubeapt.io/displayName: "Adds a Capability Other Than NET_BIND_SERVICE"
security.kubeapt.io/description: "Added capabilities other than NET_BIND_SERVICE give an ephemeral debug container kernel privileges such as raw socket access, process tracing and filesystem mounting, extending its reach past its namespace onto the node."
security.kubeapt.io/resource: "EphemeralContainers"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Remove every entry from the added capability list except NET_BIND_SERVICE, or drop the list entirely. Field: spec.ephemeralContainers[*].securityContext.capabilities.add."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods/ephemeralcontainers
variables:
- name: allowedCaps
expression: |
["NET_BIND_SERVICE"]
validations:
- expression: |
(has(object.spec.os) &&
has(object.spec.os.name) &&
object.spec.os.name.lowerAscii() == "windows") ||
!has(object.spec.ephemeralContainers) || object.spec.ephemeralContainers.all(ec,
!has(ec.securityContext) ||
!has(ec.securityContext.capabilities) ||
!has(ec.securityContext.capabilities.add) ||
ec.securityContext.capabilities.add.all(cap,
variables.allowedCaps.exists(a, a == cap)
)
)
message: |
spec.ephemeralContainers[*].securityContext.capabilities.add must be undefined/nil or contain only "NET_BIND_SERVICE".Save it as ephemeralcontainer-capabilities-add-netbindservice.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./ephemeralcontainer-capabilities-add-netbindservice.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name ephemeralcontainer-capabilities-add-netbindservice -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name ephemeralcontainer-capabilities-add-netbindservice -A