
- - - 問題 - - - -
我的系統上運行的是 CentOS 7.6。我想在 /etc/passwd 檔案中呼叫自訂 shell 而不是標準 shell。
我啟用了 SELinux,並且由於某種原因 sshd_t 域沒有轉換到我的自訂 shell 保存的新自訂網域。
像這樣的東西:
在 /etc/passwd 中:
root:x:0:0:root:/root:/bin/myshell
SELinux 域轉換:
myshell.fc
/bin/myshell gen_context(system_u:object_r:myshell_exec_t,s0)
myshell.te
role unconfined_r types myshell_t;
role_transition unconfined_r myshell_t system_r;
domtrans_pattern(unconfined_t, myshell_exec_t, myshell_t)
預設用戶是unconfined_u:unconfined_r:unconfined_t。
我還進行了從 unconfined_r 到 system_r 的角色轉換。
- - 問題 - - -
由於某些原因 sshd_t 沒有轉換到 myshell_t 域。用戶是root。
這是角色更改日誌訊息:
type=USER_ROLE_CHANGE msg=audit(1559079004.637:339116): pid=24478 uid=0 auid=0 ses=823 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='pam: default-context=system_u:unconfined_r:unconfined_t:s0 selected-context=system_u:unconfined_r:unconfined_t:s0 exe="/usr/sbin/sshd" hostname=X.X.X.X addr=X.X.X.X terminal=ssh res=success'
type=AVC msg=audit(1559067681.085:327703): avc: granted { execute } for pid=17593 comm="sshd" name="myshell" scontext=system_u:unconfined_r:unconfined_t:s0 tcontext=system_u:object_r:myshell_exec_t:s0 tclass=file
它確實執行了二進位文件,但轉換沒有發生。可能是因為角色不同,但我確實有角色轉換——但不確定為什麼它不起作用。
答案1
這裡有兩個方面,我先講第一個方面:
- 標籤 /bin/myshell 類型 shell_exec_t: echo '(filecon "/usr/bin/myshell" file (system_u object_r shell_exec_t ((s0)(s0))))' > myshell.cil && semodule -i myshell.cil
- 建立使用者 joe 並將其與現有 user_t 受限 shell 網域關聯: useradd -Z user_u joe
ssh joe@localhost 'id -Z'
建立新的受限使用者涉及更多一些,但重點是 sshd、login 等登入程序使用 pam_selinux 來確定執行登入 shell 的上下文,並且它們手動轉換,而不是自動轉換。 /etc/selinux/TYPE/contexts/users/ 中的檔案用於與 /etc/selinux/TYPE/contexts 中的其他檔案一起使用