Zabbix 5.0 with SELinux on CentOS 8

 article  Comments Off on Zabbix 5.0 with SELinux on CentOS 8
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;

Red Hat Enterprise Linux 8やCentOS 8ではyum-utils不要な模様

 article  Comments Off on Red Hat Enterprise Linux 8やCentOS 8ではyum-utils不要な模様
Mar 042021
 

Red Hat Enterprise Linux 7やCentOS 7では、yum-utilsパッケージに含まれるコマンドを使用してパッケージのダウンロード(yumdownloader)や不要になったパッケージの検索(package-cleanup)などをおこなっていました。

Red Hat Enterprise Linux 8やCentOS 8でも同パッケージは提供されていますが、導入される各コマンドは/usr/libexec/dnf-utilsへのシンボリックリンクとなっています。

/usr/libexec/dnf-utilsはPython実行ファイルになっており、以下のようにdnfコマンドへのマッピングがおこなわれています。

MAPPING = {'debuginfo-install': ['debuginfo-install'],
            'needs-restarting': ['needs-restarting'],
            'find-repos-of-install': ['list', 'installed'],
            'package-cleanup': [],
            'repo-graph': ['repograph'],
            'repoclosure': ['repoclosure'],
            'repodiff': ['repodiff'],
            'repomanage': ['repomanage'],
            'repoquery': ['repoquery'],
            'reposync': ['reposync'],
            'repotrack': ['download', '--resolve', '--alldeps'],
            'yum-builddep': ['builddep'],
            'yum-config-manager': ['config-manager'],
            'yum-debug-dump': ['debug-dump'],
            'yum-debug-restore': ['debug-restore'],
            'yumdownloader': ['download']
            }

yumdownloaderであればdnf downloadyum-config-managerであればdnf config-managerといった具合です。

package-cleanupは更に先のif文で詳細なマッピングとオプション指定がおこなわれています。

if command == 'package-cleanup':
     if '--dupes' in args:
         args[args.index('--dupes')] = '--duplicates'
         MAPPING[command] = ['repoquery']
     elif '--leaves' in args:
         args[args.index('--leaves')] = '--unneeded'
         MAPPING[command] = ['repoquery']
     elif '--orphans' in args:
         args[args.index('--orphans')] = '--extras'
         MAPPING[command] = ['repoquery']
     elif '--problems' in args:
         args[args.index('--problems')] = '--unsatisfied'
         MAPPING[command] = ['repoquery']
     elif '--cleandupes' in args:
         args[args.index('--cleandupes')] = '--duplicates'
         MAPPING[command] = ['remove']
     else:
         sys.stderr.write('package-cleanup has to be executed with one of the options: --dupes, '
                          '--leaves, --orphans, --problems or --cleandupes\n')

package-cleanup --leavesdnf repoquery --unneededということですね。

ただ、マッピングもいまいちわからないし(man dnfできちんと調べればわかるのでしょうが)、dnf-utilsの中身を見るぐらいなら結局yum-utils暫く使いそうです。