svnserve with selinux on nfs mount unable to start (Centos8)

might be a silly question. Struggling with my subversion server on a Centos8 with selinux enforced. We have an NFS mount to store the data (/mnt/data/svn).

The problem (when selinux is in enforcement mode) is that the service won't start as it has not the permissions to access /mnt/data/svn:

> service svnserve start # error
> journalctl -xe

systemd[1]: Starting Subversion protocol daemon...
-- Subject: Unit svnserve.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
-- 
-- Unit svnserve.service has begun starting up.
... svnserve[2445049]: svnserve: E000013: Can't check path '/mnt/data/svn': Permission denied
... systemd[1]: svnserve.service: Control process exited, code=exited status=1
... systemd[1]: svnserve.service: Failed with result 'exit-code'.
... systemd[1]: Failed to start Subversion protocol daemon.

SVN environment: /etc/sysconfig/svnserve:

OPTIONS="-r /mnt/data/svn"

Directory permissions: Recursive ...

drwxr-xr-x. 36 svn svn 4096 Nov 17 16:40 /mnt/data/svn

SE config: via semanage

> semanage fcontext -l | egrep "/mnt/data/svn"
/mnt/data/svn           all files          system_u:object_r:svnserve_content_t:s0 
/mnt/data/svn(/.*)?    all files          system_u:object_r:svnserve_content_t:s0 

SE context type

> ls -ldaZ /mnt/data/svn
drwxr-xr-x. 36 svn svn system_u:object_r:nfs_t:s0 4096 Nov 17 16:40 /mnt/data/svn

Without selinux enforced everything works as expected. The problem: cannot add svnserve_content_t type to /mnt/data/svn via semanage:

chcon -Rv --user system_u /mnt/data/svn             # fine
chcon -Rv --type svnserve_content_t /mnt/data/svn   # fails

Seems snvserve_content_t is invalid, or I can't assign nfs_t and svnserve_content_t at the same time. I am a the end of good ideas. Quite likely there is a super simple solution and I am already super happy for any ideas (disabling selinux enforcement is not an option).

Thank you very much in advance,

R


Solution 1:

My solution

The audit log indeed shows what was going wrong:

type=AVC msg=audit(1606892987.322:161301): avc:  denied  { search } for  pid=2570843 comm="svnserve" name="/" dev="0:46" ino=2131353823 scontext=system_u:system_r:svnserve_t:s0 tcontext=system_u:object_r:nfs_t:s0 tclass=dir permissive=0

No permission to search the directories. My solution was to write a custom selinux policy module/rule:

module svnserve_nfs 1.0;

require {
        type svnserve_t;
        type nfs_t;
        class dir { getattr search read write };
        class file { getattr unlink append open read setattr write lock create rename };
}

#============= svnserve_t ==============
allow svnserve_t nfs_t:dir { getattr search read write };
allow svnserve_t nfs_t:file { getattr unlink append open read setattr write lock create rename };

... checked, compiled, installed, works. Might be a bit more restrictive but at the moment I am happy it works as expected.