ansible:如何重新启动centos 7上的auditd服务获取有关依赖的错误

问题描述 投票:5回答:5

在我的剧本中,我有一个任务来更新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的单位定义时,我可以看到refuseManualStop = 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
ansible centos7 systemctl
5个回答
0
投票

将手动停止更改为NO并尝试

sudo服务auditd restart

如果这样可行,那么代码也可以工作

systemctl启动审计

systemctl启用auditd

适用于CentOS版本7。请点击链接获取进一步的帮助。

Link

Auditd in CentOS7


2
投票

这已在Red Hat Bugzilla #1026648Anisble Issue # 22171 (github)报告中进行了探索,讨论和解决(主要)。

解析度

  • 使用ansible service模块参数use=service强制执行/sbin/service实用程序而不是systemd(调用/sbin/systemctl)的collect-fact值,如下所示: - service: name=auditd state=restarted use=service
  • Example playbook (pastebin.com)

解决方法:

  • 使用ansible command模块显式运行服务可执行文件,如下所示: - command: /sbin/service auditd restart

分析 - 根本原因:

  • 这是auditd.service unit的上游包装创建的问题。当systemctl采取行动时,它不会启动/停止/重新启动,显然是by design
  • Ansible服务控制功能进一步复杂化,它使用收集系统事实时识别的首选方法,并且“ansible_service_mgr”返回“systemd”。这与用于管理service.unit的实际模块无关。
  • 如果在即将发布的更新中被视为问题,RHEL开发团队可能会修复(ERRATA)
  • Ansible开发团队提供了一种解决方法,并且(从2.2开始)使用service参数更新了use模块。

0
投票

我会正确验证auditd服务重新加载,因为即使使用命令模块,您指定的命令也不会按照您期望的方式工作或运行;

通过确认

service auditd status

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-starting_the_audit_service.html

试试吧

service auditd condrestart

:)


0
投票

也许是因为答案迟了,但如果其他人遇到同样的问题,你可以用这个命令导入auditd的新规则:

auditctl -R /path/to_your_rules_file

因此,无需重新启动auditd.service来导入新规则


0
投票

您不应该更改参数refuseManualStop,它是为了保证您的系统安全。在创建新规则后,您可以做什么,重新启动主机,等待它,然后继续使用Playbook。

手册示例:

- name: Create new rules file
  copy:
    src: 01-personalized.rules
    dest: /etc/audit/rules.d/01-personalized.rules
    owner: root
    group: root
    mode: 0600
  register: result

- name: Reboot server
  shell: "sleep 5 && reboot"
  async: 1
  poll: 0
  when: result is changed

- name: Wait for server to become available
  wait_for_connection:
    delay: 60
    sleep: 5
    timeout: 300
  when: result is changed
© www.soinside.com 2019 - 2024. All rights reserved.