防止在Redhat 7中停止审计服务

时间:2016-07-22 07:10:44

标签: linux service redhat systemd

当然,我希望审计服务永远运行,用户无法通过任何命令停止此操作。

目前我的审计服务:

~]# systemctl cat auditd

# /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

[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

[Install]
WantedBy=multi-user.target


# /etc/systemd/system/auditd.service.d/override.conf
[Service]
ExecReload=
ExecReload=/bin/kill -HUP $MAINPID ; /sbin/augenrules --load

我无法从命令中停止此服务:

# systemctl stop auditd.service

Failed to stop auditd.service: Operation refused, unit auditd.service may be requested by dependency only.

但是当我使用service auditd stop命令时。我可以正常停止这项服务。

# service auditd stop
Stopping logging:                                          [  OK  ]

我该如何预防呢?感谢

2 个答案:

答案 0 :(得分:3)

管理员(root)将始终能够手动终止审计进程(这是service命令所执行的操作)。 systemd在这里做的只是为了阻止管理员通过systemctl接口来做这件事。

在这两种情况下,没有特权的用户都无法杀死该守护进程。

如果您想限制root用户可以执行的操作,则必须使用SELinux并自定义策略。

答案 1 :(得分:0)

服务命令的某些操作不会重定向到systemctl,而是运行位于/usr/libexec/initscripts/legacy-actions中的某些特定脚本。 在这种情况下,停止命令将调用此脚本:

/usr/libexec/initscripts/legacy-actions/auditd/stop

如果您希望这样做,则不能通过service命令停止审核的服务,可以删除此脚本,将“ stop”操作重定向到systemctl,这将阻止该脚本的b / c。参数“ RefuseManualStop =是”。 但这并不意味着您当然不能终止该过程。