Skip to content

Commit 2d34335

Browse files
authored
Fail2ban 1.0.1 (#130)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent 9f379d0 commit 2d34335

File tree

13 files changed

+147
-292
lines changed

13 files changed

+147
-292
lines changed

.dockerignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/.dev
2-
/.idea
3-
/*.iml
4-
51
/.git
62
/.github
73
/examples

.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

Dockerfile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# syntax=docker/dockerfile:1
22

3-
ARG FAIL2BAN_VERSION=0.11.2
3+
ARG FAIL2BAN_VERSION=1.0.1
44
ARG ALPINE_VERSION=3.16
55

66
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS fail2ban-src
7-
RUN apk add --no-cache git patch
7+
RUN apk add --no-cache git
88
WORKDIR /src/fail2ban
9+
RUN git init . && git remote add origin "https://github.com/fail2ban/fail2ban.git"
910
ARG FAIL2BAN_VERSION
10-
RUN <<EOT
11-
git clone https://github.com/fail2ban/fail2ban.git .
12-
git reset --hard $FAIL2BAN_VERSION
13-
EOT
14-
COPY patches /src/patches
15-
RUN for i in /src/patches/*.patch; do patch -p1 < $i; done
11+
RUN git fetch origin "${FAIL2BAN_VERSION}" && git checkout -q FETCH_HEAD
1612

1713
FROM alpine:${ALPINE_VERSION}
1814
RUN --mount=from=fail2ban-src,source=/src/fail2ban,target=/tmp/fail2ban,rw \
@@ -40,7 +36,7 @@ RUN --mount=from=fail2ban-src,source=/src/fail2ban,target=/tmp/fail2ban,rw \
4036
&& pip3 install dnspython3 pyinotify \
4137
&& cd /tmp/fail2ban \
4238
&& 2to3 -w --no-diffs bin/* fail2ban \
43-
&& python3 setup.py install \
39+
&& pip3 install . \
4440
&& apk del build-dependencies \
4541
&& rm -rf /etc/fail2ban/jail.d
4642

README.md

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
## About
1313

14-
[Fail2ban](https://www.fail2ban.org) Docker image based on Alpine Linux.<br />
15-
If you are interested, [check out](https://hub.docker.com/r/crazymax/) my other Docker images!
14+
[Fail2ban](https://www.fail2ban.org) Docker image to ban hosts that cause
15+
multiple authentication errors.
1616

17-
💡 Want to be notified of new releases? Check out 🔔 [Diun (Docker Image Update Notifier)](https://github.com/crazy-max/diun) project!
17+
> **Note**
18+
>
19+
> Want to be notified of new releases? Check out 🔔 [Diun (Docker Image Update Notifier)](https://github.com/crazy-max/diun)
20+
> project!
1821
1922
___
2023

@@ -52,10 +55,10 @@ docker buildx bake image-all
5255

5356
## Image
5457

55-
| Registry | Image |
56-
|--------------------------------------------------------------------------------------------------|---------------------------------|
57-
| [Docker Hub](https://hub.docker.com/r/crazymax/fail2ban/) | `crazymax/fail2ban` |
58-
| [GitHub Container Registry](https://github.com/users/crazy-max/packages/container/package/fail2ban) | `ghcr.io/crazy-max/fail2ban` |
58+
| Registry | Image |
59+
|-----------------------------------------------------------------------------------------------------|------------------------------|
60+
| [Docker Hub](https://hub.docker.com/r/crazymax/fail2ban/) | `crazymax/fail2ban` |
61+
| [GitHub Container Registry](https://github.com/users/crazy-max/packages/container/package/fail2ban) | `ghcr.io/crazy-max/fail2ban` |
5962

6063
Following platforms for this image are available:
6164

@@ -97,21 +100,22 @@ Image: crazymax/fail2ban:latest
97100

98101
### Docker Compose
99102

100-
Docker compose is the recommended way to run this image. Copy the content of folder
101-
[examples/compose](examples/compose) in `/var/fail2ban/` on your host for example. Edit the compose and env files
102-
with your preferences and run the following commands:
103+
Docker compose is the recommended way to run this image. Copy the content of
104+
folder [examples/compose](examples/compose) in `/var/fail2ban/` on your host
105+
for example. Edit the Compose and env files with your preferences and run the
106+
following commands:
103107

104-
```
105-
docker-compose up -d
106-
docker-compose logs -f
108+
```console
109+
$ docker-compose up -d
110+
$ docker-compose logs -f
107111
```
108112

109113
### Command line
110114

111115
You can also use the following minimal command :
112116

113-
```
114-
docker run -d --name fail2ban --restart always \
117+
```console
118+
$ docker run -d --name fail2ban --restart always \
115119
--network host \
116120
--cap-add NET_ADMIN \
117121
--cap-add NET_RAW \
@@ -124,29 +128,33 @@ docker run -d --name fail2ban --restart always \
124128

125129
Recreate the container whenever I push an update:
126130

127-
```bash
128-
docker-compose pull
129-
docker-compose up -d
131+
```console
132+
$ docker-compose pull
133+
$ docker-compose up -d
130134
```
131135

132136
## Notes
133137

134138
### `DOCKER-USER` chain
135139

136140
In Docker 17.06 and higher through [docker/libnetwork#1675](https://github.com/docker/libnetwork/pull/1675),
137-
you can add rules to a new table called `DOCKER-USER`, and these rules will be loaded before any rules Docker creates
138-
automatically. This is useful to make `iptables` rules created by Fail2Ban persistent.
141+
you can add rules to a new table called `DOCKER-USER`, and these rules will be
142+
loaded before any rules Docker creates automatically. This is useful to make
143+
`iptables` rules created by Fail2Ban persistent.
139144

140-
If you have an older version of Docker, you may just change the chain definition for your jail to `chain = FORWARD`.
141-
This way, all Fail2Ban rules come before any Docker rules but these rules will now apply to ALL forwarded traffic.
145+
If you have an older version of Docker, you may just change the chain
146+
definition for your jail to `chain = FORWARD`. This way, all Fail2Ban rules
147+
come before any Docker rules but these rules will now apply to ALL forwarded
148+
traffic.
142149

143150
More info : https://docs.docker.com/network/iptables/
144151

145152
### `DOCKER-USER` and `INPUT` chains
146153

147-
If your Fail2Ban container is attached to `DOCKER-USER` chain instead of `INPUT`, the rules will be applied
148-
**only to containers**. This means that any packets coming into the `INPUT` chain will bypass these rules that now
149-
reside under the `FORWARD` chain.
154+
If your Fail2Ban container is attached to `DOCKER-USER` chain instead of
155+
`INPUT`, the rules will be applied **only to containers**. This means that any
156+
packets coming into the `INPUT` chain will bypass these rules that now reside
157+
under the `FORWARD` chain.
150158

151159
This is why the [sshd](examples/jails/sshd) jail contains a [`chain = INPUT`](examples/jails/sshd/jail.d/sshd.conf)
152160
in its definition and [traefik](examples/jails/traefik) jail contains
@@ -166,64 +174,67 @@ And others using the `INPUT` chain:
166174

167175
### Use iptables tooling without nftables backend
168176

169-
As you may know, [nftables](https://wiki.nftables.org) is available as a modern replacement for the kernel's iptables
170-
subsystem on Linux.
177+
As you may know, [nftables](https://wiki.nftables.org) is available as a modern
178+
replacement for the kernel's iptables subsystem on Linux.
171179

172-
This image still uses `iptables` to preserve backwards compatibility but
173-
[an issue is opened](https://github.com/crazy-max/docker-fail2ban/issues/29) about its implementation.
180+
This image still uses `iptables` to preserve backwards compatibility but [an issue is opened](https://github.com/crazy-max/docker-fail2ban/issues/29)
181+
about its implementation.
174182

175-
If your system's `iptables` tooling uses the nftables backend, this will throw the error
176-
`stderr: 'iptables: No chain/target/match by that name.'`. You need to switch the `iptables` tooling to 'legacy' mode
177-
to avoid these problems. This is the case on at least Debian 10 (Buster), Ubuntu 19.04, Fedora 29 and newer releases
178-
of these distributions by default. RHEL 8 does not support switching to legacy mode, and is therefore currently
179-
incompatible with this image.
183+
If your system's `iptables` tooling uses the nftables backend, this will throw
184+
the error `stderr: 'iptables: No chain/target/match by that name.'`. You need
185+
to switch the `iptables` tooling to 'legacy' mode to avoid these problems. This
186+
is the case on at least Debian 10 (Buster), Ubuntu 19.04, Fedora 29 and newer
187+
releases of these distributions by default. RHEL 8 does not support switching
188+
to legacy mode, and is therefore currently incompatible with this image.
180189

181190
On Ubuntu or Debian:
182191

183-
```
184-
update-alternatives --set iptables /usr/sbin/iptables-legacy
185-
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
186-
update-alternatives --set arptables /usr/sbin/arptables-legacy
187-
update-alternatives --set ebtables /usr/sbin/ebtables-legacy
192+
```console
193+
$ update-alternatives --set iptables /usr/sbin/iptables-legacy
194+
$ update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
195+
$ update-alternatives --set arptables /usr/sbin/arptables-legacy
196+
$ update-alternatives --set ebtables /usr/sbin/ebtables-legacy
188197
```
189198

190199
On Fedora:
191200

192-
```
193-
update-alternatives --set iptables /usr/sbin/iptables-legacy
201+
```console
202+
$ update-alternatives --set iptables /usr/sbin/iptables-legacy
194203
```
195204

196205
Then reboot to apply changes.
197206

198207
### Use fail2ban-client
199208

200-
[Fail2ban commands](http://www.fail2ban.org/wiki/index.php/Commands) can be used through the container. Here is an
201-
example if you want to ban an IP manually :
209+
[Fail2ban commands](http://www.fail2ban.org/wiki/index.php/Commands) can be used
210+
through the container. Here is an example if you want to ban an IP manually:
202211

203-
```
204-
docker exec -t <CONTAINER> fail2ban-client set <JAIL> banip <IP>
212+
```console
213+
$ docker exec -t <CONTAINER> fail2ban-client set <JAIL> banip <IP>
205214
```
206215

207216
### Global jail configuration
208217

209218
You can provide customizations in `/data/jail.d/*.local` files.
210219

211-
For example to change the default bantime for all jails, send an e-mail with whois report and relevant log lines
212-
to the destemail:
220+
For example to change the default bantime for all jails, send an e-mail with
221+
whois report and relevant log lines to the destemail:
213222

214-
```
223+
```text
215224
[DEFAULT]
216225
bantime = 1h
217226
destemail = root@localhost
218227
sender = root@$(hostname -f)
219228
action = %(action_mwl)s
220229
```
221230

222-
> :warning: If you want email to be sent after a ban, you have to configure SSMTP env vars
231+
> **Warning**
232+
>
233+
> If you want email to be sent after a ban, you have to configure SSMTP env vars
223234
224235
FYI, here is the order *jail* configuration would be loaded:
225236

226-
```
237+
```text
227238
jail.conf
228239
jail.d/*.conf (in alphabetical order)
229240
jail.local
@@ -234,16 +245,20 @@ A sample configuration file is [available on the official repository](https://gi
234245

235246
### Custom jails, actions and filters
236247

237-
Custom jails, actions and filters can be added respectively in `/data/jail.d`, `/data/action.d` and `/data/filter.d`.
238-
If you add an action/filter that already exists, it will be overriden.
248+
Custom jails, actions and filters can be added respectively in `/data/jail.d`,
249+
`/data/action.d` and `/data/filter.d`. If you add an action/filter that already
250+
exists, it will be overriden.
239251

240-
> :warning: Container has to be restarted to propagate changes
252+
> **Warning**
253+
>
254+
> Container has to be restarted to propagate changes
241255
242256
## Contributing
243257

244-
Want to contribute? Awesome! The most basic way to show your support is to star the project, or to raise issues. You
245-
can also support this project by [**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max) or by making
246-
a [Paypal donation](https://www.paypal.me/crazyws) to ensure this journey continues indefinitely!
258+
Want to contribute? Awesome! The most basic way to show your support is to star
259+
the project, or to raise issues. You can also support this project by [**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max)
260+
or by making a [Paypal donation](https://www.paypal.me/crazyws) to ensure this
261+
journey continues indefinitely!
247262

248263
Thanks again for your support, it is much appreciated! :pray:
249264

docker-bake.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ target "image-local" {
2424
target "image-all" {
2525
inherits = ["image"]
2626
platforms = [
27+
"linux/386",
2728
"linux/amd64",
2829
"linux/arm/v6",
2930
"linux/arm/v7",
3031
"linux/arm64",
31-
"linux/386",
3232
"linux/ppc64le",
3333
"linux/s390x"
3434
]

examples/compose/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.5"
2-
31
services:
42
fail2ban:
53
image: crazymax/fail2ban:latest

examples/jails/guacamole/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Guacamole
22

3-
Create the logback configuration in `./config/guacamole/logback.xml` :
3+
Create the logback configuration in `./config/guacamole/logback.xml`:
44

5-
```
5+
```xml
66
<configuration>
77
<!-- Appender for debugging -->
88
<appender name="GUAC-DEBUG" class="ch.qos.logback.core.ConsoleAppender">
@@ -25,23 +25,25 @@ Create the logback configuration in `./config/guacamole/logback.xml` :
2525
</configuration>
2626
```
2727

28-
Create this compose file for guacamole :
29-
30-
```
31-
version: "2"
28+
Create this compose file for guacamole:
3229

30+
```yaml
3331
services:
3432
guacamole:
3533
image: oznu/guacamole
3634
volumes:
3735
- ./config:/config
3836
- /var/log/guacamole:/usr/local/tomcat/logs
3937
ports:
40-
- 8080:8080
38+
- target: 8080
39+
published: 8080
40+
protocol: tcp
4141
```
4242
43-
Guacamole will write logs into `/usr/local/tomcat/logs` and bind the folder to `/var/log/guacamole` on the host.
43+
Guacamole will write logs into `/usr/local/tomcat/logs` and bind the folder
44+
to `/var/log/guacamole` on the host.
4445

4546
## Fail2ban container
4647

47-
* Copy files from [filter.d](filter.d) and [jail.d](jail.d) to `./data` in their respective folders.
48+
* Copy files from [filter.d](filter.d) and [jail.d](jail.d) to `./data` in
49+
their respective folders.

examples/jails/sshd/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## SSHD
22

3-
To block IPs that have SSHD authentication failures on your host, you have to :
3+
To block IPs that have SSHD authentication failures on your host, you have to:
44

55
* Copy files [jail.d](jail.d) to `./data`
66

7-
For example :
7+
For example:
88

9-
```bash
10-
docker run -it --name fail2ban --restart always \
9+
```console
10+
$ docker run -it --name fail2ban --restart always \
1111
--network host \
1212
--cap-add NET_ADMIN \
1313
--cap-add NET_RAW \
@@ -17,9 +17,9 @@ docker run -it --name fail2ban --restart always \
1717
crazymax/fail2ban:latest
1818
```
1919

20-
Here is the log output if an IP is banned :
20+
Here is the log output if an IP is banned:
2121

22-
```
22+
```text
2323
2018-11-18 21:38:42,410 fail2ban.filterpoll [1]: DEBUG /var/log/auth.log has been modified
2424
2018-11-18 21:38:44,427 fail2ban.filterpoll [1]: DEBUG /var/log/auth.log has been modified
2525
2018-11-18 21:38:44,427 fail2ban.filter [1]: DEBUG Processing line with time:1542573523.0 and ip:192.168.51.100

0 commit comments

Comments
 (0)