Skip to main content

SKY-D411 · Deployment and infrastructure

Kubernetes container mounts a sensitive host path

High

A hostPath volume puts a file or folder of the node into the container. SKY-D411 reports one that mounts the node's root, its system and credential folders (/etc, /proc, /sys, /var/lib/kubelet), or the container runtime's socket such as /var/run/docker.sock.

Languages
Kubernetes YAML
Quality gate
counted toward the gate limits (full and diff scans). Reported under security (danger). It counts toward max_high and max_security; the rule never reports CRITICAL.
Finding type
review
Catalog name
Kubernetes sensitive host path mounted
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Whoever can talk to the Docker or containerd socket can start a privileged container on the node, so the mount is root on the node in one step. /etc and /var/lib/kubelet hold the node's credentials and other pods' secrets.

What Skylos flags

deploy/node-agent.yaml · YAMLReported on line 19
apiVersion: apps/v1kind: DaemonSetmetadata:  name: node-agent  namespace: monitoringspec:  selector:    matchLabels:      app: node-agent  template:    metadata:      labels:        app: node-agent    spec:      containers:        - name: agent          image: registry.example.com/node-agent:2.4.1          volumeMounts:            - name: docker-sock              mountPath: /var/run/docker.sock      volumes:        - name: docker-sock          hostPath:            path: /var/run/docker.sock            type: Socket

What Skylos leaves alone

deploy/node-agent.yaml · YAML
apiVersion: apps/v1kind: DaemonSetmetadata:  name: node-agent  namespace: monitoringspec:  selector:    matchLabels:      app: node-agent  template:    metadata:      labels:        app: node-agent    spec:      containers:        - name: agent          image: registry.example.com/node-agent:2.4.1          volumeMounts:            - name: logs              mountPath: /var/log              readOnly: true      volumes:        - name: logs          hostPath:            path: /var/log

Why Skylos leaves it alone

A log collector that mounts the node's /var/log is a common and narrower hostPath. /var/log is not on the list of sensitive paths.

How Skylos decides

  1. Runs with --danger (or -a). Reads every .yaml and .yml file that declares an apiVersion and a kind, skipping .git, node_modules, build and virtual-environment folders. It never renders Helm templates or Kustomize overlays and never contacts a cluster.
  2. Checks the pod spec of Pod, PodTemplate, ReplicationController, Deployment, DaemonSet, ReplicaSet, StatefulSet, Job and CronJob, including items of a v1 List. Values containing template markers such as {{ or ${ are treated as unknown and never reported.
  3. For each volumeMounts entry of each container, finds the pod volume with the same name. Only hostPath volumes count.
  4. Works out the host path that is really mounted, including a subPath. A path with a template marker, .., a subPathExpr or a volume name used twice is not judged.
  5. Reports /, any path inside or above /etc, /proc, /sys and /var/lib/kubelet (so /var/lib counts too), and the Docker, containerd, CRI-O, cri-dockerd, dockershim, k3s and Podman sockets under /run or /var/run, or a folder that holds one.
  6. Reports HIGH on the volume mount entry. readOnly: true does not remove the finding: a read-only socket still accepts API calls.

How to fix it

Do not give workloads the runtime socket. Build images in CI or with a rootless builder, read container data through the Kubernetes API, and mount only the narrow paths an agent needs, read-only.

deploy/node-agent.yaml · YAML · the fix, against the flagged file
apiVersion: apps/v1kind: DaemonSetmetadata:  name: node-agent  namespace: monitoringspec:  selector:    matchLabels:      app: node-agent  template:    metadata:      labels:        app: node-agent    spec:      containers:        - name: agent          image: registry.example.com/node-agent:2.4.1          volumeMounts:Removed:             - name: docker-sockRemoved:               mountPath: /var/run/docker.sockAdded:             - name: logsAdded:               mountPath: /var/logAdded:               readOnly: true      volumes:Removed:         - name: docker-sockAdded:         - name: logs          hostPath:Removed:             path: /var/run/docker.sockRemoved:             type: SocketAdded:             path: /var/log

When it can be wrong

  • Node agents such as log shippers that read /var/lib/docker containers or monitoring agents that read /proc are reported. Accept reviewed ones with a baseline.
  • volumeDevices (raw block devices) are not judged.
  • Helm chart templates are not rendered. A value written as {{ .Values.x }} is not judged, and a template file that is not valid YAML on its own (most are not) stops the scan as incomplete, exit 2, with a Kubernetes parse error. Exclude the chart's templates folder and scan the output of helm template instead.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • The Kubernetes rules read no inline marker: # skylos: ignore[SKY-D411] on the reported mount does not hide the finding.

  • [tool.skylos] ignore = ["SKY-D411"] turns the rule off for the project.

  • A baseline (skylos baseline ., then --baseline) accepts the workloads that exist today and reports new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.