Selinux 和 cgi-bin -> 权限被拒绝。

Selinux 和 cgi-bin -> 权限被拒绝。

尝试使用 RHEL 7 在标准 cgi-bin 位置 /var/www/cgi-bin/test.pl 中运行 hello-world Perl 脚本。仅当 selinux 设置为强制时,我才在 httpd 错误日志中收到权限被拒绝的信息

AH01215: (13)Permission denied: exec of '/var/www/cgi-bin/test.pl' failed  
End of script output before headers: test.pl

将 selinux 设置为宽容后,脚本可以正常运行,并且 httpd 错误日志中不会发布任何内容。

在审计日志中我得到了长篇大论

type=PROCTITLE msg=audit(27482): proctitle=2F7573722F62696E2F7065726C002F7661722F7777772F6367692D62696E2F746573742E706C
type=PATH msg=audit(27482): item=2 name="/lib64/ld-linux-x86-64.so.2" inode=134467951 dev=fd:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:ld_so_t:s0 objtype=NORMAL
type=PATH msg=audit(27482): item=1 name="/usr/bin/perl" inode=67148821 dev=fd:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:bin_t:s0 objtype=NORMAL
type=PATH msg=audit(27482): item=0 name="/var/www/cgi-bin/test.pl" inode=269726961 dev=fd:07 mode=0100775 ouid=0 ogid=1007 rdev=00:00 obj=system_u:object_r:httpd_sys_script_exec_t:s0 objtype=NORMAL
type=CWD msg=audit(27482):  cwd="/var/www/cgi-bin"
type=EXECVE msg=audit(27482): argc=2 a0="/usr/bin/perl" a1="/var/www/cgi-bin/test.pl"
type=SYSCALL msg=audit(27482): arch=c000003e syscall=59 success=yes exit=0 a0=561ae60b3cd0 a1=561ae60ad370 a2=561ae60ad388 a3=7ffe850d64a0 items=3 ppid=23749 pid=24488 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="test.pl" exe="/usr/bin/perl" subj=system_u:system_r:httpd_t:s0 key=(null)
type=SELINUX_ERR msg=audit(27482): op=security_bounded_transition seresult=denied oldcontext=system_u:system_r:httpd_t:s0 newcontext=system_u:system_r:httpd_sys_script_t:s0

最后一行似乎很有趣“SELINUX_ERR op=security_bounded_transition seresult=被拒绝 oldcontext=... newcontext=...”但找不到太多相关内容。

最后,文件上下文和权限设置正确。

drwxrwxr-x. root   webdev system_u:object_r:httpd_sys_script_exec_t:s0 /var/www/cgi-bin
-rwxrwxr-x. root webdev system_u:object_r:httpd_sys_script_exec_t:s0 /var/www/cgi-bin/test.pl

http.conf 中的所有内容都设置正确

<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options +ExecCGI
   Require all granted 
</Directory>
AddHandler cgi-script .pl

必须关闭 selinux 直到我弄清楚发生了什么。

相关内容