All,
I'm developing a modification to systemd that will extend systemd-sleep to support calling user-defined scripts on suspend, hybrid-sleep, etc. similar to systemd-sleep. This is working quite well, however when I started testing on an SELinux-enabled system, things began to fall apart.
I'm not well versed in SELinux, so I'm not even sure on where to begin looking. Fundamentally, the service calls a script as a configured user (/usr/lib/systemd/systemd-sleep-user) which in turn executes any executable under $HOME/.config/systemd/system-sleep
.
The associated error message is: SELinux is preventing systemd-sleep-u from execute_no_trans access on the file /home/stallion/.config/systemd/system-sleep/kill-scdaemon.sh.
Since this behavior is similar to how systemd-sleep works (albeit, it uses /usr/lib/systemd/system-sleep) I was hoping this would just require applying the same properties to the user location.
Any thoughts?
Edit: Relevant audit log entry below:
type=AVC msg=audit(1508702442.885:388): avc: denied { execute_no_trans } for pid=3539 comm="systemd-sleep-u" path="/home/stallion/.config/systemd/system-sleep/kill-scdaemon.sh" dev="dm-3" ino=533984 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:config_home_t:s0 tclass=file permissive=0
/var/log/audit/audit.log
, it probably relevant enough to include in the question.SELinuxContext=system_u:system_r:unconfined_t:s0
to systemd service file? This would make your scripts run in unconfined domain, in which SELinux does not place (almost any) restrictions. (I can write this as an answer should this work)User=
andSELinuxContext=
. I was able to work around this by just usingrunuser
so I'm good to go. I'd love to see a write up on why this works. Thanks!