openSUSE Leap 16

SELinux : ポリシータイプの設定2025/10/22

 

SELinux が [enforcing/permissive] で動作している場合、どのポリシータイプを適用するかを設定することができます。
設定したポリシータイプをベースに、必要に応じて、個別に要/不要なポリシーを追加/変更/削除して、カスタマイズ設定します。

ポリシータイプは [/etc/selinux/config] 設定ファイルで設定変更可能です。
デフォルトは [targeted] ポリシーです。

ただし、ポリシータイプを変更する場合、ポリシーファイルがインストールされている必要があります。
最小構成インストールの場合、デフォルトでは [targeted] ポリシーのみがインストールされています。

インストールされてないポリシータイプを指定すると、システムが起動しなくなるため、重々注意が必要です。

[1] ポリシータイプは [SELINUXTYPE=***] で設定します。
# デフォルトは [targeted] ポリシー

dlp:~ #
cat /etc/selinux/config


# This file controls the state of SELinux on the system.
# SELinux can be completly disabled with the "selinux=0" kernel
# commandline option.
#
# SELINUX= can take one of these two values:
#     enforcing  - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
# Previously SELinux could be disabled by changing the value to
# 'disabled'. This is deprecated and should not be used anymore.
# If you want to disable linux add 'selinux=0' to the kernel
# command line. For details see
# https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-runtime-disable
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
SELINUXTYPE=targeted

# 例として [minimum] ポリシーに変更
# 事前にポリシーファイルをインストール

dlp:~ #
zypper -n install selinux-policy-minimum
# ポリシーファイルが [minimum] ディレクトリ配下にインストールされる

dlp:~ #
ll /etc/selinux

total 8
-rw-r--r--. 1 root root    0 Oct 22 08:46 .relabelled
-rw-r--r--. 1 root root  847 Oct  9 14:05 config
drwxr-xr-x. 1 root root  142 Oct 22 08:58 minimum
-rw-r--r--. 1 root root 2321 Mar  7  2025 semanage.conf
drwxr-xr-x. 1 root root  142 Oct  9 14:05 targeted

dlp:~ #
vi /etc/selinux/config
# [SELINUXTYPE] 変更
# ポリシー変更の際は動作モードを [permissive] に変更
# * [enforcing] のまま再起動するとリラベリングできずシステムが起動しなくなるため注意

.....
.....
SELINUX=permissive
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
SELINUXTYPE=minimum

# 変更後はリラべリングをセットしてシステム再起動

dlp:~ #
fixfiles -F onboot

System will relabel on next boot
dlp:~ #
dlp:~ #
sestatus

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             minimum
Current mode:                   permissive
Mode from config file:          permissive
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33
[2]

パッケージとして提供されているポリシーは以下の 2 種類です。

ポリシー 説明
Targeted システム上で攻撃対象となる可能性の高いプロセスに対してアクセス制御を適用するポリシー (デフォルト)。
Minimum ベースポリシーと unconfined.pp のみをインストールする最小構成のポリシー

関連コンテンツ