SELinux

Linux 系统的实现是基于MAC访问控制机制的SELinux;python

访问控制机制又分为两类:
DAC:自主访问控制机制;
积极与文件或数据被文件系统赋予的访问权限(r,w,x)的方式实现的访问控制;
MAC:强制访问控制机制;
对于文件或数据的访问权限不是针对用户身份来设定,当某个用户发起某个进程以后,该进程是否可以操纵或处理此文件或数据,取决于进程和文件是否具有能够匹配的domain和type;linux

SElinux为每一个文件提供了一套安全标签,也为每一个进程提供了一套安全标签,这些安全标签能够称为SELinux的安全上下文(Security context);
user-identify:role:domain|type:sencitivity安全

user-identify:Selinux的用户身份标识,一般指用户的类型;

        role:角色

        domain|type:进程的域或文件的类型;

        sencitivity:敏感度;

Selinux的策略库:
规则库:存放规则
规则:进程的那个域能够以哪一种方式访问或操纵那些类型的文件,存放于/etc/selinux/targeted/policy目录中;dom

/etc/sysconfig/selinux文件中定义了SElinux的工做模式和使用的策略结果集;

image.png
SElinux的工做模式:
enforcing - SELinux security policy is enforced.
permissive - SELinux prints warnings instead of enforcing.
disabled - No SELinux policy is loaded.tcp

注意:
    1.凡是从enforcing或premissive模式切换至disabled模式,或者从disabled模式切换至enforcing或premissive模式,都必须通过操做系统的从新引导才能生效;
    2.从enforcing切换至premissive模式,可使用命令行工具完成且当即生效;

        setenforce命令:
            setenforce - modify the mode SELinux is running in

            setenforce [Enforcing|Permissive|1|0]
                1:Enforcing
                0:Permissive

        getenforce命令:
            getenforce - get the current mode of SELinux

        注意:使用setenfoce命令修改的SELinux的工做模式会当即生效,但并不是永久生效;
            若是向SELinux的工做模式永久生效,须要修改/etc/sysconfig/selinux文件中的内容,并须要从新引导;

查看进程或文件的SElinux的安全上下文;
        文件安全上下文查看:
            ls -Z|--context

image.pngide

进程安全上下文查看;
            ps -auxZ
            ps -efZ

image.png工具

查看或修改策略中的内容:
getsebool命令:
getsebool - get SELinux boolean value(s)操作系统

-a:Show all SELinux booleans.

    setsebool命令:
        setsebool - set SELinux boolean value

        -P:If the -P option is given, all pending values are written to the policy file  on disk. So they will be persistent across reboots.

    使用场景:支持二进制策略修改的系统服务;
        vsftpd的匿名用户的上传功能被SELinux限制的场景:
            ~]# setsebool -P ftpd_anon_write on
            ~]# setsebool -P ftpd_full_access=1

        samba服务中samba用户访问本身的家目录的共享结果被SELinux限制的场景:
            ~]# setsebool -P samba_enable_home_dirs on

        samba服务中共享的目录是由管理员自行建立并指定的:
            chcon -t samba_share_t /path/to/directory

    semanage命令:
        semanage - SELinux Policy Management tool
            注意:若是没有此命令,须要安装policycoreutils-python程序包便可;

            semanage port命令:
                -a, --add
                    Add a record of the specified object type

                -d, --delete
                    Delete a record of the specified object type

                -m, --modify
                    Modify a record of the specified object type

                -l, --list
                    List records of the specified object type

            示例:
                ~]# semanage port -a -t http_port_t -p tcp 8088
相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息