Misha Vyrtsev
Notes by Misha Vyrtsev
About

f2b, fail2ban with a web interface and an API

f2b is fail2ban with a web interface and an API. Until now fail2ban on my servers was a folder of jail and filter files for each of them, with a docker-compose file and a script to deploy it. In f2b the jails, filters and actions are still files, but they’re edited in the browser, in an editor that knows fail2ban’s syntax. A save fail2ban would refuse is refused, in fail2ban’s own words, and nothing is written. One it accepts is written, and fail2ban reloads, keeping its bans.

A filter can be tried on a log before it’s saved. fail2ban-regex runs over the end of a log a jail reads, any other log on the server, rotated .gz ones too, or lines pasted in, and marks each line matched, missed or ignored, again with every change to the filter. A line from the log can start a failregex: its date and address are taken out, and the rest is escaped.

  • Who is banned now, where, since when and until when, and the log lines that did it. A ban can be lifted, and an address or a range banned by hand
  • The history: bans per day by jail, the most banned addresses, and every ban fail2ban’s database holds
  • fail2ban’s own filters and actions, to read and to override in one press
  • fail2ban’s log, following along
  • One password, from the environment, and every wrong one is a line for fail2ban to read
  • API tokens for scripts and agents, read-only or read and write, for a JSON:API described by an OpenAPI document. A link to paste into an agent opens a brief on the API, with a token that works for thirty minutes

Like mailio, emguio and taskio, it runs in Docker, as two containers sharing a volume. The engine, fail2ban with the API, runs in the host’s network, because fail2ban writes the host’s firewall. The interface runs behind your reverse proxy and talks to the engine over a socket on the volume.

The code and docs are on GitHub.