Back to Checks
kubernetes

Pod does not use HostPorts

core_minimize_admission_hostport_containers
Service: coreSeverity: high
OfficialBuilt-inVerified
Categories:internet-exposedtrust-boundaries
Resource Type:Pod

Kubernetes Pods are inspected for any container declaring ports[].hostPort. The finding highlights workloads that bind container ports directly to the node's network stack via HostPorts.

Risk

Using HostPorts exposes Pods on node IPs outside centralized Service/Ingress controls. Attackers can directly probe and access workloads (confidentiality/integrity). Port conflicts or saturation on nodes can disrupt traffic (availability). Network segmentation and some policies may be less effective.

Run this check with Prowler

Run in Prowler Cloud
Run
prowler kubernetes --checks core_minimize_admission_hostport_containers

Recommendation

Avoid hostPort; publish services via ClusterIP with Ingress/LoadBalancer. Enforce admission policies to deny hostPort by default, permitting only a narrowly justified allowlist. Apply least privilege network rules, segment nodes, and monitor for unexpected host port bindings as defense in depth.

Remediation

Terraform

resource "kubernetes_pod" "<example_resource_name>" {
  metadata { name = "<example_resource_name>" }
  spec {
    container {
      name  = "<example_resource_name>"
      image = "nginx"
      # Critical: do NOT set host_port; omitting it ensures no host port is used
      port { container_port = 80 }
    }
  }
}

Other

1Open your Kubernetes Dashboard and go to Workloads
2Select the affected Deployment/DaemonSet/StatefulSet (or Pod) and click Edit
3In the YAML, remove every `hostPort` field under `spec.template.spec.containers[].ports[]` (or `spec.containers[]` for a standalone Pod)
4Save the changes; allow the workload to restart
5Verify the new Pods have no `hostPort` defined

Check Code

from prowler.lib.check.models import Check, Check_Report_Kubernetes
from prowler.providers.kubernetes.services.core.core_client import core_client


class core_minimize_admission_hostport_containers(Check):
    def execute(self) -> Check_Report_Kubernetes:
        findings = []
        for pod in core_client.pods.values():
            report = Check_Report_Kubernetes(metadata=self.metadata(), resource=pod)
            report.status = "PASS"
            report.status_extended = f"Pod {pod.name} does not use HostPorts."

            for container in pod.containers.values():
                if container.ports and "host_port" in str(container.ports):
                    report.status = "FAIL"
                    report.status_extended = (
                        f"Pod {pod.name} uses HostPorts in container {container.name}."
                    )
                    break

            findings.append(report)

        return findings