2025-02-02 19:35:13 +01:00
# **Fail2Ban UI**
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
🚀 **Fail2Ban-UI ** is a Swiss-made **web-based management interface ** for [Fail2Ban ](https://www.fail2ban.org/ ).
2025-11-12 19:32:45 +01:00
It provides an intuitive dashboard to **monitor, configure, and manage Fail2Ban ** instances in real time, supporting both local and remote Fail2ban servers.
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
Developed by * * [Swissmakers GmbH ](https://swissmakers.ch )**.
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
## **✨ Features**
2025-01-25 16:21:14 +01:00
2025-11-12 19:32:45 +01:00
✅ **Multi-Server Management **
- Manage **multiple Fail2ban servers ** from a single interface
- Support for **local ** , **SSH ** , and **API agent ** connections
- Add, edit, delete, and configure remote Fail2ban instances
- Switch between servers seamlessly via server selector
- Test connections before saving server configurations
2025-02-02 19:35:13 +01:00
✅ **Real-time Dashboard **
- View **all active Fail2Ban jails ** and **banned IPs ** in a clean UI
2025-11-12 19:32:45 +01:00
- Displays **live ban events ** from all configured servers
- **Internal log overview** with ban events stored in SQLite database
- Statistics per server and global overview
- Track ban events with country information and log lines
2025-02-02 19:35:13 +01:00
✅ **Ban & Unban Management **
2025-11-12 19:32:45 +01:00
- **Unban IPs** directly via the UI (works for local and remote servers)
- **Search** for banned IPs across all active jails
- View ban history with detailed information (IP, jail, hostname, country, logs)
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
✅ **Fail2Ban Configuration Management **
2025-11-12 19:32:45 +01:00
- **Edit & Save** active Fail2Ban jail/filter configs (local and remote)
- **Manage Jails**: Enable/disable jails on local and remote servers
- **Filter Debug**: Test filters against log lines using `fail2ban-regex`
2025-02-02 19:35:13 +01:00
- Get automatic **email alerts ** for specific country-based bans
- Configure own SMTP settings for email alerts (STARTTLS only)
- Adjust default ban time, find time, and set ignore IPs
- Auto-detects changes and prompts for **reload ** to apply
- Enable debug-mode for detailed module logs
2025-01-25 16:21:14 +01:00
2025-11-12 19:32:45 +01:00
✅ **SSH Remote Management **
- Connect to remote Fail2ban servers via SSH
- Automatic deployment of custom action for ban notifications
- Passwordless sudo support for seamless operation
- Configurable SSH key selection per server
- Test SSH connections before saving
✅ **API Agent Support ** (Future)
- Connect to remote Fail2ban instances via lightweight API agents
- Secure communication using shared secrets
- Push ban notifications from remote servers to the UI
✅ **Persistent Storage **
- **SQLite database** for storing server configurations and ban events
- All settings and server configurations persist across restarts
- Automatic migration from legacy JSON-based settings
2025-02-02 19:35:13 +01:00
✅ **Mobile-Friendly & Responsive UI / Fast **
- Optimized for **mobile & desktop **
2025-11-18 00:10:37 +01:00
- Powered by **Tailwind CSS ** (works offline when built locally)
2025-02-02 19:35:13 +01:00
- **Go-based backend** ensures minimal resource usage
2025-11-12 19:32:45 +01:00
- Parallel execution for improved performance on remote connections
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
✅ **Systemd & SELinux Support **
- **Run as a systemd service** (Standalone or Container)
- **Supports SELinux** for secure execution (also container version)
2025-01-25 16:21:14 +01:00
2025-11-12 19:32:45 +01:00
✅ **Internationalization **
- Multi-language support (English, German, French, Italian, Spanish)
- Easy to add new languages via JSON translation files
2025-02-02 19:35:13 +01:00
## **📸 Screenshots**
Some images from the UI in action:
2025-01-25 16:21:14 +01:00
2025-11-12 19:32:45 +01:00
| Dashboard | Server Management | Filter Debug |
|-----------|-------------------|--------------|
|  |  |  |
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
📌 **More screenshots are found [here](./screenshots/) **
2025-01-25 16:21:14 +01:00
---
2025-02-02 19:35:13 +01:00
## **📥 Installation & Deployment**
Fail2Ban-UI can be currently deployed in **two main ways ** :
**1️ ⃣ Running from local source**
**2️ ⃣ Running as a container**
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
### **🔹 Method 1: Running from Local Source**
To install and run directly on the system:
📌 * * [Follow the basic systemd setup guide ](./deployment/systemd/README.md )**
```bash
git clone https://github.com/swissmakers/fail2ban-ui.git /opt/fail2ban-ui
cd /opt/fail2ban-ui
2025-11-18 00:10:37 +01:00
# Build Tailwind CSS for production (optional but recommended)
# This requires Node.js and npm to be installed
./build-tailwind.sh
# Build Go application
2025-11-12 19:32:45 +01:00
go build -o fail2ban-ui ./cmd/server/main.go
2025-02-02 19:35:13 +01:00
...
```
2025-01-25 16:21:14 +01:00
2025-11-18 00:10:37 +01:00
**📌 Note on Tailwind CSS:**
- For **production/offline use ** , build Tailwind CSS using `./build-tailwind.sh` before building the application
- This creates a local CSS file at `pkg/web/static/tailwind.css` that works offline
- The build script uses **Tailwind CSS v3 ** (latest v3.x, matches CDN version)
- If the local file is not found, the application will automatically fall back to the CDN (requires internet connection)
- The build script requires **Node.js ** and **npm ** to be installed
- The script works for both fresh installations and existing development environments
2025-01-25 16:21:14 +01:00
---
2025-02-02 19:35:13 +01:00
### **🔹 Method 2: Running as a Container**
For an easy containerized deployment:
📌 * * [Follow the basic container deployment guide ](./deployment/container/README.md )**
2025-11-14 10:48:32 +01:00
You can either build the image locally or pull the **official, automatically built image ** from the Swissmakers registry.
Every merge into the `main` branch triggers a new build that is published at:
```
registry.swissmakers.ch/infra/fail2ban-ui:latest
```
2025-02-02 19:35:13 +01:00
```bash
2025-11-14 10:48:32 +01:00
# Pull the latest pre-built image
podman pull registry.swissmakers.ch/infra/fail2ban-ui:latest
# Run the container
2025-02-02 19:35:13 +01:00
podman run -d \
--name fail2ban-ui \
--network=host \
-v /opt/podman-fail2ban-ui:/config:Z \
-v /etc/fail2ban:/etc/fail2ban:Z \
-v /var/log:/var/log:ro \
-v /var/run/fail2ban:/var/run/fail2ban \
-v /usr/share/GeoIP:/usr/share/GeoIP:ro \
2025-11-14 10:48:32 +01:00
registry.swissmakers.ch/infra/fail2ban-ui:latest
2025-02-02 19:35:13 +01:00
```
> **📌 Note:** The container can also be managed as a **systemd service**.
2025-11-12 19:32:45 +01:00
---
## **🚀 Getting Started**
### **First Launch**
1. After starting Fail2Ban-UI, access the web interface at `http://localhost:8080` (or your configured port)
2. You'll be prompted to **add your first Fail2ban server ** or **enable the local connector **
3. For local connections: Enable the local connector if Fail2ban is running on the same host
4. For remote connections: Add a new server via SSH or API agent
### **Adding a Server**
#### **Local Server**
- The local connector is available by default but **disabled ** initially
- Enable it in the server management settings if Fail2ban runs on the same host
- Requires root access or passwordless sudo to the Fail2ban socket
#### **SSH Server**
1. Go to **Settings ** → **Manage Servers **
2. Click **Add Server **
3. Select **SSH ** as connection type
4. Fill in:
- **Name**: A descriptive name for this server
- **Host**: IP address or hostname
- **Port**: SSH port (default: 22)
- **SSH User**: Username for SSH connection
2025-11-14 09:41:43 +01:00
- **SSH Key**: Select an SSH key from your `~/.ssh/` directory (or `/config/.ssh/` when running in a container)
2025-11-12 19:32:45 +01:00
5. Click **Test Connection ** to verify before saving
6. The UI will automatically deploy the custom action for ban notifications
**Requirements for SSH connections:**
- SSH key-based authentication (passwordless login)
- Network connectivity from UI host to remote server
2025-11-14 09:41:43 +01:00
- The SSH user must have:
- Sudo access to run `systemctl restart fail2ban` and `/usr/bin/fail2ban-client` (configured via sudoers)
- File system ACLs on `/etc/fail2ban` for read/write access to configuration files (no sudo needed for file operations)
**Recommended SSH setup (using service account with ACLs):**
```bash
# Create service account
sudo useradd -r -s /bin/bash sa_fail2ban
# Configure sudoers for fail2ban-client and systemctl restart
sudo visudo -f /etc/sudoers.d/fail2ban-ui
# Add:
sa_fail2ban ALL=(ALL) NOPASSWD: /usr/bin/fail2ban-client *
sa_fail2ban ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart fail2ban
# Set ACLs for /etc/fail2ban directory
sudo setfacl -Rm u:sa_fail2ban:rwX /etc/fail2ban
sudo setfacl -dRm u:sa_fail2ban:rwX /etc/fail2ban
```
This setup provides fine-grained permissions without requiring full passwordless sudo access.
2025-11-12 19:32:45 +01:00
#### **API Agent Server** (Future)
- API agent support is planned for future releases
- Will allow connecting to remote Fail2ban instances via a lightweight API service
---
2025-02-02 19:35:13 +01:00
## **🔒 Security Considerations**
2025-11-12 19:32:45 +01:00
2025-11-14 09:41:43 +01:00
- Fail2Ban-UI requires **root privileges ** or **passwordless sudo ** to interact with Fail2Ban sockets (for local connections).
- For SSH connections, use a **dedicated service account ** with:
- **Limited sudo access** (only for `fail2ban-client` and `systemctl restart fail2ban` )
- **File system ACLs** on `/etc/fail2ban` for configuration file access (more secure than full sudo)
2025-02-02 19:35:13 +01:00
- **Restrict access** using **firewall rules ** or a **reverse proxy ** with authentication.
- Ensure that Fail2Ban logs/configs **aren't exposed publicly ** .
2025-11-12 19:32:45 +01:00
- For SSH connections, use **SSH key-based authentication ** and restrict SSH access.
- Store SSH keys securely and use strong passphrases.
- The SQLite database contains sensitive information - ensure proper file permissions.
2025-02-02 19:35:13 +01:00
For **SELinux users ** , apply the **Fail2Ban-UI security policies ** :
```bash
# Basic rule to allow fail2ban access the fail2ban-ui API
semodule -i fail2ban-curl-allow.pp
# Also needed for a secure container deployment
semodule -i fail2ban-container-ui.pp
semodule -i fail2ban-container-client.pp
```
2025-11-12 19:32:45 +01:00
---
2025-02-02 19:35:13 +01:00
## **🛠️ Troubleshooting**
### **UI not accessible?**
2025-11-12 19:32:45 +01:00
- Ensure **port 8080 ** (or your configured port) is open:
2025-02-02 19:35:13 +01:00
```bash
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
```
- Check logs:
```bash
journalctl -u fail2ban-ui.service -f
```
2025-11-12 19:32:45 +01:00
### **No servers configured?**
- On first launch, you need to either:
- Enable the local connector (if Fail2ban runs locally)
- Add a remote server via SSH or API agent
- Go to **Settings ** → **Manage Servers ** to configure your first server
### **SSH connection issues?**
- Verify SSH key authentication works manually:
```bash
ssh -i ~/.ssh/your_key user@remote -host
```
2025-11-14 09:41:43 +01:00
- Ensure the SSH user has proper permissions:
- Check sudo access for `fail2ban-client` and `systemctl restart fail2ban` :
```bash
sudo -l -U sa_fail2ban
```
- Verify ACLs on `/etc/fail2ban` :
```bash
getfacl /etc/fail2ban
```
2025-11-12 19:32:45 +01:00
- Check debug mode in settings for detailed error messages
- Verify the SSH user has access to `/var/run/fail2ban/fail2ban.sock`
### **Local connector not working?**
- Ensure Fail2ban is running: `sudo systemctl status fail2ban`
- Check socket permissions: `ls -la /var/run/fail2ban/fail2ban.sock`
- Verify the UI has access (runs as root or has sudo permissions)
### **Database issues?**
- The SQLite database is stored in the application directory
- Check file permissions if you see database errors
- Backup the database before major updates
---
## **📊 Database**
Fail2Ban-UI uses an embedded **SQLite database ** (`fail2ban-ui.db` ) to store:
- **Server configurations**: All configured Fail2ban servers (local, SSH, API agent)
- **Application settings**: UI preferences, SMTP settings, etc.
- **Ban events**: Historical ban records with IP, jail, hostname, country, and log lines
The database is automatically created on first launch and migrated from legacy JSON settings if present.
---
## **🌐 Internationalization**
Fail2Ban-UI supports multiple languages:
- English (en)
- German (de, de_ch)
- French (fr)
- Italian (it)
- Spanish (es)
Change the language in **Settings ** → **Language ** . New languages can be added by creating translation files in `internal/locales/` .
---
2025-02-02 19:35:13 +01:00
## **🤝 Contributing**
We welcome **pull requests ** and **feature suggestions ** !
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
1. **Fork ** this repository
2. **Create ** a new branch:
2025-01-25 16:21:14 +01:00
```bash
2025-02-02 19:35:13 +01:00
git checkout -b feature/my-feature
2025-01-25 16:21:14 +01:00
```
2025-02-02 19:35:13 +01:00
3. **Commit ** your changes:
2025-01-25 16:21:14 +01:00
```bash
2025-02-02 19:35:13 +01:00
git commit -m "Add new feature"
2025-01-25 16:21:14 +01:00
```
2025-02-02 19:35:13 +01:00
4. **Push ** to the branch:
2025-01-25 16:21:14 +01:00
```bash
2025-02-02 19:35:13 +01:00
git push origin feature/my-feature
2025-01-25 16:21:14 +01:00
```
2025-02-02 19:35:13 +01:00
5. **Open ** a Pull Request
2025-01-25 16:21:14 +01:00
2025-02-02 19:35:13 +01:00
## **📜 License**
Fail2Ban-UI is licensed under **GNU GENERAL PUBLIC LICENSE, Version 3 ** .
2025-11-12 19:32:45 +01:00
See [`LICENSE` ](./LICENSE ) for details.