selinux设置由Apache运行脚本拉git回购

在启用selinux的CentOS中,我有一台运行apache的web服务器。 我有一个运行gitlab的单独的服务器。

我试图创build一个工作stream使用gitlab的networking钩子,所以当代码被推到git,gitlab将请求我的生产服务器上,然后将拉最新版本的代码的页面。

脚本运行良好,但是selinux不允许从脚本运行git pull 。 它失败,退出码128。

简化的PHP脚本

 <?php $data = json_decode(file_get_contents("php://input")); exec('./.hooks/received-push.sh ' . $data->repository->url); 

简化的bash脚本

 #!/bin/sh if [ "$#" -ne 1]; then echo "Repo URL must be provided" fi GIT=/usr/local/bin/git TMP=mktemp cd $TMP $GIT clone $1 || echo "git clone failed with exit code $?" 

我已经发现httpd_can_network_connect被设置为closures,所以我打开了。 如果我禁用selinux,一切正常,所以我知道有一些东西在这里的方式。 手动运行时脚本工作正常。

看一下audit.log,我看到这行在git clone运行的时候出现(为了可读性,在这里放了多行)

 type=AVC msg=audit(1420243675.063:1041): avc: denied { search } for pid=4376 comm="ssh" name="apache" dev=dm-2 ino=133906 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=unconfined_u:object_r:user_home_dir_t:s0 tclass=dir type=SYSCALL msg=audit(1420243675.063:1041): arch=c000003e syscall=2 success=no exit=-13 a0=7fff9e4e4380 a1=0 a2=1b6 a3=0 items=0 ppid=4375 pid=4376 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="ssh" exe="/usr/bin/ssh" subj=system_u:system_r:httpd_sys_script_t:s0 key=(null) 

有没有其他的selinux布尔值可以设置为允许httpd使用ssh? 我可以修改文件标签,使其运行SSH?

谢谢 :)

通过audit2allow运行AVC audit2allow发出以下提示:

 #!!!! This avc can be allowed using one of the these booleans: # httpd_read_user_content, httpd_enable_homedirs 

在这种情况下, httpd_read_user_content将是适当的使用 。


请注意,将SELinux设置为宽容是一个好主意,以便您可以一次收集所有的AVC。 这样你通常需要经历一次设置布尔运算和可能的自定义策略的迭代,而不是几次迭代。