
我正在編寫支援 SELinux 的程式碼。我是這個安全模組的新手,學習曲線很陡峭。
為了讓我的程式碼在 SELinux 環境中運作,我需要能夠重新標記檔案。例如,我正在掛載臨時檔案系統,並希望在掛載後恢復原始標籤。
顯然,我需要成為安裝部分的 root(具有 CAP_SYS_ADMIN 功能),但是我需要成為重新標記部分的 root 嗎?
在 Fedora 上,我可以重新標記自己擁有的文件,例如,我可以作為非特權用戶執行以下操作:
$ touch /tmp/test
$ ls -Z /tmp/test
unconfined_u:object_r:user_tmp_t:s0 /tmp/test
$ chcon system_u:object_r:etc_t:s0 /tmp/test
$ ls -Z /tmp/test
system_u:object_r:etc_t:s0 /tmp/test
似乎沒有權限重新標記不同使用者擁有的檔案。
但現在我在RedHat中發現了以下內容手動的:
SELinux 策略控制使用者是否能夠修改任何給定檔案的 SELinux 上下文。
這似乎表明這種行為確實是可配置的,而且我不能依賴能夠重新標記我自己擁有的檔案。
編輯:
Fedora 似乎使用constraints
.
# dnf install setools-console
# seinfo --constrain
...
constrain file {relabelto create relabelfrom } (u1 == u2 or ( t1 == can_change_object_identity ));
...