為自訂 systemd 服務建立 SELinux 策略

為自訂 systemd 服務建立 SELinux 策略

我正在使用的Fedora Workstation 27 Live作業系統希望在EnableBIOS.service作業系統啟動的同時運行自訂服務。為此,我必須停用SELinux在我的環境中導致問題的功能。所以,我無法禁用SELinux.

作為替代方案,我嘗試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

該腳本應該不受限制地運行並擁有它所需的所有權限

相關內容