Skip to content

Commit

Permalink
send emails using a sidecar container with msmtpd
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed May 9, 2024
1 parent 613dbdd commit 70d4684
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ___
* [Use fail2ban-client](#use-fail2ban-client)
* [Global jail configuration](#global-jail-configuration)
* [Custom jails, actions and filters](#custom-jails-actions-and-filters)
* [Sending email using a sidecar container](#sending-email-using-a-sidecar-container)
* [Contributing](#contributing)
* [License](#license)

Expand Down Expand Up @@ -169,7 +170,7 @@ through the container. Here is an example if you want to ban an IP manually:

```console
$ docker exec -t <CONTAINER> fail2ban-client set <JAIL> banip <IP>
```
```

### Global jail configuration

Expand Down Expand Up @@ -202,6 +203,12 @@ exists, it will be overriden.
> [!WARNING]
> Container has to be restarted to propagate changes
### Sending email using a sidecar container

If you want to send emails using a sidecar container, see the example in
[examples/smtp](examples/smtp). It uses the [smtp.py action](https://github.com/fail2ban/fail2ban/blob/1.1.0/config/action.d/smtp.py)
and [msmtpd SMTP relay](https://github.com/crazy-max/docker-msmtpd) image.

## Contributing

Want to contribute? Awesome! The most basic way to show your support is to star
Expand Down
29 changes: 29 additions & 0 deletions examples/smtp/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: fail2ban

services:
msmtpd:
image: crazymax/msmtpd:latest
container_name: fail2ban_msmtpd
env_file:
- "./msmtpd.env"
ports:
- "127.0.0.1:2500:2500"
environment:
- "TZ"
restart: always

fail2ban:
image: crazymax/fail2ban:latest
container_name: fail2ban
depends_on:
- msmtpd
network_mode: "host"
cap_add:
- NET_ADMIN
- NET_RAW
volumes:
- "./data:/data"
- "/var/log:/var/log:ro"
env_file:
- "./fail2ban.env"
restart: always
2 changes: 2 additions & 0 deletions examples/smtp/data/jail.d/00-jail.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[DEFAULT]
action = smtp.py[host=localhost:2500, sendername=Fail2Ban, [email protected], [email protected]]
5 changes: 5 additions & 0 deletions examples/smtp/fail2ban.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TZ=Europe/Paris

F2B_LOG_TARGET=STDOUT
F2B_LOG_LEVEL=INFO
F2B_DB_PURGE_AGE=1d
10 changes: 10 additions & 0 deletions examples/smtp/msmtpd.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://github.com/crazy-max/docker-msmtpd
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_TLS=on
SMTP_STARTTLS=on
SMTP_TLS_CHECKCERT=on
SMTP_AUTH=on
SMTP_USER=foo
SMTP_PASSWORD=bar
SMTP_FROM=[email protected]

0 comments on commit 70d4684

Please sign in to comment.