目前,我想使auditd服务永远运行,并且用户不能通过任何命令停止它.
我目前的审核服务:
~]# 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 ]
我该如何预防呢?谢谢
解决方法:
管理员(超级用户)将始终能够手动终止审核的进程(service命令执行的操作). systemd在这里所做的只是防止管理员通过systemctl界面进行操作.
在这两种情况下,没有特权的用户都无法杀死该守护程序.
如果您甚至想限制root用户可以执行的操作,就必须使用SELinux并自定义策略.