Skip to main content

More Info:

Sharing the host network namespace exposes node network interfaces and bypasses network policies. Enforce policies that restrict admission of hostNetwork containers.

Risk Level

High

Address

Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

Manual Steps

  1. Identify all pods using hostNetwork across the cluster
    • Run on: any machine with kubectl access
    • Command:
    • Review: Determine which are platform/infra components (e.g., CNI, DNS, ingress) vs. user workloads; list user workloads that use hostNetwork.
  2. Review existing admission controls / policies per namespace
    • Run on: any machine with kubectl access
    • Commands:
    • Review: For each user-workload namespace, check if there is any admission controller (e.g., OPA Gatekeeper, Kyverno, custom webhooks) or policy that explicitly restricts spec.hostNetwork: true. Note which namespaces lack such protection.
  3. Determine business/operational need for each hostNetwork pod
    • For each user-workload pod from step 1, review deployment manifests and owners:
    • Decide with application owners whether hostNetwork is truly necessary (e.g., low-latency network access, node-local ports). Document which workloads can drop hostNetwork and which must retain it.
  4. Plan and apply namespace-level admission policies to restrict hostNetwork
    • Choose or confirm your admission mechanism (e.g., Kyverno, OPA Gatekeeper, custom webhook).
    • For each user-workload namespace that should disallow hostNetwork, create/update a policy that:
      • Denies new pods (and controllers: Deployments, DaemonSets, etc.) with spec.hostNetwork: true, except for explicitly allowed labels/namespaces.
    • Apply policy manifests from any machine with kubectl access:
    • Ensure policies are scoped per-namespace as required by your governance.
  5. Refactor or reconfigure existing workloads to stop using hostNetwork where possible
    • For each pod that does not strictly require hostNetwork:
      • Update the workload manifest (Deployment/StatefulSet/DaemonSet/etc.) to remove or set hostNetwork: false.
    • Apply the updated manifest from any machine with kubectl access:
    • Coordinate with application teams and schedule changes to avoid disruption; be aware that networking behavior (ports, policies, source IPs) will change.
  6. Verify effectiveness of policies and remaining hostNetwork usage
    • Confirm that new hostNetwork pods are blocked in protected namespaces (expect admission denial):
    • Re-run the audit query to ensure only justified workloads use hostNetwork:
    • Confirm that any remaining hostNetwork pods are documented, approved exceptions and that corresponding namespaces still have admission policies in place.

Using kubectl

1. List pods that request hostNetwork

Run on: any machine with kubectl access.
Problem indication: Any line returned (namespace/name with HOSTNETWORK = true) is using the host network and must be reviewed for necessity and risk.To see details for a specific pod:
Review .spec.hostNetwork: true and the pod’s purpose.

2. Discover whether pod security controls exist

a. Pod Security admission labels on namespaces (if using built-in PSA)
Problem indication: Namespaces with user workloads that lack any pod-security.kubernetes.io/* labels, or are labeled with an overly-permissive level (e.g., privileged) likely do not restrict hostNetwork.Check a specific namespace:
Inspect metadata.labels for pod-security.kubernetes.io/enforce (or audit/warn). Levels restricted/baseline are stricter; privileged means essentially unrestricted.
b. PodSecurityPolicy (legacy clusters only)Check if PSP is enabled and list existing policies:
If PSPs exist, inspect them:
Problem indication: Policies that apply to user workloads (via RBAC bindings) and allow hostNetwork: true without clear justification or scoping. In a PSP YAML, look at:
This indicates the policy permits host networking.
c. Admission webhooks / OPA / Gatekeeper / Kyverno (if used)List all Mutating/ValidatingWebhookConfigurations:
Inspect each security-related webhook:
Problem indication: No webhook configurations that reference policies about spec.hostNetwork, or policy engines (OPA Gatekeeper, Kyverno, etc.) installed without any constraints/policies targeting hostNetwork. You will need to review the webhook/policy definitions themselves (in the policy engine’s CRDs) to determine whether hostNetwork is restricted.

3. Verify after policy decisions

After you adjust policies (outside the scope of kubectl alone), re-run:
If any HOSTNETWORK=true pods remain, they should be explicitly approved exceptions; otherwise, they indicate a remaining policy gap.