<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Audit on ./concord.sh</title><link>https://concord.sh/tags/audit/</link><description>Recent content in Audit on ./concord.sh</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Tue, 22 Sep 2020 15:11:42 -0400</lastBuildDate><atom:link href="https://concord.sh/tags/audit/index.xml" rel="self" type="application/rss+xml"/><item><title>Wrong run_init Authentication</title><link>https://concord.sh/posts/2020/09/wrong-run_init-authentication/</link><pubDate>Tue, 22 Sep 2020 15:11:42 -0400</pubDate><guid>https://concord.sh/posts/2020/09/wrong-run_init-authentication/</guid><description>&lt;p>Today I noticed that for some reason on one of my Gentoo boxes, I needed to authenticate as root in order to start and stop services, when on my other boxes I would authenticate as my currently logged in user. Normally I like to run &lt;code>sudo -i&lt;/code> or &lt;code>sudo -s&lt;/code> in order to run multiple tasks in the same session, and this was never previously a problem until I recently locked down the root account such that I could no longer enter its password (it no longer had one).&lt;/p></description><content>&lt;p>Today I noticed that for some reason on one of my Gentoo boxes, I needed to authenticate as root in order to start and stop services, when on my other boxes I would authenticate as my currently logged in user. Normally I like to run &lt;code>sudo -i&lt;/code> or &lt;code>sudo -s&lt;/code> in order to run multiple tasks in the same session, and this was never previously a problem until I recently locked down the root account such that I could no longer enter its password (it no longer had one).&lt;/p>
&lt;p>On Gentoo at least, when you need to execute some action on some service, the usage of &lt;code>run_init&lt;/code> is required. The purpose of this utility is to change SELinux contexts from a user context to a system context for the purpose of running some action on some service. The reason for this is that doing this requires a change to the SELinux system user, role, and type, a highly privileged action. You can read more about this &lt;a href="https://wiki.gentoo.org/wiki/SELinux/Tutorials/Linux_services_and_the_system_u_SELinux_user">here&lt;/a>. With this in mind, I started digging through my SELinux configuration, looking for anything out of the ordinary. Everything was in place. My SELinux login mapping was correct and I had access to all the correct roles. Then, I started looking through PAM. &lt;code>run_init&lt;/code> is configured to authenticate through PAM using the configuration in &lt;code>/etc/pam.d/run_init&lt;/code> which had no differences between both of my systems. Also checking &lt;code>/etc/pam.d/system-auth&lt;/code> turned up no differences.&lt;/p>
&lt;p>At this point I was beginning to pull my hair out a little, and went down the path of running &lt;code>strace&lt;/code> against &lt;code>run_init&lt;/code> to see what exactly was going on. I noticed that on the system where &lt;code>run_init&lt;/code> was working as I was expecting, by asking me for my credentials instead of root&amp;rsquo;s, &lt;code>run_init&lt;/code> was reading the contents of &lt;code>/proc/self/loginuid&lt;/code>, and the other system was not. Immediately after this file was read, PAM was invoked using the UID present in this file. That&amp;rsquo;s when I had a vague realization of what was happening.&lt;/p>
&lt;p>I did a quick search for what package was providing the &lt;code>run_init&lt;/code> binary and thought to check its USE flags.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># equery b `which run_init`&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> * Searching &lt;span style="color:#66d9ef">for&lt;/span> /usr/sbin/run_init ...
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sys-apps/policycoreutils-3.1 &lt;span style="color:#f92672">(&lt;/span>/usr/sbin/run_init&lt;span style="color:#f92672">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># equery u policycoreutils&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span> Legend : U - final flag setting &lt;span style="color:#66d9ef">for&lt;/span> installation&lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span> : I - package is installed with flag &lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span> Colors : set, unset &lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> * Found these USE flags &lt;span style="color:#66d9ef">for&lt;/span> sys-apps/policycoreutils-3.1:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> U I
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - - audit : Enable support &lt;span style="color:#66d9ef">for&lt;/span> sys-process/audit and use the audit_* functions &lt;span style="color:#f92672">(&lt;/span>like audit_getuid instead of
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> getuid&lt;span style="color:#f92672">())&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - - dbus : Enable dbus support &lt;span style="color:#66d9ef">for&lt;/span> anything that needs it &lt;span style="color:#f92672">(&lt;/span>gpsd, gnomemeeting, etc&lt;span style="color:#f92672">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> + + pam : Add support &lt;span style="color:#66d9ef">for&lt;/span> PAM &lt;span style="color:#f92672">(&lt;/span>Pluggable Authentication Modules&lt;span style="color:#f92672">)&lt;/span> - DANGEROUS to arbitrarily flip
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - - python_targets_python3_6 : Build with Python 3.6
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> + + python_targets_python3_7 : Build with Python 3.7
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Ah ha! Sure enough, on the system where my user was being authenticated, the &lt;code>audit&lt;/code> USE flag was set, and here it wasn&amp;rsquo;t. A quick flip of this flag and a rebuild of &lt;code>policycoreutils&lt;/code> fixed the problem.&lt;/p>
&lt;p>This was a little bit of an oddity at first. I feel like this functionality should be separated from the &lt;code>audit&lt;/code> USE flag in some way, as it looks like &lt;code>run_init&lt;/code> checks what user is invoking some action in order to log it, but this information is also passed along to PAM. Without this check, &lt;code>run_init&lt;/code> seems to assume that the root user is the one performing the action and does not authenticate the actual user against PAM. In any case, this simple change implemented the exact behavior I was looking for.&lt;/p></content></item></channel></rss>