fall2ban PostgreSQL 필터가 작동하지 않습니다

fall2ban PostgreSQL 필터가 작동하지 않습니다

나는 postgresql에 이 필터를 사용합니다:

[Definition]
failregex = ^<HOST>.+FATAL:  password authentication failed for user.+$
            ^<HOST>.+FATAL:  no pg_hba.conf entry for host .+$
ignoreregex = duration:#

내 감옥 파일에는 다음과 같은 구성이 있습니다.

[postgresql]
enabled = true
port    = 5432
protocol = tcp
filter = custom-postgresql
logpath = /var/log/postgresql/postgresql-12-main.log
maxretry = 3

내 postgresql.conf에서 로그 정보를 변경합니다.

log_line_prefix = '%h %m [%p] %q%u@%d '

하지만 실패 금지를 사용하여 테스트하려고 하면 다음 오류가 발생합니다.

root@server:/etc/fail2ban# fail2ban-regex /etc/fail2ban/filter.d/custom-postgresql.conf /var/log/postgresql/postgresql-12-main.log

Running tests
=============

Use   failregex file : /var/log/postgresql/postgresql-12-main.log
Wrong config file: File contains no section headers.
file: '/var/log/postgresql/postgresql-12-main.log', line: 1
'2020-08-30 01:19:48.411 CEST [28837] [unknown]@[unknown] FATAL:  unsupported frontend protocol 0.0: server supports 2.0 to 3.0\n'
ERROR: failed to load filter /var/log/postgresql/postgresql-12-main.log

내 오류는 무엇입니까? 내가 놓친 게 무엇입니까?

postgresql의 오류일까요? 로그에 다음이 표시되기 때문입니다.

2020-08-30 01:19:48.411 CEST [28837] [unknown]@[unknown] FATAL:  unsupported frontend protocol 0.0: server supports 2.0 to 3.0
2020-08-30 01:19:48.619 CEST [28838] [unknown]@[unknown] FATAL:  unsupported frontend protocol 255.255: server supports 2.0 to 3.0
2020-08-30 01:19:48.828 CEST [28839] [unknown]@[unknown] FATAL:  no PostgreSQL user name specified in startup packet
2020-08-30 02:20:12.462 CEST [29766] [unknown]@[unknown] FATAL:  unsupported frontend protocol 65363.19778: server supports 2.0 to 3.0
2020-08-30 03:16:01.172 CEST [31372] [unknown]@[unknown] LOG:  invalid length of startup packet
2020-08-30 03:16:01.189 CEST [31373] [unknown]@[unknown] LOG:  invalid length of startup packet
2020-08-30 03:16:01.205 CEST [31374] [unknown]@[unknown] FATAL:  unsupported frontend protocol 65363.19778: server supports 2.0 to 3.0

답변1

매개변수를 잘못된 순서로 제공하고 있습니다.

에서 man fail2ban-regex:

fail2ban-regex [OPTIONS] <LOG> <REGEX> [IGNOREREGEX]

먼저 로그 파일을 제공한 다음 구성 파일을 제공해야 합니다. 반대의 경우입니다.

답변2

[Definition]
failregex = ^<HOST>.*FATAL:\s\spassword authentication failed for user
            ^<HOST>.*FATAL:\s\sno pg_hba.conf entry for host
ignoreregex =

관련 정보