I have a webserver running CentOS 6.2 and the latest Apache from repositories. Todey I encountered a problem when running an executable program via CGI on Apache. The program is supposed to connect to some site, download something and then returns it to user (normal port-80 request, nothing fishy).
The problem is, that the CGI programs returns Permission denied
on socket_open
command.
Other simpler CGI programs that do not require network connectivity work fine and this program works just as well when invoked from command line, so I suspected some permissions issue and since setting a setuid
on the executable didn't resolve a problem, I came to a conclusion that it is something that SELinux has control over.
I have never really worked with SELinux, but getsebool -a | grep httpd
returns
allow_httpd_anon_write --> off
allow_httpd_mod_auth_ntlm_winbind --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> on
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_read_user_content --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_tmp_exec --> off
httpd_tty_comm --> on
httpd_unified --> on
httpd_use_cifs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
I suspect that httpd_can_network_connect --> off
is the problematic one here, but this is a permision for the httpd
, not the actual executable. Are SELinux permissions inherited from parent process? How would I set it to be enabled for the script only and not for the whole httpd
? Or is there a whole different problem and not a SELinux related one?
Thank you for help.
Edit: I tried setenforce 0
and the script is working then, so it is a SELinux thing.
Edit 2: ausearch -ts recent -m avc
returns
time->Thu May 3 23:52:29 2012
type=SYSCALL msg=audit(1336081949.221:18563): arch=c000003e syscall=42 success=no exit=-13 a0=8 a1=7fff21161cb0 a2=10 a3=7fff21161a30 items=0 ppid=6813 pid=6814 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm=".stutsk" exe="/var/www/html/stutsk-cgi/.stutsk" subj=system_u:system_r:httpd_sys_script_t:s0 key=(null)
type=AVC msg=audit(1336081949.221:18563): avc: denied { name_connect } for pid=6814 comm=".stutsk" dest=80 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket