Skip to main content

More Info:

Do not generally permit containers to be run with the hostNetwork flag set to true.

Risk Level

High

Address

Security

Compliance Standards

  • CIS Kubernetes

Triage and Remediation

Remediation

Manual Steps

  1. List pods using hostNetwork (discovery)
    Run on: any machine with kubectl access
  2. Identify user workload namespaces that allow hostNetwork (review)
    Run on: any machine with kubectl access
    Review which of the above pods are in user workload namespaces (exclude kube-system and other control-plane/system namespaces). For each user namespace you decide should not allow hostNetwork, proceed to the next step. For namespaces that legitimately need hostNetwork (e.g., CNI, ingress), document the exception instead of applying the restriction.
  3. Create a baseline admission policy to deny hostNetwork (example Kyverno)
    Run on: any machine with kubectl access
    If you use Kyverno, create a ClusterPolicy denying hostNetwork for pods in selected namespaces (replace <NAMESPACE1>,<NAMESPACE2> with a comma‑separated list of target namespaces):
    Adapt the tool and syntax to your existing admission controller (e.g., OPA Gatekeeper, ValidatingAdmissionPolicy) but keep the same intent: match Pods in selected namespaces and deny when spec.hostNetwork == true.
  4. Handle existing hostNetwork pods in restricted namespaces (migration)
    Run on: any machine with kubectl access
    For each affected namespace from step 2, list existing hostNetwork pods again and plan replacement without hostNetwork:
    For each listed workload (Deployment/DaemonSet/StatefulSet/Job, etc.), edit its manifest to remove or set hostNetwork: false under spec.template.spec, then apply:
    Replace pods created directly (not via controllers) by deleting and recreating them with hostNetwork disabled.
  5. Optionally scope exceptions per-namespace (refine policy)
    Run on: any machine with kubectl access
    For namespaces where specific workloads must use hostNetwork, narrow your policy instead of blanket denying the namespace. Example Kyverno rule that allows hostNetwork only for pods with a specific label:
    Then explicitly label exception pods/workloads:
  6. Verification (re-run the audit with expectation)
    Run on: any machine with kubectl access
    Re-run the audit and confirm no pods with spec.hostNetwork=true exist in namespaces where you applied restrictions:
    For user namespaces meant to be restricted, ensure all lines show is_pod_hostnetwork: false and is_compliant: true; any remaining non-compliant pods should be investigated or migrated.

Additional Reading: