【问题标题】:Tell SELinux to Give Apache Execute Access to PHP Files Outside Document Root告诉 SELinux 授予 Apache 对文档根目录外 PHP 文件的执行访问权限
【发布时间】:2017-01-09 13:30:01
【问题描述】:

我有一个保存共享 PHP 脚本的目录(名称是任意的,但它不是 /var/、/usr/ 或 SELinux 具有特定设置的任何东西):
/随便/脚本/

这些脚本可以由 cronjobs 执行,也可以由 Apache 或 Tomcat 执行,因此输出可以包含在网页中。

SELinux 拒绝权限:

type=AVC msg=audit(1363205612.276:476923):avc: denied { execute } for pid=6855 comm="sh" name="script.php" dev=sda3 ino=4325828 scontext=system_u:system_r:httpd_t:s0 tcontext =unconfined_u:object_r:etc_runtime_t:s0 tclass=文件

type=SYSCALL msg=audit(1363205612.276:476923):arch=c000003e syscall=59 成功=没有退出=-13 a0=2431d10 a1=2431d70 a2=24301e0 a3=50 项=0 ppid=23100 pid=6855 auuid=4294967295 =48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="sh" exe="/bin/bash" subj=system_u:system_r: httpd_t:s0 key=(null)

type=AVC msg=audit(1363205612.277:476924):avc: denied { execute } for pid=6855 comm="sh" name="script.php" dev=sda3 ino=4325828 scontext=system_u:system_r:httpd_t:s0 tcontext =unconfined_u:object_r:etc_runtime_t:s0 tclass=文件

type=SYSCALL msg=audit(1363205612.277:476924):arch=c000003e syscall=21 成功=没有退出=-13 a0=2431d10 a1=1 a2=0 a3=50 项=0 ppid=23100 pid=6855 auid=4294967295 uid =48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="sh" exe="/bin/bash" subj=system_u:system_r: httpd_t:s0 key=(null)

我知道有一个命令可以用来告诉 SELinux 允许这样做,但它让我无法理解。

即使将目录和脚本所有者和组设为 apache 也不起作用,因此这不是典型的权限问题,而是 SELinux 特有的。

系统是CentOS 6.3。

【问题讨论】:

    标签: php apache selinux


    【解决方案1】:

    我通过这两个命令找到了解决方案:

    semanage fcontext -a -t httpd_sys_script_exec_t '/whatever/scripts(/.*)?'
     
    restorecon -R -v /whatever/scripts/

    这允许 Apache 在该目录中执行 PHP 脚本,并在重新启动或系统范围重新标记后仍然存在。

    【讨论】:

    • 这可以为单个脚本而不是整个目录完成吗?
    【解决方案2】:

    我将它与我需要从我的 PHP 脚本和 Apache 运行的可执行程序一起使用

    sudo chcon -v -t httpd_sys_script_exec_t my-executable
    

    【讨论】:

      猜你喜欢
      • 2018-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 2015-09-14
      相关资源
      最近更新 更多