Debian 的 AppArmor 安全模块
AppArmor 是什么、Debian 默认如何管理(apparmor 服务与 enabled/disabled 目录)、服务被拦截(denied)怎么排查放行,以及和 SELinux 的定位差异。
结论先行
AppArmor 是内核级路径约束模块:给特定程序画一个「允许操作的白名单」,程序越界就记 denied 日志。Debian 默认随 Debian 13.7.0 DVD-1 条目 安装时带入,由 apparmor systemd 服务统管;Ubuntu 同样内置(见 Ubuntu 索引)。
三个核心概念
- profile:一个程序对应的白名单文件,放
/etc/apparmor.d/。 - enforce 模式:越界即拦截;complain 模式:越界只记录不拦截(排查用)。
- 加载目录:
/etc/apparmor.d/下默认 enforce;挪到/etc/apparmor.d/disable/即停用该 profile。
常用命令
sudo apparmor_status # 看每个 profile 模式
sudo aa-enforce /etc/apparmor.d/nginx
sudo aa-complain /etc/apparmor.d/nginx
sudo aa-complain /etc/apparmor.d/* # 全转记录模式(仅排查时)
被 denied 怎么修
journalctl -k | grep -i apparmor或sudo dmesg | grep -i apparmor看被拦路径。- 先
aa-complain让服务跑起来,观察日志。 - 把确实需要的路径加进 profile,再
aa-enforce转回拦截。
和 SELinux 的差异:AppArmor 是「按程序画白名单」,SELinux 是「按全局标签体系」。Debian 默认装 AppArmor,SELinux 不默认启用。