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社区的一个好地方。

[转] AppArmor的更多相关文章

  1. [问题]apparmor 问题导致mysql切换datadir目录失败

    问题: 在mysql切换datadir后,mysql服务无法启动.出现错误说plugin表无法读取,需要用mysql_upgrade创建.但是其实不是这个问题. 原因: apparmor 会限制程序对 ...

  2. Ubuntu apparmor何方神圣

    AppArmor 是一款与SeLinux类似的安全框架/工具,其主要作用是控制应用程序的各种权限,例如对某个目录/文件的读/写,对网络端口的打开/读/写等等. 来之Novell网站的引用: AppAr ...

  3. Apparmor——Linux内核中的强制访问控制系统

      AppArmor 因为最近在研究OJ(oline judge)后台的安全模块的实现,所以一直在研究Linux下沙箱的东西,同时发现了Apparmor可以提供访问控制. AppArmor(Appli ...

  4. apparmor介绍

    AppArmor AppArmor 类似于selinux ,主要的作用是设置某个可执行程序的访问控制权限,主要区别就在于apparmor是以路径(path)为基础,而selinux以i节点(inode ...

  5. [PATCH] UBUNTU: SAUCE: (no-up) apparmor: Sync to apparmor3 - RC1(v3.4.x kernel)

    ubuntu touch v3.4 kernel AppArmor v3 backport patch 地址1:https://github.com/multirom-aries/ubuntu-pho ...

  6. "UBUNTU: SAUCE: apparmor: 3.0 backport of apparmor3"

    下面提供的commit是为了让nexus 4g的内核支持ubunt touch的一些功能. 链接地址如下: "UBUNTU: SAUCE: apparmor: 3.0 backport of ...

  7. [转] Introduction to AppArmor

    Introduction to AppArmor http://ubuntuforums.org/showthread.php?t=1008906 Contents Post 1 Introducti ...

  8. apparmor 引起自定义mysql 日志问题

    今天手贱,看到mysql 的日志在/var/log/mysql下面.总是觉得别扭,于是就想改变日志的位置, 本人开发环境 vagrant  + ubuntu12.04 ,在/etc/mysql/mys ...

  9. 学习LSM(Linux security module)之三:Apparmor的前世今生和基本使用

    感冒了,感觉一脑子浆糊,真是蛋疼. 先粗略讲一些前置知识. 一:MAC和DAC DAC(Discretionary Access Control),自主访问控制,是最常用的一类访问控制机制,意思为主体 ...

随机推荐

  1. 20175126《Java程序设计》第七周学习总结

    # 20175126 2016-2017-2 <Java程序设计>第七周学习总结 ## 教材学习内容总结 - 本周学习方式主要为手动敲代码并理解内容学习. - 学习内容为教材第八章,本章主 ...

  2. 牛客小白月赛13 小A的回文串(Manacher)

    链接:https://ac.nowcoder.com/acm/contest/549/B来源:牛客网 题目描述 小A非常喜欢回文串,当然我们都知道回文串这种情况是非常特殊的.所以小A只想知道给定的一个 ...

  3. 4-16 css

    1.背景是图片 <style> body {background-image:url('bgdesert.jpg');} </style> 2. 十六进制 - 如:" ...

  4. H5真机调试

    为什么要做H5真机调试? 第一,样式调试.浏览器的效果和真机上的效果不一定相同,没有真机调试,我们都是先上传到服务器,然后再用手机访问,显然对于样式调试来说,这样效率很低. 第二,调用到底层.真机才拥 ...

  5. 分布式ID方案有哪些以及各自的优劣势,我们当如何选择

    作者介绍 段同海,就职于达达基础架构团队,主要参与达达分布式ID生成系统,日志采集系统等中间件研发工作. 背景 在分布式系统中,经常需要对大量的数据.消息.http请求等进行唯一标识,例如:在分布式系 ...

  6. ArrayList的ConcurrentModificationException异常和多线程下的异常

    一.ConcurrentModificationException ArrayList源码看为什么出现异常: public class ArrayList<e> extends Abstr ...

  7. centos 下使用vscode 调试egg.js 注意事项

    这两天在centos下,直接用vscode运行egg.js的例子.遇到个问题就是当安装了vscode-egg插件,会遇到一个现象.就是同样的代码,Windows下调试可以顺利进行,但是centos有时 ...

  8. linux学习第十四天 (Linux就该这么学)找到一本不错的Linux电子书

    今天老师讲了,DNS的相关,安装,配置,由来,13台根服务器,配置了主服务器,从服务器,和缓存服务器,等,今天补个大概吧,没有 记  还有正向解析,反向解析.

  9. Linux 查看网络状态工具

    1. iftop 效果如下图: 界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的. 中间的<= =>这两个左右箭头,表示的是流量的方向. TX:发送流量RX:接收流量T ...

  10. spring jar包解读(转)

    作者:http://www.cnblogs.com/leehongee/archive/2012/10/01/2709541.html spring.jar 是包含有完整发布模块的单个jar 包.但是 ...