Skip to content
Path traversal Write-up Intermediate

Kubernetes Container Escape With Hostpath Mounts

A pod with a writable HostPath volume for /var/log allows an attacker to replace the pod's log symlink with a symlink to /etc/shadow, then read the host's shadow file via kubectl logs. This gives access to sensitive host files.

Joshua Stuts Follow

Published on infosecwriteups.com

Mounting the host filesystem into a container as a volume should keep you up at night if you work with Kubernetes. Let me explain why.

Joshua Stuts, on infosecwriteups.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the pod mounts a writable HostPath volume for /var/log, allowing the container to modify the log symlink that kubelet follows when serving kubectl logs.

Impact

An attacker with the ability to create or compromise such a pod could read sensitive host files like /etc/shadow, potentially leading to further privilege escalation.

What the attacker needed

Ability to create a pod with a HostPath volume; writable HostPath mount of /var/log

The fix

HostPath volumes should be scoped to only the required directory and mounted as read-only, and access to HostPath volumes should be restricted through an admission controller.

How it was found

  1. Create a pod that mounts the host's /var/log directory as a writable volume.
  2. Replace the pod's log file symlink with a symlink to /etc/shadow.
  3. Run kubectl logs on the pod to read the contents of /etc/shadow.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Kubernetes lets containers use folders from the host machine by mounting them as 'volumes'. If that folder is writable and contains log files, an attacker inside the container can change a log file link to point at a sensitive system file, then read it through normal log commands. This means a compromised container can steal secrets from the host.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by Joshua Stuts

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.