modernleft-docs/Applications/fail2ban-manager.md

95 lines
3.7 KiB
Markdown
Raw Normal View History

2025-01-17 16:21:59 +00:00
---
title: fail2ban-manager
draft: true
date: 2025-01-16
---
2025-01-16 02:00:12 +00:00
An extensible CLI tool for managing [fail2ban](https://github.com/fail2ban/fail2ban).
2025-01-17 16:27:10 +00:00
- [Introduction](#introduction)
- [Working with Jails](#working-with-jails)
- [Plugins](#plugins)
- [Cloudflare](#cloudflare)
- [Plugin: Hetzner](#plugin-hetzner)
- [Plugin: Telegram](#plugin-telegram)
- [Credits](#credits)
2025-01-16 02:00:12 +00:00
2025-01-13 04:17:24 +00:00
## Introduction
Source Code hosted on my [Forgejo instance](https://forgejo.gravityfargo.dev/gravityfargo/fail2ban-manager). Registration is enabled for the public with GitHub via Authentik.
2025-01-16 02:00:12 +00:00
Any issues and feature requests can be submitted here on GitHub.
This tool is designed to make managing fail2ban easier without the need to edit configuration files. It is designed to be extensible via plugins, and easy to use.
2025-01-13 04:17:24 +00:00
## Working with Jails
## Plugins
2025-01-16 02:00:12 +00:00
### Cloudflare
> Ban an IP address using IP Rules in [Cloudflare WAF](https://developers.cloudflare.com/waf/tools/ip-access-rules/create/). Jails are configured create rules in a specific DNS zone. Bans are cached in a database for fail2ban's check action to use.
| Notes | |
| -------------------- | ----------------------------------------------------------------- |
| Typer generated docs | [Link](man/cloudflare.md) |
| Provided via | [Officicial SDK](https://github.com/cloudflare/cloudflare-python) |
---
| Variable | Purpose |
| ---------------------- | ----------------------------------------- |
| `CLOUDFLARE_EMAIL` | Email address for Cloudflare account |
| `CLOUDFLARE_API_TOKEN` | Token with permissions to manage IP Rules |
1. Enable the Cloudflare plugin
```bash
f2bm plugin enable cloudflare
```
1. Create an [API Token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/)
2. Get the [Zone ID](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/) from Cloudflare and create a zone in the database
```bash
f2bm cloudflare create-zone 11111111111111111111111111111111 example.com
```
2025-01-13 04:17:24 +00:00
### Plugin: Hetzner
2025-01-16 02:00:12 +00:00
> Whitelist ip addresses in the [Hetzner](https://www.hetzner.com/) cloud firewall, and bulk whitelist Cloudflare IP addresses.
| Notes | |
| -------------------- | --------------------------------------------------------------- |
| Typer generated docs | [Link](man/hetzner.md) |
| Provided via | [Officicial SDK](https://github.com/hetznercloud/hcloud-python) |
---
2025-01-13 04:17:24 +00:00
2025-01-16 02:00:12 +00:00
1. Enable the Hetzner plugin
2025-01-13 04:17:24 +00:00
2025-01-16 02:00:12 +00:00
```bash
f2bm plugin enable hetzner
```
2. Create an [API Token](https://docs.hetzner.com/cloud/api/getting-started/generating-api-token/)
2025-01-13 04:17:24 +00:00
### Plugin: Telegram
2025-01-16 02:00:12 +00:00
> Send a message to a Telegram chat. Custom messages per-jail are supported as well as seperate groups for each jail.
| Notes | |
| -------------------- | ----------------------------------------------------------------- |
| Typer generated docs | [Link](man/telegram.md) |
| Provided via | [Rest API](https://forgejo.gravityfargo.dev/gravityfargo/envoyer) |
---
## Credits
- [Typer](https://github.com/fastapi/typer), build great CLIs. Easy to code. Based on Python type hints.
- [Rich](https://github.com/Textualize/rich) is a Python library for rich text and beautiful formatting in the terminal.
- [envoyer](https://forgejo.gravityfargo.dev/gravityfargo/envoyer) Stupid simple notifications library. (My Project)