Bug 1777562

Summary: Update to fail2ban 0.10.4 requires adaption of SELinux policy
Product: Red Hat Enterprise Linux 7 Reporter: Robert Scheck <redhat-bugzilla>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED WONTFIX QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.7CC: lvrabec, mmalik, orion, plautrba, prasun.gera, rmullett, robert.scheck, ssekidde, vmojzis, zpytela
Target Milestone: rcKeywords: Patch, Reopened
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-12-10 17:20:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Robert Scheck 2019-11-27 20:17:06 UTC
Description of problem:
After updating fail2ban from 0.9.7 to 0.10.4 (from EPEL), some AVC denied messages are raised (below copy & paste might origin from different systems, but each message occured on each system):

type=AVC msg=audit(1574695222.87:338081): avc:  denied  { read } for  pid=51600 comm="fail2ban-server" name="disable" dev="sysfs" ino=4296 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:sysfs_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1574695222.87:338081): arch=x86_64 syscall=open success=no exit=EACCES a0=7f394c5f7110 a1=80000 a2=1b6 a3=24 items=0 ppid=1 pid=51600 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=fail2ban-server exe=/usr/bin/python2.7 subj=system_u:system_r:fail2ban_t:s0 key=(null)

type=AVC msg=audit(1574729848.51:345109): avc:  denied  { open } for  pid=60026 comm="fail2ban-server" path="/sys/module/ipv6/parameters/disable" dev="sysfs" ino=4296 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:sysfs_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1574729848.51:345109): arch=x86_64 syscall=open success=no exit=EACCES a0=7f993bbf0110 a1=80000 a2=1b6 a3=24 items=0 ppid=1 pid=60026 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=fail2ban-server exe=/usr/bin/python2.7 subj=system_u:system_r:fail2ban_t:s0 key=(null)

type=AVC msg=audit(1574840369.454:471274): avc:  denied  { search } for  pid=51600 comm="fail2ban-server" name="net" dev="proc" ino=332 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=dir permissive=0
type=SYSCALL msg=audit(1574840369.454:471274): arch=x86_64 syscall=open success=no exit=EACCES a0=7f394c5f7138 a1=80000 a2=1b6 a3=24 items=0 ppid=1 pid=51600 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=fail2ban-server exe=/usr/bin/python2.7 subj=system_u:system_r:fail2ban_t:s0 key=(null)

type=AVC msg=audit(1574840369.453:471273): avc:  denied  { getattr } for  pid=51600 comm="fail2ban-server" path="/sys/module/ipv6/parameters/disable" dev="sysfs" ino=4296 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:sysfs_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1574840369.453:471273): arch=x86_64 syscall=fstat success=no exit=EACCES a0=9 a1=7f395b242e30 a2=7f395b242e30 a3=0 items=0 ppid=1 pid=51600 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=fail2ban-server exe=/usr/bin/python2.7 subj=system_u:system_r:fail2ban_t:s0 key=(null)

type=AVC msg=audit(1574885547.891:508939): avc:  denied  { read } for  pid=41351 comm="fail2ban-server" name="disable_ipv6" dev="proc" ino=362 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1574885547.891:508939): arch=x86_64 syscall=open success=no exit=EACCES a0=7fa6d05f7138 a1=80000 a2=1b6 a3=24 items=0 ppid=1 pid=41351 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=fail2ban-server exe=/usr/bin/python2.7 subj=system_u:system_r:fail2ban_t:s0 key=(null)

type=AVC msg=audit(1574885623.670:509015): avc:  denied  { open } for  pid=41535 comm="fail2ban-server" path="/proc/sys/net/ipv6/conf/all/disable_ipv6" dev="proc" ino=362 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1574885623.670:509015): arch=x86_64 syscall=open success=no exit=EACCES a0=7fce681ad138 a1=80000 a2=1b6 a3=24 items=0 ppid=1 pid=41535 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=fail2ban-server exe=/usr/bin/python2.7 subj=system_u:system_r:fail2ban_t:s0 key=(null)

type=AVC msg=audit(1574885664.477:509068): avc:  denied  { getattr } for  pid=41672 comm="fail2ban-server" path="/proc/sys/net/ipv6/conf/all/disable_ipv6" dev="proc" ino=362 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1574885664.477:509068): arch=x86_64 syscall=fstat success=no exit=EACCES a0=12 a1=7ffff1a8abc0 a2=7ffff1a8abc0 a3=0 items=0 ppid=1 pid=41672 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=fail2ban-server exe=/usr/bin/python2.7 subj=system_u:system_r:fail2ban_t:s0 key=(null)

