>_ IzzyLab

Hands-on task

This task is step 11 of the course “Linux server security”

sudo audit: who quietly became root

hard~15 min

An access audit on the server. Three service accounts should have only the rights their jobs need: deployer restarts the service (/usr/bin/systemctl restart app), monitor checks the size of the logs (/usr/bin/du -sh /var/log), and archiver shouldn't have sudo at all. But the rules have piled up over the years, and one of them has effectively been given full root through sudo.

Remove everything that lets these accounts run arbitrary commands through sudo, keep both job rules, and don't break the sudo configuration. Don't delete the accounts themselves or their groups.

What you'll practise:
  • sudo -l -U
  • sudoers.d
  • User_Alias
  • NOPASSWD
  • visudo -c
  • access audit

Topic breakdown

sudo reads /etc/sudoers and, through @includedir, every file in /etc/sudoers.d; a rule in any of them works the same way, so auditing a single file is incomplete. A rule line reads who where=(as whom) what, and "who" isn't always a plain name: %group covers all of its members, and a User_Alias puts a list of accounts under one name. The danger is on the right-hand side: ALL allows any command, and NOPASSWD: drops the password prompt on top of that, which amounts to root with no trace. Grepping the text is unreliable (aliases, groups, optional spaces, comments), so you check the result with sudo itself: sudo -l -U account prints the effective rights, and with a command at the end it tells you whether that exact command is allowed. Close every edit with visudo -c: a syntax error or wrong file permissions break sudo for everyone.

What's checked

  1. none of the three accounts can run an arbitrary command through sudo
  2. deployer still has its job rule
  3. monitor still has its job rule
  4. the sudo configuration is valid

What it looks like