Cobra Forum

Plesk Panel => Others => Topic started by: mahesh on Jan 24, 2025, 07:33 AM

Title: Fail2Ban unable to block IP Addresses on a Plesk server
Post by: mahesh on Jan 24, 2025, 07:33 AM
Symptoms
ERROR:__main__Command ['set', 'plesk-one-week-ban', 'banip', '203.0.112.1'] failed with error UnknownJailException('plesk-one-week-ban').

#fail2ban-client reload
2024-12-05 16:11:12,990 fail2ban [3005163]: ERROR NOK: (13, 'Permission denied')
[Errno 13] Permission denied: '/var/www/vhosts/system/example.com/logs/error_log'

#ls -Z /var/www/vhosts/system/example.com/logs/error_log
system_u:object_r:httpd_sys_content_t:s0 /var/www/vhosts/system/example.com/logs/error_log
#egrep "fail2ban-server" /var/log/audit/audit.log | grep denied
type=AVC msg=audit(1733411472.982:1927101): avc: denied { read } for pid=2373127 comm="fail2ban-server" name="error_log" dev="sda1" ino=230808319 scontext=system_u:system_r:fail2ban_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file permissive=0

Cause
The issue is caused by incorrect SELinux context for the log files that Fail2Ban needs to access.

Resolution
1.Connect to the server via SSH

2.Remove currently installed psa-selinux package via Plesk installer:

#plesk installer --select-product-id plesk --select-release-current --remove-component selinux
3.Reinstall currently installed psa-selinux package via Plesk installer

#plesk installer --select-product-id plesk --select-release-current --install-component selinux
4.Check again context of affected file, it should look like this:

#ls -Z /var/www/vhosts/system/example.com/logs/error_log
system_u:object_r:httpd_log_t:s0 /var/www/vhosts/system/example.com/logs/error_log