CentOS Stream 8
Sponsored Link

SELinux : audit2allow 基本操作2021/03/02

 
[audit2allow] コマンドにより AVC 拒否のログを分析し SELinux ポリシーに対してアクセス許可するルールを生成することができます。これにより容易にポリシーのカスタマイズが可能です。
ただし、SETroubleShoot 等を利用して自身でログを確認し、解決方法を判断して、[restorecon] コマンド や [chcon] コマンドにより必要最小限の許可を与える方法と比べると、[audit2allow] によって生成される許可ルールは粗い場合があり、必要以上の許可を与えてしまうこともあるため、利用する際は注意が必要です。
なお、[audit2allow] コマンドがない場合は [dnf install policycoreutils-python-utils] としてインストール可能です。
[1] ログを読み込み、拒否された理由を表示します。
ログファイルを指定しない場合のデフォルトは [/var/log/audit/audit.log] を読み込みます。
ログファイルを指定する場合は [-a] の代わりに [-i ログファイル] と指定します。
# audit.log から AVC 拒否を全て読み取って理由を表示

[root@dlp ~]#
audit2allow -w -a

type=AVC msg=audit(1614664861.679:94): avc:  denied  { name_bind } for  pid=1161 comm="httpd" src=85 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket permissive=0
        Was caused by:
                Missing type enforcement (TE) allow rule.

                You can use audit2allow to generate a loadable module to allow this access.

type=AVC msg=audit(1614666021.668:78): avc:  denied  { getattr } for  pid=1186 comm="login" name="/" dev="tmpfs" ino=12323 scontext=system_u:system_r:local_login_t:s0-s0:c0.c1023 tcontext=system_u:object_r:tmpfs_t:s0 tclass=filesystem permissive=0
        Was caused by:
                Unknown - would be allowed by active policy
                Possible mismatch between this policy and the one under which the audit message was generated.

                Possible mismatch between current in-memory boolean settings vs. permanent ones.
.....
.....

# 例えば ausearch と併用して特定のログに絞っての表示も可

[root@dlp ~]#
ausearch -m AVC --start 03/01/2021 12:00:00 --end 03/02/2021 18:00:00 | audit2allow -w

type=AVC msg=audit(1614666578.083:78): avc:  denied  { getattr } for  pid=1183 comm="login" name="/" dev="tmpfs" ino=12365 scontext=system_u:system_r:local_login_t:s0-s0:c0.c1023 tcontext=system_u:object_r:tmpfs_t:s0 tclass=filesystem permissive=0

        Was caused by:
                Unknown - would be allowed by active policy
                Possible mismatch between this policy and the one under which the audit message was generated.

                Possible mismatch between current in-memory boolean settings vs. permanent ones.

type=AVC msg=audit(1614666872.742:78): avc:  denied  { getattr } for  pid=1182 comm="login" name="/" dev="cgroup" ino=1 scontext=system_u:system_r:local_login_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cgroup_t:s0 tclass=filesystem permissive=0

        Was caused by:
                Unknown - would be allowed by active policy
                Possible mismatch between this policy and the one under which the audit message was generated.

                Possible mismatch between current in-memory boolean settings vs. permanent ones.
.....
.....

# -a オプションで必要なアクセス権を表示

[root@dlp ~]#
ausearch -m AVC --start 03/01/2021 12:00:00 --end 03/02/2021 18:00:00 | audit2allow -a


#============= httpd_t ==============
allow httpd_t reserved_port_t:tcp_socket name_bind;

#============= local_login_t ==============
allow local_login_t cgroup_t:filesystem getattr;
allow local_login_t tmpfs_t:filesystem getattr;
[2] 許可ルールを生成するには以下のように設定します。
# 例として [test_rule] というモジュールを生成

[root@dlp ~]#
ausearch -m AVC --start 03/01/2021 12:00:00 --end 03/02/2021 18:00:00 | audit2allow -a -M test_rule

******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i test_rule.pp

# 表示された通りにコマンド実行してモジュールインストール

[root@dlp ~]#
semodule -i test_rule.pp
# モジュールが読み込まれているか確認

[root@dlp ~]#
semodule -l | grep test_rule

test_rule
 
以上で以下のようにアクセス可能になる場合もあります。また、そうでない場合もあります。
アクセスできない場合は [audit2allow] による対策を再度繰り返す必要があります。
関連コンテンツ