SELinux
SELinux の状態確認
code:console
$ getenforce
Enforcing
table:getenforce
Enforcing SELinux 有効。強制
Permissive SELinux 有効。ログに警告のみ
Disabled SELinux 無効
詳細な状態確認
code:console
$ sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 33
SELinux の停止(永続的)
セキュリティ的にはよくないが、ローカルの開発機では利便性のために外すのは許される範囲だと考える。
code:/etc/selinux/config
SELINUX=disabled
使い分け
開発機では、SELINUX=disabled にする。
テスト機では、SELINUX=permissive にする。(ここで SELinux に伴うエラーを潰す。)
本番機では、SELINUX=enforcing にする。
SELinux の一時停止(Permissive に変更)
$ setenforce 0
SELinux の有効化(Enfocing に変更)
$ setenforce 1
ディレクトリやファイルに付いているラベルの確認
$ ls -Z /var/www/
ディレクトリやファイルのラベルの一時的な変更
$ sudo chcon -t httpd_sys_content_t /var/www/mywebsite
httpd でスクリプトを実行可能にする。(ディレクトリ /foo/bar 以降の *.php ファイルの例)
$ sudo semanage fcontext -a -t httpd_sys_script_exec_t "/foo/bar(/.*)?\.php$"
$ sudo restorecon -Rv /foo/bar/
SELinux はパスを正規表現で判定している。
定義を削除する。
$ sudo semanage fcontext -d -t httpd_sys_script_exec_t "/foo/bar(/.*)?\.php$"
$ sudo restorecon -Rv /foo/bar/
httpd に関わる定義を確認する。
$ sudo semanage fcontext -l | grep httpd
管理者が設定した定義を確認する。
$ sudo semanage fcontext -l -C
ログの確認
$ sudo less /var/log/audit/audit.log
$ sudo tail -f /var/log/audit/audit.log
httpd に関する基本的なタイプ
table:httpd_type
httpd_sys_content_t 読み込み専用
httpd_sys_rw_content_t 読み書き可能
httpd_sys_script_exec_t スクリプト実行可能
問題
システムの標準的な作法に従っているうちはまだ対処がしやすい。
非標準のディレクトリやファイル
非標準のポート
非標準の実行ファイル