A couple months ago, one of my customers' cyber-security teams handed down an edict that all IPA-managed users needed to have SELinux confinements applied. For admistrative accounts, this meant that administrators would SSH system and have an SELinux assignment of:
And that when such administrative-users executed `sudo`, they would end up with an SELinux assignment of:$ id -Z staff_u:staff_r:staff_t:s0-s0:c0.c1023
# id -Z staff_u:sysadm_r:sysadm_t:s0-s0:c0.c1023
Not long after this, that same cyber-security team opened up a bug-ticket complaining that their scanners were no longer able to conduct all the tests they were able to conduct prior to the implementation of the confinement scheme (shocking, I know).
Since their scan-user operated with the same privilege set as human administrators did, their scan-user was getting similarly constrained. As an example of the practical impacts of this confinement, one need only try to look at the contents of the /etc/shadow file:
$ sudo cat /etc/shadow /bin/cat: /etc/shadow: Permission denied
Since their security tooling was using that confined user-account to do – among a whole host of other check-tasks – functionally similar tests, naturally, some of their tests started failing and red lights started showing up on their dashboards. Worse (for them), their boss started asking why his summary-reports suddenly started to look like the elevator scene in The Shining after months of being mostly green.
Their problem ended up in my task-pile. I'm not really an SELinux guy …even if I can usually figure out how to get most third-party applications working that don't come with SELinux policy without having to resort to disabling SELinux. And, as much of "not really an SELinux guy" as I am, I'm really not an IPA guy. So, "fun times ahead".
Not wanting to waste time on the problem, and knowing that my customer had a Red Hat Enterprise Support entitlement, I opted to try to avail myself of that support. With my customer being part of a large, very-siloed organization, just getting a support case opened – and then actually able to directly read and comment on it rather than having to play "grape vine" – proved to be its own, multi-week ordeal.
After several days of back-and-forth, I was finally able to get the case escalated to people with SELinux and IPA expertise …but, seemingly, no one with both sets of expertise (yay). So, I was getting SELinux answers that included no "how do we actually do this wholly within IPA" and I was getting generic IPA guidance. The twain never quite met.
Ultimately, I was given guidance to do (after creating a scan-user POSIX-group to put the scan-user into):
ipa selinuxusermap-add --hostcat='all' --selinuxuser=unconfined_u:s0-s0:c0.c1023 <SCAN_GROUP_NAME> ipa selinuxusermap-add-user <SCAN_GROUP_NAME> --group=<SCAN_GROUP_NAME> ipa sudorule-add <SCAN_USER_SUDO_RULE_NAME> --hostcat='all' --cmdcat='all'
ipa sudorule-add-option <SCAN_GROUP_RULE_NAME> --sudooption '!authenticate' ipa sudorule-add-option <SCAN_GROUP_RULE_NAME> --sudooption role=unconfined_r ipa sudorule-add-option <SCAN_GROUP_RULE_NAME> --sudooption type=unconfined_t ipa sudorule-add-user <SCAN_GROUP_RULE_NAME> --group=<SCAN_GROUP_NAME> sudo bash -c "service sssd stop ; rm -f /var/lib/sss/db/* ; service sssd start"
Unfortunately, this didn't solve my problem. My scan-user continued to be given the same SELinux profile upon logging in and executing `sudo` that my "normal" administrative users were. Support came back and told me to re-execute the above, but to give the sudorule a precedence-setting:
ipa selinuxusermap-add --hostcat='all' --selinuxuser=unconfined_u:s0-s0:c0.c1023 <SCAN_GROUP_NAME> ipa selinuxusermap-add-user <SCAN_GROUP_NAME> --group=<SCAN_GROUP_NAME> ipa sudorule-add <SCAN_USER_SUDO_RULE_NAME> --hostcat='all' --cmdcat='all' --order=99 ipa sudorule-add-option <SCAN_GROUP_RULE_NAME> --sudooption '!authenticate' ipa sudorule-add-option <SCAN_GROUP_RULE_NAME> --sudooption role=unconfined_r ipa sudorule-add-option <SCAN_GROUP_RULE_NAME> --sudooption type=unconfined_t ipa sudorule-add-user <SCAN_GROUP_RULE_NAME> --group=<SCAN_GROUP_NAME> sudo bash -c "service sssd stop ; rm -f /var/lib/sss/db/* ; service sssd start"
Still, even having set a precedence on the `sudo` rule, my scan-user wasn't getting the right confinement rules applied. The support rep had me execute `ipa user-show <SCAN_USER> --all`. Upon doing that, we noticed that the <SCAN_USER> account was affiliated with two `sudo` rules. Then using `ipa sudorule-show <SUDO_RULE_NAME> --all` for each rule, was able to find that one of the two rules was applying the `!authenticate`, `role=sysadm_r` and `type=sysadm_t` sudo-options.
I made the assumption that, even though we'd explicitly set a precedence-value on the one rule, the previously-existing rule likely didn't have a precedence-value set and that, as a result, implicit-precedence rules were still being applied ...and that the previously-existing rule "won" in that scenario. To test, I did:
ipa sudorule-mod <EXISTING_RULE> --order=10
And then retested with my scan-user. At this point, the scan-user was functioning as desired. This meant that:
- My supposition about implicit and explicit rule-ordering was correct
- That the rules are processed on a "higher-number == higher-priority" precedence-processing