So, I kind of manage a server for somebody else, running on CentOS and Plesk. Today I found out again why I hate this combo so much. The box auto-updates Plesk and other stuff, and all of the sudden my fail2ban wasn’t working anymore. I accidently found out because of all the password errors in de syslog.
Turns out there is a problem with SELinux. I have heard of that name before, but never knew what it was or what it did. Now I do, although I still don’t really understand. All I wanted was to get fail2ban running again.
So when you google for SELinux and fail2ban you get a lot of posts about this error. The suggestion I saw most was to run
sudo /sbin/restorecon -v -R -F /sbin but for me this had no effect. The label was still bin_t after that.
Then I tried to create my own module. This didn’t succeed in the beginning, but after adding and adding stuff from the log, I finally got to the point where a restart of fail2ban didn’t give me errors. First I had to install audit2allow, because that wasn’t on my system.
Eventually, I came up with this. Save this under /root/myFail2ban.te :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
module myFail2ban 1.0; require { type mail_spool_t; type insmod_exec_t; type home_root_t; type var_t; type auditd_log_t; type fail2ban_t; type sendmail_t; type sysfs_t; type inotifyfs_t; type postfix_cleanup_t; type ldconfig_exec_t; type tmp_t; type sysctl_modprobe_t; type system_cronjob_lock_t; type system_mail_t; type sysctl_kernel_t; type postfix_master_t; class capability { net_admin net_raw }; class lnk_file read; class dir { read search getattr }; class file { execute read execute_no_trans write getattr open }; class rawip_socket { setopt getopt create }; } #============= fail2ban_t ============== allow fail2ban_t auditd_log_t:dir { getattr search }; allow fail2ban_t auditd_log_t:file read; allow fail2ban_t home_root_t:dir search; allow fail2ban_t insmod_exec_t:file { read execute open }; allow fail2ban_t ldconfig_exec_t:file { read execute open getattr execute_no_trans }; allow fail2ban_t self:capability { net_admin net_raw }; allow fail2ban_t self:rawip_socket { setopt getopt create }; allow fail2ban_t sysctl_kernel_t:dir search; allow fail2ban_t sysctl_modprobe_t:file read; allow fail2ban_t sysfs_t:dir search; #============= postfix_cleanup_t ============== allow postfix_cleanup_t var_t:lnk_file read; #============= postfix_master_t ============== allow postfix_master_t mail_spool_t:file read; allow postfix_master_t var_t:lnk_file read; #============= sendmail_t ============== allow sendmail_t system_cronjob_lock_t:file { read write }; allow sendmail_t tmp_t:file write; allow sendmail_t var_t:file write; #============= system_mail_t ============== allow system_mail_t inotifyfs_t:dir read; allow system_mail_t var_t:file write; allow system_mail_t var_t:lnk_file read; |
Now, as root, compile this thing. Enter this while you are in /root:
make -f /usr/share/selinux/devel/Makefile
Output should be something like this:
[root@web ~]# make -f /usr/share/selinux/devel/Makefile
Compiling targeted myFail2ban module
/usr/bin/checkmodule: loading policy configuration from tmp/myFail2ban.tmp
/usr/bin/checkmodule: policy configuration loaded
/usr/bin/checkmodule: writing binary representation (version 10) to tmp/myFail2ban.mod
Creating targeted myFail2ban.pp policy package
rm tmp/myFail2ban.mod.fc tmp/myFail2ban.mod
Now, enable the module:
semodule -i myFail2ban.pp
Restart fail2ban and check your fail2ban logs for errors, and your /var/log/audit/audit.log if ACL’s are still denied. This worked for me, with just the ssh jail active. Maybe if you enable other jails, extra acl’s are needed to those logfiles.
If it doesn’t work, you probably want to remove the module again. Just type:
semodule -r myFail2ban
You can list all active modules with semodule -l.