SELinux

Linux 系統的實現是基於MAC訪問控制機制的SELinux;

訪問控制機制又分爲兩類:
DAC:自主訪問控制機制;
積極與文件或數據被文件系統賦予的訪問權限(r,w,x)的方式實現的訪問控制;
MAC:強制訪問控制機制;
對於文件或數據的訪問權限不是針對用戶身份來設定,當某個用戶發起某個進程之後,該進程是否能夠操縱或處理此文件或數據,取決於進程和文件是否具備可以匹配的domain和type;

SElinux爲每個文件提供了一套安全標籤,也爲每個進程提供了一套安全標籤,這些安全標籤可以稱爲SELinux的安全上下文(Security context);
user-identify:role:domain|type:sencitivity

        user-identify:Selinux的用戶身份標識,通常指用戶的類型;

        role:角色

        domain|type:進程的域或文件的類型;

        sencitivity:敏感度;

Selinux的策略庫:
規則庫:存放規則
規則:進程的那個域可以以哪種方式訪問或操縱那些類型的文件,存放於/etc/selinux/targeted/policy目錄中;

            /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.

    注意:
    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.png

        進程安全上下文查看;
            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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章