SELinux Management Principles

Source: Internet
Author: User

SELinux uses so-called Delegated access control (Mandatory access Control,mac) to manage permissions based on specific programs and specific file resources. Even the root user, when using a different program, the permissions you can obtain are not necessarily root, need to be based on the program settings.
I. SELinux mode of operation

1、主体(Subject)        SELinux主要管理的就是程序。可以相比于process。2、目标(Object)        主体程序访问的目标资源一般就是文件系统。3、策略(Policy)        访问安全性策略,规则等。centos6.x提供targeted和mls两个主要的策略。    targeted:针对网络服务限制较多,针对本机限制较少,是默认的策略。    mls:完整的SELinux限制,限制方面较为严格。4、安全性环境(Security Context)        类似于文件系统的rwx。

View the security environment for files under/root

[[email protected] ~]# ls -Z-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log-rw-r--r--. root root system_u:object_r:admin_home_t:s0 install.log.syslogIdentify:role:type身份识别:角色:类型身份识别(Identify):相当于账号方面的身份识别。主要的身份识别有:1、root:表示root的账号身份2、system_u:表示系统程序方面的识别,通常就是程序3、user_u:代表的是一般用户账号相关的身份角色(Rule):通过角色字段,我们可以知道这个数据是代表程序、文件资源还是用户。1、object_r:代表的是文件或目录等资源,这是最常见的。2、system_r:代表的就是程序了。不过一般用户也会被指定成为system_r类型(Type):一个主体程序能否读取到这个文件资源,与类型字段有关1、Type:在文件资源中被称为类型2、Domain:在主体程序中被称为域

Ii. SELinux startup, shutdown, and viewing

三种模式:# SELINUX= can take one of these three values:#     enforcing - SELinux security policy is enforced.#     permissive - SELinux prints warnings instead of enforcing.#     disabled - No SELinux policy is loaded.查看:getenforce临时设置:setenforce 【0 | 1】永久修改:vim /etc/selinux/config,再重新启动注意:setenforce无法在disabled的模式下进行切换

Iii. the SELinux Type field modification
The Type field of the copied file is inherited from the destination directory, and the moved file remains unchanged.
1, Chcon

chcon [-R] [-t type] [-u user] [-r role] 文件chcon [-R] --reference=范例文件 文件-R:连同该目录下的子目录也进行修改-t:后面接安全性环境的类型字段-u:后面接身份识别-r:后面接角色--reference:参考范例文件

2, Restorecon

restorecon [-Rv] 文件或目录-R:连同子目录修改-v:过程显示到屏幕

3, Semanage

semanage {login|user|port|interface|fcontext|translation} -lsemanage fcontext -{a|d|m} [-frst] file_specfcontext:主要用作安全性环境方面,-l为查询-a:增加-m:修改-d:删除

Iv. rules in SELinux policy Boolean revision
1. Policy review

seinfo [-Atrub]-A:列出SELinux的状态-t:所有类别-r:所有角色种类-u:所有身份识别种类-b:所有规则的种类(布尔值)详细的规则:sesearch [--all] [-s 主体类别] [-t 目标类别] [-b 布尔值]

2. Query and modification of Boolean value

查阅:getsebool [-a] [布尔值条款]修改:getsebool [-P] 布尔值=[0|1]

V. The required services for SELinux log file records
Using Setsebool, Chcon, Restorecon, and so on are some of the command actions that need to be modified when some network services are unable to provide the relevant functionality properly. CentOS provides several detection services to detect errors that occur when logging on to SELinux, which is AUDITD, Setroubleshoot.
1. Setroubleshoot: Write error message to/var/log/message and/var/log/setroubleshoot/*

Install and start the service

[[email protected] ~ ]yum install setroubleshoot setroubleshoot-server[[email protected] ~ ]service auditd restart

Mode of operation:

1、先由auditd去呼叫audispd服务2、然后audispd服务去启动sedispatch程序3、sedispatch再将原本的auditd信息转成setroubleshoot的信息,进一步储存下来。

Take the error of HTTPD program as an example

2, using e-mail or directly above the command line to provide setroubleshoot error message
3. Summary of SELinux Error overcoming
Network connection to be able to go through SELinux authority to determine the authority to continue to compare rwx, and the SELinux comparison needs to be compared with the rules of the policy before the SELinux type security environment comparison. The subsequent selinux modifications are handled by Chcon, Restorecon, Setsebool and other commands. By analyzing the information provided within the/var/log/messsage Setroubleshoot.

a】在服务和rwx权限都没有问题,却无法成功的使用网络服务时,先使用setenforce 0 设置为宽容模式b】再次使用该网络服务,如果这样就能使用,则问题出现在SELinux上面,若仍无法使用则应从其他方面考虑排错。c】分析/var/log/message中的信息,找到sealert -l相关的信息并且执行d】找到Allow Access的关键词,按照里面的动作来进行SELinux的错误克服。e】处理完毕重新setenforce 1,再次测试网络服务

SELinux Management Principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.