Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mount network share with nfs with username / password

Tags:

docker

nfs

I am trying to mount a NAS using nfs for an application. The Storage team has exported it to the host server and I can access it at /nas/data.

I am using containerized application and this file system export to the host machine will be a security issue as any container running on the host will be able to use the share. So this linux to linux mounting will not work for me.

So the only alternate solution I have is mounting this nas folder during container startup with a username /password.

The below command works fine on a share supporting Unix/Windows. I can mount on container startup

mount -t cifs  -osec=ntlmv2,domain=mydomain,username=svc_account,password=password,noserverino //nsnetworkshare.domain.company/share/folder /opt/testnas

I have been told that we should use nfs option instead of cifs. So just trying to find out whether using nfs or cifs will make any difference.

Specifying nfs option gives below error.

 mount -t nfs -o nfsvers=3,domain=mydomain,username=svc_account,password=password,noserverino //nsnetworkshare.domain.company/share/folder /opt/testnas


mount.nfs: remote share not in 'host:dir' format

Below command doesnt' seem to work either.

 mount -t nfs -o nfsvers=3,domain=mydomain,username=svc_account,password=password,noserverino nsnetworkshare.domain.company:/share/folder /opt/testnas

mount.nfs: an incorrect mount option was specified

I couldn't find a mount -t nfs option example with username /password. So I think we can't use mount -t nfs with credentials.

Please pour in ideas.

Thanks,
Vishnu

like image 564
VVP Avatar asked Jan 27 '23 01:01

VVP


1 Answers

CIFS is a file sharing protocol. NFS is a volume sharing protocol. The difference between the two might not initially be obvious.

NFS is essentially a tiny step up from directly sharing /dev/sda1. The client actually receives a naked view of the shared subset of the filesystem, including (at least as of NFSv4) a description of which users can access which files. It is up to the client to actually manage the permissions of which user is allowed to access which files.

CIFS, on the other hand, manages users on the server side, and may provide a per-user view and access of files. In that respect, it is similar to FTP or WebDAV, but with the ability to read/write arbitrary subsets of a file, as well as a couple of other features related to locking.

This may sound like NFS is distinctively inferior to CIFS, but they are actually meant for a different purpose. NFS is most useful for external hard drives connected via Ethernet, and virtual cloud storage. In such cases, it is the intention to share the drive itself with a machine, but simply do it over Ethernet instead of SATA. For that use case, NFS offers greater simplicity and speed. A NAS, as you're using, is actually a perfect example of this. It isn't meant to manage access, it's meant to not be exposed to systems that shouldn't access it, in the first place.

If you absolutely MUST use NFS, there are a couple of ways to secure it. NFSv4 has an optional security model based on Kerberos. Good luck using that. A better option is to not allow direct connection to the NFS service from the host, and instead require going through some secure tunnel, like SSH port forwarding. Then the security comes down to establishing the tunnel. However, either one of those requires cooperation from the host, which would probably not be possible in the case of your NAS.

Mind you, if you're already using CIFS and it's working well, and it's giving you good access control, there's no good reason to switch (although, you'd have to turn the NFS off for security). However, if you have a docker-styled host, it might be worthwhile to play with iptables (or the firewall of your choice) on the docker-host, to prevent the other containers from having access to the NAS in the first place. Rather than delegating security to the NAS, it should be done at the docker-host level.

like image 60
SlugFiller Avatar answered Jan 29 '23 15:01

SlugFiller