跳转到内容
搜索 RHEL 文档

    浏览当前文档目录

    RHEL 10 auditd:规则生效但 ausearch 说没记录?加 -if

    审计规则加了、文件也改了,ausearch 却回 <no matches>——在 RHEL 10 上这通常不是规则没生效,而是 ausearch 没有读到 /var/log/audit/audit.log。本页用 /etc/hosts 做一次可还原的实测。

    在 PVE 390 rhel10-lab(RHEL 10.2,auditd 4.0.3)执行:

    Terminal window
    systemctl is-active auditd
    sudo auditctl -s
    sudo auditctl -w /etc/hosts -p wa -k hosts_changes
    echo '# audit test' | sudo tee -a /etc/hosts
    sudo ausearch -k hosts_changes -i
    sudo ausearch -if /var/log/audit/audit.log -k hosts_changes -i

    E3 记录:plans/content-expansion/evidence/rhel/rhel-auditd/run.json(6 步,含触发事件与两种 ausearch 输出 sha256)。

    先给结论:规则没坏,是输入路径

    Section titled “先给结论:规则没坏,是输入路径”
    • auditctl -l 能看到规则;
    • audit.log 里确实有 key="hosts_changes";
    • ausearch -k 默认输入找不到;
    • 加 -if /var/log/audit/audit.log 就能查到。

    auditd.conf 里 log_format = ENRICHED、log_file = /var/log/audit/audit.log,但默认输入路径在这个环境没有命中,显式 -if 最稳。

    Terminal window
    sudo auditctl -w /etc/hosts -p wa -k hosts_changes
    sudo auditctl -l | grep hosts_changes
    # -w /etc/hosts -p wa -k hosts_changes
    • -w 监视文件/目录;
    • -p wa 监视写(w)与属性(a);
    • -k 给事件打 key,便于 ausearch -k。

    运行时规则重启会丢;要持久化写 /etc/audit/rules.d/*.rules 再 augenrules --load。

    Terminal window
    cp /etc/hosts /tmp/hosts.bak
    echo '# audit test' | sudo tee -a /etc/hosts
    sudo grep hosts_changes /var/log/audit/audit.log | tail -2
    type=SYSCALL ... syscall=openat success=yes ... key="hosts_changes"
    type=PATH ... name=/etc/hosts ... nametype=NORMAL

    openat 的 flags 是 O_WRONLY|O_CREAT|O_APPEND,和追加写一致。测试完:

    Terminal window
    sudo cp /tmp/hosts.bak /etc/hosts
    $ sudo ausearch -k hosts_changes -i
    <no matches>
    $ sudo ausearch -if /var/log/audit/audit.log -k hosts_changes -i
    type=SYSCALL ... key=hosts_changes ...

    同一份日志、同一条规则,差别只在 -if。排查顺序:

    1. grep <key> /var/log/audit/audit.log,确认事件在不在;
    2. 在 → 用 ausearch -if /var/log/audit/audit.log;
    3. 不在 → 再查规则、auditctl -s、journalctl -u auditd。
    $ sudo aureport -k
    <no events of interest were found>
    $ sudo aureport -if /var/log/audit/audit.log -k | tail -4
    3. 11/05/26 07:23:41 passwd_changes yes /usr/bin/touch 1000 4299
    4. 11/05/26 07:24:29 audit_test yes /usr/sbin/auditctl 1000 4342
    5. 11/05/26 07:24:29 audit_test yes /usr/bin/bash 1000 4343
    6. 11/05/26 07:26:52 hosts_changes yes /usr/sbin/auditctl 1000 4470
    7. 11/05/26 07:26:52 hosts_changes yes /usr/bin/bash 1000 4471
    Terminal window
    sudo auditctl -W /etc/hosts -p wa -k hosts_changes
    sudo auditctl -l

    -W 删除运行时规则;持久化规则要从 /etc/audit/rules.d/ 删除对应行再 augenrules --load。

    • auditd active、auditctl -s enabled=1;
    • auditctl -l 能看到规则;
    • 触发后 grep key /var/log/audit/audit.log 有记录;
    • ausearch 加 -if 能查到;
    • aureport 同样加 -if;
    • 测试文件/配置已还原;
    • 持久化规则写入 rules.d 并 augenrules --load。
    • 未测试 augenrules --load 持久化后的重启;
    • 未测试 audit 规则对性能的影响;
    • 未测试远程 syslog/audisp 转发;
    • 未测试 auditctl -e 2 锁定规则。