После перехода одного клиента с RHEL6 на репозитоий от Scientific Linux 6 стали приходить нотификации от nagios - check_mount.pl отказывался видеть примонтированную шару, хотя она была и
И получаем такой модуль
# /usr/lib64/nagios/plugins/check_mount.pl -m /someshare
/someshare is mounted!
рапотровал что всё ok.
Однако
# /usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_mount
/someshare is not mounted!
валился.
Стал разбираться и нашёл причину - SELinux (ну кто бы сомневался).
Игры с restorecon не помогли. Возможно ребут с Relabeling помог бы (http://www.centos.org/docs/5/html/5.2/Deployment_Guide/sec-sel-fsrelabel.html), но перезагружать сервак не хотелось, да и просто fixfiles делать тоже не улыбалось.
Из несотыковок со старым сервером (там где ещё был чистый RHEL6) было
[root@new ~]# ps auxZ | grep nrpe|grep -v grep
unconfined_u:system_r:nrpe_t:s0 nrpe 23079 0.0 0.0 40944 1312 ? Ss Jan11 0:05 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
[root@old ~]# ps auxZ | grep nrpe|grep -v grep
system_u:system_r:nrpe_t:s0 nrpe 1618 0.0 0.0 40888 1116 ? Ss 2012 0:23 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
Но ошибки в логах были про типы.
Поочерёдным разрешением был выведен полный лог:
type=AVC msg=audit(1357998818.538:612779): avc: denied { read open } for pid=1779 comm="check_mount.pl" name="bash" dev=dm-0 ino=913934 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:shell_exec_t:s0 tclass=file
type=AVC msg=audit(1357999043.623:612812): avc: denied { execute } for pid=2450 comm="check_mount.pl" name="bash" dev=dm-0 ino=913934 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:shell_exec_t:s0 tclass=file
type=AVC msg=audit(1357999147.645:612833): avc: denied { execute_no_trans } for pid=2571 comm="check_mount.pl" path="/bin/bash" dev=dm-0 ino=913934 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:shell_exec_t:s0 tclass=file
type=AVC msg=audit(1357999256.580:612863): avc: denied { getattr } for pid=3124 comm="sh" path="/bin/bash" dev=dm-0 ino=913934 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:shell_exec_t:s0 tclass=file
type=AVC msg=audit(1357999256.581:612864): avc: denied { execute } for pid=3125 comm="sh" name="mount" dev=dm-0 ino=913990 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:mount_exec_t:s0 tclass=file
type=AVC msg=audit(1357999256.581:612865): avc: denied { getattr } for pid=3125 comm="sh" path="/bin/mount" dev=dm-0 ino=913990 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:mount_exec_t:s0 tclass=file
type=AVC msg=audit(1357999256.581:612866): avc: denied { getattr } for pid=3125 comm="sh" path="/bin/mount" dev=dm-0 ino=913990 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:mount_exec_t:s0 tclass=file
type=AVC msg=audit(1357999376.586:612887): avc: denied { read open } for pid=3252 comm="sh" name="mount" dev=dm-0 ino=913990 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:mount_exec_t:s0 tclass=file
type=AVC msg=audit(1357999376.586:612888): avc: denied { read } for pid=3252 comm="sh" name="mount" dev=dm-0 ino=913990 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:mount_exec_t:s0 tclass=file
type=AVC msg=audit(1357999376.586:612889): avc: denied { read } for pid=3252 comm="sh" name="mount" dev=dm-0 ino=913990 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:mount_exec_t:s0 tclass=file
type=AVC msg=audit(1357999481.484:612914): avc: denied { execute_no_trans } for pid=3626 comm="sh" path="/bin/mount" dev=dm-0 ino=913990 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=system_u:object_r:mount_exec_t:s0 tclass=file
type=AVC msg=audit(1357999594.918:612928): avc: denied { setattr } for pid=4172 comm="mount" name="mtab" dev=dm-0 ino=655655 scontext=unconfined_u:system_r:nagios_services_plugin_t:s0 tcontext=unconfined_u:object_r:etc_runtime_t:s0 tclass=file
Потом
cat nrpe|audit2allow -M nrpe(Кстати теперь audit2allow в пакете policycoreutils-python.)
semodule -i nrpe.pp
И получаем такой модуль
# cat ~/nrpe.teОшибки пропали и nrpe заработал.
module nrpe 1.0;
require {
type shell_exec_t;
type etc_runtime_t;
type mount_exec_t;
type nagios_services_plugin_t;
class file { execute setattr read execute_no_trans getattr open };
}
#============= nagios_services_plugin_t ==============
allow nagios_services_plugin_t etc_runtime_t:file setattr;
#!!!! This avc is allowed in the current policy
allow nagios_services_plugin_t mount_exec_t:file { read execute open getattr execute_no_trans };
#!!!! This avc is allowed in the current policy
allow nagios_services_plugin_t shell_exec_t:file { read execute open getattr execute_no_trans };
Хотя это не сказать что правильное решение. Вероятно После обновления поменялись политики, но опять же - разница в версиях минорна.
wget http://ftp.scientificlinux.org/linux/scientific/6x/SRPMS/vendor/selinux-policy-3.7.19-155.el6_3.14.src.rpm
wget http://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/selinux-policy-3.7.19-93.el6_1.2.src.rpm
rpm2cpio selinux-policy-3.7.19-93.el6_1.2.src.rpm | cpio -idmv
tar xvf serefpolicy-3.7.19.tgz
mv serefpolicy-3.7.19 serefpolicy-3.7.19_old
rm serefpolicy-3.7.19.tgz
rpm2cpio selinux-policy-3.7.19-155.el6_3.14.src.rpm | cpio -idmv
tar xvf serefpolicy-3.7.19.tgz
vimdiff serefpolicy-3.7.19/policy/modules/services/nagios.te serefpolicy-3.7.19_old/policy/modules/services/nagios.te
И... И никакой разницы.
И тут приходит мысль - сервер то был ещё давно и ставил его не я.
Смотрим что есть у selinux
# semanage fcontext -l|grep nagios
и нет его
# rpm -q --whatprovides /usr/lib64/nagios/plugins/check_mount.pl
file /usr/lib64/nagios/plugins/check_mount.pl is not owned by any package
Файл не из репозитория и соответственно к нему нет политики.
И вот как оно работало раньше...
В общем, попробовав все типы для плагинов взятые из semanage "fcontext -l|grep nagios" я понял, что надо либо наследоваться от уже существующего типа и добавлять роли вроде mount_exec_t, либо просто установить тип nagios_unconfined_plugin_exec_t.
Лень взяла вверх:
semanage fcontext -a -s system_u -t nagios_unconfined_plugin_exec_t -f -- '/etc/nagios/plugins/check_mount.pl'
restorecon -v check_mount.pl
/usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_mount
Выгружаем наш модуль
semodule -r nrpe
И проверяем
# /usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_mount
/someshare is mounted!
Ну вот так получше.
Заодно написал автору коммент - http://binfalse.de/software/nagios/check_mount-pl/comment-page-1/#comment-417
Комментарии