2026-03-01 10:23:11 +01:00
|
|
|
|
# Fail2Ban Integration with Proxmox Firewall
|
|
|
|
|
|
|
2026-03-01 10:31:36 +01:00
|
|
|
|
This Ansible playbook deploys and configures **Fail2Ban** on a Proxmox VE
|
|
|
|
|
|
environment, integrating it with the **Proxmox firewall** for cluster-aware
|
|
|
|
|
|
IP banning. It supports both single-node and clustered Proxmox setups.
|
2026-03-01 10:23:11 +01:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
|
|
|
|
|
|
- Detects Proxmox VE installation.
|
|
|
|
|
|
- Checks cluster filesystem (`pmxcfs`) and quorum before modifying firewall.
|
|
|
|
|
|
- Detects cluster membership via `corosync.conf`.
|
|
|
|
|
|
- Installs and configures Fail2Ban with:
|
|
|
|
|
|
- SSH protection
|
|
|
|
|
|
- Proxmox GUI / AD login protection
|
|
|
|
|
|
- Progressive ban escalation (recidive jail)
|
2026-03-01 10:31:36 +01:00
|
|
|
|
- Deploys a **cluster-aware Fail2Ban action** (`proxmox-fw`) for Proxmox
|
|
|
|
|
|
firewall integration.
|
2026-03-01 10:23:11 +01:00
|
|
|
|
- Ensures safe firewall updates without affecting Corosync ports (5404/5405).
|
|
|
|
|
|
- Supports single-node Fail2Ban using `iptables-multiport`.
|
|
|
|
|
|
- Enables and starts the Fail2Ban service.
|
|
|
|
|
|
- Provides tasks to list or manually unban IPs in the cluster.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
|
|
|
|
- **Proxmox VE** (any supported version)
|
|
|
|
|
|
- **Ansible** ≥ 2.9
|
|
|
|
|
|
- Root or sudo access on target nodes
|
|
|
|
|
|
- Proxmox firewall enabled for cluster-wide banning (optional, but recommended)
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Variables
|
|
|
|
|
|
|
2026-03-01 10:31:36 +01:00
|
|
|
|
The playbook uses the following variables (can be defined in a `vars` file or
|
|
|
|
|
|
inventory group vars):
|
2026-03-01 10:23:11 +01:00
|
|
|
|
|
2026-03-01 10:52:57 +01:00
|
|
|
|
| Variable | Description | Default |
|
|
|
|
|
|
|-------------------------|---------------------------------|-----------------|
|
|
|
|
|
|
| `f2b_bantime` | Ban per tentativi falliti | `600s` |
|
|
|
|
|
|
| `f2b_findtime` | Finestra per contare fallimenti | `1200s` |
|
|
|
|
|
|
| `f2b_maxretry` | Tentativi prima del ban | `5` |
|
|
|
|
|
|
| `f2b_bantime_increment` | Abilita ban incrementale | `true` |
|
|
|
|
|
|
| `f2b_bantime_factor` | Fattore aumento ban | `2` |
|
|
|
|
|
|
| `f2b_bantime_max` | Durata massima del ban | `7d` |
|
|
|
|
|
|
| `f2b_recidive_bantime` | Ban per recidiva | `3600` |
|
|
|
|
|
|
| `f2b_recidive_findtime` | Finestra recidiva | `86400` |
|
|
|
|
|
|
| `f2b_recidive_maxretry` | Tentativi recidiva | `3` |
|
|
|
|
|
|
| `f2b_ipset_name` | Nome IPSet per IP bannati | `f2b-blacklist` |
|
|
|
|
|
|
| `f2b_unban_ip` | IP da sbloccare | `""` |
|
2026-03-01 10:48:13 +01:00
|
|
|
|
|
|
|
|
|
|
> All `clustered` and `pmxcfs_running` checks default to `false` to prevent
|
|
|
|
|
|
> errors on non-clustered or single-node setups.
|
2026-03-01 10:23:11 +01:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
### 1. Apply the playbook
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
ansible-playbook -i inventory fail2ban-proxmox.yml
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 2. List current banned IPs
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-03-01 10:52:57 +01:00
|
|
|
|
ansible-playbook \
|
|
|
|
|
|
-i inventory \
|
|
|
|
|
|
fail2ban-proxmox.yml \
|
|
|
|
|
|
-e "f2b_ipset_name=fail2ban" \
|
|
|
|
|
|
-t list_banned
|
2026-03-01 10:23:11 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 3. Unban a specific IP
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
ansible-playbook -i inventory fail2ban-proxmox.yml -e "f2b_unban_ip=1.2.3.4"
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## How It Works
|
|
|
|
|
|
|
|
|
|
|
|
- Detects Proxmox – ensures the playbook runs only on Proxmox VE hosts.
|
2026-03-01 10:31:36 +01:00
|
|
|
|
- Cluster safety checks – verifies /etc/pve/.members and corosync.conf
|
|
|
|
|
|
for quorum.
|
|
|
|
|
|
- Installs Fail2Ban – ensures /etc/fail2ban/jail.local exists and applies
|
|
|
|
|
|
configuration.
|
|
|
|
|
|
- Cluster-aware action – for clustered nodes, Fail2Ban bans are added to
|
|
|
|
|
|
Proxmox firewall and compiled immediately (pve-firewall compile).
|
|
|
|
|
|
- Single-node fallback – uses iptables-multiport for nodes not in
|
|
|
|
|
|
a cluster.
|
|
|
|
|
|
- Corosync protection – prevents firewall rules from dropping cluster
|
|
|
|
|
|
communication ports (5404/5405).
|
2026-03-01 10:23:11 +01:00
|
|
|
|
|
|
|
|
|
|
## Notes & Safety
|
|
|
|
|
|
|
|
|
|
|
|
- The playbook does not copy jail.conf, only manages jail.local.
|
|
|
|
|
|
- Firewall rules for clustered nodes are only modified if quorum exists.
|
2026-03-01 10:31:36 +01:00
|
|
|
|
- pve-firewall compile is called safely (>/dev/null 2>&1 || true)
|
|
|
|
|
|
to prevent playbook failure on minor compilation warnings.
|
2026-03-01 10:23:11 +01:00
|
|
|
|
- Manual unban is supported via f2b_unban_ip variable.
|
2026-03-01 10:48:13 +01:00
|
|
|
|
- Always verify that the Proxmox firewall is enabled when using
|
|
|
|
|
|
cluster-wide bans.
|
2026-03-01 10:23:11 +01:00
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
2026-03-01 10:48:13 +01:00
|
|
|
|
MIT License
|