CentOS 7 : SELinux Trouble With Fail2ban

Home » CentOS » CentOS 7 : SELinux Trouble With Fail2ban
CentOS 7 Comments

Hi,

Some time ago I had SELinux problems with Fail2ban. One of the users on this list suggested that it might be due to the fact that I’m using a bone-headed iptables script instead of FirewallD.

I’ve spent the past few weeks getting up to date with doing things in a more orthodox manner. So currently my internet-facing CentOS server has a nicely configured NetworkManager, and FirewallD has replaced the iptables script.

Unfortunately when I install FirewallD from EPEL, I still get the same error.

SELinux is preventing /usr/bin/python2.7 from read access on the file disable.

***** Plugin catchall (100. confidence) suggests *****

If you believe that python2.7 should be allowed read access on the disable file by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing:
# ausearch -c ‘f2b/server’ –raw | audit2allow -M my-f2bserver
# semodule -i my-f2bserver.pp

Weirdly enough, when I follow this suggestion and then empty audit.log and restart my server, I still get the exact same error again.

Which makes Fail2ban unusable with SELinux in enforcing mode in the current state.

Any suggestions ?

Niki


Microlinux – Solutions informatiques durables
7, place de l’église – 30730 Montpezat Site : https://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32
Mob. : 06 51 80 12 12

7 thoughts on - CentOS 7 : SELinux Trouble With Fail2ban

  • Le 26/02/2020 à 11:51, Nicolas Kovacs a écrit :

    I reinstalled this server from scratch and took some notes. This time I was successful, though I don’t know exactly what I did differently this time.

    Usually I work as non-root user and call sudo whenever I need root permissions.

    But is this OK when enabling SELinux modules? Let’s consider the example given above:

    # ausearch -c ‘f2b/server’ –raw | audit2allow -M my-f2bserver
    # semodule -i my-f2bserver.pp

    Can I also perform it like this?

    $ sudo ausearch -c ‘f2b/server’ –raw | sudo audit2allow -M my-f2bserver
    $ sudo semodule -i my-f2bserver.pp

    I’m not sure with SELinux.

    Cheers,

    Niki


    Microlinux – Solutions informatiques durables
    7, place de l’église – 30730 Montpezat Site : https://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32
    Mob. : 06 51 80 12 12

  • https://bugzilla.redhat.com/show_bug.cgi?id=1777562
    This bug was posted earlier. Sadly, it was closed WONTFIX, but the policy you need is:

    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 };
    Honestly, if this really affects all users of fail2ban, I’ll probably push back on the ticket to get it updated. I’ve successfully had the policy updated to handle issues with popular non-RHEL/CentOS packages.


    Jonathan Billings

  • So I am thinking that packages are probably going to start having to carry around their own policies to fix things like this. Nagios had to start doing this a couple of years ago and it might be occurring on all branches.


    Stephen J Smoogen.

  • This is certainly the plan for fail2ban – but the bundled SELinux packaging guidelines currently make use of conditional dependencies so that’s not going to fly for EL7. And unfortunately since RHEL7 is in maintenance the selinux-policy package isn’t going to be updated either.


    Orion Poplawski Manager of NWRA Technical Systems 720-772-5637
    NWRA, Boulder/CoRA Office FAX: 303-415-9702
    3380 Mitchell Lane orion@nwra.com Boulder, CO 80301 https://www.nwra.com/

  • EPEL packages are often crap quality (as packages), merely blind imports of the upstream package without any adjustments needed for the RHEL/CentOS environment (sometimes not even for Fedora), which is often somewhat different than the Fedora environment which go unnoticed or unrepaired, for years.

    Have you reported it? To the Fail2Ban EPEL package maintainer, not to the (upstream) Fail2Ban maintainers, nor the CentOS (thus RHEL) Python package maintainer, nor the Python maintainers, i.e., the issue is that the EPEL Fail2Ban package does not (seem to, based on your message) have the correct RHEL/CentOS SELinux definitions.

    This sometimes needs multiple iterations to catch all the types of access attempted, e.g., initially it might be that read is denied, but later the process would want other permissions like write but which were never logged because of the initial read failure.

    Try repeating. That either means multiple binary modules, or a text module that you add each new audit2allow “fix”, increment the version number, rebuild the policy and module then re-insert — lather, rinse,

    /mark

  • This should work. Likely the reason that it didn’t resolve in one go is that there were multiple denials – but the first time it just failed on the first one. Someone else mentioned running in non-enforcing mode to allow the audit log to collect all of the denials and then generating the module – this is a good practice.


    Orion Poplawski Manager of NWRA Technical Systems 720-772-5637
    NWRA, Boulder/CoRA Office FAX: 303-415-9702
    3380 Mitchell Lane orion@nwra.com Boulder, CO 80301 https://www.nwra.com/