【发布时间】:2016-12-09 04:51:34
【问题描述】:
在我的剧本中,我有一个更新 audit.rules 的任务,然后通知应该重新启动 auditd 服务的处理程序。
task:
- name: 6.6.7 - audit rules configuration
template: src=X/ansible/templates/auditd_rules.j2
dest=/etc/audit/rules.d/audit.rules
backup=yes
owner=root group=root mode=0640
notify:
- restart auditd
handlers:
- name: restart auditd
service: name=auditd state=restarted
当 playbook 运行时,会更新审计规则并请求重新启动 auditd,但失败如下。
RUNNING HANDLER [restart auditd] ***********************************************
fatal: [ipX-southeast-2.compute.internal]: FAILED! => {"changed": false, "failed": true, "msg": "Unable to restart service auditd: Failed to restart auditd.service: Operation refused, unit auditd.service may be requested by dependency only.\n"}
当我查看auditd 的单元定义时,我可以看到rejectManualStop=yes。这就是我无法重新启动服务的原因吗?新的审计规则是怎么过来的?
systemctl cat auditd.service
# /usr/lib/systemd/system/auditd.service
[Unit]
Description=Security Auditing Service
DefaultDependencies=no
After=local-fs.target systemd-tmpfiles-setup.service
Conflicts=shutdown.target
Before=sysinit.target shutdown.target
RefuseManualStop=yes
ConditionKernelCommandLine=!audit=0
Documentation=man:auditd(8) https://people.redhat.com/sgrubb/audit/
[Service]
ExecStart=/sbin/auditd -n
## To not use augenrules, copy this file to /etc/systemd/system/auditd.service
## and comment/delete the next line and uncomment the auditctl line.
## NOTE: augenrules expect any rules to be added to /etc/audit/rules.d/
ExecStartPost=-/sbin/augenrules --load
#ExecStartPost=-/sbin/auditctl -R /etc/audit/audit.rules
ExecReload=/bin/kill -HUP $MAINPID
# By default we don't clear the rules on exit. To enable this, uncomment
# the next line after copying the file to /etc/systemd/system/auditd.service
#ExecStopPost=/sbin/auditctl -R /etc/audit/audit-stop.rules
[Install]
WantedBy=multi-user.target
【问题讨论】:
-
将手动停止更改为 NO 并尝试
sudo service auditd restart如果这样有效,那么代码也将有效。 -
systemctl start auditd和systemctl enable auditd适用于 CentOS 版本 7。按照链接获取更多帮助。 link -
还有一份不错的文档。 AuditD in CentOS7..希望对您有所帮助。
-
谢谢。我真的不想弄乱操作系统方面,因为他们一定是出于某种原因而实施的。我还需要在每个主机上更改它。似乎标准服务命令可以调用适用于 sudo service auditd restart 的 systemctl 停止日志记录:[OK] 将开始重定向到 /bin/systemctl start auditd.service sudo service auditd stop
code停止日志记录:[OK] sudo service auditd start 重定向到 /bin/systemctl start auditd.service -
感谢您的指点,看起来使用 RHEL7 重新启动审计的官方方法是使用标准服务命令。 service 命令是与 auditd 守护进程正确交互的唯一方法。您需要使用 service 命令,以便正确记录 auid 值。您只能将 systemctl 命令用于两个操作:启用和状态。更改了我的处理程序以调用命令模块,现在可以使用
handlers: - name: restart auditd command: service auditd restart