kubernetes: "/dev/termination-log must have noexec so unpriviledged user cannot exec from it"
What happened?
An unprivileged process/user running inside of a pod is able to write to /dev/termination-log file.
I thought this was preventable with both pod/container securityContext but that didn’t turn out to be the case.
I didn’t test it till the end but I tried redirecting the output of /dev/urandom from within the container to /dev/termination-log and filled it with gibberish until it reached the size of 2GB.
I suspect this is a way to compromise/crash node.
Is this an exploitable scenario and what can be done to mount the termination log in a way that doesn’t allow unprivileged user/process to write arbitrary stuff to it?
What did you expect to happen?
Permissions to be denied when attempting to write /dev/termination-log file.
How can we reproduce it (as minimally and precisely as possible)?
Exec pod container with maximally unprivileged securityContext and write /dev/termination-log file with:
cat /dev/urandom > /dev/termination-log
Anything else we need to know?
No response
Kubernetes version
Any
Cloud provider
N/A
OS version
Any
Install tools
N/A
Container runtime (CRI) and version (if applicable)
N/A
Related plugins (CNI, CSI, …) and versions (if applicable)
N/A
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (13 by maintainers)
Right, I agree you’ve found a bug - and we should include this file in the ephemeral quota calculation. I was trying to say we don’t need a radically new mechanism here, and the implication is a DoS not compromise.
@identw thanks for the detailed investigation. Yes, if /dev/termination-log is not monitored by kubelet then GC won’t remove it.
We have https://github.com/kubernetes/kubernetes/issues/122224 which if solved should solve the DDOS approach.
That issue is looking for an owner if you are interested.
Hi @anguslees I attempted to work with the ephemeral-storage quota. I’m afraid this isn’t a solution.
For instance, I deployed this Deployment:
If I run
dd if=/dev/urandom of=/app/violation_quota bs=1M count=1024, then kubelet will evict this pod (error: Pod ephemeral local storage usage exceeds the total limit of containers 1Mi). This is the correct behavior.However, when I run
dd if=/dev/urandom of=/dev/termination-log bs=1M count=1024kubelet doesn’t take any action. Instead, I observe filled space on the worker node:If I run
dd if=/dev/urandom of=/dev/termination-log bs=1M(without the count), the node’s disk will fill up to approximately 90% until the kubelet sends an eviction signal because the node needs to resolve the DiskPressure status. However, kubelet’s GC will not clean the node until the pod is deleted manually or another solution is applied to remove evicted pods.