SELinux的特别权限

[linux] 2024-03-29 圈点415

摘要:SELinux很是奇怪,SELinux的特别权限。里面的逻辑也比较不是那么容易理解,但凡权限出现“非逻辑”问题,基本就是它在搞鬼!举几个简单的例子,文件夹的权限明明是777,可是却只能读取不能删除,也不能写入文件

SELinux很是奇怪,里面的逻辑也比较不是那么容易理解,但凡权限出现“非逻辑”问题,基本就是它在搞鬼!举几个简单的例子,文件夹的权限明明是777,可是却只能读取不能删除,也不能写入文件,attr也正常。百思不得姐(解)啊!!!一关selinux,马上好了!还有移动一个文件到网站根目录,发现没权限;而复制却正常!查看属性权限,都正常!


下面以上面说的第二个例子,解释一下原因。

回到问题的开始,拷贝之所以没出现问题,是因为cp自动修改上下文属性,而剪切之所以出现问题是因为mv保留原文件的上下文属性。

借助ls命令的-Z参数即可:

$ ls -Z /root/test.html

unconfined_u:object_r:admin_home_t:s0 /root/test.html


$ ls -Z /var/www/html/test.html

system_u:object_r:httpd_sys_content_t:s0 /var/www/html/test.html


httpd_sys_content_t,admin_home_t就是这种属性


Fix Command:如何修复呢?用下面的命令

/sbin/restorecon '/var/www/html/test.html'


Detailed Description:

SELinux denied access requested by httpd. /var/www/html/test.html may be a

mislabeled. /var/www/html/test.html default SELinux type is httpd_sys_content_t,

but its current type is admin_home_t. Changing this file back to the default

type, may fix your problem.


File contexts can be assigned to a file in the following ways.


  * Files created in a directory receive the file context of the parent

    directory by default.

  * The SELinux policy might override the default label inherited from the

    parent directory by specifying a process running in context A which creates

    a file in a directory labeled B will instead create the file with label C.

    An example of this would be the dhcp client running with the dhclient_t type

    and creating a file in the directory /etc. This file would normally receive

    the etc_t type due to parental inheritance but instead the file is labeled

    with the net_conf_t type because the SELinux policy specifies this.

  * Users can change the file context on a file using tools such as chcon, or

    restorecon.


This file could have been mislabeled either by user error, or if an normally

confined application was run under the wrong domain.


However, this might also indicate a bug in SELinux because the file should not

have been labeled with this type.


If you believe this is a bug, please file a bug report against this package.


Allowing Access:


You can restore the default system context to this file by executing the

restorecon command. restorecon '/var/www/html/test.html', if this file is a

directory, you can recursively restore using restorecon -R

'/var/www/html/test.html'.



SELinux  

感谢反馈,已提交成功,审核后即会显示