1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RHEL9でSELinuxを無効化する方法

Posted at

はじめに

SELinux(Security-Enhanced Linux)は、Linuxのセキュリティをより強固なものにするため、米国国家安全保障局(NSA)によって開発されました。
Red Hat Enterprise Linuxでは標準で有効化されています。

有効化のままだとアプリケーションやミドルウェアが正常に動作しない場合が多く、仕様も難しいため、現場では無効化していることが多いと思います。

今回は、RHEL9でSELinuxの無効化方法が変更されたため、その方法をご紹介します。

RHEL8からRHEL9へのSELinux無効化の変更点

RHEL8以前での無効化方法

RHEL8以前では、以下の方法でSELinuxを無効化できました。

# /etc/selinux/config ファイルを編集
SELINUX=disabled

RHEL9での変更点

RHEL9では、設定ファイルによる無効化(SELINUX=disabled)の動作が変更され、以下の理由で推奨されなくなりました。

  1. 動作の変更

    • RHEL8まで:/etc/selinux/configSELINUX=disabledを設定すると、ブート時にカーネルレベルでSELinuxが完全に無効化されていました。
    • RHEL9から:SELINUX=disabledを設定しても、カーネル自体はSELinux機能を有効にしたまま起動し、SELinuxポリシーがロードされない状態となります。
  2. 推奨される無効化方法

    • RHEL9でSELinuxを完全に無効化したい場合は、カーネルパラメータselinux=0を指定する必要があります。
    • 公式には、grubbyコマンドでカーネルパラメータを追加し、再起動する方法が推奨されています。

参考リンク

実際のRHEL9設定ファイルの内容

実際のRHEL9システムの/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.
# See also:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_selinux/changing-selinux-states-and-modes_using-selinux#changing-selinux-modes-at-boot-time_changing-selinux-states-and-modes
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
#    grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
#    grubby --update-kernel ALL --remove-args selinux
#
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.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

設定ファイルの各項目の説明

SELinuxの状態設定

SELINUX=enforcing  # 現在の設定
  • enforcing:SELinuxポリシーが強制される(デフォルト)
  • permissive:警告のみでポリシーを強制しない
  • disabled:ポリシーが読み込まれない(RHEL9では完全無効化ではない)

SELinuxタイプの設定

SELINUXTYPE=targeted  # 現在の設定
  • targeted:対象プロセスのみ保護(一般的)
  • minimum:最小限のプロセスのみ保護
  • mls:マルチレベルセキュリティ保護

このファイルの注意書きで最も重要な部分は以下です。

# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line.

翻訳すると、RHEL 8リリースまでにおいては、SELINUX=disabled の設定で起動時にSELinuxが完全に無効化されていました。
もしSELinuxが動作する状態ではなく、完全に無効化されたシステムが必要な場合は、カーネルのコマンドラインに selinux=0 を渡す必要があります。
つまり、設定ファイルをSELINUX=disabledにしても完全に無効化できないのです。
SELinuxポリシーが読み込まれていない状態ではあるものの、予期せぬ動作が起こる可能性は残っています。
私も現場で従来通りviで設定ファイルを編集した際、注意書きがあることに気づきました。

RHEL9での正しいSELinux無効化手順

grubbyコマンドを使用した無効化

# 1. grubbyパッケージがインストールされていることを確認(標準でインストールされている)
rpm -q grubby

# 2. カーネルパラメータにselinux=0を追加
grubby --update-kernel ALL --args selinux=0

# 3. システムを再起動
reboot

# 4. 無効化の確認
getenforce
# 出力: Disabled
sestatus
# 出力: SELinux status: disabled

SELinuxの再有効化

SELinuxを再度有効にしたい場合は、以下のコマンドを使用します。

# selinux=0パラメータを削除
grubby --update-kernel ALL --remove-args selinux

# システムを再起動
reboot

# 有効化の確認
getenforce
# 出力: Enforcing

まとめ

  • RHEL9ではgrubbyコマンドが標準的な無効化方法
  • /etc/selinux/configでのSELINUX=disabled設定は動作が変更され、完全無効化ではない

以上です。この記事が皆さんのお役に立てれば幸いです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?