Skip to content

Commit 35753c7

Browse files
committed
fail2ban with systemd journal
- Improved load testing / siege article
1 parent 142c8f5 commit 35753c7

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

src/code/cv.html

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ <h2>TECHNOLOGY</h2>
9898
<li>Network security: Metasploit, Burp suite, nmap, tcpdump, dig</li>
9999
<li>Device security: nftables, iptables, LUKS, ssh</li>
100100
<li>App security: Sonarqube, OWASP</li>
101+
<li>Observability: Nagios/Icinga, Grafana, Dynatrace, Open Telemetry</li>
101102

102103
<h2>PERFORMANCE TUNING</h2>
103104
<li>Allow running Linux on work machine</li>

src/craftsmanship/mean-load-testing.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: The world is mean, let your load test be mean too
1+
title: The World is Mean, So Your Load Tests Must Be Meaner
22
date: 2025-02-11
33
category: craftsmanship
44
tags: craftsmanship, testing, unix
@@ -12,8 +12,9 @@ unleashing a mean load testing tool like
1212
- HTTP connector settings out of sync with other components
1313
- Integrations with 3rd party systems stall
1414
- Basically, with any scarce resource you thought the app would
15-
recycle when you write object.close(), will potentially come back
16-
and bite you.
15+
recycle when you write `connection.close()`, will potentially come
16+
back and bite you since your app spends longer _actually_ closing it
17+
than what you assume in your code.
1718

1819
The world is mean, so prepare your app by using a mean testing
1920
tool. My favourite is
@@ -37,7 +38,7 @@ write performance of a backend system:
3738
$ siege \
3839
--concurrent=255 \
3940
--time 10S \
40-
--header="Authorization: hunter2" \
41+
--header="Authorization: Bearer eyhunter2.." \
4142
--header="X-Important-Id-For-App: foo-bar-baz" \
4243
--content-type=application/json \
4344
--json-output \
@@ -67,7 +68,9 @@ http://localhost:8000/library POST {"name": "The Attic called ${attic_name}"}
6768
```
6869

6970
As you can see in the library example, `siege` has rudimentary support
70-
for variables too.
71+
for variables too. Read the fine manual with [man
72+
siege](https://man.archlinux.org/man/siege.1.en) and learn further
73+
details about this excellent tool.
7174

7275
Happy load testing!
7376

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
title: fail2ban with systemd journal
2+
date: 2025-02-05
3+
category: linux
4+
tags: linux, aws, security
5+
6+
The [fail2ban](https://github.com/fail2ban/fail2ban) package installed
7+
on the Debian version offered by AWS has a default configuration that
8+
depends on reading log files. This doesn't work when
9+
e.g. [sshd](https://www.openssh.com/) writes failed login attempts to
10+
the systemd journal rather than the traditional `/var/log/auth.log`.
11+
12+
The error looks like this:
13+
```text
14+
# systemctl status fail2ban
15+
× fail2ban.service - Fail2Ban Service
16+
Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; preset: enabled)
17+
Active: failed (Result: exit-code) since Wed 2025-02-05 19:43:14 UTC; 2s ago
18+
Duration: 82ms
19+
Docs: man:fail2ban(1)
20+
Process: 7698 ExecStart=/usr/bin/fail2ban-server -xf start (code=exited, status=255/EXCEPTION)
21+
Main PID: 7698 (code=exited, status=255/EXCEPTION)
22+
CPU: 80ms
23+
24+
systemd[1]: Started fail2ban.service - Fail2Ban Service.
25+
..
26+
fail2ban-server[8032]: 2025-02-05 19:51:15,947 fail2ban [8032]: ERROR Failed during configuration: Have not found any log file for sshd jail
27+
..
28+
systemd[1]: fail2ban.service: Main process exited, code=exited, status=255/EXCEPTION
29+
systemd[1]: fail2ban.service: Failed with result 'exit-code'.
30+
```
31+
32+
The fix is simple, though, just add the following to the enabled jail,
33+
or set it in `/etc/fail2ban/jail.conf` to apply this to all jails:
34+
35+
```text
36+
# vim /etc/fail2ban/jail.d/defaults-debian.conf
37+
```
38+
39+
And add the line with `backend`:
40+
```conf
41+
[sshd]
42+
enabled = true
43+
backend = systemd
44+
```
45+
46+
Now, restart `fail2ban` and check its status:
47+
```text
48+
# systemctl restart fail2ban
49+
# systemctl status fail2ban
50+
● fail2ban.service - Fail2Ban Service
51+
Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; preset: enabled)
52+
Active: active (running) since Wed 2025-02-05 19:52:34 UTC; 9min ago
53+
Docs: man:fail2ban(1)
54+
Main PID: 8041 (fail2ban-server)
55+
Tasks: 5 (limit: 1107)
56+
Memory: 16.3M
57+
CPU: 458ms
58+
CGroup: /system.slice/fail2ban.service
59+
└─8041 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
60+
61+
systemd[1]: Started fail2ban.service - Fail2Ban Service.
62+
..
63+
fail2ban-server[8041]: Server ready
64+
```
65+
66+
Finally, check `fail2ban` itself to see that the `sshd` jail is
67+
working:
68+
69+
```text
70+
# fail2ban-client status sshd
71+
Status for the jail: sshd
72+
|- Filter
73+
| |- Currently failed: 0
74+
| |- Total failed: 0
75+
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd
76+
`- Actions
77+
|- Currently banned: 0
78+
|- Total banned: 0
79+
`- Banned IP list:
80+
```
81+
82+
As you can see, `fail2ban` is keeping tabs on failed ssh login
83+
attempts and will put failed IPs in jail. Happy banning!

0 commit comments

Comments
 (0)