Making SELinux context on NFS mounts persistent

If you want to use for example a central NFS export with your Nagios configuration under /etc/nagios on your Nagios server the nfs mount is basically mounted with the “nfs_t” context. To start Nagios you need the context “nagios_etc_t” for /etc/nagios instead. Unfortunately a simple “semanage fcontext -a -t …” is not sufficient. You need to add the context as a mount option to your /etc/fstab file like this:

server:/export /etc/nagios	nfs	vers=4,context="system_u:object_r:nagios_etc_t:s0"  0 0