ja:documentation:pandorafms:technical_annexes:09_selinux_configuration_for_pandora_fms

Pandora FMS のための SELinux 設定

In Pandora FMS the installation should always be done with Security-Enhanced Linux (SELinux ) deactivated. After the installation and due to the need to have it enabled in some environments, we're going to detail the configuration settings in CentOS 7.

Pandora FMS では、インストールは常に Security-Enhanced Linux (SELinux ) を無効にして行う必要があります。 インストール後、環境によって有効にする必要がある場合の CentOS 7 での設定について詳しく説明します。

To create this type of rules, Audit2allow is used, which will be in charge of allowing the necessary actions.

Audit2allow を利用したルールを作成します。これは必要なアクションを許可する役割を持ちます。

Before starting to create the rules for the policies, you may need to install a number of packages in order to use Audit2allow.

ポリシーのルール作成を開始する前に、Audit2allow を使用できるようにいくつかのパッケージをインストールする必要がある場合があります。

Enter in the command terminal with root key or equivalent rights (prefix the command sudo):

root または同等の権限でコマンドラインから入力します (コマンドの先頭に sudo を付けます):

dnf install selinux-policy-devel -y
dnf install policycoreutils-python-utils -y

The errors returned by SELinux can be found in the following paths:

SELinux が返すエラーは、以下にあります。

  • /var/www/html/pandora_console/log/audit.log
  • /var/log/messages

In case of updating Pandora FMS by OUM you should modify the logrotate file corresponding.

OUM によって Pandora FMS を更新する場合は、対応するlogrotate ファイルを変更する必要があります。

To check more clearly what SELinux blocks, it is recommended to delete the previous logs and wait for them to be generated again with new records.

SELinux がブロックするものをより明確に確認するには、以前の logs を削除し、新しいレコードで再度生成されるまで待つことをお勧めします。

syslog must be stopped (this service could also be called rsyslog). Enter in the command terminal with root key or equivalent rights (prefix the command sudo):

syslog を停止する必要があります (このサービスは rsyslog とも呼ばれます)。root または同等の権限でコマンドターミナルに入力します (コマンドの前に sudo を付けます)。

systemctl stop syslog

The audit.log and the log system messages file must be deleted:

audit.log および log システムメッセージファイルを削除する必要があります。

rm /var/www/html/pandora_console/log/audit.log /var/log/messages

Restart syslog (this service could also be called rsyslog):

syslog を再起動します (このサービスは rsyslog とも呼ばれます)。

systemctl start syslog

To configure SELinux to the desired value, modify its configuration file /etc/selinux/config:

SELinux を設定するには、設定ファイル /etc/selinux/config を変更します。

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
  • If you need SELinux to run in restrictive mode, allowing to execute only what appears within the module rules, you must set it to enforcing, thus removing (through the audit.log) the executions denied by SELinux.
  • If instead you need to print warnings (warnings) instead of blocking actions, leave them permissive, and then check these warnings in the audit.log file.
  • SELinux を制限モードで実行し、モジュールルール内に表示されているものだけを実行できるようにする必要がある場合は、これを enforcing に設定して、SELinux によって拒否された実行を (audit.log を通じて) 削除する必要があります。
  • アクションをブロックするのではなく、警告 (warnings) を表示する必要がある場合は、それらを permissive のままにして、audit.log ファイルでこれらの warnings を確認します。

To display the latest logs entries, enter the command terminal with root key or equivalent rights (prefix the command with sudo):

最新の ログ エントリを表示するには、root または同等の権限でコマンドターミナルを入力します (コマンドの前に sudo を付けます)。

tail -f /var/www/html/pandora_console/log/audit.log /var/log/messages

You may notice that errors will be displayed, for example:

次のようなエラーが表示される場合があります。

type=AVC msg=audit(1431437562.755:437): avc:  denied  { write } for  pid=1835 comm="httpd" name="collections" dev=dm-0 ino=266621 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_spool_t:s0 tclass=dir

To convert these errors into rules that SELinux can interpret, you must execute:

これらのエラーを SELinux が解釈できるルールに変換するには、以下を実行する必要があります。

grep collections /var/www/html/pandora_console/log/audit.log | audit2allow -M pandora

This will create two files in the current directory:

これにより、現在のディレクトリに 2 つのファイルが作成されます。

pandora.pp
pandora.te

To activate the new rule you must execute:

新しいルールを有効にするには、以下を実行する必要があります。

sudo semodule -i pandora.pp

Repeat the process to add the missing rules. After adding all the rules, SELinux will stop reporting errors.

不足しているルールを追加するには、このプロセスを繰り返します。すべてのルールを追加すると、SELinux はエラーの報告をしなくなります。

For Pandora FMS to be able to execute all the services correctly, rules should be created for the following functionalities:

