zoukankan      html  css  js  c++  java
  • linux系统中 SElinux安全子系统

    1、SElinux 是什么?

    SElinux(Security-Enhanced Linux)是美国国家安全局在linux开源社区的帮助下开发的一个强制访问控制(Mandatory Access Control)的安全子系统。使用SElinux技术的目的是为了让各个服务进程都受到约束,使其仅获取到本应获取的资源

    SElinux能够从多方面监控违法行为:对服务程序的功能进行限制SElinux域限制可以确保服务程序做不了出格的事情);对文件资源的访问限制SElinux安全上下文确保文件资源只能被其所属的服务程序进行访问)。

    2、SElinux服务有三种配置模式

    • enforcing:强制启用安全策略模式,将拦截服务的不合法请求
    • permissinve:遇到服务越权访问时,只发出警告而不强制拦截
    • disabled:对于越权的行为不警告也不拦截

    3、 SElinux的配置文件为/etc/selinux/config, 默认的模式为enforcing。

    [root@PC1linuxprobe /]# 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 enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=enforcing
    # SELINUXTYPE= can take one of these two values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected.
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted

    4、为了验证SElinux效果,首先查看 httpd服务的主配置文件,关注此时的网站数据目录,及httpd服务程序的默认首页

    [root@PC1linuxprobe /]# vim /etc/httpd/conf/httpd.conf

    查看网站数据目录下文件:

    [root@PC1linuxprobe /]# ls /home/wwwroot/
    index.html
    [root@PC1linuxprobe /]# cat /home/wwwroot/index.html
    xxxxyyyyyyzzzz

    查看此时httpd服务程序的首页:

    5、getenforce命令可以用来查看SElinux当前的运行模式,setenforce命令可以修改SElinux当前的运行模式(0为禁用,1未启用,临时生效)

    [root@PC1linuxprobe /]# getenforce   ## 查看此时SElinux服务模式
    Enforcing
    [root@PC1linuxprobe /]# setenforce 0  ## 设为禁用
    [root@PC1linuxprobe /]# getenforce
    Permissive

    看此时的httpd服务首页:

    6、解释

     httpd服务程序的功能是允许用户访问网站内容,因此SElinux可定会默认放行用户对网站的请求操作。但是,我们将网站数据的默认保存目录修改为了/home/wwwroot,这就产生问题了。 /home目录是用来存放普通用户的家目录数据的,而现在,httpd提供的网站服务却要去获取普通用户家目录中的数据了,这显然违反了SElinux的监管原则。

    7、拥有不同的SElinux安全上下文值?????

    [root@PC1linuxprobe /]# setenforce 1
    [root@PC1linuxprobe /]# ls -lZ /var/www/html/
    -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
    [root@PC1linuxprobe /]# ls -lZ /home/wwwroot/
    -rw-r--r--. root root unconfined_u:object_r:home_root_t:s0 index.html
  • 相关阅读:
    Kubernetes实战指南(三十三):都0202了,你还在手写k8s的yaml文件?
    Hadoop学习笔记
    Anaconda、Pycharm的安装与运行和Python环境的搭建
    常用编程软件文件配置(下载安装教程)
    error C2678: 二进制“<”: 没有找到接受“const _Ty”类型的左操作数的运算符
    Java 移位运算、符号位扩展
    c++ 集合操作
    c++ 输入与缓冲区
    python 装饰器
    python global 与 nonlocal
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14021505.html
Copyright © 2011-2022 走看看