You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not really sure if this is a bug or by-design. If it is expected, I could not find any hints about it online.
I found a situation where a Dockerfile can start processes on the buildkitd host that keep running even after the build job terminates. This only happens when running Buildkit in rootless mode.
In essence, this allows anyone that can start container builds to install a permanent daemon on the buildkitd host, although probably/hopefully restricted.
Testcase
The following testcase triggers the problem consistently and easily on Kubernetes k3s v1.32.1, but I don't think the problem is specific to Kubernetes.
That's just to make the testcase simpler. The same end result can be observed when binding buildkitd to a TCP socket and run buildctl on a different host that can contact said TCP socket.
Now, still in the buildkitd-rootless-test pod, when running ps auxw shows two firebird processes left from the build, which should not be there. At least that's the case for me and I would except that this should not be possible for a non-malicious build:
$ ps auxw
PID USER TIME COMMAND
1 user 0:00 rootlesskit buildkitd --addr unix:///run/user/1000/buildkit/buildkitd.sock --oci-worker-no-process-sandbox
13 user 0:00 /proc/self/exe buildkitd --addr unix:///run/user/1000/buildkit/buildkitd.sock --oci-worker-no-process-sandbox
32 user 0:01 buildkitd --addr unix:///run/user/1000/buildkit/buildkitd.sock --oci-worker-no-process-sandbox
74 user 0:00 /bin/sh
5526 100083 0:00 /opt/firebird/bin/fbguard -pidfile /var/run/firebird/firebird.pid -daemon -forever
5527 100083 0:00 /opt/firebird/bin/firebird
5543 user 0:00 ps auxw
(here PIDs 5526 and 5527)
Notes
I guess this has something to do with --oci-worker-no-process-sandbox and the Buildkit docs mention a warning:
Note that --oci-worker-no-process-sandbox allows build executor containers to kill (and potentially ptrace depending on the seccomp configuration) an arbitrary process in the BuildKit daemon container.
Anyway, it does not mention that processes can also survive the build process and live on the buildkitd host. I don't expect build containers to be unbreakable, but at least provide a isolation good enough to prevent accidental process leftovers.
If that's "by-design" or expected, I wonder if there is a way to prevent it.
The text was updated successfully, but these errors were encountered:
tonistiigi
changed the title
processes from Dockerfile remain active after build finishes
processes can remain active after build finishes with --oci-worker-no-process-sandbox
Feb 20, 2025
This is by design, as it does not create a PID namespace.
On Docker, a workaround is to remove --oci-worker-no-process-sandbox (buildkitd flag) and set --security-opt systempaths=unconfined (docker run flag) instead.
This is not really different from --privileged though, but the processes still work as an unprivileged user.
However, it is still hard to set its equivalent (procMount: Unmasked) on Kubernetes.
Will open a PR to update the example manifests and the docs.
I'm not really sure if this is a bug or by-design. If it is expected, I could not find any hints about it online.
I found a situation where a Dockerfile can start processes on the buildkitd host that keep running even after the build job terminates. This only happens when running Buildkit in rootless mode.
In essence, this allows anyone that can start container builds to install a permanent daemon on the buildkitd host, although probably/hopefully restricted.
Testcase
The following testcase triggers the problem consistently and easily on Kubernetes k3s v1.32.1, but I don't think the problem is specific to Kubernetes.
Start a Kubernetes pod with Buildkitd in rootless mode (based on the official Buildkit rootless deployment example):
Then exec into the container:
kubectl exec -it buildkitd-rootless-test -- /bin/sh
Within the container prepare the problematic Dockerfile:
Build that Dockerfile:
The build should complete with no errors.
Now, still in the
buildkitd-rootless-test
pod, when runningps auxw
shows twofirebird
processes left from the build, which should not be there. At least that's the case for me and I would except that this should not be possible for a non-malicious build:(here PIDs 5526 and 5527)
Notes
I guess this has something to do with
--oci-worker-no-process-sandbox
and the Buildkit docs mention a warning:Anyway, it does not mention that processes can also survive the build process and live on the buildkitd host. I don't expect build containers to be unbreakable, but at least provide a isolation good enough to prevent accidental process leftovers.
If that's "by-design" or expected, I wonder if there is a way to prevent it.
The text was updated successfully, but these errors were encountered: