ラベル SELinux の投稿を表示しています。 すべての投稿を表示
ラベル SELinux の投稿を表示しています。 すべての投稿を表示

2013年4月29日月曜日

[SELinux]SELinux を無効にする

テスト環境で Linux を使用している場合、SELinux がブロックすることで通信できないことが多々ある。テストで使用しているだけなので SELinux をとりあえず無効にしておく。
Example: /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 - SELinux is fully disabled.
SELINUX=enforcing
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
SELINUX=enforcing を SELINUX=disabled とすることで無効になる。

[SELinux]セキュリティ・レベル

セキュリティ・レベルを調整する時は boolean パラメータを変更する。
例えば httpd の CGI 実行可否を設定しているパラメータは httpd_enable_cgi である。
# getsebool httpd_enable_cgi
httpd_enable_cgi --> on
# setsebool httpd_enable_cgi 0
# getsebool httpd_enable_cgi
httpd_enable_cgi --> off
httpd_enable_cgi を禁止すると /var/log/audit/audit.log に CGI 実行できなかったことが保存される。
type=AVC msg=audit(1289629357.378:26529): avc:  denied  { getattr } for  pid=1640 comm="httpd" path="/var/www/cgi-bin/python/test00.cgi" dev=dm-0 ino=22608 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_script_exec_t:s0 tclass=file
boolean パラメータ一覧は getsebool -a で表示できる。
[root@fedora ~]# getsebool -a
abrt_anon_write --> off
allow_console_login --> off
allow_cvs_read_shadow --> off
allow_daemons_dump_core --> on
allow_daemons_use_tty --> off
allow_domain_fd_use --> on
allow_execheap --> off
allow_execmem --> on
allow_execmod --> off
allow_execstack --> on
(以下略)

[SELinux]起動時の設定

起動時の設定は /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 - SELinux is fully disabled.
SELINUX=enforcing
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted

[SELinux]動作状態

動作状態は sestatus コマンドでも確認できる。
# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

[SELinux]動作モード

モード確認
動作モードを確認するには getenforce コマンドを使用する。
# getenforce
Enforcing
Enforcingポリシーに違反するアクセスはログに書き出して "拒否" する。
Permissiveポリシーに違反するアクセスはログに書き出して "許可" する。

モード変更
動作モードの変更は setenforce コマンドを使用する。
# setenforce 0
# getenforce
Permissive
# setenforce 1
# getenforce
Enforcing

[SELinux]セキュリティ・コンテキスト

ファイルのセキュリティ・コンテキスト
ファイルのセキュリティ・コンテキストは ls -Z で確認できる。
"User" : "Role" : "Type or Domain" の順に表示される
# ls -Z
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html
この html ディレクトリには system_u:object_r:httpd_sys_content_t というセキュリティコンテキストが付いている。User 識別子:Role 識別子:Type 識別子の順に並んでいる。
User 識別子Linux システム上のユーザー (uid) との紐付けはシステムへのログイン時に行われる。
Role 識別子RBAC (Role Based Access Control) で使用する root 権限の最小化で効果を発揮する。
Type 識別子, Domain 識別子すべてのアクセス制御はこの Type 識別子の組み合わせがセキュリティポリシーで定義されているかに基づいて決定される。

プロセスのセキュリティ・コンテキスト
プロセスのセキュリティ・コンテキストは ps -eZ で確認できる。
# ps -eZ
LABEL                                                 PID TTY       TIME     CMD
system_u:system_r:httpd_t:s0                          1594 ?        00:00:00 httpd
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 2450 ?        00:00:02 emacs
httpd の Domain 識別子は httpd_t となっている。emacs には unconfined_t が割り当てられている。
ログイン・ユーザーが起動したプログラムは unconfined_t で動作する。これにより SELinux の制限を受けなくなる。
  1. httpd が Web ページを読み込む前に SELinux モジュールに読み込み要求を伝える。
  2. SELinux モジュールは要求されたアクセスが許可されているか、「ポリシー・ファイル」を参照してセキュリティ・チェックをする。
  3. アクセスが許可された場合は httpd がアクセスを行う。アクセスが拒否された場合はアクセス拒否されたことがログに記録される。

[SELinux]用語

(Type-Enforcement)アクセス制御機能。ファイルなどのリソースにアクセスする時は TE によるチェックが入る。
ドメインすべてのプロセス (httpd など) に付与されるラベル。httpd の場合は httpd_t というドメイン
タイプすべてのリソース (ファイルやポートなど) に付与されるラベル。/var/www/html 以下のファイルは httpd_sys_content_t とういラベル
ポリシーどのドメインがどのタイプにアクセスできるかを示したルール。
ポリシー・ファイルSELinux がアクセス可否を判断するためのポリシーが書かれたファイル。
セキュリティ・コンテキストSELinux がプロセス, リソースに付与しているラベル。 リソースに対しては User 識別子, Role 識別子, Type 識別子を組み合わせたものになっている。プロセスに対しては User 識別子, Role 識別子, Domain 識別子を組み合わせたものになっている。