Repository navigation
Conversation
running_as_user() let "sudo -g group" skip authentication if the user was in the runas group, but it checked that with user_in_group() on the group's name. That matches against the names of the user's groups, case-insensitively by default, so a different group whose name only matches one of the user's groups (Staff vs. staff, or a second "admins" with another gid from a different NSS source) was treated as one the user already has. The command then ran with that group's gid without a password. Check the runas group-ID against the user's primary and supplementary group-IDs instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
running_as_user()letscheck_user()skip authentication when the command runs as the invoking user, includingsudo -g groupwhen the user is already in that group. Membership was checked withuser_in_group(ctx->user.pw, ctx->runas.gr->gr_name), which compares the resolved group's name with the names of the user's groups, usingstrcasecmp()by default becausecase_insensitive_groupis on (that option is documented for group names written in sudoers). A different group whose name merely matches one of the user's groups was therefore treated as one the user already has. Withstaff(gid 50, user is a member) andStaff(gid 5000, not a member), or a localadmins(gid 1001) next to a directoryadmins(gid 5001),sudo -g Staff cmdorsudo -g '#5001' cmdruns with gid 5000 or 5001 (policy.cpassesrunas_gid=fromgr_gid) without asking for a password, for any user whose rule allows the group, such as the usual(ALL:ALL).Compare the runas group-ID with the user's primary gid and group-ID list instead, the same list
user_in_group()already uses for#gidnames. Running a command with one of your own groups still needs no password. I checked this by calling the realrunning_as_user()with the testsudoers passwd/group backend: for a user instaffand the firstadmins,Staffand the secondadminsreturned true before the change and false after it, whilestaff,admins(1001) and the primary group stay true.make checkresults are unchanged from main.