pod-dns-policy
ClusterFirstWithHostNet pairs cluster DNS with host networking, so a workload that already bypasses pod network isolation can still resolve and reach every internal cluster service by name.
!has(object.spec.dnsPolicy) || object.spec.dnsPolicy != "ClusterFirstWithHostNet"
spec.dnsPolicy must not be set to ClusterFirstWithHostNet.
Set spec.dnsPolicy to ClusterFirst or Default and run the workload on the pod network. Field: spec.dnsPolicy.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-dns-policy
annotations:
kubeapt.io/uuid: "cfbd76cd-b41a-4146-a2dd-1d08e125f7a4"
security.kubeapt.io/displayName: "Uses ClusterFirstWithHostNet DNS Policy"
security.kubeapt.io/description: "ClusterFirstWithHostNet pairs cluster DNS with host networking, so a workload that already bypasses pod network isolation can still resolve and reach every internal cluster service by name."
security.kubeapt.io/resource: "Pods"
security.kubeapt.io/severity: "Low"
security.kubeapt.io/remediation: "Set spec.dnsPolicy to ClusterFirst or Default and run the workload on the pod network. Field: spec.dnsPolicy."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods
validations:
- expression: |
!has(object.spec.dnsPolicy) || object.spec.dnsPolicy != "ClusterFirstWithHostNet"
message: |
spec.dnsPolicy must not be set to ClusterFirstWithHostNet.Save it as pod-dns-policy.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-dns-policy.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-dns-policy -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-dns-policy -A