Skip to content
Access control Disclosed report Intermediate

Kubelet follows symlinks as root in /var/log from the /logs server endpoint

The kubelet serves the /var/log directory via an HTTP file server and follows symlinks as root, allowing a pod with write access to /var/log to read any file on the node. An attacker could read sensitive files like /etc/shadow and potentially take over the cluster.

danielsagi Follow

Originally disclosed on HackerOne

Medium 4.0 View original
  • Triaged in 6 days
  • Disclosed after 4 months

Summary:

Privilege escalation from a pod, to root read permissions on the entire filesytem of the node, by creating symlinks inside /var/log. The kubelet is simply serving a fileserver at /var/log:

kubernetes\pkg\kubelet\kubelet.go:1371

GOLANG
if kl.logServer == nil {
		kl.logServer = http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log/")))
	}

The kubelet naturally runs as root on the node, so this basically gives the ability for pods with write permissions to /var/log directory a directory traversal as a root user on the host (potentially taking over the whole cluster by getting secret keys) An easy fix is checking the symlink destination, to figure out whether it is inside /var/lib/docker or other whitelisted paths to not break to mechanism of logs correlations

A while back, I discovered this bug, when you didn't had the Bug Bounty program. I Published the following blog: https://blog.aquasec.com/kubernetes-security-pod-escape-log-mounts Describing the vulnerability.

(it requires RBAC permissions to read logs, or a kubelet configured with AlwaysAllow. and a mount point to any child directory inside /var/log) I researched some log collectors projects in github, seems like alot of them are freely using this mount point. As a user I would not imagine those projects can potentially take clusters.

Kubernetes Version:

All versions

Component Version:

The kubelet

Steps To Reproduce:

  1. create a pod with a mount path to /var/log
  2. create a symlink in the mount point: /var/log/rootfs_symlink -> /
  3. curl from within the pod: https://<ip_of_node>:10250/logs/rootfs_symlink/etc/shadow

Supporting Material/References:

https://blog.aquasec.com/kubernetes-security-pod-escape-log-mounts https://github.com/danielsagi/kube-pod-escape

Impact

Root read permissions on the entire filesystem of the node

The original report as published on HackerOne, by danielsagi. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

How it worked

Root cause

The kubelet's log server uses http.FileServer without checking symlink destinations, so it follows symlinks outside the intended /var/log directory.

Impact

An attacker could read any file on the node as root, potentially taking over the whole cluster by obtaining secret keys.

What the attacker needed

RBAC permission to read logs or kubelet AlwaysAllow; pod with write access to /var/log

The fix

The kubelet should check symlink destinations to ensure they are inside whitelisted paths like /var/lib/docker, or otherwise prevent following symlinks outside /var/log.

How it was found

  1. Create a pod with a mount path to /var/log.
  2. Create a symlink in the mount point: /var/log/rootfs_symlink -> /.
  3. From within the pod, request the symlink path via the kubelet's /logs endpoint to read a sensitive file.

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 report has not been written yet. The Original tab links to the source.

The kubelet is a program that runs on every machine in a Kubernetes cluster and manages containers. It also provides a web service that shows log files from the /var/log folder. Because the kubelet runs with the highest permissions (root), if someone can create a shortcut (symlink) inside /var/log that points to another folder, the kubelet will follow it and show files from anywhere on the machine, even secret ones.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.