# This file is managed remotely, all changes will be lost

# Fail2Ban configuration file
#
# Copyright (C) 2015 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
#
# $Revision: 2 $
#

[Definition]

# Option:  actionstart
# Notes.:  command executed once at the start of Fail2Ban.
# Values:  CMD
#
# Changing iptables rules requires root priviledges. If fail2ban is
# configured to run as root, firewall setup can be performed by
# fail2ban automatically. However, if fail2ban is configured to run as
# a normal user, the configuration must be done by some other means
# (e.g. using static firewall configuration with the
# iptables-persistent package).
#
# Explanation of the rule below:
#    Check if any packets coming from an IP on the fail2ban-<name>
#    list have been seen in the last <bantime> seconds. If yes, update the
#    timestamp for this IP and drop the packet. If not, let the packet
#    through.
#
#    Fail2ban inserts blacklisted hosts into the fail2ban-<name> list
#    and removes them from the list after some time, according to its
#    own rules. The <bantime> second timeout is independent and acts as a
#    safeguard in case the fail2ban process dies unexpectedly. The
#    shorter of the two timeouts actually matters.
actionstart = iptables -I <chain> <position> -m recent --update --seconds {{ fail2ban_bantime_distribution_map[ansible_distribution_release] if ansible_distribution_release in fail2ban_bantime_distribution_map.keys() else "<bantime>" }} --name fail2ban-<name> --jump REJECT --reject-with icmp-admin-prohibited

# Option:  actionstop
# Notes.:  command executed once at the end of Fail2Ban
# Values:  CMD
#
actionstop = echo / > /proc/net/xt_recent/fail2ban-<name>
             iptables -D <chain> -m recent --update --seconds {{ fail2ban_bantime_distribution_map[ansible_distribution_release] if ansible_distribution_release in fail2ban_bantime_distribution_map.keys() else "<bantime>" }} --name fail2ban-<name> --jump REJECT --reject-with icmp-admin-prohibited

# Option:  actioncheck
# Notes.:  command executed once before each actionban command
# Values:  CMD
#
actioncheck = test -e /proc/net/xt_recent/fail2ban-<name>

# Option:  actionban
# Notes.:  command executed when banning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    <ip>  IP address
#          <failures>  number of failures
#          <time>  unix timestamp of the ban time
# Values:  CMD
#
actionban = echo +<ip> > /proc/net/xt_recent/fail2ban-<name>

# Option:  actionunban
# Notes.:  command executed when unbanning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    <ip>  IP address
#          <failures>  number of failures
#          <time>  unix timestamp of the ban time
# Values:  CMD
#
actionunban = echo -<ip> > /proc/net/xt_recent/fail2ban-<name>

[Init]

# Defaut name of the chain
#
name = default

# Option:  protocol
# Notes.:  internally used by config reader for interpolations.
# Values:  [ tcp | udp | icmp | all ] Default: tcp
#
protocol = tcp

# Option:  position
# Notes.:  the iptables chain line number where the rule will be inserted
#
position = 1

# Option:  bantime
# Notes.:  length of time in seconds to keep the IP address on the banlist
#
bantime  = 3600

