Mar 142021
 

SELinux環境下で動かそうとしたらいろいろあったので覚書。

前提

環境

  • CentOS 8.3
  • Zabbix 5.0.9
  • PostgreSQL 10.15
  • Apache 2.4

利用テンプレート

  • Template App Zabbix Server
  • Template App Apache by HTTP
  • Template App PHP-FPM by HTTP
  • Template OS Linux by Zabbix agent
  • Template DB PostgreSQL

適用したSELinuxブール値

  • httpd_can_connect_zabbix –> on
  • httpd_can_network_connect_db –> off
  • zabbix_can_network –> on

作成したSELinuxポリシーなど

Zabbix Server用

module zabbix-server_local 1.0;

require {
        type zabbix_t;
        type zabbix_var_run_t;
        type krb5_keytab_t;
        type var_log_t;
        class sock_file create;
        class sock_file unlink;
        class unix_stream_socket connectto;
        class dir search;
        class file open;
        class file read;
}

#============= zabbix_t ==============
allow zabbix_t zabbix_var_run_t:sock_file create;
allow zabbix_t zabbix_var_run_t:sock_file unlink;
allow zabbix_t self:unix_stream_socket connectto;
allow zabbix_t krb5_keytab_t:dir search;
allow zabbix_t var_log_t:file open;
allow zabbix_t var_log_t:file read;

上記ポリシーに加えてdac_overrideも要求されるが、/run/zabbixの所有者権限がzabbix:zabbix 700となっており、厳密なDACとしてはrootでの書き込みが許可されていないため発生している。
dac_overrideは許可したくないので/run/zabbixの権限をzabbix:root 775に変更してrootにも書き込み許可を与えるようにした。サービスユニットファイルを以下のとおり修正している。

[Service]
ExecStartPre=/usr/bin/mkdir -p /run/zabbix
ExecStartPre=/usr/bin/chgrp root /run/zabbix
ExecStartPre=/usr/bin/chmod g+w  /run/zabbix

Apache用

httpd_can_network_connect_dbをoffにしたので、PostgreSQLへの接続のみを明示的に許可している。

module httpd_local 1.0;

require {
        type httpd_t;
        type postgresql_port_t;
        class tcp_socket name_connect;
}

#============= httpd_t ==============
allow httpd_t postgresql_port_t:tcp_socket name_connect;

Zabbix Agent監視用

PostgreSQL監視用に/var/lib/zabbix/.pgpass読み込み(zabbix_var_lib_t)と、system.sw.packagesキーでrpm一覧を取得するためのrpm_exec_t実行権限やvar_lib_rpm_tの読み込み権限が必要だった。

module zabbix-agent_local 1.0;

require {
        type zabbix_agent_t;
        type zabbix_var_lib_t;
        type rpm_exec_t;
        type rpm_var_lib_t;
        type devlog_t;
        type initctl_t;
        type proc_kcore_t;
        class file open;
        class file read;
        class file execute;
        class file execute_no_trans;
        class file map;
        class sock_file getattr;
        class fifo_file getattr;
        class file getattr;
}

#============= zabbix_agent_t ==============
allow zabbix_agent_t zabbix_var_lib_t:file open;
allow zabbix_agent_t zabbix_var_lib_t:file read;
allow zabbix_agent_t rpm_exec_t:file execute;
allow zabbix_agent_t rpm_exec_t:file execute_no_trans;
allow zabbix_agent_t rpm_exec_t:file map;
allow zabbix_agent_t rpm_var_lib_t:file open;
allow zabbix_agent_t rpm_var_lib_t:file read;
allow zabbix_agent_t devlog_t:sock_file getattr;
allow zabbix_agent_t initctl_t:fifo_file getattr;
allow zabbix_agent_t proc_kcore_t:file getattr;

Sorry, the comment form is closed at this time.