一,selinux的用途
1,什麼是selinux
SELinux:即安全增強型 Linux(Security-Enhanced Linux)
它是一個 Linux 核心子產品,也是 Linux 的一個本機安全性授權
它主要由美國國家安全局開發,
它的主要作用:最大限度地減小系統中服務程序可通路的資源(最小權限原則)
2,為什麼要關閉selinux?
有的軟體對于selinux的安全規則支援不夠好,就會建議在安裝前把selinux先關閉,
例如:k8s:
附:k8s的相應說明:
Setting SELinux in permissive mode by runningsetenforce 0andsed ...effectively disables it.
This is required to allow containers to access the host filesystem, which is needed by pod networks for example.
You have to do this until SELinux support is improved in the kubelet...
其目的在于允許容器通路主控端的檔案系統,
這種情況下隻能先關閉selinux
說明:如果不是要運作的軟體有相應需求,不建議關閉selinux
二,檢視目前selinux的狀态?
1,selinux的三種運作模式:
enforcing:強制模式,SELinux 正在運作中,已經在限制 domain/type
permissive:寬容模式:SELinux 正在運作中,但僅發出警告資訊,并不會實際限制 domain/type 的存取
(permissive模式可以用在測試環境中供調試規則時使用)
disabled:關閉,SELinux 沒有實際運作。
2,用sestatus檢視
[[email protected] ~]$ sestatus -v
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 31
...
可以看到: Current mode: enforcing
3,用getenforce檢視(常用)
[[email protected] ~]$ getenforce
Enforcing
三,臨時關閉/開啟selinux
檢視目前的運作模式
[[email protected] liuhongdi]# getenforce
Enforcing
配置selinux運作模式為:Permissive
#0: Permissive
#1: Enforcing
[[email protected] liuhongdi]# setenforce 0
檢視效果:
[[email protected] liuhongdi]# getenforce
Permissive
四,永久關閉selinux
1, 修改配置檔案
[[email protected] liuhongdi]# vi /etc/selinux/config
設定配置項為:
SELINUX=disabled
說明:預設值是: #SELINUX=enforcing
然後重新開機機器
2,修改/etc/sysconfig/selinux 這個檔案也可以生效
因為它其實就是/etc/selinux/config的符号連結
[[email protected] liuhongdi]# ll /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 11月 11 2019 /etc/sysconfig/selinux -> ../selinux/config
五,selinux的相關知識:
1,selinux預設的審計日志位于:/var/log/audit/audit.log
[[email protected] ~]# ll /var/log/audit/audit.log
-rw------- 1 root root 5093679 5月 29 13:57 /var/log/audit/audit.log
2,如何分析selinux的日志?
#-a:--analyze=FILE: 分析一個檔案
[[email protected] ~]# sealert -a /var/log/audit/audit.log
3,查詢系統中的布爾型規則及其狀态
[[email protected] liuhongdi]# getsebool -a
六,檢視linux的版本
[[email protected] ~]$ cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)