SELinux:如何启用写入访问Joomlacaching目录?

我已经在运行Joomla网站的Debian挤压系统上build立了SELinux。 Joomla PHP代码希望对某些caching目录有写权限。

/ var / log / messages文件包含这些条目:

Dec 31 10:26:16 s0022 kernel: [ 2116.423199] type=1400 audit(1356945976.634:14831): avc: denied { write } for pid=1886 comm="apache2" name="_system" dev=xvda3 ino=790893 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_t:s0 tclass=dir Dec 31 10:26:16 s0022 kernel: [ 2116.447613] type=1400 audit(1356945976.658:14837): avc: denied { write } for pid=1886 comm="apache2" name="mod_mainmenu" dev=xvda3 ino=791346 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_t:s0 tclass=dir 

与inode值相对应的目录可以由apache2(以wwwrun运行)写入。 caching文件是在SELinuxclosures时创build的,而不是在激活时创build的。 这些目录的path与Debian Squeeze的默认DocumentRoot不同。

 # ls -ldZ cache cache/_system cache/mod_mainmenu drwxrwxr-x. 5 wwwrun www unconfined_u:object_r:httpd_t:s0 4096 Dec 29 23:13 cache drwxrwxr-x. 2 wwwrun www unconfined_u:object_r:httpd_t:s0 4096 Dec 30 19:31 cache/mod_mainmenu drwxrwxr-x. 2 wwwrun www unconfined_u:object_r:httpd_t:s0 4096 Dec 30 19:31 cache/_system 

我也尝试启用写相关的布尔标志,但是这也没有帮助:

 # getsebool -a | grep httpd allow_httpd_anon_write --> on allow_httpd_mod_auth_pam --> off allow_httpd_sys_script_anon_write --> on allow_httpd_user_script_anon_write --> on httpd_builtin_scripting --> off httpd_can_network_connect --> off httpd_can_network_connect_db --> on httpd_can_network_relay --> off httpd_can_sendmail --> off httpd_dbus_avahi --> off httpd_enable_cgi --> off httpd_enable_ftp_server --> off httpd_enable_homedirs --> on httpd_ssi_exec --> off httpd_tty_comm --> off httpd_unified --> off httpd_use_cifs --> off httpd_use_gpg --> off httpd_use_nfs --> off 

我已经使用audit2allow来创build可加载的模块,以启用其他守护进程的写入权限(例如rotatelog),但我不认为这是在这种情况下去的方式。 httpd模块已经存在,我不想以任何方式触摸它,如果我能避免它。

我只是寻找一种方法来让apache2 / php / Joomla在特定的DocumentRoot中的特定目录中写入,而不会授予任何其他的写权限。 请指教。

caching目录被所有不同types的用户使用,就像你已经提到的那样,apache用户,php用户,甚至是一个单独的Joomla用户,如果你使用mod_fcgid。 对于这样的目录,有public_content_rw_ttypes的上下文。 这使得它对于所涉及的所有服务都是可写的,并且(因为它只是“具有临时文件的caching目录”)不应该施加太多的安全风险。 所以我会build议改变types为公众之一,使用命令

 chcon -R -t public_content_rw_t /path/to/wwwroot/cache 

您需要告诉SELinuxcaching位置是typeshttpd_cache_t

 # semanage fcontext -a -t 'httpd_cache_t' '/path/to/wwwroot/cache(/.*)?' # restorecon -Rvvv /path/to/wwwroot/cache