AppArmor零知识学习十五、理论与实操(1)
本文内容参考:
Documentation · Wiki · AppArmor / apparmor · GitLab
接前一篇文章:AppArmor零知识学习十四、实操与实践(2)
上一篇文章通过一个简单例程、利用aa-genprof添加了规则,并进行了实际的操作演示。除了aa-genprof和aa-status(apparmor_status)外,还有不少其它命令(如aa-audit、aa-logprof、aa-autodep等)。本文来对它们一一进行介绍,过程中会结合实例进行实际操作。
1. aa-status
参考:Ubuntu Manpage: aa-status - display various information about the current AppArmor policy.
Usage: aa-status [OPTIONS]
Displays various information about the currently loaded AppArmor policy.
OPTIONS (one only):--enabled returns error code if AppArmor not enabled--profiled prints the number of loaded policies--enforced prints the number of loaded enforcing policies--complaining prints the number of loaded non-enforcing policies--kill prints the number of loaded enforcing policies that kill tasks on policy violations--special-unconfined prints the number of loaded non-enforcing policies in the special unconfined mode--process-mixed prints the number processes with mixed profile modes--json displays multiple data points in machine-readable JSON format--pretty-json same data as --json, formatted for human consumption as well--verbose (default) displays multiple data points about loaded policy set--help this message
(1)概述
显示有关当前AppArmor策略的各种信息。
(2)语法
aa-status [option]
(3)描述
aa-status将报告AppArmor限制的当前状态的各个方面。默认情况下,它与给定--verbose参数时显示相同的信息。示例如下:
apparmor module is loaded.110 profiles are loaded.102 profiles are in enforce mode.8 profiles are in complain mode.Out of 129 processes running:13 processes have profiles defined.8 processes have profiles in enforce mode.5 processes have profiles in complain mode.
在笔者电脑上,经过前文步骤,执行aa-status命令的结果如下:
$ sudo aa-status
[sudo] penghao 的密码:apparmor module is loaded.
1 profiles are loaded.
1 profiles are in enforce mode./home/penghao/AppArmor/sample_code/test_app
0 profiles are in complain mode.
0 profiles are in kill mode.
0 profiles are in unconfined mode.
0 processes have profiles defined.
0 processes are in enforce mode.
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.
0 processes are in mixed mode.
0 processes are in kill mode.
其它参数选项被提供来报告各个方面,以支持在脚本中使用。
(4)选项
aa-status一次只接受以下参数的一个:
- --enabled
如果AppArmor未使能则返回错误码。
在笔者电脑上结果如下:
$ sudo aa-status --enabled$
- --profiled
显示已加载的AppArmor策略的数量。
在笔者电脑上结果如下:
sudo aa-status --profiled
1
- --enforced
显示已加载的强制AppArmor策略的数量。
在笔者电脑上结果如下:
$ sudo aa-status --enforced
1
- --complaining
显示已加载的非强制AppArmor策略的数量。
在笔者电脑上结果如下:
$ sudo aa-status --complaining
0
- --kill
显示已加载的将杀掉违反策略的任务的强制AppArmor策略的数量。
在笔者电脑上结果如下:
$ sudo aa-status --kill
0
- --special-unconfined
显示已加载的处于特殊无限制模式的非强制AppArmor策略的数量。
在笔者电脑上结果如下:
$ sudo aa-status --special-unconfined
0
- --process-mixed
显示被不同模式下的配置文件(profile)的配置文件堆栈限制的进程数。
在笔者电脑上结果如下:
$ sudo aa-status --process-mixed
0
- --verbose
显示关于已加载的AppArmor策略集的多个数据点(如果没有给定任何参数,则为默认操作)。
在笔者电脑上结果如下:
$ sudo aa-status --verbose
apparmor module is loaded.
1 profiles are loaded.
1 profiles are in enforce mode./home/penghao/AppArmor/sample_code/test_app
0 profiles are in complain mode.
0 profiles are in kill mode.
0 profiles are in unconfined mode.
0 processes have profiles defined.
0 processes are in enforce mode.
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.
0 processes are in mixed mode.
0 processes are in kill mode.
- --json
以JSON格式显示关于加载的AppArmor策略集的多个数据点,适合机器使用。
在笔者电脑上结果如下:
$ sudo aa-status --json
{"version": "2", "profiles": {"/home/penghao/AppArmor/sample_code/test_app": "enforce"}, "processes": {}}
- --pretty-json
与--json相同,以人类和机器都可读的格式显示。
在笔者电脑上结果如下:
$ sudo aa-status --pretty-json
{"version": "2","profiles": {"/home/penghao/AppArmor/sample_code/test_app": "enforce"},"processes": {}
}
- --help
显示简短的使用说明。
在笔者电脑上结果如下:
$ sudo aa-status --help
Usage: aa-status [OPTIONS]
Displays various information about the currently loaded AppArmor policy.
OPTIONS (one only):--enabled returns error code if AppArmor not enabled--profiled prints the number of loaded policies--enforced prints the number of loaded enforcing policies--complaining prints the number of loaded non-enforcing policies--kill prints the number of loaded enforcing policies that kill tasks on policy violations--special-unconfined prints the number of loaded non-enforcing policies in the special unconfined mode--process-mixed prints the number processes with mixed profile modes--json displays multiple data points in machine-readable JSON format--pretty-json same data as --json, formatted for human consumption as well--verbose (default) displays multiple data points about loaded policy set--help this message
与开头的提示信息对应。
(5)退出状态
退出时,aa-status将其退出状态设置为以下值:
0 —— 如果apparmor使能并且策略被加载。
1 —— 如果apparmor未被使能/加载。
2 —— 如果apparmor使能但没有策略被加载。
3 —— 如果在/sys/kernel/security/下的apparmor配置文件不可用。
4 —— 如果运行脚本的用户没有足够的权限读取apparmor控制文件。
42 —— 如果内部错误发生。
(6)注
aa-status必须以root权限运行,以从apparmor模块中读取已加载的策略的状态。它使用proc文件系统以决定哪些过程受到限制,因此容易受到竞争条件的影响。
aa-status属于监视工具类。
(7)相关
apparmor(7), apparmor.d(5), and <https://wiki.apparmor.net>.