SELinux

SELinux

访问控制

DAC

  • DAC:Discretionary Access Control,自主访问控制
  • 依据进程的所有者与文件资源的rwx权限来决定有无访问权限
  • DAC针对用户,对用户进行访问控制
  • 缺点:
    • root有最高权限无法限制
    • r,w,x权限划分太宽泛,无法针对不同的进程实现限制

MAC

  • MAC:Mandatory Access Control,强制访问控制
  • 依据策略规则决定进程可以访问哪些文件
  • MAC针进程,对进程进行访问控制
  • 优点:
    • 即使是root用户,在使用不同进程时,所能取得的权限并不一定是root,需要看当时进程的设置而定
    • 即使不小心httpd被取得了控制权,也无权浏览/etc/shadow等重要的文档

SELinux介绍

  • SELinux:Security-Enhanced Linux)安全增强型linux,是美国国家安全局(NSA)开发,用于实现强制访问控制(MAC)
  • selinux用于限制进程对系统中文件及目录的访问
  • 被设计成内核模块包含到linux内核中
  • SELinux提供一些默认的策略(Policy), 并在该策略内提供多个规则(rule),让用户可以选择是否启用该控制规则
  • selinux策略模式
[root@server1 ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of disabled.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
模式中文说明
enforcing强制模式违反SELinux规则的行为将被阻止并记录到日志中
permissive宽容模式违反SELinux规则的行为只会记录到日志中,一般为调试用
disabled关闭模式关闭SELinux

SELinux使用

  • 基本使用
配置文件
[root@server1 ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of disabled.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

开启selinux
[root@server1 ~]# sed -i 's/SELINUX=disabled/SELINUX=enforing/' /etc/selinux/config 

重启系统(不然selinux不生效)
[root@server1 ~]# reboot

查看selinux的模式
[root@server1 ~]# getenforce 
Permissive

命令行设置selinux的模式(0为permissive;1为enforing)
[root@server1 ~]# setenforce 1
[root@server1 ~]# getenforce 
Enforcing

查看文件selinux规则
[root@server1 ~]# touch file1
[root@server1 ~]# ll -Z file1 
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 file1

查看进程selinux规则
[root@server1 ~]# ps -efZ |grep httpd
system_u:system_r:httpd_t:s0    root       1565      1  0 14:58 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache     1567   1565  0 14:58 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache     1568   1565  0 14:58 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache     1569   1565  0 14:58 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache     1570   1565  0 14:58 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
  • 当开启selinux时,网卡中配置的域名解析会失效,需要在/etc/resolv.conf文件中配置
[root@server1 ~]# ping www.baidu.com
ping: www.baidu.com: 未知的名称或服务
[root@server1 ~]# vim /etc/resolv.conf 
[root@server1 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 114.114.114.114
[root@server1 ~]# ping www.baidu.com
PING www.a.shifen.com (112.80.248.75) 56(84) bytes of data.
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=1 ttl=128 time=9.42 ms
64 bytes from 112.80.248.75 (112.80.248.75): icmp_seq=2 ttl=128 time=9.50 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 9.421/9.463/9.506/0.106 ms
  • 当开启selinux时,修改http的端口,会导致不能重启httpd服务
端口改为8090
[root@server1 ~]# vim /etc/httpd/conf/httpd.conf 
[root@server1 ~]# cat /etc/httpd/conf/httpd.conf |grep Listen |grep -v '^#'
Listen 8090
[root@server1 httpd]# systemctl restart httpd.service 
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

重新改回80
[root@server1 ~]# cat /etc/httpd/conf/httpd.conf |grep Listen |grep -v '^#'
Listen 80
[root@server1 ~]# systemctl restart httpd.service
[root@server1 ~]# 
  • 基于selinux有很多坑,建议将selinux永久关闭
[root@server1 ~]# setenforce 0
[root@server1 ~]# sed -i 's/SELINUX=enforing/SELINUX=disabled/' /etc/selinux/config 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值