feat(fail2ban): reload instead of restart when jail.local changes #332

Merged
Dragonish merged 2 commits from feat/fail2ban-reload into main 2026-11-23 20:15:08 +00:00
Collaborator

What and why

Closes #157

The main entry point now notifies Reload Fail2Ban when jail.local changes, as service_jail already did, instead of restarting the daemon. A restart stops every jail, which flushes its bans out of the firewall until they are restored from Fail2Ban's database when the jail starts again, and forgets failures counted toward maxretry. A reload applies the new settings to the running jails and does neither. state: reloaded starts the service when it is not running, so a first install still works. fail2ban-client -t still runs before the reload when the whole role runs.

Following your comment on #157 (handler names are not part of the interface), the Restart Fail2Ban handler is removed: nothing in the role notifies it any more, and no other role of the collection does either (searched the whole repository).

The issue's open question (does any setting the role writes need a restart?): no, none that the role writes. From the Fail2Ban 1.1.0 source: a reload re-reads jail.local, jail.d and filter.d and re-applies each jail's ignoreip, filters and journalmatch; a changed backend restarts that jail by itself; server-level settings (loglevel, dbfile, socket, pidfile) are not reloaded, and the role writes none of them. Three differences from the old restart are now stated in the README: a reload does not unban an address that a widened fail2ban_ignoreip newly covers (only a restart skips ignored addresses when it restores bans; fail2ban-client unban <address> releases it), it does not change existing bans when bantime changes, and with --tags fail2ban_configure only, the configuration test does not run first (the reload still rejects a bad configuration).

Verified

  • All commit-stage hooks pass (yamllint, ansible-lint, REUSE, changelog lint, Conventional Commit); --syntax-check passes on the converge, verify and side_effect playbooks.
  • Molecule: side_effect.yml records the daemon's PID, bans 198.51.100.77, and rewrites jail.local with maxretry: 4; verify.yml asserts the new maxretry is active, the ban is in force and the PID is unchanged. The PID is what separates a reload from a restart, because bans come back from the database after a restart.
  • The ignored-address behaviour of the restart path was checked in the Fail2Ban 1.1.0 source (Jail.restoreCurrentBans skips ignored addresses; Server.reloadJails unbans only with --unban).
  • An independent review of the diff, no blocking finding; its documentation findings are applied.

Not verified

  • Molecule itself (CI only): the side_effect and verify steps have not run on the image. They rely on ExecReload=fail2ban-client reload keeping MainPID (read from the upstream unit, not checked against the Ubuntu 24.04 package unit).
  • The reload on a real host running a changed jail, and the three differences above: read from the source, not run.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code

## What and why Closes #157 The main entry point now notifies `Reload Fail2Ban` when `jail.local` changes, as `service_jail` already did, instead of restarting the daemon. A restart stops every jail, which flushes its bans out of the firewall until they are restored from Fail2Ban's database when the jail starts again, and forgets failures counted toward `maxretry`. A reload applies the new settings to the running jails and does neither. `state: reloaded` starts the service when it is not running, so a first install still works. `fail2ban-client -t` still runs before the reload when the whole role runs. Following your comment on #157 (handler names are not part of the interface), the `Restart Fail2Ban` handler is removed: nothing in the role notifies it any more, and no other role of the collection does either (searched the whole repository). **The issue's open question** (does any setting the role writes need a restart?): no, none that the role writes. From the Fail2Ban 1.1.0 source: a reload re-reads `jail.local`, `jail.d` and `filter.d` and re-applies each jail's `ignoreip`, filters and `journalmatch`; a changed `backend` restarts that jail by itself; server-level settings (`loglevel`, `dbfile`, `socket`, `pidfile`) are not reloaded, and the role writes none of them. Three differences from the old restart are now stated in the README: a reload does not unban an address that a widened `fail2ban_ignoreip` newly covers (only a restart skips ignored addresses when it restores bans; `fail2ban-client unban <address>` releases it), it does not change existing bans when `bantime` changes, and with `--tags fail2ban_configure` only, the configuration test does not run first (the reload still rejects a bad configuration). ## Verified - All commit-stage hooks pass (yamllint, ansible-lint, REUSE, changelog lint, Conventional Commit); `--syntax-check` passes on the converge, verify and side_effect playbooks. - Molecule: `side_effect.yml` records the daemon's PID, bans `198.51.100.77`, and rewrites `jail.local` with `maxretry: 4`; `verify.yml` asserts the new `maxretry` is active, the ban is in force and the PID is unchanged. The PID is what separates a reload from a restart, because bans come back from the database after a restart. - The ignored-address behaviour of the restart path was checked in the Fail2Ban 1.1.0 source (`Jail.restoreCurrentBans` skips ignored addresses; `Server.reloadJails` unbans only with `--unban`). - An independent review of the diff, no blocking finding; its documentation findings are applied. ## Not verified - Molecule itself (CI only): the side_effect and verify steps have not run on the image. They rely on `ExecReload=fail2ban-client reload` keeping `MainPID` (read from the upstream unit, not checked against the Ubuntu 24.04 package unit). - The reload on a real host running a changed jail, and the three differences above: read from the source, not run. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code
Dragonish added 1 commit 2026-11-23 20:01:59 +00:00
feat(fail2ban): reload instead of restart when jail.local changes
Build / build (pull_request) Successful in 16s
Molecule / molecule (pull_request) Canceled after 0s
Lint / lint (pull_request) Canceled after 1m23s
e0e9fa1b17
The main entry point notified a restart. A restart stops every jail, which
flushes its bans out of the firewall until they are restored from Fail2Ban's
database when the jail starts again, and forgets failures counted toward
maxretry. A reload applies the new settings to the running jails. service_jail
already reloads.

The Restart Fail2Ban handler is removed: nothing notifies it any more, and a
handler name is not part of the role's interface (#257). A new side_effect.yml
bans an address, records the daemon's PID and rewrites jail.local; verify
asserts the new maxretry is active, the ban is in force and the PID is
unchanged (the PID is what separates a reload from a restart, since bans are
restored from the database).

Assisted-by: Claude Code
Defame1297 approved these changes 2026-11-23 20:08:08 +00:00
Defame1297 added 1 commit 2026-11-23 20:08:27 +00:00
Merge branch 'main' into feat/fail2ban-reload
Build / build (pull_request) Successful in 15s
Molecule / molecule (pull_request) Successful in 3m48s
Lint / lint (pull_request) Successful in 1m20s
9d31fd9461
Dragonish merged commit 40b79ea985 into main 2026-11-23 20:15:08 +00:00
Dragonish deleted branch feat/fail2ban-reload 2026-11-23 20:15:08 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#332