Linux Security: SELinux

Source: Internet
Author: User

SELinux

Chapter Content

SELinux概念  启用SELinux  管理文件安全标签  管理端口标签  管理SELinux布尔值开关  管理日志  查看SELinux帮助  

SELinux Introduction

SELinux: Secure Enhanced Linux, 是美国国家安全局(NSA=The NationalSecurity Agency)和SCC(Secure Computing Corporation)开发的 Linux的一个强制访问控制的安全模块。2000年以GNU GPL发布,Linux内核2.6版本后集成在内核中DAC:Discretionary Access Control自由访问控制MAC:Mandatory Access Control 强制访问控制? DAC环境下进程是无束缚的? MAC环境下策略的规则决定控制的严格程度? MAC环境下进程可以被限制的? 策略被用来定义被限制的进程能够使用那些资源(文件和端口)? 默认情况下,没有被明确允许的行为将被拒绝  

SELinux type of work

SELinux有四种工作类型:strict: centos5,每个进程都受到selinux的控制targeted: 用来保护常见的网络服务,仅有限进程受到selinux控制,只监控容易被***的进程,centos4只保护13个服务,centos5保护88个服务minimum:centos7,修改的targeted,只对选择的网络服务mls:提供MLS(多级安全)机制的安全性targeted为默认类型,minimum和mls稳定性不足,未加以应用,strict已不再使用  

SELinux Security Context

传统Linux,一切皆文件,由用户,组,权限控制访问在SELinux中,一切皆对象(object),由存放在inode的扩展属性域的安全元素所控制其访问所有文件和端口资源和进程都具备安全标签:安全上下文(securitycontext)安全上下文有五个元素组成:user:role:type:sensitivity:categoryuser_u:object_r:tmp_t:s0:c0 实际上下文:存放在文件系统中,ls –Z;ps –Z期望(默认)上下文:存放在二进制的SELinux策略库(映射目录和期望安全上下文)中semanage fcontext –l  

Five Elements of security

User:指示登录系统的用户类型,如root,user_u,system_u,多数本地进程都属于自由(unconfined)进程Role:定义文件,进程和用户的用途:文件:object_r,进程和用户:system_rType:指定数据类型,规则中定义何种进程类型访问何种文件Target策略基于type实现,多服务共用:public_content_tSensitivity:限制访问的需要,由组织定义的分层安全级别,如unclassified,secret,top,secret, 一个对象有且只有一个sensitivity,分0-15级,s0最低,Target策略默认使用s0Category:对于特定组织划分不分层的分类,如FBI Secret,NSA secret, 一个对象可以有多个categroy, c0-c1023共1024个分类, Target 策略不使用category  

SELinux Policy

对象(object):所有可以读取的对象,包括文件、目录和进程,端口等主体:进程称为主体(subject)SELinux中对所有的文件都赋予一个type的文件类型标签,对于所有的进程也赋予各自的一个domain的标签。domain标签能够执行的操作由安全策略里定义当一个subject试图访问一个object,Kernel中的策略执行服务器将检查AVC (访问矢量缓存Access Vector Cache), 在AVC中,subject和object的权限被缓存(cached),查找“应用+文件”的安全环境。然后根据查询结果允许或拒绝访问安全策略:定义主体读取对象的规则数据库,规则中记录了哪个类型的主体使用哪个方法读取哪一个对象是允许还是拒绝的,并且定义了哪种行为是充许或拒绝  

Set SELinux

配置SELinux:    SELinux是否启用    给文件重新打安全标签    给端口设置安全标签    设定某些操作的布尔型开关    SELinux的日志管理SELinux的状态:    enforcing: 强制,每个受限的进程都必然受限    permissive: 允许,每个受限的进程违规操作不会被禁止,但会被记录于审    计日志    disabled: 禁用  

Configuring SELinux

相关命令:    getenforce: 获取selinux当前状态    sestatus :查看selinux状态    setenforce 0|1        0: 设置为permissive        1: 设置为enforcing        disabled是不能装换的配置文件:    /boot/grub/grub.conf    使用selinux=0禁用SELinux    /etc/selinux/config    /etc/sysconfig/selinux    SELINUX={disabled|enforcing|permissive}  

Modifying the SELinux security label

给文件重新打安全标签:    chcon [OPTION]... [-u USER] [-r ROLE] [-t TYPE] FILE...     chcon [OPTION]... --reference=RFILE FILE...    -R:递归打标;恢复目录或文件默认的安全上下文:      restorecon [-R] /path/to/somewhere  

Default security context Query and modification

Semanage:来自policycoreutils-python包查看默认的安全上下文    semanage fcontext –l添加安全上下文    semanage fcontext -a –t httpd_sys_content_t ‘/testdir(/.*)?’    restorecon –Rv /testdir删除安全上下文    semanage fcontext -d –t httpd_sys_content_t ‘/testdir(/.*)?’  

SELinux Port Label

查看端口标签    semanage port –l- a添加- d删除- m修改添加端口    semanage port -a -t port_label -p tcp|udp PORThttp 为例【http端口默认是80 然后再给他加一个9627端口】【-t 后面加的是标签,-p 后面加的是协议】semanage port -a -t http_port_t -p tcp 9527 然后 修改配置文件  vim /etc/httpd/conf/httpd.conf[把默认80   该成想要的端口9527]然后重新启动就完成修改【这是selinux 启动的状态】【如果selinux没有启动的状态修改端口号 】vim /etc/httpd/conf/httpd.conf[把默认80   该成想要的端口9527]然后重启服务删除端口    semanage port -d -t port_label -p tcp|udp PORT    semanage port -d -t http_port_t -p tcp 9527修改现有端口为新标签    semanage port -m -t port_label -p tcp|udp PORT    semanage port -m -t http_port_t -p tcp 9527   

SELinux Boolean value

布尔型规则:    getsebool    setsebool查看bool命令:    getsebool [-a] [boolean]    semanage boolean –l    semanage boolean -l 查看修改过的布尔值设置bool值命令:    setsebool [-P] boolean value(on,off)    setsebool [-P] Boolean=value(0,1)  

SELinux Log Management

yum install setroubleshoot(重启生效)将错误的信息写入/var/log/messagegrep setroubleshoot /var/log/messagessealert -l UUID查看安全事件日志说明sealert -a /var/log/audit/audit.log扫描并分析日志  

Seliunx Help

yum –y install selinux-policy-devel ( centos7.2)yum –y install selinux-policy-docmandb | makewhatisman -k _selinux

Linux Security: SELinux

Related Article

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.