
我一直在遵循 Gitlab 的指南來啟用授權 SSH 金鑰的快速尋找。指南指示使用 AuthorizedKeysCommand。授權命令正在呼叫本地https伺服器。此命令鏈會導致違反 SELinux 策略。
我收到的錯誤如下:
type=AVC msg=audit(1559126095.648:64173782): avc: denied { name_connect } for pid=13839 comm="gitlab-shell-au" dest=8081 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:transproxy_port_t:s0 tclass=tcp_socket permissive=0
如果我沒記錯的話,我需要一個自訂 SELinux 策略。然而,我能找到的所有指南都過於複雜。編寫允許此異常的策略檔案應該是一項微不足道的任務。
您知道允許 sshd_t 程序使用 transproxy_port_t 的策略 (.te) 檔案應該是什麼樣子嗎?
編輯。在標準連接埠(8080)運行 unicorn 時,Gitlab 確實配置了所需的策略
答案1
你可以這樣做:
# generate the policy .te file
echo "type=AVC msg=audit(1559126095.648:64173782): avc: denied { name_connect } for pid=13839 comm="gitlab-shell-au" dest=8081 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:transproxy_port_t:s0 tclass=tcp_socket permissive=0" | audit2allow -m gitlabfix1 > gitlabfix1.te
# create a module from the .te file
checkmodule -M -m -o gitlabfix1.mod gitlabfix1.te
# package it
semodule_package -o gitlabfix1.pp -m gitlabfix1.mod
# install it
semodule -i gitlabfix1.pp
有一種更短的方法,但不會建立 .te 中間檔案。 .te 檔案對於存檔和理解目的很方便:-)。
較短的方法是這樣的:
# generate the policy module package in one go
echo "type=AVC msg=audit(1559126095.648:64173782): avc: denied { name_connect } for pid=13839 comm="gitlab-shell-au" dest=8081 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:transproxy_port_t:s0 tclass=tcp_socket permissive=0" | audit2allow -M gitlabfix2
# and load it
semodule -i gitlabfix2.pp
出於教育目的,.te 文件如下所示:
module gitlabfix1 1.0;
require {
type transproxy_port_t;
type sshd_t;
class tcp_socket name_connect;
}
#============= sshd_t ==============
allow sshd_t transproxy_port_t:tcp_socket name_connect;