RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1766415 - selinux blocks fail2ban nftables access
Summary: selinux blocks fail2ban nftables access
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: selinux-policy
Version: 8.0
Hardware: All
OS: Linux
medium
low
Target Milestone: rc
: 8.2
Assignee: Lukas Vrabec
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-10-29 01:36 UTC by Dan Tucny
Modified: 2020-04-28 16:41 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-04-28 16:41:25 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2020:1773 0 None None None 2020-04-28 16:41:38 UTC

Description Dan Tucny 2019-10-29 01:36:38 UTC
Description of problem:
Attempting to use fail2ban with it's nftables actions results in a failure as a result of selinux blocking access to netfilter socket.

Version-Release number of selected component (if applicable):


How reproducible:
Always when using the nftables action

Steps to Reproduce:
1. Install fail2ban from epel
2. Configure it to use banaction = nftables-multiport
3. Start the service

Actual results:
Fail2ban fails to add it's initial set and rule.

e.g.
2019-10-29 08:17:15,115 fail2ban.utils          [709]: #39-Lev. 7f37701a8d20 -- exec: nft add set inet filter f2b-sshd \{ type ipv4_addr\; \}
nft insert rule inet filter input tcp dport \{ ssh \} ip saddr @f2b-sshd reject
2019-10-29 08:17:15,115 fail2ban.utils          [709]: ERROR   7f37701a8d20 -- stderr: 'netlink.c:62: Unable to initialize Netlink socket: Permission denied'
2019-10-29 08:17:15,116 fail2ban.utils          [709]: ERROR   7f37701a8d20 -- stderr: 'netlink.c:62: Unable to initialize Netlink socket: Permission denied'
2019-10-29 08:17:15,116 fail2ban.utils          [709]: ERROR   7f37701a8d20 -- returned 3


Expected results:
Fail2ban is able to create rules/sets using nftables the same way that it can with iptables and firewall-cmd.

Additional info:
SELinux Enforcing audit log:
type=AVC msg=audit(1572312631.453:443): avc:  denied  { create } for  pid=6442 comm="nft" scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:system_r:fail2ban_t:s0 tclass=netlink_netfilter_socket permissive=0
type=SYSCALL msg=audit(1572312631.453:443): arch=c000003e syscall=41 success=no exit=-13 a0=10 a1=3 a2=c a3=560750d5e010 items=0 ppid=6441 pid=6442 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="nft" exe="/usr/sbin/nft" subj=system_u:system_r:fail2ban_t:s0 key=(null)ARCH=x86_64 SYSCALL=socket AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=AVC msg=audit(1572312631.455:444): avc:  denied  { create } for  pid=6441 comm="nft" scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:system_r:fail2ban_t:s0 tclass=netlink_netfilter_socket permissive=0
type=SYSCALL msg=audit(1572312631.455:444): arch=c000003e syscall=41 success=no exit=-13 a0=10 a1=3 a2=c a3=55ec973b5010 items=0 ppid=6435 pid=6441 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="nft" exe="/usr/sbin/nft" subj=system_u:system_r:fail2ban_t:s0 key=(null)ARCH=x86_64 SYSCALL=socket AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"

SELinux Permissive audit log:
type=AVC msg=audit(1572312672.597:463): avc:  denied  { setopt } for  pid=6480 comm="nft" scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:system_r:fail2ban_t:s0 tclass=netlink_netfilter_socket permissive=1
type=SYSCALL msg=audit(1572312672.597:463): arch=c000003e syscall=54 success=yes exit=0 a0=3 a1=1 a2=20 a3=7ffd9825074c items=0 ppid=6479 pid=6480 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="nft" exe="/usr/sbin/nft" subj=system_u:system_r:fail2ban_t:s0 key=(null)ARCH=x86_64 SYSCALL=setsockopt AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"

Audit2allow generated rule from audit log:
#============= fail2ban_t ==============
allow fail2ban_t self:netlink_netfilter_socket { create setopt };

Comment 1 Lukas Vrabec 2019-10-29 09:44:14 UTC
Fixes from Fedora: 
commit 0f1e997af97e443afea394e896e8a368ad80c32b (HEAD -> rawhide)
Author: Lukas Vrabec <lvrabec>
Date:   Tue Oct 29 10:43:34 2019 +0100

    Allow fail2ban_t domain to create netlink netfilter sockets.

Comment 4 Milos Malik 2019-10-29 15:19:04 UTC
Please run the following commands and attach their output here:

# rpm -qa selinux\* | sort
# ls -Z `which nft`
# matchpathcon `which nft`

Thank you.

Comment 11 Dan Tucny 2020-02-27 12:04:33 UTC
I had some challenges reproducing this later when trying and found that this can only currently be reproduced in 8.0, either by installing 8.0 and not updating to 8.1 or by switching to the 8.0 track.

Updates included in 8.1 appear to have resolved the specifically reported issue.

On an 8.0 fresh install:
[root@localhost ~]# rpm -qa selinux\* | sort
selinux-policy-3.14.1-61.el8.noarch
selinux-policy-targeted-3.14.1-61.el8.noarch
[root@localhost ~]# ls -Z `which nft`
system_u:object_r:bin_t:s0 /usr/sbin/nft
[root@localhost ~]# matchpathcon `which nft`
/usr/sbin/nft   system_u:object_r:bin_t:s0

On a host updated to 8.1:
[root@r8-test1 ~]# rpm -qa selinux\* | sort
selinux-policy-3.14.3-20.el8.noarch
selinux-policy-targeted-3.14.3-20.el8.noarch
[root@r8-test1 ~]# ls -Z `which nft`
system_u:object_r:iptables_exec_t:s0 /usr/sbin/nft
[root@r8-test1 ~]# matchpathcon `which nft`
/usr/sbin/nft   system_u:object_r:iptables_exec_t:s0

Comment 12 Milos Malik 2020-02-27 13:11:21 UTC
(In reply to Dan Tucny from comment #11)

> Updates included in 8.1 appear to have resolved the specifically reported
> issue.

Most likely result of https://bugzilla.redhat.com/show_bug.cgi?id=1656891

Comment 14 errata-xmlrpc 2020-04-28 16:41:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:1773


Note You need to log in before you can comment on or make changes to this bug.