>_ IzzyLab

Hands-on task

This task is step 3 of the course “New server: setup from scratch”

Only nginx reload for the deployer

medium~7 min

The user releaser will handle site deployments: after uploading files they need to reload the nginx config without typing a password. Full root isn't on the table. Use sudoers to let releaser run only /usr/sbin/service nginx reload without a password — they must not be able to stop nginx, touch other services or start a shell.

What you'll practise:
  • sudoers.d
  • NOPASSWD
  • visudo -c
  • least privilege
  • sudo -l

Topic breakdown

The principle of least privilege: automation and people get exactly the command they need for the job, not all of root. sudo rules go into a separate file in /etc/sudoers.d/ — it's easy to find, check and remove. A rule line describes the user, the hosts, whom to run as, and the list of commands; the NOPASSWD: tag removes the password prompt. If you give the command with its full path and arguments, sudo allows only that exact call, and the same binary with other arguments — no. A mistake in sudoers can cut everyone off from sudo, so the file is always checked with visudo -c, and the result with sudo -l -U user.

What's checked

  1. the sudoers configuration is valid
  2. releaser can run service nginx reload without a password
  3. releaser's rights are limited to one command

What it looks like