sahlberg / fuse-nfs

A FUSE module for NFSv3/4
GNU General Public License v3.0
172 stars 41 forks source link

?uid=x&gid=x only sort of works #6

Closed julian-hj closed 7 years ago

julian-hj commented 8 years ago

We've been looking into the possibility of using fuse-nfs with the uid/gid flags in order to set the effective user for a mount to be different from the currently running user. What we've found is that it doesn't work very well unless the currently running user is root.

The reason is that while it works fine for write operations--the file owner information is sent as the specified arbitrary uid/gid, for list/stat operations, the uid/gid is not translated back to the uid of the running user.

So, if as a non-root user, I mount a volume with some other uid/gid: fuse-nfs -n "nfs://127.0.0.1/export/share1?uid=2000&gid=2000" -m ./mymount2

I can write new files to the volume, but then, because the client OS doesn't think the resulting files are owned by the current user, I cannot edit them:

vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ echo "strange" > strangeness
vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ cat strangeness
strange
vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ echo "strange" >> strangeness
bash: strangeness: Permission denied
vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ cat strangeness
strange

We found that we can resolve this by just adding a check to fuse_nfs_getattr() to test if the file is owned by the UID set in the mount URL, and set the current user UID into stbuf instead, but we are wondering if this is really a bug, or if we are just misunderstanding the intent of putting UID and GID in as options to begin with.

sahlberg commented 8 years ago

On Mon, Nov 14, 2016 at 12:28 PM, Julian Hjortshoj <notifications@github.com

wrote:

We've been looking into the possibility of using fuse-nfs with the uid/gid flags in order to set the effective user for a mount to be different from the currently running user. What we've found is that it doesn't work very well unless the currently running user is root.

The reason is that while it works fine for write operations--the file owner information is sent as the specified arbitrary uid/gid, for list/stat operations, the uid/gid is not translated back to the uid of the running user.

So, if as a non-root user, I mount a volume with some other uid/gid: fuse-nfs -n "nfs://127.0.0.1/export/share1?uid=2000&gid=2000" -m ./mymount2

I can write new files to the volume, but then, because the client OS doesn't think the resulting files are owned by the current user, I cannot edit them:

vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ echo "strange" > strangeness vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ cat strangeness strange vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ echo "strange" >> strangeness bash: strangeness: Permission denied vcap@vagrant-ubuntu-trusty-64:/home/vagrant/mymount2$ cat strangeness strange

We found that we can resolve this by just adding a check to fuse_nfs_getattr() to test if the file is owned by the UID set in the mount URL, and set the current user UID into stbuf instead, but we are wondering if this is really a bug, or if we are just misunderstanding the intent of putting UID and GID in as options to begin with.

Good analysis. This sounds like a bug.

The uid and gid arguments were originally meant for to cope with native windows builds of the nfs library as well as make it work under aros. I never really gave it much thought when it came to being used via fuse-nfs.

I think you are largely correct in that the right fix is probably to add remapping to the stat function. This remapping should be conditional and only happen iff uid/gid arguments are present in the url.

But I think this is the right thing to do. Can you send me a pull request with this change so that you get proper credit for the fix?

( Btw, I never expected many/any real use of this module as almost all systems have nfs clients in the kernel anyway, mind if I ask what your use-case for fuse-nfs is? )

regards ronnie sahlberg

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sahlberg/fuse-nfs/issues/6, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeNkKDGQcgqO6jI5IY9l8f-84aIGTkOks5q-MR8gaJpZM4KxxYd .

lwoydziak commented 8 years ago

Ronnie,

A couple of us are working on this from our side so I am answering for Julian. The use case is remote-user to container-user mapping for a form of tenancy.

lwoydziak commented 8 years ago

We'll put up the PR shortly.

julian-hj commented 8 years ago

^^^ Specifically we are working in an environment where applications are launched into containers running as a fixed UID, and that UID is mapped to some other fixed uid on the host. Our challenge is to get different applications to appear to the NFS server as discrete UIDs so that per-application access control is possible.

Eventually, we think it will be possible to have arbitrary mappings from container uids to host uids using shiftfs, and at that point, we can use non-fuse mounts with the standard nfs-tools, but until shiftfs makes it into the kernel, fuse-nfs is looking like a pretty attractive option.

Thanks for the speedy response! -Julian

sahlberg commented 8 years ago

On Mon, Nov 14, 2016 at 2:59 PM, Julian Hjortshoj notifications@github.com wrote:

^^^ Specifically we are working in an environment where applications are launched into containers running as a fixed UID, and that UID is mapped to some other fixed uid on the host. Our challenge is to get different applications to appear to the NFS server as discrete UIDs so that per-application access control is possible.

Eventually, we think it will be possible to have arbitrary mappings from container uids to host uids using shiftfs, and at that point, we can use non-fuse mounts with the standard nfs-tools, but until shiftfs makes it into the kernel, fuse-nfs is looking like a pretty attractive option.

Ah, interesting. While fuse-nfs does not have much usage compared to libnfs itself, I am happy to extend the help I can give to make sure that fuse-nfs will work well for you.

Thanks for the speedy response! -Julian

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sahlberg/fuse-nfs/issues/6#issuecomment-260491697, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeNkNJe6LJtPjD8N8FKVZ-JPNBiH66Dks5q-OfXgaJpZM4KxxYd .

sahlberg commented 7 years ago

I think this is sorted now.