Selinux
SELinux 正在阻止 /usr/bin/bash 通過 php-fpm 對 nginx 中的文件 myfilename.sh 執行訪問
背景: 我有兩台 CentOS7 伺服器。
Test
&Prod
.我的網站中有一個腳本
myfilename.sh
,由 .php 在 php 中執行shell_exec
。兩台伺服器中的腳本和所有父文件夾具有相同的 selinux 上下文。
httpd_sys_rw_content_t
問題陳述: 腳本在
Test
伺服器上執行良好,但在Prod
.審核日誌
Prod
顯示SELinux is preventing /usr/bin/bash from execute access on the file myfilename.sh.
,但Test
框中沒有顯示任何內容。知道可能出了什麼問題,以及為什麼腳本在
Test
盒子上執行。我需要在Test
伺服器上重現該問題,然後再在產品上修復它。這是審核日誌:
SELinux is preventing /usr/bin/bash from execute access on the file myfilename.sh. ***** Plugin catchall (100. confidence) suggests ************************** If you believe that bash should be allowed execute access on the myfilename.sh file by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # ausearch -c 'sh' --raw | audit2allow -M my-sh # semodule -i my-sh.pp Additional Information: Source Context system_u:system_r:httpd_sys_script_t:s0 Target Context unconfined_u:object_r:httpd_sys_rw_content_t:s0 Target Objects myfilename.sh [ file ] Source sh Source Path /usr/bin/bash Port <Unknown> Host <Unknown> Source RPM Packages bash-4.2.46-21.el7_3.x86_64 Target RPM Packages Policy RPM selinux-policy-3.13.1-102.el7_3.16.noarch Selinux Enabled True Policy Type targeted Enforcing Mode Enforcing Host Name ip-X-X-X-X Platform Linux ip-X-X-X-X 3.10.0-327.10.1.el7.x86_64 #1 SMP Tue Feb 16 17:03:50 UTC 2016 x86_64 x86_64 Alert Count 23 First Seen 2017-06-17 06:33:36 CDT Last Seen 2017-06-18 02:18:01 CDT Local ID 340158ca-61f6-4472-aadb-18a3bbc34a22 Raw Audit Messages type=AVC msg=audit(1497770281.465:12508): avc: denied { execute } for pid=10042 comm="sh" name="myfilename.sh" dev="xvdc" ino=3416830 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=unconfined_u:object_r:httpd_sys_rw_content_t:s0 tclass=file type=SYSCALL msg=audit(1497770281.465:12508): arch=x86_64 syscall=execve success=no exit=EACCES a0=20d5650 a1=20d5730 a2=20d3c20 a3=7ffe9f4d7de0 items=0 ppid=10041 pid=10042 auid=4294967295 uid=995 gid=992 euid=995 suid=995 fsuid=995 egid=992 sgid=992 fsgid=992 tty=(none) ses=4294967295 comm=sh exe=/usr/bin/bash subj=system_u:system_r:httpd_sys_script_t:s0 key=(null) Hash: sh,httpd_sys_script_t,httpd_sys_rw_content_t,file,execute
httpd_sys_rw_content_t上下文不適用於執行檔。我們需要為此設置httpd_sys_script_exec_t上下文
sudo semanage fcontext -a -t httpd_sys_script_exec_t "/PATH_TO_FILE/myfilename.sh"
然後不要忘記執行 restorecon。
sudo restorecon -Rv /PATH_TO_FILE/