Given /sys/module/ipv6/parameters/disable was tried to access, I found this is likely due to socket_ipv6_is_supported() which belongs to systemd code. This again seems to belong to libnss_myhostname.so.2, which is referenced in /etc/nsswitch.conf, which seems to be called during some "getent host" operation or similar (as per bug #1444824). As the new fail2ban version introduces IPv6 support, there seems to be a good chance for an overlap - and as conclusion some allow rules for the SELinux policy.

Version-Release number of selected component (if applicable):
fail2ban-server-0.10.4-1.el7.noarch
selinux-policy-targeted-3.13.1-252.el7.1.noarch

How reproducible:
Everytime, update from fail2ban 0.9.7 to 0.10.4 (from EPEL)

Actual results:
Update to fail2ban 0.10.4 requires adaption of SELinux policy

Expected results:
Adapted SELinux policy :)

Additional info:
The following allow rules seem to do the trick here:

allow fail2ban_t sysfs_t:file { getattr open read };
allow fail2ban_t sysctl_net_t:dir { search };
allow fail2ban_t sysctl_net_t:file { getattr open read };

Comment 2 Robert Scheck 2019-11-27 20:28:25 UTC
Cross-filed ticket 02529186 at the Red Hat customer portal.

Comment 3 Orion Poplawski 2019-11-29 22:46:29 UTC
Lukas - perhaps time to move the SELinux config into the fail2ban package?  There are a number of other fail2ban SELinux issues on EL.

Comment 4 Orion Poplawski 2019-11-30 02:25:28 UTC
I guess one complication - the standard SELinux requires uses rich dependencies which is not supported on EL7:

Requires: (%{name}-selinux if selinux-policy-%{selinuxtype})

so I'm not sure what would be the best way to proceed.

Comment 5 Orion Poplawski 2019-11-30 02:36:29 UTC
This moves the current policy into the fail2ban package: https://src.fedoraproject.org/rpms/fail2ban/pull-request/2

Comment 6 Lukas Vrabec 2019-12-02 12:28:04 UTC
Hi Orion, 

Thank you very much for the PR. Let's deliver this in Fedora and RHEL-8. For RHEL-7 let's keep it in selinux-policy. 

Thanks,
Lukas.

Comment 8 Lukas Vrabec 2019-12-09 14:30:19 UTC
This issue was not selected to be included in Red Hat Enterprise Linux 7 because it is seen either as low or moderate impact to a small number of use-cases. Current minor release will be in Maintenance Support 1 Phase, which means that qualified Critical and Important Security errata advisories (RHSAs) and Urgent Priority Bug Fix errata advisories (RHBAs) may be released as they become available.

We will now close this issue, but if you believe that it qualifies for the Maintenance Support 1 Phase, please re-open; otherwise, we recommend moving the request to Red Hat Enterprise Linux 8 if applicable.

Comment 14 Orion Poplawski 2020-02-27 03:06:56 UTC
Lukas - do you have a suggestion for the way forward here on EL7?  The SELinux IndependentPolicy guidelines use conditional dependencies that do not work in EL7.

Comment 15 Lukas Vrabec 2020-02-27 22:18:29 UTC
@Vito, 

Do we have a way to deliver fail2ban policy in EL7?

Comment 16 prasun.gera 2020-04-02 19:06:58 UTC
I am seeing these denials too along with other SELinux issues on RHEL 7. If there is an overall decision to update the selinux-policy package in RHEL 7, I would appreciate it. For instance, this is another bug that is affected by selinux-policy (https://bugzilla.redhat.com/show_bug.cgi?id=1657549).

Comment 17 Vit Mojzis 2020-06-04 16:10:38 UTC
(In reply to Lukas Vrabec from comment #15)
> @Vito, 
> 
> Do we have a way to deliver fail2ban policy in EL7?

You can use unconditional "Requires: selinux-policy-targeted". It's not ideal (the policy and the whole selinux userspace would be pulled as a dependency even into containers or other systems that do not use SELinux), but it works (it was the preferred method before conditional "requires" became available).