カスタム systemd サービス用の SELinux ポリシーを作成する

カスタム systemd サービス用の SELinux ポリシーを作成する

OS の起動と同時にFedora Workstation 27 Liveカスタム サービスを実行したい OSを使用しています。これを機能させるには、私の環境で問題が発生している を無効にする必要があります。そのため、 を無効にすることはできません。EnableBIOS.serviceSELinuxSELinux

代わりに、SELinux policyカスタム サービス用の を作成してみましたが、何の成果も得られませんでした。

サービスは以下のメッセージをログに記録しています/var/log/audit/audit.log:

type=SERVICE_START msg=audit(1527782475.777:239): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=EnableHBA comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
type=AVC msg=audit(1527782475.779:240): avc:  denied  { execute } for  pid=4223 comm="(leHBA.sh)" name="enableHBA.sh" dev="dm-0" ino=38164 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file permissive=0
type=SERVICE_STOP msg=audit(1527782475.782:241): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=EnableHBA comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'

そして、

[root@localserver]# audit2allow -w -a
type=AVC msg=audit(1527782475.779:240): avc:  denied  { execute } for  pid=4223 comm="(leHBA.sh)" name="enableHBA.sh" dev="dm-0" ino=38164 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file 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.

を作成するためにSELinux policy、以下のコマンドを実行しました。

[root@localserver]# grep enableHBA /var/log/audit/audit.log | audit2allow -M enablehba
[root@localserver]# semodule -i enablehba.pp

これを行った後、サービスを再度実行しようとすると、次のメッセージが記録されました:

[root@localserver]# audit2allow -w -a
type=AVC msg=audit(1527782959.912:250): avc:  denied  { read open } for  pid=4612 comm="(leHBA.sh)" path="/root/enableHBA/enableHBA.sh" dev="dm-0" ino=38164 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file permissive=0
        Was caused by:
                Missing type enforcement (TE) allow rule.

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

どこが間違っているのか、または要件を満たす他の方法はあるのかを知りたいです。

答え1

スクリプトを/usr/local/sbinに移動し、スクリプトが次のように適切にラベル付けされていることを確認します。bin_t

スクリプトは制限なく実行され、必要なすべての権限を持つ必要があります。

関連情報