RHEL SELinux: /etc/sysconfig/selinux または /etc/selinux/config?

RHEL SELinux: /etc/sysconfig/selinux または /etc/selinux/config?

私は CentOS Linux リリース 7.5.1804 (Core) を実行しており、通常の SELinux を Permissive に設定するタスクに遭遇しました。しかし、2 つのソースから、構成を設定する 2 つの異なる場所が示されました。

  1. sysconfig の

/etc/sysconfig/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=permissive
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
  1. 設定ファイル

/etc/selinux/config を編集する

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

関連するRedHatフォーラムを読みましたが、誰も特にどちらかにこだわっているようには見えませんでした。また、Selinux - Centos - /etc/selinux/config が見つかりません両方の解決策が答えとしてあります。

現在のバージョンではどれを使用すればよいですか?

今後、新しいバージョンではどちらを使用すればよいでしょうか?

更新: 私のシステムでは、これらはシンボリックリンクされていません。 fat では、これらは 2 つの異なるファイルです。

ls -la /etc/selinux/ | grep config
-rw-r--r--.  1 root root  550 Jan 14 15:55 config
ls -la /etc/sysconfig/ | grep selinux
-rw-r--r--.  1 root root  543 Jan 10 14:12 selinux

答え1

手元にあるCentOS 7システムからだが、CentOS 6とFedora 31は同じである

lrwxrwxrwx. 1 root root   17 Oct 31  2018 selinux -> ../selinux/config

同じファイルのようです。個人的には、筋肉の記憶により /etc/selinx/config を使用しています。


しかし私のシステムではそれらは異なるファイルであり、サイズが異なり、変更時間も異なります

次に、システムが「壊れている」と考えます。これは簡単にテストできます。一方に permissive を設定し、もう一方に enforcing を設定します。再起動します...

答え2

デフォルトのselinux設定ファイルは、/etc/selinux/configperにありますman 8 selinuxRHEL 6 導入ガイド(RHEL 7 のドキュメントでは見つけられませんでした)、/etc/sysconfig以下へのシンボリック リンクであると記載されています/etc/selinux/config

/etc/sysconfig/selinuxファイルにはSELinuxの基本設定オプションが含まれています。これは/etc/selinux/configへのシンボリックリンクです。

ls -la出力を見ると、最初のフィールドがlリンクの で、 が になっているため、シンボリックリンクであるugoことがわかりますrwx

[root@test sysconfig]# ls -lah selinux
lrwxrwxrwx. 1 root root 19 Nov 24 00:58 selinux -> /etc/selinux/config

sedこれがシンボリックリンクであることを知る前に、デフォルトではsedシンボリックリンクをたどらないため、誤ってファイルを上書きしてしまいました。

[root@test sysconfig]# ls -lah selinux
lrwxrwxrwx. 1 root root 17 Jul 24 23:16 selinux -> ../selinux/config
[root@test sysconfig]# grep '^SELINUX=' selinux
SELINUX=enforcing
[root@test sysconfig]# sed -i 's/SELINUX=enforcing/SELINUX=permissive/' selinux
[root@test sysconfig]# ls -lah selinux
-rw-r--r--. 1 root root 544 Nov 24 00:50 selinux

そのような状況に陥った場合は、シンボリックリンクを復元するだけで簡単に修正できます。

[root@test sysconfig]# rm /etc/sysconfig/selinux
rm: remove regular file ‘/etc/sysconfig/selinux’? y
[root@test sysconfig]# ln -s /etc/selinux/config selinux
[root@test sysconfig]# ls -lah selinux
lrwxrwxrwx. 1 root root 19 Nov 24 00:52 selinux -> /etc/selinux/config

私は個人的に のみを変更しています/etc/selinux/config。1つはシンボリックリンクで別の間違いを起こさないようにするためですが、もう1つは、そのディレクトリ内のいくつかの構成ファイルが新しいリリースで非推奨になっているためです。たとえば、nfsRHEL 8 の場合。

関連情報