减少 auditd 的冗长程度,我的最小规则可以捕获它们不应该捕获的内容(apparmor)

减少 auditd 的冗长程度,我的最小规则可以捕获它们不应该捕获的内容(apparmor)

我的审计规则和需求相当简单,我只想记录根操作。

# auditctl -l
-a always,exit -S all -F euid=0 -F perm=x -F key=ROOT_ACTION

这是唯一且有效的规则:

type=SYSCALL msg=audit(1550318220.514:11479): arch=c000003e syscall=59 success=yes exit=0 a0=56002fde79a8 a1=56002fdeffc8 a2=56002fdee3a0 a3=0 items=2 ppid=7250 pid=7251 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts6 ses=1 comm="tail" exe="/usr/bin/tail" key="ROOT_ACTION"

但是,我也有 apparmor 配置文件来明确拒绝某些应用程序不需要的权限。这是故意的,并且按预期工作。但是,它们导致我的 auditd.log 被充斥着类似以下内容的垃圾信息:

type=AVC msg=audit(1550309442.438:207): apparmor="DENIED" operation="exec" profile="/usr/lib/slack/slack" name="/bin/dash" pid=2893 comm="slack" requested_mask="x" denied_mask="x" fsuid=1000 ouid=0

如您所见,这是由以非 root 用户身份运行的 Slack 执行的,不会被我的 ROOT_ACTION 审核规则捕获。

它经常这样做:

# cat /var/log/audit/*| egrep apparmor | wc -l
40574

这还不到 24 小时。

我意识到我可以使用 aureport 和 ausearch 或大量其他方法来过滤我看到的内容。然而,我宁愿不引入只发现我所关注的怪异之处的偏见期待,因为我担心的是意外发生。

那么,我该如何:

  1. 停止 auditd 将这些事件附加到 /var/log/audit/audit.log?
  2. 防止 apparmor 在个人资料上下文中(而非全局)记录被拒绝的活动(更新,Hargut 的以下回答解决了这个问题,解决方案是明确使用不记录的“拒绝”)

帮助!

答案1

进一步了解细节后,您还可以配置auditd级别要求。有一个列表,exclude您可以在其中添加要过滤的规则。

例如以下命令将排除任何 AVC 消息:

auditctl -a never,exclude -F msgtype=AVC

apparmor在这种情况下,审计事件由加载的配置生成并控制。内核审计子系统上apparmor没有可以控制/删除的相应规则。auditctl

auditctl可以使用exclude具有相应匹配规则的列表来创建显式过滤规则。

就我个人而言,我更倾向于通过配置apparmor来避免生成审计事件(如果不需要的话deny)。

AVC 也称为访问向量缓存。SELinux/Apparmor 使用此缓存来记录访问决策,并且似乎默认情况下此消息类型由 auditd 记录,并且必须明确拒绝以防用户不希望这样做。手册auditctl页在 部分中将此列为示例exclude。此外,在 SELinux 中,还有一种机制,当 auditd 未运行时将 AVC 日志写入磁盘。

答案2

查看文档,我发现这需要在相应的 apparmor 配置文件中进行设置。

http://manpages.ubuntu.com/manpages/cosmic/man5/apparmor.d.5.html

引用自手册页:

Rule Qualifiers

There are several rule qualifiers that can be applied to permission rules. Rule qualifiers can modify the rule and/or permissions within the rule.

allow
Specifies that permissions requests that match the rule are allowed. This is the default value for rules and does not need to be specified. Conflicts with the deny qualifier.

audit
Specifies that permissions requests that match the rule should be recorded to the audit log.

deny
Specifies that permissions requests that match the rule should be denied without logging. Can be combined with 'audit' to enable logging. Conflicts with the allow qualifier. 

相关内容