This question is related to my previous question: Log all commands run by admins on production servers
It is company policy for admins to login to the servers via a personal username, and then run sudo -i
to become root. Upon running sudo -i
, sudo will create an environmental variable called SUDO_USER
, which contains the original user's username.
Is it possible to have auditd
include this variable in it's logs for each command? Or a functional equivalent.
This is the current rule set for auditd
:
# First rule - delete all
-D
# Increase the buffers to survive stress events.
# Make this bigger for busy systems
-b 320
# Log any command run on this system
#-a exit,always -F arch=b64 -S execve
-a exit,always -F arch=b32 -S execve
As stated here:
Using
session required pam_loginuid.so
in all login related PAM config files (not the ones for su and sudo) will let
auditd
log the calling user's uid in the fieldauid
.You can search
auditd
's logs for this id withausearch -ua <uid>
yielding all commands the user issued, even while impersonating another account.
The information you're requesting is, joyfully, already included in the logs. The specific field that you want to look for is
aud
. From the manpage forauditctl
:As an example, here is a lot entry that I generated using the following methodology:
-a always,exit -S sethostname -S setdomainname -k system-locale
su -
hostname audit-test.home.private
So, while yes, the log message is quite verbose we can clearly see
auid=1000
in the log message, which corresponds to the uid of my user account.For more details on the above example, as well as a brief description of auditd, check out this blog post from IT Security a community blogger (me) imaginatively entitled A Brief Introduction to Auditd.
The
ausearch
command mentioned by fuero is part of a suite of applications used to search and run reports against these rather thorough logs.