최근에 웹에서 PHP를 이용하여 Python 스크립트를 실행할 일이 있어 구성 후 실행을 하였으나 정상적으로 실행이 안되어 문제를 확인하다 보니 SELinux 문제로 확인되었다. 문제 확인 방법은 'audit2allow -a' 명령어를 통해 SELinux 관련 로그를 파싱에서 볼 수 있다.
[root@localhost Honeypot]# audit2allow -a
#============= httpd_sys_script_t ==============
#!!!! This avc can be allowed using one of the these booleans:
# allow_ypbind, httpd_can_network_connect
allow httpd_sys_script_t smtp_port_t:tcp_socket name_connect;
allow httpd_sys_script_t sysfs_t:dir search;
#============= httpd_t ==============
#!!!! This avc can be allowed using one of the these booleans:
# httpd_read_user_content, httpd_enable_homedirs
allow httpd_t user_home_dir_t:dir getattr;
Apache와 SELinux와 관계된 설정값은 아래와 같다.
httpd_sys_content_t : 아파치의 모든 스크립트와 데몬에서 제공되는 모든 콘텐츠에 대한 설정
httpd_sys_script_exec_t : CGI실행을 허용 여부에 대한 설정
httpd_sys_script_ro_t : httpd_sys_script_exec_t 실행시 읽기 전용으로 사용 설정.
httpd_sys_script_rw_t : httpd_sys_script_exec_t 실행시 읽기/쓰기 전용으로 사용 설정.
httpd_sys_script_ra_t : httpd_sys_script_exec_t 실행시 읽기/append 전용으로 사용 설정
httpd_unconfined_script_exec_t : SELinux 보호 설정에 보호받지 않고 실행하기 위한 설정
아래와 같이 설정을 하여 정상적으로 운영이 됨을 확인하였다.
[root@localhost Honeypot]# chcon -t httpd_unconfined_script_exec_t test.py
[root@localhost Honeypot]# ls -alZ
drwxr-xr-x root root root:object_r:httpd_sys_content_t .
drwxr-x--- root apache system_u:object_r:httpd_sys_content_t ..
drwx---rwx root root user_u:object_r:httpd_sys_content_t Download
-rw-r--r-- root root user_u:object_r:httpd_sys_content_t index.php
drwx---rwx root root user_u:object_r:httpd_sys_content_t tmp
drwx---rwx root root user_u:object_r:httpd_sys_content_t Upload
-rwx---r-x root root user_u:object_r:httpd_sys_content_t upload.php
-rw-r--r-x root root user_u:object_r:httpd_unconfined_script_exec_t test.py
[root@localhost Honeypot]#