11.4. Configuration Examples
11.4.1. Rsync as a daemon Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
When using Red Hat Enterprise Linux, rsync can be used as a daemon, so that multiple clients can directly communicate with it as a central server in order to house centralized files and keep them synchronized. The following example demonstrates running rsync as a daemon over a network socket in the correct domain, and how SELinux expects this daemon to be running on a pre-defined (in SELinux policy) TCP port. This example then shows how to modify SELinux policy to allow the
rsync daemon to run normally on a non-standard port.
This example is performed on a single system to demonstrate SELinux policy and its control over local daemons and processes. Note that this is an example only and demonstrates how SELinux can affect rsync. Comprehensive documentation of rsync is beyond the scope of this document. See the official rsync documentation for further details. This example assumes that the rsync, setroubleshoot-server and audit packages are installed, that the SELinux targeted policy is used, and that SELinux is running in enforcing mode.
Procedure 11.1. Getting rsync to launch as rsync_t
- Run the
getenforcecommand to confirm SELinux is running in enforcing mode:getenforce
~]$ getenforce EnforcingCopy to Clipboard Copied! Toggle word wrap Toggle overflow Thegetenforcecommand returnsEnforcingwhen SELinux is running in enforcing mode. - Run the
whichcommand to confirm that the rsync binary is in the system path:which rsync
~]$ which rsync /usr/bin/rsyncCopy to Clipboard Copied! Toggle word wrap Toggle overflow - When running
rsyncas a daemon, a configuration file should be used and saved as/etc/rsyncd.conf. Note that the following configuration file used in this example is very simple and is not indicative of all the possible options that are available, rather it is just enough to demonstrate thersyncdaemon:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Now that a simple configuration file exists for rsync to operate in daemon mode, this step demonstrates that simply running the
rsync --daemoncommand is not sufficient for SELinux to offer its protection over rsync. See the following output:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that in the output from the finalpscommand, the context shows thersyncdaemon running in theunconfined_tdomain. This indicates that rsync has not transitioned to thersync_tdomain as it was launched by thersync --daemoncommand. At this point, SELinux cannot enforce its rules and policy over this daemon. See the following steps to see how to fix this problem.In the following steps,rsynctransitions to thersync_tdomain because it launched it from a properly-labeled init script. Only then can SELinux and its protection mechanisms have an effect overrsync. Thisrsyncprocess should be killed before proceeding to the next step. - A custom init script for rsync is needed for this step. Save the following to
/etc/rc.d/init.d/rsyncd.Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following steps show how to label this script asinitrc_exec_t: - Run the
semanagecommand to add a context mapping for/etc/rc.d/init.d/rsyncd:semanage fcontext -a -t initrc_exec_t "/etc/rc.d/init.d/rsyncd"
~]# semanage fcontext -a -t initrc_exec_t "/etc/rc.d/init.d/rsyncd"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - This mapping is written to the
/etc/selinux/targeted/contexts/files/file_contexts.localfile:grep rsync /etc/selinux/targeted/contexts/files/file_contexts.local
~]# grep rsync /etc/selinux/targeted/contexts/files/file_contexts.local /etc/rc.d/init.d/rsyncd system_u:object_r:initrc_exec_t:s0Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Now use the
restoreconcommand to apply this context mapping to the running system:restorecon -R -v /etc/rc.d/init.d/rsyncd
~]# restorecon -R -v /etc/rc.d/init.d/rsyncdCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Run the
ls -lZcommand to confirm the script has been labeled appropriately. Note that in the following output, the script has been labeled asinitrc_exec_t:ls -lZ /etc/rc.d/init.d/rsyncd
~]$ ls -lZ /etc/rc.d/init.d/rsyncd -rwxr-xr-x. root root system_u:object_r:initrc_exec_t:s0 /etc/rc.d/init.d/rsyncdCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Turn on the
rsync_serverSELinux boolean:setsebool rsync_server on
~]# setsebool rsync_server onCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that this setting is not permanent and as such, it will revert to its original state after a reboot. To make the setting permanent, use the-Poption with thesetseboolcommand. - Launch
rsyncdvia the new script. Now that rsync has started from an init script that had been appropriately labeled, the process has started asrsync_t:service rsyncd start
~]# service rsyncd start Starting rsyncd: [ OK ] $ ps -eZ | grep rsync unconfined_u:system_r:rsync_t:s0 9794 ? 00:00:00 rsyncCopy to Clipboard Copied! Toggle word wrap Toggle overflow SELinux can now enforce its protection mechanisms over thersyncdaemon as it is now runing in thersync_tdomain.
This example demonstrated how to get
rsyncd running in the rsync_t domain. The next example shows how to get this daemon successfully running on a non-default port. TCP port 10000 is used in the next example.
Procedure 11.2. Running the rsync daemon on a non-default port
- Modify the
/etc/rsyncd.conffile and add theport = 10000line at the top of the file in the global configuration area (that is, before any file areas are defined). The new configuration file will look like:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - After launching rsync from the init script with this new setting, a denial similar to the following is logged by SELinux:
Jul 22 10:46:59 localhost setroubleshoot: SELinux is preventing the rsync (rsync_t) from binding to port 10000. For complete SELinux messages, run sealert -l c371ab34-639e-45ae-9e42-18855b5c2de8
Jul 22 10:46:59 localhost setroubleshoot: SELinux is preventing the rsync (rsync_t) from binding to port 10000. For complete SELinux messages, run sealert -l c371ab34-639e-45ae-9e42-18855b5c2de8Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Run
semanageto add TCP port 10000 to SELinux policy inrsync_port_t:semanage port -a -t rsync_port_t -p tcp 10000
~]# semanage port -a -t rsync_port_t -p tcp 10000Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Now that TCP port 10000 has been added to SELinux policy for
rsync_port_t,rsyncdwill start and operate normally on this port:service rsyncd start
~]# service rsyncd start Starting rsyncd: [ OK ]Copy to Clipboard Copied! Toggle word wrap Toggle overflow netstat -lnp | grep 10000
~]# netstat -lnp | grep 10000 tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 9910/rsyncCopy to Clipboard Copied! Toggle word wrap Toggle overflow
SELinux has had its policy modified and is now permitting
rsyncd to operate on TCP port 10000.