Pandora FMS が実行するすべてのサービスが正しく動作するようにしたい場合は、次の操作を許可するいくつかのルールを作成する必要があります。

  • Create, update and delete collections.
  • Sending e-mail messages using scheduled tasks (Cronjob).
  • Remote configuration of agents.
  • Monitoring snmptrapd.
  • Monitoring NetFlow.\
  • コレクションの作成、更新、削除
  • 計画タスクによるメール送信 (cronジョブ)
  • エージェントのリモート設定
  • snmptrapd 監視
  • NetFlow 監視

Otherwise, SELinux will block any action associated with these features.

そうでないと、SELinux はこれらの操作に関連するアクションをブロックします。

A way to unite all these rules in one, to be able to use Pandora FMS completely, would be:

これらすべてのルールを 1 つに統合して、Pandora FMS を完全に使用できるようにする方法は次のとおりです。

grep -e data_in -e collections -e var_spool_t -e zip -e md5 -e denied /var/log/audit/audit.log | audit2allow -M pandora

Then you should repeat the step described above to activate the rule. This would cover all possible conflicts between Pandora FMS and SELinux. Enter in the command terminal with root key or equivalent rights (prefix the command sudo):

次に、上記の手順を繰り返してルールを有効にします。これにより、Pandora FMS と SELinux 間のすべての競合が解消されます。root または同等の権限 (コマンドの前に sudo を付けます) を使用してコマンドターミナルに入力します。

sudo semodule -i pandora.pp

実践的なまとめ

The rules to use SELinux with Pandora FMS are summarized, taking into account that for each particular case the values and parameters should be changed in a customized way such as dev=sdaX or pid=XXX.

Pandora FMS で SELinux を使用するためのルールがまとめられています。特定のケースごとに、値とパラメータを dev=sdaXpid=XXX などのカスタマイズされた方法で変更する必要があることに注意してください。

The setsebool command is a tool for setting booleans for SELinux. The -P option indicates to persist the set value across restarts, and the 1 at the end of the instruction indicates true value, thus activating your application. Enter in the command terminal with root key or equivalent rights (prefix the command sudo):

setsebool コマンドは、SELinuxbooleans を設定するためのツールです。-P オプションは、再起動後も設定された値を維持することを示し、命令の末尾の 1 は true 値を示し、アプリケーションを有効化します。root または同等の権限でコマンドターミナルに入力します (コマンドの前に sudo を付けます)。

setsebool -P httpd_unified 1
setsebool -P httpd_read_user_content 1
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_execmem 1
setsebool -P httpd_can_network_connect_db 1
setsebool -P httpd_can_connect_ldap 1
setsebool -P authlogin_nsswitch_use_ldap 1
setsebool -P nis_enabled 1
setsebool -P httpd_setrlimit 1

The chcon command changes the SELinux context of files. The -t option indicates a SELinux file type and the -R option applies it to a directory and all its contents recursively. Enter in the command terminal with root key or equivalent rights (prefix the command sudo):

chcon コマンドは、ファイルの SELinux コンテキストを変更します。-t オプションは SELinux ファイルタイプを示し、-R オプションはそれをディレクトリとそのすべての内容に再帰的に適用します。root または同等の権限でコマンドターミナルに入力します (コマンドの前に sudo を付けます)。

chcon -R -t httpd_sys_content_rw_t /var/www/html/pandora
chcon -R -t httpd_sys_content_rw_t /var/spool/pandora/
chcon -R -t httpd_sys_content_rw_t /tmp/

The following rules are added, always remembering the necessary customization for each case. Enter in the command terminal with root key or equivalent rights (prefix the command sudo):

以下のルールが追加され、それぞれのケースで必要なカスタマイズが常に適用されます。root または同等の権限でコマンドターミナルに入力します (コマンドの前に sudo を付けます)。

echo 'type=AVC msg=audit(1709637797.944:2074063): avc:  denied  { write } for  pid=176072 comm="php-fpm" name="collections" dev="sda5" ino=142704842 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_spool_t:s0 tclass=dir permissive=1' | audit2allow -a
echo 'type=AVC msg=audit(1709639101.328:2100929): avc:  denied  { unlink } for  pid=152354 comm="php-fpm" name="gotty_cron_tmp.log" dev="sda5" ino=134725871 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:user_home_t:s0 tclass=file permissive=1'  | audit2allow -a
echo 'type=AVC msg=audit(1710850539.491:32359350): avc:  denied  { write } for  pid=3895348 comm="connection" name="tmp" dev="sda5" ino=8398230 scontext=system_u:system_r:mysqld_t:s0 tcontext=system_u:object_r:httpd_sys_rw_content_t:s0 tclass=dir permissive=1' | audit2allow -a

The following command is used to create the rules in a file named rules_apply.pp:

次のコマンドは、ru​​les_apply.pp という名前のファイルにルールを作成するために使用されます。

audit2allow -a -M rules_apply

The rules created in the previous step with the semodule command are applied:

