I try to write custom jail for PostgreSQL. My log line looks like this:
2025-01-24 14:43:17.769 CET [112253] postgres@postgres FATAL: no pg_hba.conf entry for host "x.x.x.x", user "postgres", database "postgres", SSL off
My fail2ban filter file:
[Definition] failregex = ^\s*\S+\s+\S+\s+\S+\s+\[\d+\]\s+\S+@\S+\s+FATAL:\s+no pg_hba\.conf entry for host "<ADDR>", user '<F-USER>.*</F-USER>', database '.*', SSL off.*$
After testing with this command:
echo '2025-01-24 14:43:17.769 CET [112253] postgres@postgres FATAL: no pg_hba.conf entry for host "x.x.x.x", user "postgres", database "postgres", SSL off' | fail2ban-regex - /etc/fail2ban/filter.d/postgresql.conf
Output:
Running tests ============= Use failregex filter file : postgresql, basedir: /etc/fail2ban Use single line : - Results ======= Failregex: 0 total Ignoreregex: 0 total Date template hits: Lines: 1 lines, 0 ignored, 0 matched, 1 missed [processed in 0.01 sec] |- Missed line(s): | - `-
What is wrong with regex?