<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>SELinux on rooiratel</title><link>https://rooiratel.red/tags/selinux/</link><description>Stephan Snyman's personal website</description><language>en-gb</language><generator>Hugo</generator><atom:link href="https://rooiratel.red/tags/selinux/index.xml" rel="self" type="application/rss+xml"/><item><title>When being root is not enough</title><link>https://rooiratel.red/posts/when-being-root-is-not-enough/</link><pubDate>Fri, 25 Nov 2022 15:19:31 +0200</pubDate><guid isPermaLink="true">https://rooiratel.red/posts/when-being-root-is-not-enough/</guid><description>The other day, when I logged into my server, I realised that I hadn’t upgraded it in a while. Fedora 37 had just been released, so it was a good time for an upgrade. The process went smoothly, but I noticed after rebooting that the Caddy service failed to start. At first I thought that maybe something in the config was no longer compatible with the new version of Caddy. Everything checked out fine. When I manually executed the command in the caddy.service file then the service would start up without any issues.</description><content:encoded><![CDATA[<p>The other day, when I logged into my server, I realised that I hadn&rsquo;t upgraded it in a while. Fedora 37 had just been released, so it was a good time for an upgrade. The process went smoothly, but I noticed after rebooting that the <a href="https://caddyserver.com/">Caddy</a> service failed to start. At first I thought that maybe something in the config was no longer compatible with the new version of Caddy. Everything checked out fine. When I manually executed the command in the caddy.service file then the service would start up without any issues.</p>
<p>That was strange. The Caddyfile is owned by root, the caddy.service file is owned by root, and the service is executed and run as root. So it wasn&rsquo;t a permission issue.</p>
<p>Let&rsquo;s see what systemd has to say for itself.</p>
<p>I ran the command <code>journalctl -u caddy --no-pager | less</code>, and that is when I saw this:</p>
<p><code>caddy[736]: run: reading config file: open /the/path/to/Caddyfile: permission denied</code></p>
<p>So it was a permission issue after all. But how? Is being root not enough?</p>
<p>I furiously started searching the web and eventually stumbled upon <a href="https://stackoverflow.com/questions/51209967/systemd-service-file-failed-to-execute-command-permission-denied">this StackOverflow post</a>, which suggested that SELinux could cause this type of behaviour.</p>
<p>I temporarily disabled SELinux with <code>sudo setenforce Permissive</code> to see if it would fix my issue ‒ and it did. Cool, but why would SELinux cause the issue in the first place? What didn&rsquo;t it like about my caddy.service file?</p>
<p>To find out, I started with the <code>semanage fcontext --list</code> command. This is when I realised that I was storing my Caddyfile in a directory that SELinux didn&rsquo;t approve of. So my final solution was just to move it to a directory that SELinux was happy with. The last thing I needed to do was update the caddy.service file to point to the new location of the Caddyfile and restart the service.</p>
]]></content:encoded></item></channel></rss>