# Housecarl's action for fail2ban: a ban goes into a Housecarl ban list, # and the list says what the banned address is kept from (the firewall # itself, some hosts behind it, or everything). See docs/bans.md. # # Copy this file to /etc/fail2ban/action.d/housecarl.conf, make a ban # list and a token for it alone on the firewall: # # hc banlist add web --scope hosts --host 10.0.10.57 # hc user add f2b-web --no-password --grant bans:write:web # hc token create web --user f2b-web # as root on the firewall # # put the token in /etc/fail2ban/housecarl.token (mode 0600), and use it # in a jail: # # [sshd] # enabled = true # action = housecarl[list=web, url="https://router.lan:8070"] # # The jail's port and protocol go along: port = ssh bans only tcp/22; # fail2ban's default (0:65535) bans every port. IPv6 addresses are banned # with the list's grouping (a /64 unless set otherwise). Housecarl never # bans inside networks, its own addresses or the list's "never". # # On the firewall itself, the local socket works too, still with the # token: url = http://localhost, curlopts = --unix-socket # /run/housecarl/housecarl.sock. [Definition] actionstart = actionstop = actioncheck = # A ban renews one already there; a bantime of -1 is the list's longest. actionban = <_curl> -f -X POST -H "Content-Type: application/json" "/api/v1/banlists//bans" -d '{"address": "", "protocol": "", "ports": "", "time": , "source": "fail2ban/"}' # A ban Housecarl already ended (its own time ran out) is no error. actionunban = <_curl> -X DELETE "/api/v1/banlists//bans?address=" [Init] # The ban list, and Housecarl's URL (its listen address). list = url = https://127.0.0.1:8070 # The API token, in a file only root reads. tokenfile = /etc/fail2ban/housecarl.token # More curl options: --cacert /etc/fail2ban/housecarl-ca.pem for a # private CA, --unix-socket for the local socket. curlopts = _curl = curl -sS --max-time 10 -o /dev/null -H "Authorization: Bearer $(cat )"