Page MenuHomePhabricator

toolforge: we may be allowing arbitrary host path mounts in containers
Closed, ResolvedPublicSecurity

Description

As of this writing, our kyverno pod policies don't disallow arbitrary host path mounts, which may mean that containers could mount arbitrary host paths from the k8s worker filesystem.

Preventing this using kyverno is easy, see for example: https://kyverno.io/policies/pod-security/baseline/disallow-host-path/disallow-host-path/

If we add a policy similar to that in kyverno, we may need to specify which host files are OK to mount:

  • NFS dirs
  • dumps dirs
  • ldap files
  • openstack credentials
  • etc

This may not need to be a per-tool policy.

Event Timeline

taavi changed the visibility from "Custom Policy" to "Custom Policy".
taavi changed the edit policy from "Custom Policy" to "Custom Policy".
taavi changed the subtype of this task from "Task" to "Security Issue".
aborrero raised the priority of this task from Medium to High.Feb 20 2025, 1:30 PM
aborrero moved this task from Backlog to Doing on the User-aborrero board.

I tried exploiting this from a random tool account, and it looks like we are indeed allowing arbitrary host mounts:

tools.whopaintedthis@tools-bastion-13:~$ cat test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: testmount
    image: docker-registry.tools.wmflabs.org/toolforge-bookworm-sssd:latest
    command: ["sleep", "60"]
    volumeMounts:
    - name: hostmount
      mountPath: /testmount
  volumes:
  - name: hostmount
    hostPath:
      path: /

tools.whopaintedthis@tools-bastion-13:~$ kubectl apply -f test.yaml
pod/test created
tools.whopaintedthis@tools-bastion-13:~$ kubectl exec -it test -- bash
I have no name!@test:/$ ls /testmount/
bin  boot  data  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  public  root  run  sbin  srv  sys  tmp  usr  var

Linux user permissions apply, so you cannot just access any random file on the host:

I have no name!@test:/$ ls /testmount/root/
ls: cannot open directory '/testmount/root/': Permission denied

I'm not sure if there is any real security risk, but it's probably a good idea to limit what can be mounted anyway.

dcaro claimed this task.
dcaro edited projects, added Toolforge (Toolforge iteration 18); removed Toolforge.
dcaro moved this task from Next Up to Done on the Toolforge (Toolforge iteration 18) board.
taavi changed the visibility from "Custom Policy" to "Public (No Login Required)".Mar 24 2025, 3:46 PM
taavi changed the edit policy from "Custom Policy" to "All Users".