我想告诉,有没有真正的问题,一切都会按我希望开始,但我遇到一个奇怪的行为,我无法解释,所以寻找一些有识之士从更熟练的工程师。SELinux的fcontext
奇数行为与SELinux的如何应用于fcontext映射定义观察。
让我通过打印它适用于我的情况的SELinux fcontext政策启动:
[[email protected] wp-content]# semanage fcontext -l | grep "^/var/www.*httpd_sys_rw_content_t:s0\s$"
/var/www/svn(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/uploads(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/wp-content(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/sites/default/files(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/sites/default/settings\.php regular file system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/moodledata(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/moodle/data(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/gallery/albums(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html/owncloud/data(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html/configuration\.php all files system_u:object_r:httpd_sys_rw_content_t:s0
正如你可以从命令看,我很感兴趣,让httpd的fcontext政策写入内部在/ var/WWW 。
我设置了一个WordPress安装,所以我的眼睛锁定在这些政策:
/var/www/html(/.*)?/uploads(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/wp-content(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
从政策的RegExp我可以desifer我需要有什么目录结构。我们来为项目和结账创建一个目录。
[[email protected] /]# mkdir -p /var/www/html/sun
[[email protected] /]# cd /var/www/html/sun
[[email protected] sun]# svn co http://server/ .
让我们来看看,如果我们有合适的fcontext应用:
[[email protected] sun]# cd /var/www/html/sun/public/wp-content
[[email protected] wp-content]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 index.php
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 languages
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 mu-plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 themes
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 uploads
太好了!只是为了一个兴趣和仔细检查,让我们尝试恢复fcontext,看看会发生什么:
[[email protected] wp-content]# restorecon -Rv /var/www/html/sun/
[[email protected] wp-content]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 index.php
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 languages
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 mu-plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 themes
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 uploads
太棒了!按预期工作。
要完成测试,让我们来模拟一个预期故障。让我们创建一个项目目录的/HTML/外,喜欢这里:在/ var/WWW /太阳和结账。
[[email protected] wp-content]# mkdir -p /var/www/sun
[[email protected] wp-content]# cd /var/www/sun/
[[email protected] sun]# svn co http://server/ .
让我们来看看,如果我们有合适的fcontext应用:
[[email protected] sun]# cd /var/www/sun/public/wp-content/
[[email protected] wp-content]# ls –Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.php
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 languages
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 mu-plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 themes
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 uploads
奇怪,我期待看到httpd_sys_content_t(默认fcontext),让我们尝试恢复到默认值:
[[email protected] wp-content]# restorecon -Rv /var/www/sun
...Output omitted
[[email protected] wp-content]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.php
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 languages
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 mu-plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 plugins
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 themes
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 uploads
使用的restorecon为在/ var/WWW /太阳按预期工作,但是...难题是:
为什么在/ var/www/sun中svn co使用了非现有策略?该策略匹配fcontext但不适合这个位置:
/var/www/html(/.*)?/wp-content(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
除了指数。PHP有differect fcontext,但目录具有相同的:httpd_sys_rw_content_t