Possible Workarounds for Inability to Mount as non-root under Linux #10648
Replies: 11 comments 7 replies
-
To add to this discussion, there are existing tools designed to allow non-privileged users to mount removable devices, including |
Beta Was this translation helpful? Give feedback.
-
Personally I prefer the SUID solution. Basically all the implementation requires a root/CAP_SYS_ADMIN binary (running or with suid bit). That binary must examine permission and input options carefully to prevent privilege-escalation attack. Podman and other daemon-less, rootless approaches try to avoid a daemon. Especially if the daemon is stateful, a hotfix will be problem (e.g. dbus-daemon). I am trying to implement it as a standalone helper binary, instead of patching |
Beta Was this translation helpful? Give feedback.
-
This is the architecture being used on ZSys, which seems to be a relatively major concentration of effort for Ubuntu's purposes regarding enhanced ZFS support. I believe the architecture was developed in communication with the OpenZFS Dev team, and might be worth looking at . I agree that the SETUID option would be quite easy to achieve, and in fact it may be possible mostly to move parts of the existing codebase and add some boilerplate in order to separate it, but equally if a more client-server model is what would be best adopted by other projects, then maybe this would be easier forming a part of the core interface, or perhaps wrapping around the C library as an alternative to facilitate interaction at a programmatic level rather than calling out to the CLI utilities. Regarding that, I believe Joyent was wrapping some core Solaris libraries in node.js to help with some of their tools. Also, AFAIK, but I may be wrong, things like udisks require FUSE support, and it seems the zfs-fuse package is long unmaintained and has been deprecated in many places I have read, however maybe that would be a more appropriate model, or again, some modest changes that would bridge the gap a little and make maintenance of a FUSE interface easier. |
Beta Was this translation helpful? Give feedback.
-
@ivzhh Do you have a repo for your helper binary? Sounds quite similar to something I was trying to do for the rootless docker setup. I'm lacking time right now but would be happy to have a look at it if I did get round to it, especially as this was preventing me from using the rootless setup after quite an investment into it for my server. |
Beta Was this translation helpful? Give feedback.
-
@stellarpower Not yet. I am extending go-libzfs and still work-in-progress. A basic version will be ready in a week or two. Glad to hear you are working towards the same direction. |
Beta Was this translation helpful? Give feedback.
-
@stellarpower Zsys is a cool project and it led me to use go-libzfs. According to Zsys,
I really like the solution too. In addition, my solution is go-based and go cannot do However, the reason I tried to go through SUID is daemonless. For people like podman, rootless and daemonless are two important values. So that's the main reason why I chose SUID. |
Beta Was this translation helpful? Give feedback.
-
I know you're asking for a workaround, but I've been digging more into ZFS internals and I wonder if the right way to fix this would be to expose another ZFS ioctl for mounting move calling the mount syscall into the zfs module. Then delegation can all be verified the same way all other ioctl calls are. |
Beta Was this translation helpful? Give feedback.
-
I came across this thread while trying to mount as non-root, but it didn't seem like there was any ready-to-use solution available. After futzing with it for way too long, I came up with this solution for doing what I needed. This uses the Unfortunately, it does not perform any authorization checks to determine if the user is permitted to mount the dataset (via |
Beta Was this translation helpful? Give feedback.
-
This is probably going to sound stupid, but I'm assuming namespaces don't allow us any leverage here. My understanding is that this would be limited, as if the dataset could be mounted within the non-root dataset, it still can't be viewed outsidde of that namespace. But, maybe someone knows the topic in a lot more intricate detail and might be aware of a hack, or way this can at least be used to some effect. E.g., if we're talking setuid workarounds, helper binaries, etc., then would it be less harmful to run some sort of server process in the namespace that can then feed bak to the root namespace as a normal user. |
Beta Was this translation helpful? Give feedback.
-
I've written a small It does so by using An alternative solution, as @clinta mentioned, would be to expose the verification procedure with a new ioctl. I think this is preferrable to this solution -- however, this one doesn't need changes on the kernel-level. !!NOTENOTENOTE!! I usually use a self-hosted gitea instance to publish my code and would link to it here but I don't have access to it because I don't carry my MFA token with me right now, so I just copy-paste this experimental code here.
|
Beta Was this translation helpful? Give feedback.
-
Came across this discussion, and found no easy to use approach for me. Created this Feature Request : #16512 |
Beta Was this translation helpful? Give feedback.
-
System information
Distribution Name | Ubuntu Server
Distribution Version | 20.04
Linux Kernel | 5.4.0-1012-raspi #12-Ubuntu
Architecture | aarch64
ZFS Version | 0.8.3-1ubuntu12 (dkms)
SPL Version | 0.8.3-1ubuntu12 (dkms)
Describe the problem you're observing
It seems to be a well-known problem that mounting datasets as non-root users on linux is not possible. I have seen a variety of possible options discussed online, for example, here and here.
After encountering the issue earlier in a manner that is preventing me from completing my system setup, a couple of possible workarounds has come to mind, a hackier version of one of which I have successfully implemented to an extent in Crystal (daemon running as root). If, as it seems, the kernel limitation that prevents the current OpenZFS implementation on linux from being able to mount these datasets as non-root looks like it won't be changing any time soon, I am opening this issue as a potential way to discuss any workaround options that may be feasible.
I feel this specific missing feature is a significant factor limiting my being able to use zfs on a number of my linux systems, which is a great shame as whilst not perfect, it is a huge step up from e.g. ext4. It appears to me that perhaps previous discussions naturally concentrated on the more logical solution, fixing the core of the problem at the lower level with the issues with the mount syscall in the global context. If making any required changes with this will not be possible with limitations in the linux kernel that cannot be overcome for a significant amount of time, then I am opening this issue here to open up the discussion if any less elegant but workable solutions might be considered, implemented, and integrated in some way in order to provide a 1) satisfactory, 2) secure enough and 3) workable solution to the problem, where (3) is in the sense that even if not ideal, the solution will function correctly on a linux system, and (2) implies that the fix will not compromise security in any way above the normal levels of risk - for example, if such a fix provides a new vector that could be used to compromise security (e.g. listening as root on a socket) but this vector can and should be locked off under a normal setup (appropriate permission on this socket to prevent misuse), then we could consider (2) to have been met.
Even if a workaround feature is not ideal, I believe it would be worth considering in some level of detail, as for the reasons given below in the motivation, it seems ZFS is coming towards linux more often these days, and has been adopted quite fondly within the BSD community, in any case, quite a way beyond the initial illumos/Solaris base for which it was designed.
Motivations:
Please note most of these are somewhat personal, I will add to them over time if others would like to put forward their own use cases
overlayfs
driver is more complicated as non-root. Docker is a very popular tool in the world of containerisation and rootless docker may well gain popularity as it develops over time to fix some small features that are lacking.Given the prevalence of docker and Ubuntu currently, and that docker's main reference support for linux lies with Ubuntu, I reckon that if both of these platforms are looking to make ZFS support more standard and tightly integrated in the future, then that would be a good indication that a number of linux projects may seek to utilise ZFS as standard.
Potential Workarounds
Utilise a helper binary
Refactor the operations requiring root privileges into a distinct helper binary
Make use of an existing infrastructure for running of this binary as root,
sudo zfs-helper mount Pool/dataset options
Options include
setuid
/seteuid
bit on this binaryzfs
command could provide a more user-friendly error message with the assumption that the helper is not to be called directly, and so will also have to perform the same checks, however as the helper will run as root, it will be necessary to ensure the operation being requested is valid before executing it lest it be co-erced into an illicit operationsudo
systemsudo
installed at all.Run a mounting deamon
Place all the functionality that is required for mounting/unmounting (and any other privileged operations) of the datasets into a separate application that runs by default as a deamon, as root.zfs
program will perform basic validation of commands, ensures that the calling user passes the delegated permissions, and when any operation requires something that currently the user has permissions to perform, but cannot, due to the limits in the kernel, it passes a message to the daemon, over a socket with (global) write access.I open the floor up for any comments on the subject and will edit the issue text to add any options as they arise.
Beta Was this translation helpful? Give feedback.
All reactions