在 Centos7 上生成 /etc/audit/audit.rules 的正确方法是什么?

在 Centos7 上生成 /etc/audit/audit.rules 的正确方法是什么?

在 Centos7 的顶部/etc/audit/audit.rules它告诉我:

## This file is automatically generated from /etc/audit/rules.d

好吧,所以我去查看了一下,发现/etc/audit/rules.d/audit.rules有以下一行

# Feel free to add below this line. See auditctl man page

我照做了,结果发现看了就像也许是这样的选择:

 -R file
        Read rules from a file. The rules must be 1 per line and in the order that they are to be executed in. The rule file must  be
        owned  by  root  and not readable by other users or it will be rejected. The rule file may have comments embedded by starting
        the line with a '#' character. Rules that are read from a file are identical to what you would type on a command line  except
        they  are  not preceded by auditctl (since auditctl is the one executing the file) and you would not use shell escaping since
        auditctl is reading the file instead of bash.

但我跑了auditctl -R /etc/audit/rules.d/audit.rules,这似乎有效,然而它没有做任何事情/etc/audit/audit.rules

重新生成该文件的正确方法是什么?

答案1

实用程序 augenrules 根据目录 /etc/audit/rules.d 中的 *.rules 文件构建 /etc/audit/audit.rules。

此实用程序由 auditd 服务调用(或者您可以手动调用它,然后加载您发现的规则文件 - 但重新启动服务更简单)。

我记不清auditd系统为什么不能原生使用systemd了。检查[电子邮件保护]邮件列表档案。

答案2

文件中规则的再生/etc/audit/audit.rules使用 中包含的规则文件/etc/audit/rules.d/。RHEL7/CentOS7 就是这种情况,如果记忆不错的话,RHEL6/CentOS6 也是如此。

以 root 身份或使用 sudo 执行以下操作:sudo augenrules --check

如果检测到更改,则更新:sudo augenrules --load

对文件所做的任何更改/etc/audit/rules.d/现在也应该显示在中/etc/audit/audit.rules

为了确保所有更改均有效,请重新启动 auditd:sudo systemctl restart auditd

检查更改是否有效/正在使用:sudo auditctl -l | grep -i [your change value]

如果未发现更改,auditd 可能正在以“immutable”模式运行,这意味着您必须重新启动才能使任何更改生效,因为“immutable”不允许在正在运行的系统上进行 auditd 更改,即使以 root 身份也是如此。如果运行“immutable”,任何 auditd 重新启动尝试都将失败,并且“systemctl”会提醒您这一事实。

相关内容