feat(fail2ban): let operators exempt trusted addresses from bans (ignoreip) #155

Closed
opened 2026-11-15 11:51:44 +00:00 by Dragonish · 0 comments
Collaborator

What

Add fail2ban_ignoreip: a list of addresses, networks or hostnames written as ignoreip in the [DEFAULT] section of /etc/fail2ban/jail.local. The default is ["127.0.0.1/8", "::1"], which is fail2ban's own default, so nothing changes unless a consumer sets it.

Why

The role has no way to keep a trusted address from being banned. A mistyped key or a looping health check from the machine that runs Ansible, or from a CI runner, can get that address banned, and then automation can no longer reach the host to fix it. Operators of a home lab need to exempt those addresses on every jail.

[DEFAULT] is the one place that covers both the jails in fail2ban_jails (written to jail.local) and the per-service jails that other roles add with tasks_from: service_jail (written to jail.d). A per-jail ignoreip would have to be repeated on every jail and would be missed by service jails.

Scope

  • One variable, fail2ban_ignoreip, typed in meta/argument_specs.yml and documented in the README.
  • A [DEFAULT] block in templates/jail.local.j2.
  • Validation in tasks/validate.yml: every entry is a non-empty string without whitespace (entries are joined with spaces, so a value with a space would silently become two entries). Regexes end in \Z.
  • molecule/default/verify.yml: assert that the default is applied and that a configured value reaches the running jail (fail2ban-client get sshd ignoreip).
  • A changelog fragment (minor_changes).

Compatibility

With the default value the rendered jail.local gains a [DEFAULT] block, so the first run after upgrading restarts fail2ban once (the existing handler is Restart, which clears the current ban list). After that the role is idempotent.

Out of scope

No second _extra list. A single list is enough for a generic role; consumers who want a base list plus additions can compose it in their own variables.

## What Add `fail2ban_ignoreip`: a list of addresses, networks or hostnames written as `ignoreip` in the `[DEFAULT]` section of `/etc/fail2ban/jail.local`. The default is `["127.0.0.1/8", "::1"]`, which is fail2ban's own default, so nothing changes unless a consumer sets it. ## Why The role has no way to keep a trusted address from being banned. A mistyped key or a looping health check from the machine that runs Ansible, or from a CI runner, can get that address banned, and then automation can no longer reach the host to fix it. Operators of a home lab need to exempt those addresses on every jail. `[DEFAULT]` is the one place that covers both the jails in `fail2ban_jails` (written to `jail.local`) and the per-service jails that other roles add with `tasks_from: service_jail` (written to `jail.d`). A per-jail `ignoreip` would have to be repeated on every jail and would be missed by service jails. ## Scope - One variable, `fail2ban_ignoreip`, typed in `meta/argument_specs.yml` and documented in the README. - A `[DEFAULT]` block in `templates/jail.local.j2`. - Validation in `tasks/validate.yml`: every entry is a non-empty string without whitespace (entries are joined with spaces, so a value with a space would silently become two entries). Regexes end in `\Z`. - `molecule/default/verify.yml`: assert that the default is applied and that a configured value reaches the running jail (`fail2ban-client get sshd ignoreip`). - A changelog fragment (`minor_changes`). ## Compatibility With the default value the rendered `jail.local` gains a `[DEFAULT]` block, so the first run after upgrading restarts fail2ban once (the existing handler is `Restart`, which clears the current ban list). After that the role is idempotent. ## Out of scope No second `_extra` list. A single list is enough for a generic role; consumers who want a base list plus additions can compose it in their own variables.
Dragonish added the Kind/Enhancement label 2026-11-15 11:51:44 +00:00
Defame1297 added the
Priority
High
2
Reviewed
Confirmed
1
Status
Ready for Agent
labels 2026-11-15 12:49:57 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#155