What It Does
The script looks for potential root grants through these sources: members of the groups sudo, wheel and admin, users and groups named in /etc/sudoers and in /etc/sudoers.d (files whose names contain a dot or end in a tilde are ignored, as sudo does, with User_Alias names expanded and a rule for ALL counted as everyone), and any account other than root with UID 0.
Each row says how the account gets its rights, whether the rule covers every command (Scope all) or only some (Scope limited), and whether it needs no password. It alerts when an account with Scope all is not in ALLOWED_ACCOUNTS. root is always allowed. A rule that lets someone run only a few commands is listed but never alerts. With REQUIRE_PASSWORD=true it also alerts on an approved account with a full-access grant marked NOPASSWD. Limited grants still only appear in the report.
With no ALLOWED_ACCOUNTS, every account except root that has root rights alerts, so list your own admins there, including the account your RMM or you use.
The sudoers files are read line by line, not run through visudo, so unusual syntax such as host-specific rules, command aliases that hide ALL, or netgroups is read as written and may be missed. Accounts that exist only in LDAP or SSSD are included only if getent lists them.
Before You Run It
- List your own admin accounts in ALLOWED_ACCOUNTS before you alert on it, or every admin raises an alert.
- Run it as root. /etc/sudoers is only readable by root.
- Read the first run as a report. Decide which accounts should have rights, then turn on alerting.
- It was run on Ubuntu 24.04. Debian 12 and RHEL, Rocky and Alma 9 use the same files and groups, but are written for rather than run.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
- Risk: Low. It reads and changes nothing.
- Restart: It never restarts the machine.
- Typical run: Under 5 seconds.
- Example answer: "2 account(s) with root rights outside the policy: bob (group sudo, NOPASSWD), toor (uid 0)"
- Tested before listing on Ubuntu 24.04 (Arm64 VM) with bash, run as root, against its own test cases.
Inputs
Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.
- ALLOWED_ACCOUNTS: Accounts allowed to have root rights, comma-separated. root is always allowed. Default none.
- REQUIRE_PASSWORD: true to also alert when an allowed account can use sudo without a password. Default false.
Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.