Skip to content

default_binding_matches: match Defaults>runas by runas user only - #587

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:defaults-runas-user-only
Oct 28, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:defaults-runas-user-only

Conversation

@iefa-m

@iefa-m iefa-m commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

default_binding_matches() decides whether a Defaults>runas_list entry applies by calling runaslist_matches() with no group list. That function also checks the group given with -g, and without a group list it only accepts the runas user's primary or supplementary groups, returning UNSPEC otherwise. With a rule like %admin ALL = (ALL:ALL) ALL, sudo -u root -g users cmd therefore skips every Defaults>root setting even though the command still runs as root: with rootpw the user is asked for their own password instead of root's, and timestamp_timeout=0 or log_output are ignored. In testsudoers, Defaults:admin !authenticate plus Defaults>root authenticate reports "Password required" for -u root but not for -u root -g users.

The manual and grammar define Defaults> in terms of the runas user (Runas_User_List), so match the binding with runas_userlist_matches(), the user half of runaslist_matches(), which is no longer static. Rule matching still goes through runaslist_matches() and is unchanged. The new testsudoers test35 covers both invocations, and make check passes on Linux (--enable-warnings --enable-werror --enable-sanitizer) and macOS.

default_binding_matches() checked a Defaults>runas_list entry with
runaslist_matches(), which also looks at the group given with -g.
When the requested group is not one of the runas user's groups it
returns UNSPEC, so "sudo -u root -g users cmd" skipped every
Defaults>root setting (rootpw, timestamp_timeout, log_output, ...)
even though the command still runs as root.  A Defaults> entry is
documented to apply to commands run as a specific user, so only
match the runas user.  Adds a testsudoers regression test.

@millert millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@millert
millert merged commit 7f2e174 into sudo-project:main Oct 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants