HostPath restrictions need review in PodSecurityPolicy

Allow essential hostPath access only through narrow paths and minimal permissions.

Description

If a legacy PSP permits hostPath in volumes, use allowedHostPaths to limit the node paths Pods may mount and whether they must mount them read-only.

Potential impact

Even read-only access can expose sensitive node files. Writable mounts can allow changes to node configuration or other workloads’ files.

Remediation

Prefer workload storage over hostPath. For a necessary exception, allow only the required path and require readOnly: true unless writes are essential. Check actual Pod mounts, file permissions and other policies the workload may use.

Examples

The excerpts change /dev, which permits writable mounts, to read-only /foo. Kubernetes deprecated PSP in 1.21 and removed it in 1.25. Baseline and Restricted prohibit all hostPath mounts. For an essential exception, isolate the workload in a dedicated namespace outside that blanket restriction, then enforce the approved path and read-only mounts there with a separate admission policy.

Before

yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: example
spec:
  allowedHostPaths:
    - pathPrefix: /dev
      readOnly: false

After

yaml
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: example
spec:
  allowedHostPaths:
    - pathPrefix: /foo
      readOnly: true

References