SELinux는 /usr/bin/bash가 php-fpm을 통해 nginx의 myfilename.sh 파일에 액세스하는 것을 방지합니다.

SELinux는 /usr/bin/bash가 php-fpm을 통해 nginx의 myfilename.sh 파일에 액세스하는 것을 방지합니다.

배경: 두 개의 CentOS7 서버가 있습니다. Test& . Prod내 웹사이트에 PHP로 실행되는
스크립트가 있습니다 . 두 서버의 스크립트와 모든 상위 폴더는 동일한 selinux 컨텍스트를 갖습니다.myfilename.shshell_exec
httpd_sys_rw_content_t

문제 설명: 스크립트는 서버에서 제대로 실행되지만 감사 로그 Test에는 표시되지만 상자에는 아무것도 표시되지 않습니다 .Prod
ProdSELinux 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

답변1

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/

관련 정보