2

We have a number of script (for Openstack operations) which require privileged execution in our environment. For some of the scripts we'd like to refer back to the USERNAME or UID of the person who initiated the sudo session.

sudo already presents us with SUDO_UID, SUDO_USER environment settings. This also works fine when using sudo -s to start a shell session. However, if I use sudo -i or sudo su - then these settings are scrubbed from the environment.

Is there anything I can put into the /etc/sudoers or /etc/sudo.conf (perhaps even a "PLUGIN") which can allow me to start an interactive shell via sudo with root's environment initialized but ALSO with these specific SUDO_* settings preserved?

3
  • I hope it's clear that we're not concerned about hostile users getting access to the sudo authorized commands in this environment. The use of sudo here is merely intended to minimize the time that our operations staff are exposed the root prompt where any finger fumbling can have dire consequences. The idea is to have convenient access to a fully initialized root shell while also allowing relatively convenient access to various remote authenticated services under various ops team member names.
    – Jim Dennis
    Dec 19, 2014 at 20:01
  • 1
    Have you looked at the various env_* settings for /etc/sudoers?
    – bodgit
    Dec 21, 2014 at 18:40
  • Adding this line: Defaults env_keep += "SUDO_USER SUDO_UID SUDO_COMMAND" does resolve the issue for sudo -i ... but doesn't seem to help for sudo su -; I'm going to guess that nothing short of a patch to the su command would solve that latter issue.
    – Jim Dennis
    Dec 22, 2014 at 7:37

0

You must log in to answer this question.

Browse other questions tagged .