Strange behavior of chown on NFS share

2,414 views
Skip to first unread message

Martin André

unread,
Sep 9, 2014, 4:01:20 AM9/9/14
to vagra...@googlegroups.com
Hi list,

While experimenting with vagrant NFS share from OSX host, I faced an issue with the chown command, where it fails with Operation not permitted unless the user is changing ownership of a file to himself:

vagrant@box:~$ touch /vagrant-nfs/foo
vagrant@box
:~$ ls -l /vagrant-nfs/foo
-rw-rw-r-- 1 501 dialout 0 Sep 9 07:34 /vagrant-nfs/foo
vagrant@box
:~$ chown vagrant /vagrant-nfs/foo
vagrant@box
:~$ echo $?
0
vagrant@box
:~$ ls -l /vagrant-nfs/foo
-rw-rw-r-- 1 501 dialout 0 Sep 9 07:34 /vagrant-nfs/foo
vagrant@box
:~$ sudo chown vagrant /vagrant-nfs/foo
chown
: changing ownership of ‘/vagrant-nfs/foo’: Operation not permitted
vagrant@box
:~$ sudo chown root /vagrant-nfs/foo
vagrant@box
:~$ echo $?
0

This is problematic for me since I'm running a script that stops at the first error.

At the moment I solved the issue by providing a replacement command for chown that does a noop when the target is in my NFS mount, but doesn't seem like the right approach to me and I was wondering if there is a better one. Hopefully, I'm simply missing the right NFS mount option. I'm using default mount options from Vagrant.

On the host:
$ cat /etc/exports
[snip]
"/path/to/share" 20.20.20.10 -alldirs -mapall=501:20

On the VM:
$ mount
[snip]
20.20.20.1:/path/to/share on /vagrant-nfs type nfs (rw,vers=3,udp,addr=20.20.20.1)

Has anybody experience with this problem?

Martin

Alvaro Miranda Aguilera

unread,
Sep 9, 2014, 5:44:55 PM9/9/14
to vagra...@googlegroups.com
hello,

it looks to me that is working as expected.

yo are telling the host to map all to 501:20

user:group

what you could do, is map to the userid:groupid of what you require,

or create a user int he vm that match that 501 : 20

make sense?



--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin André

unread,
Sep 9, 2014, 11:45:23 PM9/9/14
to vagra...@googlegroups.com
Hi Alvaro and thanks for your answer.


On Wednesday, September 10, 2014 6:44:55 AM UTC+9, Alvaro Miranda Aguilera wrote:
hello,

it looks to me that is working as expected.

It works as I expect (I'm not surprised at all by owner being 501:20 even though I did a "chown vagrant file"), except for the Operation not permitted error returned by chown when changing ownership to a different user than the current user. I'd like to have chown exit with status 0 if I do

chown vagrant /vagrant-nfs/foo # => works
OR
sudo chown vagrant /vagrant-nfs/foo # => fails with Operation not permitted

I hope I clarified what my problem is.

Martin
 

Alvaro Miranda Aguilera

unread,
Sep 10, 2014, 12:27:50 AM9/10/14
to vagra...@googlegroups.com
Hello,

This is osx+nfs server -> linux+nfs client

vagrant has nothing to do here:

Check this:


vagrant@box:~$ ls -l /vagrant-nfs/foo
-rw-rw-r-- 1 501 dialout 0 Sep 9 07:34 /vagrant-nfs/foo
vagrant@box
:~$ chown vagrant /vagrant-nfs/foo
vagrant@box:~$ ls -l /vagrant-nfs/foo
-rw-rw-r-- 1 501 dialout 0 Sep 9 07:34 /vagrant-nfs/foo

is not working.

on the osx host you are forcing to be always 501:20

I can understand the question may be why vagrant user doesn't error, and root error.

I can only guess that is related that users usually can't change ownership, so that chmod as vagrant is doing nothing.

If you want to change the client side to map a user, give a check at this:

http://serverfault.com/questions/514118/mapping-uid-and-gid-of-local-user-to-the-mounted-nfs-share

at the end is a suggestion, not sure if will work, but worth the try.

Hope this helps.

Martin André

unread,
Sep 10, 2014, 8:58:34 PM9/10/14
to vagra...@googlegroups.com
Hi Alvaro,


On Wednesday, September 10, 2014 1:27:50 PM UTC+9, Alvaro Miranda Aguilera wrote:
Hello,

This is osx+nfs server -> linux+nfs client

vagrant has nothing to do here:

Check this:

vagrant@box:~$ ls -l /vagrant-nfs/foo
-rw-rw-r-- 1 501 dialout 0 Sep 9 07:34 /vagrant-nfs/foo
vagrant@box
:~$ chown vagrant /vagrant-nfs/foo
vagrant@box:~$ ls -l /vagrant-nfs/foo
-rw-rw-r-- 1 501 dialout 0 Sep 9 07:34 /vagrant-nfs/foo

is not working.

on the osx host you are forcing to be always 501:20

I can understand the question may be why vagrant user doesn't error, and root error.

Which is exactly my question :)
 
I can only guess that is related that users usually can't change ownership, so that chmod as vagrant is doing nothing.

If you want to change the client side to map a user, give a check at this:

http://serverfault.com/questions/514118/mapping-uid-and-gid-of-local-user-to-the-mounted-nfs-share

at the end is a suggestion, not sure if will work, but worth the try.

idmapd is only for NFSv4, but the NFS server that comes with OS X (at least on Mavericks) doesn't support it. As far as I can tell, there is no NFS server on OS X that supports v4 of the protocol so I don't know the behavior of NFSv4 with regards to chown command.
 
Hope this helps.

I'll stick with my small wrapper for chown command that ignores my NFS mount for the time being.

Thanks,
Martin
Reply all
Reply to author
Forward
0 new messages