PodSecurityPolicy permits sharing the host network namespace

A policy permitting host networking can weaken network isolation between Pods and the node.

Description

In a legacy PSP, hostNetwork: true lets a Pod that requests it share the node’s network interfaces and port space.

Potential impact

The Pod can reach node-local services or conflict with a port already in use. How NetworkPolicy applies to host-networked Pods depends on the network plugin.

Remediation

Set hostNetwork: false in the legacy PSP and use the Pod network for ordinary workloads. Reserve exceptions for essential system workloads and review hostPorts, hostIPC, hostPID and privileged mode.

Examples

Only the host networking setting changes in the excerpts. Kubernetes deprecated PSP in 1.21 and removed it in 1.25. On current clusters, enforce the restriction with Pod Security Admission or another policy. Test required service connectivity under the actual firewall rules and NetworkPolicies.

Before

yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: privileged
spec:
  hostNetwork: true

After

yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: privileged
spec:
  hostNetwork: false

References