Skip to content

Permanent ban (bantime=-1) causes failure when using firewalld #2179

Closed
@Tedderouni

Description

@Tedderouni

Environment:

Fill out and check ([x]) the boxes which apply. If your Fail2Ban version is outdated,
and you can't verify that the issue persists in the recent release, better seek support
from the distribution you obtained Fail2Ban from

  • Fail2Ban version (including any possible distribution suffixes):
  • OS, including release name/version:
  • Fail2Ban installed via OS/distribution mechanisms
  • You have not applied any additional foreign patches to the codebase
  • Some customizations were done to the configuration (provide details below is so)

The issue:

I've set up a vanilla install of CentOS 7.5 with firewalld and fail2ban. When I try to set bantime = -1, fail2ban fails without warning. I've tested this with the only other change to the default config being to enable the sshd jail. When I leave bantime at the default setting it works as expected.

Steps to reproduce

  1. Install CentOS 7.5 minimal installation
  2. sudo yum -y install epel-release
  3. sudo yum -y install fail2ban-firewalld
  4. Create /etc/fail2ban/jail.local with the following contents:
[sshd]
enabled = true
bantime = -1
  1. sudo systemctl start fail2ban

Expected behavior

Fail2ban starts and creates the appropriate firewall rule for the sshd jail. The rule should look something like this:

# firewall-cmd --direct --get-all-rules
ipv4 filter INPUT 0 -p tcp -m multiport --dports ssh -m set --match-set fail2ban-sshd src -j REJECT --reject-with icmp-port-unreachable

Also, an error message should be displayed from the startup script if the any errors occur while creating jails or in other steps.

Observed behavior

The startup command exits without displaying any error message, and the fail2ban service status also shows no error message.
The fail2ban process is running.
No firewall rule is created as shown by firewall-cmd --direct --get-all-rules.
Running systemctl status fail2ban looks as expected.
Running systemctl status firewalld -l shows the following error messages:

firewalld[703]: WARNING: '/usr/sbin/iptables-restore --wait=2 -n' failed: iptables-restore v1.4.21: Set fail2ban-sshd doesn't exist.

                Error occurred at line: 2
                Try 'iptables-restore -h' or 'iptables-restore --help' for more information.
firewalld[703]: ERROR: COMMAND_FAILED

The fail2ban log shows the messages shown below.

Any additional information

Running CentOS 7.5 (1804), with the following relevant package versions:
fail2ban-server-0.9.7-1.el7.noarch
fail2ban-firewalld-0.9.7-1.el7.noarch
ipset-6.29-1.el7.x86_64
firewalld-0.4.4.4-14.el7.noarch

Configuration, dump and another helpful excerpts

Any customizations done to /etc/fail2ban/ configuration

Only the following settings as mentioned above:

# cat jail.local
[sshd]
enabled = true
bantime = -1

Relevant parts of /var/log/fail2ban.log file:

2018-07-14 19:25:17,462 fail2ban.jail           [21346]: INFO    Jail 'sshd' started
2018-07-14 19:25:17,969 fail2ban.action         [21346]: ERROR   ipset create fail2ban-sshd hash:ip timeout -1
firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -p tcp -m multiport --dports ssh -m set --match-set fail2ban-sshd src -j REJECT --reject-with icmp-port-unreachable -- stdout: ''
2018-07-14 19:25:17,969 fail2ban.action         [21346]: ERROR   ipset create fail2ban-sshd hash:ip timeout -1
firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -p tcp -m multiport --dports ssh -m set --match-set fail2ban-sshd src -j REJECT --reject-with icmp-port-unreachable -- stderr: "ipset v6.29: Syntax error: '-1' is out of range 0-4294967\nError: COMMAND_FAILED\n"
2018-07-14 19:25:17,969 fail2ban.action         [21346]: ERROR   ipset create fail2ban-sshd hash:ip timeout -1
firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -p tcp -m multiport --dports ssh -m set --match-set fail2ban-sshd src -j REJECT --reject-with icmp-port-unreachable -- returned 13
2018-07-14 19:25:17,969 fail2ban.actions        [21346]: ERROR   Failed to start jail 'sshd' action 'firewallcmd-ipset': Error starting action

Relevant lines from monitored log files in question:

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions