4

I am trying to move a file from a local directory to an nfs mounted directory on a CentOS 7 server. The export is provided by FreeNAS.

Both directories are owned by the current user with at least 755 (nfs shows as 777 but I'm not sure I believe it).

My fstab looks like this

host:/path/to/export /mnt/nfs         nfs     defaults        0 0

I cannot move the file

mv /local/file /mnt/nfs/file
mv: cannot create regular file 'file': Operation not permitted

However I can copy and remove it

cp /local/file /mnt/nfs/file
rm /local/file

Output of mount

host:/path/to/export on /mnt/nfs type nfs (rw,relatime,vers=3,rsize=65536,wsize=65536,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=host,mountvers=3,mountport=908,mountproto=udp,local_lock=none,addr=host)

Directory permissions on the client

ls -ld /local /mnt/nfs
drwxrwxrwx. 15 user user 17 Nov 28 08:32 /mnt/nfs/
drwxrwxrwx. 2  root root 17 Nov 29 12:20 /local

After further investigation this seems to be regarding changing permissions. mv takes the permissions of the file with it, however cp creates a new file which inherits permissions from the parent directory. It appears the nfs mount does not allow me to chown files even if I am root or the owner of the files. So now my question is how do I allow the changing of permissions, or ignore the permissions given in the mv.

Jacob Tomlinson
  • 353
  • 2
  • 4
  • 15

1 Answers1

3
  • Are your password / group databases in sync between client and server?
  • Do you see any files on nfs mounted directory on nfs client as owned by

    nobody nobody

  • Can you post output of nfsidmap -d from server and client? Hint - when using NFSV4 outputs should match.

Most likely you are running into discrepancy between UID / GID on the NFS server and NFS client. I will show how this works based on a simple example.

Let's say you are sharing on your NFS client /nfs_share like this. Notice that nfs_share is writeable by anyone(777).

[root@nfsserver nfs_share]# cat /etc/exports
/nfs_share      192.168.0.52(rw,no_root_squash) 

[root@nfsserver nfs_share]# ls -ld /nfs_share
drwxrwxrwx. 2 root root 4096 Nov 30 23:55 /nfs_share

And mounting on your NFS Client like this

mount 192.168.0.51:/nfs_share /mnt

Now you have on nfs server user called dmitry

[root@nfsserver nfs_share]# getent passwd|grep dmitry
dmitry:x:500:500::/home/dmitry:/bin/bash
[root@nfsserver nfs_share]# getent group|grep dmitry
dmitry:x:500:

And on your nfs client you have user helen

[root@nfsclient ~]# getent passwd|grep helen
helen:x:500:500::/home/helen:/bin/bash
[root@nfsclient ~]# getent group|grep helen
helen:x:500:

Notice that despite those are different users - they have same UID and GID. So what happens if I touch as user helen file on nfs share?

[helen@nfsclient mnt]$ touch helen_client
[helen@nfsclient mnt]$ ls -lrt
[helen@nfsclient mnt]$ ls -lrt
total 0
-rw-rw-r--. 1 nobody nobody 0 Nov 30 23:58 helen_client

On NFS client this new file will show up as owned by nobody nobody. This is because nfsidmap can't map client_user_name@domain to server_user_name @domain. And now moment of truce. Let's check what's the file owner on the nfs server.

[root@nfsserver nfs_share]# ls -rlt
total 0
-rw-rw-r--. 1 dmitry dmitry 0 Nov 30 23:58 helen_client

Surprised yet?
Yet there is nothing strange actually. This works as expected.
NFS server can't map user helen, but what it received is UID and GID. So it created file (since folder is world writeable) with UID 500 and GID 500, which is mapped to dmitry:dmitry on NFS server.

Now let's say we have other user who's UID / GID and names match between server and client

[root@nfsserver mnt]# getent passwd|grep angelina
angelina:x:501:501::/home/angelina:/bin/bash
[root@nfsserver mnt]# getent group|grep angelina
angelina:x:501:

[angelina@nfsclient mnt]$ getent passwd|grep angelina
angelina:x:501:501::/home/angelina:/bin/bash
[angelina@nfsclient mnt]$ getent group|grep angelina
angelina:x:501:

And if I touch file on nfs client as user angelina - I will see correct user name / group on both Server and Client

[angelina@nfsclient mnt]$ pwd
/mnt
[angelina@nfsclient mnt]$ touch angelina_1
[angelina@nfsclient mnt]$ ls -l
total 0
-rw-rw-r--. 1 angelina angelina 0 Dec  1  2016 angelina_1
-rw-rw-r--. 1 nobody   nobody   0 Dec  1 00:16 helen_1

[root@nfsserver nfs_share]# pwd
/nfs_share
[root@nfsserver nfs_share]# ls -l
total 0
-rw-rw-r--. 1 angelina angelina 0 Dec  1 00:27 angelina_1
-rw-rw-r--. 1 dmitry   dmitry   0 Dec  1 00:16 helen_1

Bottom line is for NFSV4 to work correctly you need to have

  • Server and client password / group database in sync. Preferably use ldap.
  • client and server should agree on the common domain name nfsidmap -d
Dmitry Zayats
  • 1,378
  • 6
  • 7
  • 1
    The `mount` flags show the OP is using NFSv3 so some of this answer is not really relevant here – roaima Dec 01 '16 at 08:35
  • 1
    `nfsidmap` is not relevant, but on nfsv3 same id mapping is performed by `rpcidmapd`. Actually sorry, that's Linux flavor dependent. Still nfsv4 applicable. So yes, some of the answers are not applicable to v3, however what I described about importance of syncronized password dbs is till valid. – Dmitry Zayats Dec 01 '16 at 14:58
  • Both systems have a user with uid 1001 and gid 1001. However the username is different. All files are owned by uid 1001 on the host system. – Jacob Tomlinson Dec 02 '16 at 08:06
  • For NFSv3 at least, it's only the UIDs/GIDs that matter – roaima Dec 02 '16 at 12:34
  • 1
    Sadly this answer didn't solve my problem. But it's a well written and thought out answer and the bounty period is over, so I'm going to award it to you. – Jacob Tomlinson Dec 06 '16 at 09:35
  • What release of FreeNas do you have? Is it stable 9.10 or beta? – Dmitry Zayats Dec 07 '16 at 07:51