前の手順で semodule コマンドを使用して作成されたルールが適用されます。

semodule -i rules_apply.pp

CentOS 7 will soon reach its end of life (EOL). This documentation is retained for historical purposes.

CentOS 7 はまもなくサポート終了(EOL)になります。 このドキュメントは過去の記録のために保持しています.

To create this type of rules use Audit2allow, which will be in charge of allowing the necessary actions.

Audit2allow を利用したルールを作成します。これは必要なアクションを許可する役割を持ちます。

Before you start creating the rules for the policies, you may need to install a number of packages to be able to use Audit2allow. enter in the command terminal with root or equivalent rights (prefix the command with sudo):

ポリシーのルール作成を開始する前に、Audit2allow を使用できるようにいくつかのパッケージをインストールする必要がある場合があります。 root または同等の権限でコマンドラインから入力します (コマンドの先頭に sudo を付けます):

yum install selinux-policy-devel -y
yum install policycoreutils-python -y

CentOS 7 will soon reach its end of life (EOL). This documentation is retained for historical purposes.

CentOS 7 はまもなくサポート終了(EOL)になります。 このドキュメントは過去の記録のために保持しています.

SELinux が返すエラーは、以下にあります。

  • /var/log/audit/audit.log
  • /var/log/messages

IMPORTANT:

重要:

In versions prior to 747, the audit log path is: /var/log/audit/audit.log.

バージョン 747 までは、監査ログのパスは /var/log/audit/audit.log です。

If updating from OUM you will need to modify the logrotate file.

OUM からアップデートした場合は、logrotate ファイルを修正する必要があります。

In order to check the cleanest way, we highly recomend to remove previous logs and wait until it are generated again with new records.

確認をしやすくするために、すでに出ているログを削除し新たなログが出るまで待つことを強くお勧めします。

syslog を停止します。(rsyslog の場合もあります)

# /etc/init.d/syslog stop

audit.log とシステムのメッセージログファイルを削除します。

# rm /var/www/html/pandora_console/log/audit.log /var/log/messages

syslog を再開します。

# /etc/init.d/syslog start

CentOS 7 will soon reach its end of life (EOL). This documentation is retained for historical purposes.

CentOS 7 はまもなくサポート終了(EOL)になります。 このドキュメントは過去の記録のために保持しています.

SELinux を希望の内容で設定するには、設定ファイルを編集します。

# This file controls the state of SELinux on the system.
# SELinux= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELinux=enforcing
# SELinuxTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELinuxTYPE=targeted

プログラムの実行に制限を付けるには、SELinux を “enforcing” に設定します(SELinux での実行制限は audit.log で確認します)。別のオプションとしては SELinux を “permissive” に設定します。この場合、実行は制限されませんが、audit.log ファイルにエラーが記録されます。

CentOS 7 will soon reach its end of life (EOL). This documentation is retained for historical purposes.

CentOS 7 はまもなくサポート終了(EOL)になります。 このドキュメントは過去の記録のために保持しています.

最新のログを見るにはつぎのようにします。

# tail -f /var/www/html/pandora_console/log/audit.log /var/log/messages

次のようないくつかのエラーがみつかります。

 # type=AVC msg=audit(1431437562.755:437): avc:  denied  { write } for  pid=1835 comm="httpd" name="collections" dev=dm-0 ino=266621 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_spool_t:s0 tclass=dir

これらのエラーを SELinux ルールに変換します。

 # grep collections /var/www/html/pandora_console/log/audit.log | audit2allow -M pandora

実行すると 2つの新たなファイルが作成されます。

- pandora.pp
- pandora.te

新たなルールを有効化するには、次のようにします。

# sudo semodule -i pandora.pp

エラーが出たものをルールに追加する対応を繰り返します。その後、SELinux からエラーの出力がなくなります。

CentOS 7 will soon reach its end of life (EOL). This documentation is retained for historical purposes.

CentOS 7 はまもなくサポート終了(EOL)になります。 このドキュメントは過去の記録のために保持しています.

Pandora FMS が実行するすべてのサービスが正しく動作するようにしたい場合は、次の操作を許可するいくつかのルールを作成する必要があります。

- コレクションの作成、更新、削除

- プログラムタスクによるメール送信 (cronジョブ)

- エージェントのリモート設定

逆にいうと、SELinux はこれらの操作に関連するアクションをブロックします。

SELinux が有効化された状態で Pandora FMS を利用するためのルールを追加するには、次のようにします。

# grep -e data_in -e collections -e var_spool_t -e zip -e md5 -e denied /var/log/audit/audit.log | audit2allow -M pandora

その後、ルールを有効化するための前述の対応を行う必要があります。

# sudo semodule -i pandora.pp
  • ja/documentation/pandorafms/technical_annexes/09_selinux_configuration_for_pandora_fms.txt
  • 最終更新: 2024/06/24 02:42
  • by junichi