使用 Xymon/Selinux 進行系統監控
外觀
本示例展示瞭如何在 CentOS 5.5 下建立和安裝適合執行 Xymon 的 SELinux 策略。
預設情況下,當前版本的 Xymon 將安裝在 /home/xymon 中。
Xymon 包含 CGI 和 setuid 程式以及指令碼,它們在 Xymon 目錄中讀取、寫入和建立檔案和目錄。
SELinux 通常將 /home 下的目錄視為使用者目錄,並通常設定為阻止 Web 瀏覽器讀取、寫入、建立和刪除使用者檔案和目錄。
為了解決這個問題,我們可以建立一個新型別(xymon_t)和相應的策略(xymon),該策略允許 Web 伺服器(httpd_t)和 root 使用者(unconfined_t)訪問執行 Xymon 所需的許可權,而不會授予 Xymon 對所有使用者目錄的完全訪問許可權。
載入策略後,必須重新標記 Xymon 的安裝位置(/home/xymon)。
首先建立檔案 xymon.te
#begin
module xymon 1.0;
type xymon_t;
require {
type ping_t;
type ifconfig_t;
type mount_t;
type initrc_t;
type unconfined_t;
type unconfined_mount_t;
type restorecond_t;
type fs_t;
type httpd_t;
type xymon_t;
type port_t;
type httpd_sys_script_t;
type var_t;
type usr_t;
type var_log_t;
type unconfined_mount_t;
class filesystem associate;
class lnk_file { relabelto relabelfrom read getattr write unlink create setattr };
class dir { relabelto relabelfrom getattr search write read remove_name add_name create setattr rmdir };
class file { relabelto relabelfrom getattr execute execute_no_trans read write ioctl append unlink create rename lock setattr link };
class tcp_socket name_connect;
}
#============= httpd_sys_script_t ==============
allow httpd_sys_script_t usr_t:file execute;
#============= unconfined_t ==============
allow unconfined_t xymon_t:lnk_file { relabelto relabelfrom read create getattr write unlink setattr };
allow unconfined_t xymon_t:dir { getattr search relabelto relabelfrom write read remove_name add_name create setattr rmdir };
allow unconfined_t xymon_t:file { getattr execute relabelto relabelfrom execute_no_trans read write ioctl append unlink create rename lock setattr link };
#============= xymon_t ==============
allow xymon_t fs_t:filesystem associate;
#============= httpd_t ==============
allow httpd_t xymon_t:lnk_file { read create getattr write unlink setattr };
allow httpd_t xymon_t:dir { getattr search read write add_name remove_name create setattr rmdir };
allow httpd_t xymon_t:file { getattr execute execute_no_trans read ioctl append write setattr rename create unlink };
allow httpd_t port_t:tcp_socket name_connect;
allow httpd_t usr_t:file { execute execute_no_trans };
allow httpd_t var_t:file { read getattr };
allow httpd_t var_log_t:file read;
#============= unconfined_mount_t ==============
allow unconfined_mount_t xymon_t:file { getattr append };
#============= restorecond_t ==============
allow restorecond_t xymon_t:dir { read search };
#============= ifconfig_t ==============
allow ifconfig_t xymon_t:file { append getattr };
#============= mount_t ==============
allow mount_t xymon_t:file { append getattr };
#============= initrc_t ==============
allow initrc_t xymon_t:dir { getattr search write add_name remove_name relabelto relabelfrom read create setattr rmdir };
allow initrc_t xymon_t:file { getattr execute read execute_no_trans ioctl append create write rename unlink relabelto relabelfrom lock setattr link };
allow initrc_t xymon_t:lnk_file { getattr read relabelto relabelfrom create write unlink setattr };
#============= ping_t ==============
allow ping_t xymon_t:file { getattr write };
#end
編譯並載入此策略
root# checkmodule -M -m -o xymon.mod xymon.te
root# semodule_package -o xymon.pp -m xymon.mod
root# semodule -i xymon.pp
root# semodule -l
安裝新策略後,修改 selinux 許可權以允許 xymon 執行
root# chcon -R -t xymon_t /home/xymon
root# chcon -h -R -t xymon_t /home/xymon
root# ls -Z /home/xymon
現在重啟 Web 伺服器和 Xymon。
監控日誌和 /var/log/audit/audit.log 中的問題和安全違規,並根據需要修改策略。
-H-