← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Uses ClusterFirstWithHostNet DNS Policy

pod-dns-policy

severityLow resourcePods productKubernetes bundles1

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.

Rejects unless

!has(object.spec.dnsPolicy) || object.spec.dnsPolicy != "ClusterFirstWithHostNet"

spec.dnsPolicy must not be set to ClusterFirstWithHostNet.

Remediation

Set spec.dnsPolicy to ClusterFirst or Default and run the workload on the pod network. Field: spec.dnsPolicy.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

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.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./pod-dns-policy.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 pod-dns-policy -r ./manifests

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

$ kubeapt validate --policy-name pod-dns-policy -A