SELinux Is Causing An Issue With Systemd
I'm trying to write a systemd service for Jupyter‚ but it always fails with jupyter.service: Failed at step EXEC spawning /usr/local/bin/jupyter-notebook: Permission denied. My unit file is:
[Unit]
Description=Starts the Jupyter server
After=network.target
[Service]
User=jupyter
WorkingDirectory=/home/jupyter/
ExecStart=/usr/local/bin/jupyter-notebook
[Install]
WantedBy=multi-user.target
I don't want to disable SELinux, but that's the only way I can get the service to run. What do I do?
EDIT: Relabeling the user context to system_u with chcon fixed it.
Posted Mar 8, 2018, 9:44 PM UTC · edited
Start by checking the log. sealert -a /var/log/audit/audit.log is a good starting point.
Actually read the errors and you see that you can autogenerate policies with a simple command.
Lather, rinse and repeat until working state is achieved.
Unfortunately that didn't have any fixes. Fortunately the fix was a simple chcon command. Thanks for the help!
Please be aware that generally that the
chconcommand should not be used as arestorecon/ FS re-label will undo your changes.Instead you should use
semanageto update the database that contains what context everything should be and userestoreconto set that.I wasn't able to figure out how to use
semanageto change the user label, though. Any chance you know how to do that?Here are some examples, hopefully they can get you going: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security-enhanced_linux/sect-security-enhanced_linux-selinux_contexts_labeling_files-persistent_changes_semanage_fcontext