zoukankan      html  css  js  c++  java
  • [转] AppArmor

    AppArmor

    https://help.ubuntu.com/14.04/serverguide/apparmor.html

    AppArmor 是一个实施了基于名称强制存取控制的Linux安全模组。AppArmor 界定了单个程序进入一组文件列表的权限并遵循posix 1003.1e 草稿的能力。

    默认情况下AppArmor已安装并载入。它使用每个程序的profiles来确定这个程序需要什么文件和权限。有些包会安装它们自己的profiles,额外的profiles可以在apparmor-profiles包里找到。

    要安装apparmor-profiles软件包,在终端输入:

    sudo apt-get install apparmor-profiles
    

    AppArmor配置文件有两种执行模式:

    • 投诉/学习: 允许并记录配置文件的冲突。对于测试并开发新的配置文件有用途。

    • 强制/受限:强制配置策略及违规记录。

    使用 AppArmor

    apparmor-utils软件包包含一些命令行工具,使用它们您可以更改AppArmor的执行模式、查看配置文件的状态、创建新的配置文件等等。

    • apparmor_status是用来查看AppArmor配置文件的当前状态的。

      sudo apparmor_status
      
    • aa-complain将一个配置文件置入complain模式。

      sudo aa-complain /path/to/bin
      
    • aa-enforce将一个配置文件置入enforce模式。

      sudo aa-enforce /path/to/bin
      
    • /etc/apparmor.d目录是AppArmor配置文件的所在之处。可用来操作所有配置文件的模式mode。

      要将所有配置文件置入complain模式,输入:

      sudo aa-complain /etc/apparmor.d/*
      

      要将所有配置文件置入enforce模式:

      sudo aa-enforce /etc/apparmor.d/*
      
    • apparmor_parser用来将一个配置文件载入内核。它也可以通过使用-r选项来重新载入当前已载入的配置文件。要载入一个配置文件:

      cat /etc/apparmor.d/profile.name | sudo apparmor_parser -a
      

      要重新载入一个配置文件:

      cat /etc/apparmor.d/profile.name | sudo apparmor_parser -r
      
    • service apparmor can be used to reload all profiles:

      sudo service apparmor reload
      
    • The /etc/apparmor.d/disable目录可以和apparmor_parser -R选项一起使用以禁用一个配置文件。

      sudo ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/
      sudo apparmor_parser -R /etc/apparmor.d/profile.name
      

      要重新激活 一个已禁用的配置文件,请在 /etc/apparmor.d/disable/里删除到其配置文件的软链接。然后使用选项 -a载入配置文件。

      sudo rm /etc/apparmor.d/disable/profile.name
      cat /etc/apparmor.d/profile.name | sudo apparmor_parser -a
      
    • AppArmor可以被禁用,其内核模块可以通过输入以下命令卸载:

      sudo service apparmor stop
      sudo update-rc.d -f apparmor remove
      
    • 要重新启用AppArmor,输入:

      sudo service apparmor start
      sudo update-rc.d apparmor defaults
      

    用你操作的profile名称来替代profile.name。再有,用实际的执行文件的路径来代替/path/to/bin/。例如,使用/bin/ping来替代ping

    配置文件

    AppArmor profiles are simple text files located in /etc/apparmor.d/. The files are named after the full path to the executable they profile replacing the "/" with ".". For example /etc/apparmor.d/bin.ping is the AppArmor profile for the /bin/ping command.

    在配置文件中,主要有两种类型的规则

    • 路径 项: 指定文件系统中哪些文件是一个应用程序可以访问的。

    • Capability entries: determine what privileges a confined process is allowed to use.

    作为一个例子来看看/etc/apparmor.d/bin.ping:

    #include <tunables/global>
    /bin/ping flags=(complain) {
      #include <abstractions/base>
      #include <abstractions/consoles>
      #include <abstractions/nameservice>
    
      capability net_raw,
      capability setuid,
      network inet raw,
      
      /bin/ping mixr,
      /etc/modules.conf r,
    }
    
    • #include <tunables/global>:包含了来自另外文件的声明。这样做使得来自不同应用程序的相关声明都被放置在同一个文件中。

    • /bin/ping flags=(complain): path to the profiled program, also setting the mode to complain.

    • capability net_raw,: 允许程序拥有连接 CAP_NET_RAW Posix.1e 的能力。

    • /bin/ping mixr,: 允许应用程序读取和执行该文件。

    编辑配置文件后必须重新载入配置文件。参看使用 AppArmor 获取详情

    创建配置文件
    • 设计测试计划: 试着思考应用程序会怎样运行。测试计划可以分解为小的测试用例。对每个测试用例,应该有个简短的描述,并列出应该执行的步骤。

      一些标准的测试情况是:

      • 启动程序。

      • 停止程序。

      • 重新载入程序。

      • 测试所有init脚本支持的命令。

    • 生成新配置文件: 使用 aa-genprof 生成新的配置文件。在终端输入:

      sudo aa-genprof executable
      

      例如:

      sudo aa-genprof slapd
      
    • 要想让你的配置文件被包含于 apparmor-profiles 包内,在Launchpad上向AppArmor发一个bug报告:

      • 包含您的测试计划和测试用例。

      • 在bug报告里附上你的新配置文件。

    更新配置文件

    When the program is misbehaving, audit messages are sent to the log files. The program aa-logprof can be used to scan log files for AppArmor audit messages, review them and update the profiles. From a terminal:

    sudo aa-logprof
    

    参考资料

    • freenode 上的 #ubuntu-server IRC 聊天频道是一个寻求AppArmor帮助和参与Ubuntu Server社区的一个好地方。

  • 相关阅读:
    文本环加载动画html代码
    自己总结的特殊符号,大家有用可以复制
    《名侦探柯南》动画登陆bilibili
    复古风,vivo申请滑盖结构的手机外观专利
    GitHub 热榜第一!可交互全球疫情地图
    最新免费领哔哩哔哩会员教程
    百度网盘免费领取会员
    Apple Watch Series 6或将增加焦虑监测和睡眠追踪功能
    谷歌更新其社区人员流动报告 帮助了解民众遵守封锁令的情况
    计算5的n次幂html代码
  • 原文地址:https://www.cnblogs.com/popsuper1982/p/3818116.html
Copyright © 2011-2022 走看看