
私はType=simple
/etc/systemd/system/custom.service
。それはあるExecStart=/root/scripts/custom.sh
。私はこれを使用して、起動時にさまざまな管理タスクが自動的に発生するようにします。 Redhat 7.9ではうまく動作し、selinux=enforcing
selinuxの設定に問題はありません。
RHEL 8.8では/var/log/messages
。
systemd[1]: Started custom service.
systemd[96691]: custom.service: Failed to execute command: Permission denied
systemd[96691]: custom.service: Failed at step EXEC spawning /root/scripts/custom.sh: Permission denied
systemd[1]: custom.service: Main process exited, code=exited, status=203/EXEC
systemd[1]: custom.service: Failed with result 'exit-code'.
SELinux is preventing /usr/lib/systemd/systemd from execute access on the file custome.sh. For complete SELinux messages run: sealert -l 84fa818f-e23a-4686-afb5-3f2399d0d6ea
setroubleshoot[96693]: SELinux is preventing /usr/lib/systemd/systemd from execute access on the file custom.sh.#012#012
*****Plugin catchall (100. confidence) suggests
**************************#012#012If you believe that systemd should be allowed execute access
on the custom.sh file by default.#012Then you should report this as a bug.#012You can generate a
local policy module to allow this access.
#012Do#012allow this access for now by executing:
#012# ausearch -c '(ation.sh)' --raw | audit2allow -M my-ationsh#012# semodule -X 300 -i my-ationsh.pp#012
/root/scripts/custom.sh
だから私のスクリプトに正しいselinuxコンテキストがないことを知っています。しかし、何を使うべきですか?
私は自動的にインポートされ/etc/systemd/system/custom.service
たsystemd_unit_file_t
ので、すべてが設定されていると思います。
私は/root/scripts/custom.sh
現在それを持っていますunconfined_u:object_r:admin_home_t:s0
。
そのフォルダ内の他のサービスに対して異なるExecStartプロジェクトを確認すると、ls -ldZ
次のようになります。
-rwxr-xr-x. 1 root root system_u:object_r:bluetooth_exec_t:s0 1375048 May 17 2022 /usr/libexec/bluetooth/bluetoothd
-rwxr-xr-x. 1 root root system_u:object_r:NetworkManager_exec_t:s0 67752 Feb 23 04:51 /usr/libexec/nm-dispatcher
-rwxr-xr-x. 1 root root system_u:object_r:avahi_exec_t:s0 146208 Nov 3 2020 /usr/sbin/avahi-daemon
-rwxr-xr-x. 1 root root system_u:object_r:xdm_exec_t:s0 471744 Dec 12 2022 /usr/sbin/gdm
-rwxr-xr-x. 1 root root system_u:object_r:modemmanager_exec_t:s0 2203464 Dec 13 2022 /usr/sbin/ModemManager
-rwxr-xr-x. 1 root root system_u:object_r:syslogd_exec_t:s0 742168 Jan 10 06:46 /usr/sbin/rsyslogd
-rwxr-xr-x. 1 root root system_u:object_r:timedatex_exec_t:s0 33984 Aug 12 2018 /usr/sbin/timedatex
customservice_exec_t
タイプコンテキストを作成する必要がありますか?それでは、どうすればいいですか?bin_t
検索時に、一部のサービスに対応する構文が表示されない状況を発見したと思いました。コンテキストの作成に伴うオーバーヘッドを節約するための良いコンテキストはexec_t
ありますか?bin_t
- 私が何か間違っていたので、後でうまくいかないようにするには、私がやっていることの正しい規則は何ですか?
selinux=enforcing
解決策ではなく許可に設定する必要があります。
答え1
customservice_exec_t型コンテキストを生成する必要がありますか?それでは、どうすればいいですか?
これを行う必要はありません。非常に具体的なルールを作成し、そのルールにアクセスするすべてのタイプを制御したい場合にのみ、これを実行できます。これは作成に時間がかかり、メンテナンスに費用がかかります。メンテナンスの少ない最高のselinuxケースを使用したいようです。確認できますが、ここそれを行う方法。
bin_tをコンテキストで会ったと思いましたが、検索してみると、一部のサービスに対応するexec_t構文が表示されませんでした。 bin_tは、コンテキスト生成によるオーバーヘッドを節約するために使用できる優れたコンテキストですか?
はい、bin_t
ここで使用するのに最適なコンテキストです。多くのコンテキストに実行権限を与える一般的なコンテキストです。
私が何か間違っていたので、後で動作しないようにするために私がやっていることの正しい規則は何ですか?
スクリプトを/bin
then にコピーするrestorecon -RF /bin/custom.sh
か、次のコマンドを使用してscripts
フォルダに正しいコンテキストを付与できます。
semanage fcontext -a -t bin_t "/root/scripts(/.*)?"
restorecon -RF /root/scripts