SELinux causes “Permission denied” when starting lighttpd+fastcgi via upstart

lighttpdselinuxupstart

I'm have trouble launching a lighttpd fastcgi python app via upstart. I can launch the app successfully using sudo lighttpd -D -f /path/to/lighttpd.conf and via su -c "lighttpd -f /path/to/lighttpd.conf.

In upstart, I'm using the following script:

start on filesystem and started networking
stop on runlevel [06]

respawn

exec lighttpd -f /path/to/lighttpd/lighttpd.conf -D

which results in the following errors in /var/log/lighttpd/error.log:

2011-11-28 15:35:25: (mod_fastcgi.c.978) bind failed for: unix:/var/lib/lighttpd/sockets/fastcgi.python.socket-0 Permission denied 
2011-11-28 15:35:25: (mod_fastcgi.c.1399) [ERROR]: spawning fcgi failed. 
2011-11-28 15:35:25: (server.c.938) Configuration of plugins failed. Going down. 

ls -l /var/lib/lighttpd/sockets/ shows

drwxr-xr-x. 2 lighttpd lighttpd 4096 Nov 28 15:19 .
drwxr-xr-x. 3 lighttpd lighttpd 4096 Nov 28 15:19 ..

and lighttpd is configured to use the lighttpd user and group (from my lighttpd.conf):

server.username  = "lighttpd"
server.groupname = "lighttpd"

I've tried adding strace in the upstart stanza but that doesn't yield anything obviously wrong. What further steps can I take to debug? What else could be causing this issue? This is on CentOS 6.

I'm starting to suspect this is selinux related. I've found this in the audit.log:

type=AVC msg=audit(1322516700.993:6418): avc:  denied  { write } for  pid=7920 comm="lighttpd" name="sockets" dev=vda3 ino=146700 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:lib_t:s0 tclass=dir
type=SYSCALL msg=audit(1322516701.053:6419): arch=c000003e syscall=42 success=no exit=-13 a0=5 a1=7fff848dfef0 a2=39 a3=2f7374656b636f73 items=0 ppid=1 pid=7922 auid=4294967295 uid=496 gid=490 euid=496 suid=496 fsuid=496 egid=490 sgid=490 fsgid=490 tty=(none) ses=4294967295 comm="lighttpd" exe="/usr/sbin/lighttpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1322516701.053:6419): avc:  denied  { write } for  pid=7922 comm="lighttpd" name="fastcgi.python.socket-0" dev=vda3 ino=146472 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:lib_t:s0 tclass=sock_file

Thanks!

Best Answer

selinux was the guilty party. Disabling selinux with echo 0>/selinux resolved the issue. I was further able to narrow the hammer to setsebool -P httpd_can_network_connect 1 but it would be nice to apply some SELinux policy change to my application instead of the system-wide.