Hello,
I’m new to SELinux and there’s something I don’t understand.
I have created a systemd service that periodically runs a script which calls rsync to backup some files.
The script runs fine when called interactively, but fails with SELinux errors when called from the systemd unit.
Looking at the audit logs, the reason is that:
audit[47882]: AVC avc: denied { read } for pid=47882 comm="rsync" name=".rustup" dev="zfs" ino=592561 scontext=system_u:system_r:rsync_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=lnk_file permissive=1`
setroubleshoot suggests to run either setsebool -P rsync_export_all_ro 1 or setsebool -P rsync_full_access 1, but neither of this seems right to me because if were to start an rsync daemon in the future, I do not want them daemon to have unlimited access.
So I think I need to create a new SELinux type for my backup script, assign a new context to the script, and modify my SELinux policy to allow transitions from init_t to this new script. Is that correct so far?
The part that I’m struggling with is this. If rsync has assigned rsync_exec_t as its role:
root@nlp ~ [4]# ls -Z /usr/bin/rsync
system_u:object_r:rsync_exec_t:s0 /usr/bin/rsync*
why is the context transitioning to this role when systemd exec’s rsync, but not when my shell exec’s rsync interactively? And how do I make sure that when rsync is called by my backup script, it does not transition to the rsync_exec_t type, but remains in my newly defined backup type?
Is there a way for me to start a process in “SE Linux debug mode” (or something similar), where I am getting audit messages for every SELinux check (rather than just those that would fail)? I would very much like to see when a role transition happens to better understand what’s going on…