当启动lighttpd + fastcgi时,SELinux会导致“权限被拒绝”

我无法通过暴发户启动一个lighttpd fastcgi python应用程序。 我可以使用sudo lighttpd -D -f /path/to/lighttpd.conf并通过su -c "lighttpd -f /path/to/lighttpd.conf成功启动应用程序。

暴发户,我使用以下脚本:

 start on filesystem and started networking stop on runlevel [06] respawn exec lighttpd -f /path/to/lighttpd/lighttpd.conf -D 

这会在/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 .. 

而lighttpd被configuration为使用lighttpd用户和组(来自我的lighttpd.conf):

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

我已经尝试在暴发户节目中添加strace,但是这不会产生任何明显的错误。 我可以采取哪些进一步措施进行debugging? 还有什么可能导致这个问题? 这是在CentOS 6上。

我开始怀疑这是selinux相关的。 我在audit.log中find了这个:

 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 

谢谢!

selinux是有罪的一方。 使用echo 0>/selinux禁用selinux解决了这个问题。 我进一步缩小了setsebool -P httpd_can_network_connect 1的锤子,但是将一些SELinux策略更改应用到我的应用程序而不是系统范围内会更好。

  1. 我将套接字放在/var/run/lighttpd
  2. 我会事先创build套接字( touch /var/run/lighttpd/fastcgi.python.socket-0 )。 不知道是否lighttpd获得否则。

您可以通过大致执行以下步骤构build自定义SELinux目标策略:

  • 将您希望允许来自消息或审计日志的拒绝审计消息添加到名为: /etc/selinux/local/YOUR_POL.audit的新文件
  • 检查更改,如果满意创build一个新的selinux目标:
    cat /etc/selinux/local/YOUR_POL.audit | audit2allow -m audit > YOUR_POL.te
  • 检查并build立模块:
    checkmodule -M -m -o YOUR_POL.mod TOUR_POL.te
  • 打包模块:
    semodule_package -o YOUR_POL.pp -m YOUR_POL.mod
  • 加载打包的模块:
    semodule -i YOUR_POL.pp