-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failures in chroot #135
Comments
This same issue also happens when running bubblewrap inside mock. I wrote a little compat script to make it work: https://gist.github.com/jlebon/fb6e7c6dcc3ce17d3e2a86f5938ec033 Of relevance to your (2):
|
@jlebon Thank you! I could not figure out the right private/bind magic to make that happen. Let me try that out. |
See some discussion on this in opencontainers/runc#41 |
That said, I think you should bubblewrap instead of chroot - we should support nested containerization if you're root, or the host has unprivileged userns enabled. |
The nice thing about pivot_root is that we can completely clean out any references to any mounts we didn't create from the sandbox. MS_MOVE would just cover them. This seems like a safer option. |
auto-creating a mountpoint for the root seems nice though |
Yeah, I noticed that later searching around about pivot_root. I had a try hacking in the root mount, but it didn't quite work out. |
In case anyone ever feels like picking this up, https://gist.github.com/dbnicholson/da8aa72ea3bd7ee8731c9da2792fd5a3 is what I played with before but didn't get working. |
Bubblewrap uses pivot_root to provide a clean enviroment for its sandbox. Unfortunately, pivot_root requires that current root mount and its parent mount are not shared mounts, which they are by default when making new mounts. To accomplish that, make the chroot root mount private and then bind mount the chroot on top of itself. This will guarantee that both conditions are satisfied. See containers/bubblewrap#135 for details and the workaround suggested in https://gist.github.com/jlebon/fb6e7c6dcc3ce17d3e2a86f5938ec033. https://phabricator.endlessm.com/T14860
I understand how to fix this. We need to bind mount So we need to do C analog of this: But this gives another problem: all filesystems mounted in original namespace will remain mounted inside bubblewrap, even after two pivot_roots. They will be inaccessible and hidden, but still mounted. What is wrong with such situation? Consider this: we insert USB flash drive and mount it. Then start bubblewrap. Then we umount flash drive (in our host system). Actually it remained to be mounted in bubblewrap's namespace. So when we remove flash drive, we get data loss. What to do? We have two choices how to fix this situation:
I like second solution more (but I can implement both). Second solution will look like this:
I can write patch if you want. Also I can describe workaround for users of bubblewrap |
If you think you know how to solve this, please do: reviewing a pull request and checking for things that can go wrong there will be a lot easier than reviewing a text description that is less precise than code. |
@smcv , I spent some more time thinking about bubblewrap. Now I think bubblewrap don't need to work in chroot. Let me tell why. As well as I understand bubblewrap needs root privileges. And it acquires them in one of 3 ways:
In 3rd way it is absolutely impossible to make bubblewrap to work in chroot, because this is prohibited in the kernel ( https://elixir.bootlin.com/linux/v6.2/source/kernel/user_namespace.c#L105 ). You can easily verify this by running this command (as root, not in chroot): So I think in 1st way and in 2nd way bubblewrap in chroot should not work, too. For consistency purposes. (But keep in mind that sometimes it still works.) So, I will not write any patch, I'm sorry about this. (Of course, you can try to convince me.) Also, this will be very cool to disable setuid mode. I. e. simply to exit if we run as setuid binary. Because, as well as I understand, in modern distros user namespaces are enabled by default anyway |
Not exactly, it needs If you're saying "root" but you really mean " (Just to make this extra-confusing, there is a concept called a capabilities-based security system, but the capabilities(7) feature is using a different meaning for that word.)
Again, this would be more accurately stated as: bubblewrap creates a new user namespace, and thus gains all capabilities(7) in that user namespace. It doesn't matter whether it's uid 0 in the new userns or not.
Right, yes.
For what you're calling the 1st way, where bubblewrap is started such that it already has elevated capabilities (most commonly by being root, for example For what you're calling the 2nd way, where bubblewrap is setuid root, the design principle is that bubblewrap shouldn't allow anything that an unprivileged user on a suitable kernel wouldn't be allowed to do. So I agree with your assertion that a setuid bubblewrap shouldn't work when run inside a chroot.
Sorry, I don't understand "this will be very cool to". Are you requesting a new feature: the ability to configure bubblewrap at build-time so that if it is run while setuid (as detected via Or are you saying that something related to chroots would be a useful mechanism to use to provide that feature? If that, I don't understand: please be more specific. |
I don't see any reason why case 1 (bubblewrap started by a privileged user inside a chroot) couldn't work. It's why I opened the issue and started working on fixes to make it comply with This could certainly be deemed wontfix, but I think it's a legitimate use case. |
I want bubblewrap to always refuse to run and exit with an error if it detects it runs as a setuid |
In our Endless image builder, we chroot into the ostree deployment to install apps with flatpak. The triggers always fail for 2 reasons:
The slave mounting of / fails because the deployment directory is not actually a mountpoint. This is easily fixed by doing a bind mount before hand, but I think this can be done in bubblewrap, too. Systemd does this - https://github.com/systemd/systemd/blob/master/src/core/namespace.c#L910.
pivot_root fails with EINVAL for reasons I can't quite grok. See https://github.com/torvalds/linux/blob/master/fs/namespace.c#L3035. FWIW, I can't really see why the pivot_root is needed. It seems that you could just build up the newroot, then move the mount over /. This is also what systemd does. It used to use pivot_root, but changed that in systemd/systemd@ac0930c.
The text was updated successfully, but these errors were encountered: