r/Fedora•
PrimHelios

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

610
qrsBRWN•

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.

4
PrimHeliosOP•

Unfortunately that didn't have any fixes. Fortunately the fix was a simple chcon command. Thanks for the help!

2
varesa•

Please be aware that generally that the chcon command should not be used as a restorecon / FS re-label will undo your changes.

Instead you should use semanage to update the database that contains what context everything should be and use restorecon to set that.

3
PrimHeliosOP•

I wasn't able to figure out how to use semanage to change the user label, though. Any chance you know how to do that?

2
uco_•

To get a grasp of the basics of SELinux you can start by watching this video: “Security-enhanced Linux for mere mortals” by Thomas Cameron.

https://youtu.be/cNoVgDqqJmM

2
PrimHeliosOP•

This doesn't really help me, unfortunately

1
7165015874•

I also have questions about SE Linux but sadly no answers.

As of Fedora 20, apparently

In current version of Fedora, system services are controlled by the systemd daemon.

https://jfearn.fedorapeople.org/fdocs/en-US/Fedora/20/html/Security_Guide/sect-Security-Enhanced_Linux-Systemd_Access_Control.html

This guy on unix dot stack exchange has the same question and basically gave up with setenforce 0

https://unix.stackexchange.com/questions/378614/selinux-prevents-running-command-when-using-systemd-on-fedora-25

-4