sudo-rs icon indicating copy to clipboard operation
sudo-rs copied to clipboard

Error when parsing sudoers configuration with domain groups / groups with "@domain"

Open mpibpc-mroose opened this issue 10 months ago • 3 comments

Describe the bug sudo-rs seems to be unable to work with active directory domain groups in sudoers files. Seems it stumbles upon the @ when parsing those files.

To Reproduce Steps to reproduce the behavior:

  1. Install ' sudo-rs` on Ubuntu 24.04 using apt
  2. Use the default contents in /etc/sudoers-rs
  3. Create a sudoers configuration such as /etc/sudoers.d/01_server_admins_group
%[email protected]   ALL=(ALL) NOPASSWD: ALL
  1. Run the following command sudo-rs ls
  2. See error:
/etc/sudoers.d/01_server_admins_group:2:13: expected host name
%[email protected]   ALL=(ALL) NOPASSWD: ALL
            ^                  

mpibpc-mroose avatar Apr 03 '25 07:04 mpibpc-mroose

Thanks for opening this issue. For user names I based the tokeniser on the available info (e.g. a user name is an alphanumeric string which might contain dots, underscores & hyphens).

Also see https://systemd.io/USER_NAMES/

Maybe we should also allow the $ sign as a final character in user names?

squell avatar Apr 03 '25 09:04 squell

Note: a general solution allowing @ in the syntax introduces a truly locally ambiguous grammar, since then we can not distinguish (easily) between:

Defaults@host setting=value username@domain hostname=rule

E.g.

Defaults@domain env_keep=ALL

does that grant a permission to run all commands on the server env_keep to the user Defaults@domain? Of course not.

This is not a problem in the cited example above since it involves groups and those start with % which is unambiguous. So my proposed solution would be as follows:

  • Create a seperate Groupname token that is like Username but also accepts @.
  • Add support for @ in usernames using escape sequences, e.g. allowing them but they would have to be surrounded by quotes to resolve the ambiguity.
  • And like mentioned previously, probably also accept $ as the final character, since apparently those can happen.

squell avatar Apr 03 '25 11:04 squell

Alright, so since the Defaults syntax was already ambiguous, we can lean into that and it's probably actually not as messy to fix.

squell avatar Apr 03 '25 22:04 squell

Fixed by #1065

squell avatar Apr 30 '25 17:04 squell