Replace the manual handling of mounts with the contianerd's mount package - #840
Replace the manual handling of mounts with the contianerd's mount package#840cmainas wants to merge 1 commit into
Conversation
Replace the manual handling of mount options and mount calls with containerd's mount package, and use securejoin to resolve mount targets and copy destinations inside the monitor rootfs, so that symlinks in image-controlled paths cannot redirect them outside of it. containerd's option parser cannot translate propagation flags and the kernel ignores per-mount VFS flags when a bind mount is created. Therefore, split the mount options into three groups: the options forwarded to containerd, the propagation flags and the per-mount VFS flags. For bind mounts urunc reapplies the VFS flags, preserving the CL_UNPRIVILEGED locked flags of the source mount when running inside a user namespace. also, since we switch from moby/sys/mount to containerd's mount package we also switch from a lzy unmount to a strict one, which is necessary since we want to attach the block devices to the sandbox. Also fix getMonitorDevices to not append an empty device entry when /dev/net/tun does not exist on the host. Leftover from previous PR Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
d47cd30 to
7add7b8
Compare
✅ Deploy Preview for urunc canceled.
|
✅ Deploy Preview for urunc canceled.
|
7add7b8 to
ec2cdb8
Compare
1a5b996 to
c218c7c
Compare
|
thanks @cmainas! Moving all of this to containerd's mount package is the right call. I gave it a spin on our testbed ( What passesUnit tests are green both on the branch and on the branch merged with current main, it merges cleanly, and it builds. For the e2e side I ran all four suites as an A/B, pure builds of So 71 specs each, fully green on both, no difference between the two. I also checked that One caveat on that green run, and it is the reason I am still flagging things below: neither of the two issues I found is reachable from the e2e suites. Nothing there mounts a volume with Two things got better that are worth calling out. The rootless path is genuinely improved, binding a source whose mount carries kernel-locked flags fails with Two things I would fix before merging1. We now pass the raw mountinfo field 6 string to containerd as main got away with it because I would run the tokens through our own 2. The strict unmount can EBUSY the create path. I get why this changed, and the PR description is clear that it is needed for attaching the block devices. Still, moby's Both call sites ( While we are in here:
|
|
Hello @ananos , I will pass other mounts from
I have some reservations about this suggestion. In "lazy unmount" we risk data corruption because the same volume will be attached in two different places on the same time and in "strict unmount" we risk to be slower. Also, the "fallback" would not really save us neither time nor the data corruption, we will still have to wait and get EBUSY, while then ignoring it and attach the volume to the sandbox. We should also keep in mind if such a scenario, a process keeps a reference in that mount is realistic. In the case of rootfs this is not possible because it is created from the shim and then On the other hand, we do not really need to unmount using the containerd package, We can instead copy the unmount function of containerd (https://github.com/containerd/containerd/blob/v1.7.34/mount/mount_linux.go#L203) and reduce the timeout, so we can fail fast.
I will include this small change too. |
2d341d2 to
0fb9e93
Compare
|
Hello @ananos , I have addressed the comments. |
Description
Replace all the manual handling of mounts (option parsing, mount calls, unmounting) with containerd's mount package. Furthermore, use
SecureJointo safely resolve mount targets and copy destinations inside the monitor rootfs, so symlinks in image-controlled paths cannot redirect a mount outside of it.Since containerd does not parse propagation flags correctly (ignores them) and because the kernel ignores per-mount VFS flags when a bind mount is created, we split the mount options in three groups: the options forwarded to containerd, the propagation flags and the per-mount VFS flags. For bind mounts we reapply the VFS flags, preserving the CL_UNPRIVILEGED locked flags of the source mount when running inside a user namespace.
Also, since we switch from moby/sys/mount to containerd's mount package we also switch from a lazy unmount to a strict one, which is necessary since we want to attach the block devices to the sandbox.
At last, fix getMonitorDevices to not append an empty device entry when
/dev/net/tundoes not exist on the host. Leftover from #835Related issues
How was this tested?
with e2e tests
LLM usage
Opus 4.8 to update all calls for mounts
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).