pod-hostnetwork
Host networking removes network namespace isolation, letting the workload sniff all node traffic, bind directly to node ports and reach loopback-bound node services such as the kubelet and local metadata proxies.
!has(object.spec.hostNetwork) || object.spec.hostNetwork == false
Using hostNetwork is disallowed. spec.hostNetwork must be undefined or set to false.
Remove spec.hostNetwork or set it to false and expose the workload through a Service instead. Field: spec.hostNetwork.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-hostnetwork
annotations:
kubeapt.io/uuid: "0905d194-7177-43ee-a9cd-49a5d3e10e79"
security.kubeapt.io/displayName: "Shares the Host Network Namespace"
security.kubeapt.io/description: "Host networking removes network namespace isolation, letting the workload sniff all node traffic, bind directly to node ports and reach loopback-bound node services such as the kubelet and local metadata proxies."
security.kubeapt.io/resource: "Pods"
security.kubeapt.io/severity: "High"
security.kubeapt.io/remediation: "Remove spec.hostNetwork or set it to false and expose the workload through a Service instead. Field: spec.hostNetwork."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods
validations:
- expression: |
!has(object.spec.hostNetwork) || object.spec.hostNetwork == false
message: |
Using hostNetwork is disallowed. spec.hostNetwork must be undefined or set to false.Save it as pod-hostnetwork.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./pod-hostnetwork.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name pod-hostnetwork -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-hostnetwork -A