Show Table of Contents
6.2. 新規 Linux ユーザーの制限: useradd
SELinux
unconfined_u user にマッピングされた Linux ユーザーは、unconfined_t ドメインで稼働します。unconfined_u にマッピングされた Linux ユーザーでログインし、id -Z コマンドを実行すると、これが表示されます。
~]$ id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Linux ユーザーが
unconfined_t ドメインで稼働すると SELinux ポリシールールが適用されますが、unconfined_t ドメインで稼働する Linux ユーザーにほとんどすべてのアクセスを許可するポリシールールが存在します。制限のない Linux ユーザーが、unconfined_t ドメインから自身の制限のあるドメインへの移行が可能だと SELinux ポリシーが定義するアプリケーションを実行しても、制限のない Linux ユーザーはその制限のあるドメインの規定に拘束されます。ここでのセキュリティーの利点は、Linux ユーザーは制限なしで実行していてもアプリケーションには制限があることから、アプリケーションの欠点を悪用しようとしてもポリシーで制限できる、という点です。注記: これは、システムがユーザーから保護されるということではありません。ユーザーとシステムがアプリケーションの欠点による損害の可能性から守られるということです。
useradd で Linux ユーザーを作成する場合は、-Z オプションを使ってどの SELinux ユーザーにマッピングするかを指定します。以下の例では、新規の Linux ユーザー、useruuser を作成し、そのユーザーを SELinux user_u ユーザーにマッピングしています。SELinux user_u ユーザーにマッピングされた Linux ユーザーは、user_t ドメインで稼働します。このドメインでは、(passwd など) SELinux ポリシーが許可しない限り、Linux ユーザーは setuid アプリケーションを実行できず、su や sudo も実行できないので、これらのコマンドで Linux root ユーザーになることを防いでいます。
- Linux root ユーザーで
useradd -Z user_u useruuserコマンドを実行し、SELinuxuser_uユーザーにマッピングされる新規の Linux ユーザー (useruuser) を作成します。 - Linux root ユーザーで
semanage login -lコマンドを実行し、Linuxuseruuserユーザーとuser_uの間のマッピングを表示します。~]#
semanage login -lLogin Name SELinux User MLS/MCS Range __default__ unconfined_u s0-s0:c0.c1023 root unconfined_u s0-s0:c0.c1023 system_u system_u s0-s0:c0.c1023 useruuser user_u s0 - Linux root ユーザーで
passwd useruuserコマンドを実行し、Linux useruuser ユーザーにパスワードを割り当てます。~]#
passwd useruuserChanging password for user useruuser. New UNIX password: Enter a password Retype new UNIX password: Enter the same password again passwd: all authentication tokens updated successfully. - 現行セッションから一旦ログアウトし、Linux useruuser ユーザーでログインし直します。ログインすると、pam_selinux がこの Linux ユーザーを SELinux ユーザーにマッピングし (このケースでは
user_u)、SELinux コンテキストを設定します。その後は、このコンテキストで Linux ユーザーのシェルが起動されます。id -Zコマンドを実行し、Linux ユーザーのコンテキストを表示します。~]$
id -Zuser_u:user_r:user_t:s0 - Linux useruuser のセッションからログアウトし、自分のアカウントでログインし直します。Linux useruuser ユーザーが不要な場合は、Linux root ユーザーで
userdel -r useruuserコマンドを実行し、そのホームディレクトリーとともに削除します。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.