apache 运行脚本以提取 git repo 的 selinux 设置

apache 运行脚本以提取 git repo 的 selinux 设置

我有一个在 CentOS 下运行 apache 的 Web 服务器,该服务器已启用 selinux。我还有一个单独的服务器,其中运行着 gitlab。

我正在尝试使用 gitlab 的 web hooks 创建一个工作流程,以便当代码推送到 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被设置为关闭,所以我打开了它。如果我禁用 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 吗?

谢谢 :)

答案1

运行 AVCaudit2allow会出现以下提示:

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

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


请注意,最好将 SELinux 设置为宽容这样您就可以一次收集所有 AVC。这样您通常只需要进行一次迭代来设置布尔值和可能的自定义策略,而不是多次迭代。

相关内容