More Info:
HostPorts bind container ports directly to the node, bypassing network policy and exposing services on the host. Restrict their use.Risk Level
MediumAddress
SecurityCompliance Standards
- CIS Kubernetes
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
Identify current workloads using
hostPort- Run on: any machine with
kubectlaccess - Command:
- Save/record this list as the baseline of current
hostPortusage.
- Run on: any machine with
-
Review each identified pod’s necessity for
hostPort- For each
NAMESPACE/PODfrom step 1: - Manually inspect:
- Which containers/ports use
hostPortand on which nodes. - Whether they front internet-facing or sensitive services.
- Whether equivalent access could be provided via ClusterIP/LoadBalancer/Ingress instead of
hostPort.
- Which containers/ports use
- Decide for each: “required (documented justification)” or “can be removed/avoided”.
- For each
-
Review and design Pod Security / admission policy per namespace
- For each namespace that runs user workloads (and especially those with unjustified
hostPortuse):- If using built-in Pod Security Admission, check labels:
- Assess whether the effective Pod Security level (e.g.,
baseline,restricted) and any custom admission policies already limithostPort.
- Assess whether the effective Pod Security level (e.g.,
- If using another admission controller (e.g., Kyverno, OPA Gatekeeper), list policies that affect
hostPortin that namespace using your policy tool (no generickubectlcommand exists; follow your policy system’s CLI/docs).
- If using built-in Pod Security Admission, check labels:
- For each namespace that runs user workloads (and especially those with unjustified
-
Implement or tighten admission policy to restrict
hostPort- Decide per namespace:
- Namespaces where
hostPortshould be disallowed except for cluster-operator-approved workloads. - Namespaces where
hostPortis temporarily allowed but must be minimized.
- Namespaces where
- Apply or update your admission policy mechanism accordingly (Pod Security Admission level, Kyverno/Gatekeeper rules, or other). Document any namespace-specific exceptions and which service accounts / labels are allowed to use
hostPort. - This step is policy- and environment-specific; there is no single
kubectlcommand that enforces it generically.
- Decide per namespace:
-
Refactor or remove non-essential
hostPortusage- For pods marked “can be removed/avoided” in step 2:
- Update their Deployment/DaemonSet/StatefulSet/Pod manifests (in Git/IaC or via
kubectl editif appropriate) to removehostPortfields and use Services/Ingress instead. - Reapply manifests using your standard deployment process, for example:
- Update their Deployment/DaemonSet/StatefulSet/Pod manifests (in Git/IaC or via
- Ensure any required firewall or ingress changes are made so functionality is preserved without
hostPort.
- For pods marked “can be removed/avoided” in step 2:
-
Verify minimized
hostPortusage and effective restriction- Re-run the discovery from step 1:
- Confirm that:
- Only the few, explicitly justified workloads still appear.
- Creating a test pod with
hostPortin a restricted namespace is rejected by admission (use a small test manifest andkubectl apply -f test-hostport.yamlto confirm it is denied).
- Re-run the discovery from step 1:
Using kubectl
Using kubectl
Any line of output means that pod uses at least one
hostPort. Each such pod must be manually reviewed to decide if hostPort is justified.Look for:
- Unnecessary
hostPortuse (e.g.,80,443,22, or wide port ranges) where a Service/Ingress/LoadBalancer would suffice. hostPorton multi-tenant or shared nodes.
Any such cases are candidates for remediation.
If you see NetworkPolicies that appear to “lock down” traffic but many workloads use
hostPort, be aware that those policies do not protect the host-bound ports. This is an architectural risk to review.Namespaces appearing in “Namespaces with pods” but lacking any security/admission-related policy (and that also contain pods using
hostPort from step 1/2) should be prioritized for adding policy to restrict hostPort usage.If a namespace is intended to be “locked down” or multi-tenant but this output shows many pods with
hostPort, the risk is higher and manual remediation is recommended (redesign to use Services, adjust placement, or introduce admission policy).Automation
Automation
- Any line where
HOST_PORT(for Pods or workloads) is a non-zero value indicates a potential policy violation that must be reviewed. - Pay particular attention to:
- User/application namespaces (e.g., not
kube-system,kube-public,kube-node-lease). - HostPorts exposed on broad or privileged workloads (e.g., internet-facing services, DaemonSets).
- User/application namespaces (e.g., not
- Namespaces with non-zero
COUNTin the summary should have admission policies (e.g., Pod Security Admission or Admission Webhooks) evaluated or added to restrict or justify hostPort usage.

