当前位置: 首页>>技术教程>>正文


什么是apparmor?

, ,

问题描述

我听到很多关于apparmor的讨论,我想知道以下几点:

  • 什么是apparmor?

  • apparmor如何工作?

最佳解决办法

这是什么

Apparmor是强制访问控制(或MAC)系统。它使用LSM内核增强功能将程序限制到某些资源。 AppArmor会在系统启动时将配置文件加载到内核中执行此操作。 Apparmor有两种类型的配置文件模式,即执行和投诉。强制模式下的配置文件强制执行该配置文件的规则,并在syslogauditd中报告违规企图。抱怨模式下的个人档案不会强制执行任何个人档案规则,只是记录违规尝试。

在Ubuntu中,Apparmor默认安装。它将应用程序限制在配置文件中,以确定程序需要访问的文件和权限。有些应用程序会自带属性,更多可以在apparmor-profiles软件包中找到。

您可以通过运行sudo apt-get install apparmor-profiles来安装apparmor-profiles

我在Ubuntu论坛上发现了一个很好的例子,我重写了这篇文章。

Apparmor is a security framework that prevents applications from turning evil. For example: If I run Firefox and visit a bad site that tries to install malware that will delete my home folder, Apparmor has limits on Firefox though preventing it from doing anything I don’t want (like accessing my music, documents, etc). This way even if your application is compromised, no harm can be done.

怎么运行的

apparmor-utils软件包包含用于配置Apparmor的命令行工具。使用它可以更改Apparmor的执行模式,查找创建新配置文件的配置文件状态等。

这些是最常见的命令:

注::配置文件存储在/etc/apparmor.d/

  • 您可以使用sudo apparmor_status检查Apparmor的状态。您将获得所有配置文件*加载的列表,所有配置文件处于执行模式,所有配置文件处于投诉模式,在执行/投诉中定义了哪些进程等。

  • 要将配置文件置入投诉模式,请使用sudo aa-complain /path/to/bin,其中/path/to/bin是程序bin文件夹。例如,运行:sudo aa-complain /usr/bin/firefox将使Firefox进入抱怨模式。

  • 您使用sudo aa-enforce /path/to/bin执行程序配置文件。

  • 您可以分别使用sudo aa-complain /etc/apparmor.d/*sudo aa-enforce.d/*将所有配置文件加载到抱怨/强制模式。

要将配置文件加载到内核中,您可以使用apparmor_parser。您可以使用-r参数重新加载配置文件。

  • 要加载配置文件,请使用:cat /etc/apparmor.d/profile.name | sudo apparmor_parser -a,它将profile.name的内容有效地打印到Apparmor的分析器中。

  • 要重新加载配置文件,请使用-r参数,如下所示:cat /etc/apparmor.d/profile.name | sudo apparmor_parser -r

  • 要重新加载所有Apparmor的配置文件,请使用:sudo service apparmor reload

要禁用配置文件,请使用ln将其链接到/etc/apparmor.d/disable/,如下所示:sudo ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/然后运行:sudo apparmor_parser -R /etc/apparmor.d/profile.name

注意:不要混淆apparmor_parser -rapparmor_parser -R它们不是同一件事!

  • 若要将re-enable配置文件删除,请在/etc/apparmor.d/disable/中删除其符号链接,然后使用-a参数加载它。 sudo rm /etc/apparmor.d/disable/profile.name cat /etc/apparmor.d/profile.name | sudo apparmor_parser -a

  • 您可以使用sudo service apparmor stop禁用Apparmor并使用sudo update-rc.d -f apparmor defaults删除内核模块

  • sudo service apparmor start启动Apparmor并使用sudo update-rc.d apparmor defaults加载内核模块

Profiles

配置文件存储在/etc/apparmor.d/中,并以其所配置的可执行文件的完整路径命名,并用’.’替换’/’。例如/etc/apparmor.d/bin.ping/binping的配置文件。

配置文件中使用了两种主要类型的条目:

  1. 路径条目确定应用程序可以访问的文件。

  2. 能力条目决定了流程可以使用的权限。

让我们来看一下位于etc/apparmor.d/bin.ping中的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>在目录tunables中包含文件global,这允许将与多个应用程序有关的语句放置在公用文件中。

/bin/ping flags=(complain)设置分析程序的路径并将模式设置为抱怨。

capability net_raw允许应用程序访问CAP_NET_RAW Posix.1e功能。

/bin/ping mixr允许应用程序读取并执行对文件的访问。

/etc/modules.conf r, r为应用程序提供/etc/modules.conf的读取权限

注:创建/编辑配置文件后,您需要重新加载配置文件才能使更改生效。

以下是您可以使用的权限列表:

  • r – 阅读

  • w – 写

  • ux – 无约束执行

  • Ux – 无约束执行 – 擦洗环境

  • px – 离散配置文件执行

  • Px – 离散配置文件执行 – 清理环境

  • ix – 继承执行

  • m – 允许PROT_EXECmmap(2)调用

  • l – 链接

来源:

http://ubuntuforums.org/showthread.php?t=1606499

http://ubuntuforums.org/showthread.php?t=1008906

https://wiki.ubuntu.com/AppArmor

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

次佳解决办法

AppArmor is a Mandatory Access Control (MAC) system which is a kernel (LSM) enhancement to confine programs to a limited set of resources. AppArmor’s security model is to bind access control attributes to programs rather than to users. AppArmor confinement is provided via profiles loaded into the kernel, typically on boot. AppArmor profiles can be in one of two modes: enforcement and complain. Profiles loaded in enforcement mode will result in enforcement of the policy defined in the profile as well as reporting policy violation attempts (either via syslog or auditd). Profiles in complain mode will not enforce policy but instead report policy violation attempts.

AppArmor is different from some other MAC systems on Linux in that it is path-based, allows for mixing of enforcement and complain mode profiles, uses include files to ease development and has a far lower barrier to entry than other popular MAC systems.

AppArmor is an established technology first seen in Immunix, and later integrated into Ubuntu, Novell/SUSE, and Mandriva. Core AppArmor functionality is in the mainline Linux kernel from 2.6.36 onwards; work is ongoing by AppArmor, Ubuntu and other developers to merge additional AppArmor functionality into the mainline kernel.

我有几个更有用的链接给你:Wiki.Ubuntu.com Ubuntuforums.org

Apparmor指南Ubuntu 12.04& Ubuntu 12.10

希望这会帮助你。

第三种解决办法

这是来自Apparmor wiki的报价:

AppArmor is an effective and easy-to-use Linux application security system. AppArmor proactively protects the operating system and applications from external or internal threats, even zero-day attacks, by enforcing good behavior and preventing even unknown application flaws from being exploited. AppArmor security policies completely define what system resources individual applications can access, and with what privileges. A number of default policies are included with AppArmor, and using a combination of advanced static analysis and learning-based tools, AppArmor policies for even very complex applications can be deployed successfully in a matter of hours.

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/719.html,未经允许,请勿转载。