Sudo

如何省略特定使用者的 PAM 日誌消息(pam_succeed_if quiet)

  • September 26, 2018

我正在使用監控代理 ( telegraf) 來監控 fail2ban。不幸的是,它需要超級使用者權限才能執行fail2ban-client,這會導致每 10 秒出現 24 條系統日誌消息……算一算,我的系統日誌絕對是混亂的。

我想在我的系統日誌中隱藏這些消息,如果可能的話,只是由電報引起的:

sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
sudo: pam_unix(sudo:session): session closed for user root

我嘗試使用自定義“規則”/etc/pam.d/sudo來抑制這些消息,但沒有成功:

# cat /etc/pam.d/sudo
#%PAM-1.0

session    required   pam_env.so readenv=1 user_readenv=0
session    required   pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
@include common-auth
@include common-account
session [default=ignore] pam_succeed_if.so quiet uid = 0 user = root ruser = telegraf
@include common-session-noninteractive

只有以開頭的行session被添加到該文件中。該解決方案改編自How to stop auth.log for a specific user? 中的 sudo PAM 消息?

但是,日誌消息仍然出現/var/log/auth.logjournalctl -xe

我已經嘗試quiet_success過以及quiet標誌(在 中找到man pam_succeed_if)。也使用success=1make telegraffail to execute fail2ban-client,我猜是因為它需要一個互動式 tty?

這是使用debug標誌記錄的:

Sep 20 11:34:51 host sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Sep 20 11:34:51 host sudo: pam_succeed_if(sudo:session): 'uid' resolves to '0'
Sep 20 11:34:51 host sudo: pam_succeed_if(sudo:session): 'user' resolves to 'root'
Sep 20 11:34:51 host sudo: pam_succeed_if(sudo:session): 'ruser' resolves to 'telegraf'
Sep 20 11:34:51 host sudo: pam_unix(sudo:session): session closed for user root

據我所知,“規則”正確匹配 uid、user 和 ruser,但不會抑制日誌消息。我錯過了重新啟動,還是發生了什麼?

我設法讓它使用以下配置(/etc/pam.d/sudo

#%PAM-1.0

session [success=done default=ignore] pam_succeed_if.so quiet uid = 0 user = root ruser = telegraf
session    required   pam_env.so readenv=1 user_readenv=0
session    required   pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
@include common-auth
@include common-account
@include common-session-noninteractive

老實說,我不知道問題出在哪裡,但我認為順序可能很重要。請自行承擔使用此資訊的風險,我不知道我在做什麼……但是我的系統日誌現在看起來更乾淨了:)

(有人解釋情況仍將不勝感激)

引用自:https://unix.stackexchange.com/questions/470267