With an analyzing program I built, I ran into a bug where a user had a primary group set to a since then deleted group (no longer in the /etc/group file). To scope the impact I ran some tests and run into what appears to be some strange behaviors:
- Even if a group is deleted, if it is the primary group of a user and there are rights associated to its ID in the sudoers file, the user will still get those rights.
- If a group is created afterwards, it may get the same group ID as the previously deleted group and the user's primary ID then becomes that group.
It appears that for the rights check in sudoers, both the /etc/group file and the primary group of the user are searched separately and the primary group therefore doesn't have to be an actual group?
Question: Is this correct? What am I missing? I'm not sure why the client had a primary group deleted, but this doesn't seem right.
Device specs:
Linux Ubuntu 20.04.1
5.13.0-1017-azure x86_64
Steps to reproduce:
Create new user:
sudo useradd testuser
This created both the user and a separate new group with the same name, which became its primary group.Check groups of new user:
groups testuser
Result: 'testuser : testuser'Delete the new group via command:
sudo groupdel testuser
Got the following error message: groupdel: cannot remove the primary group of user 'testuser'Delete the new group via manual file adjustment:
sudo nano /etc/group
This did work as I could simply delete the last line with the relevant group and save the fileCheck groups of new user again:
groups testuser
Result: 'testuser : groups: cannot find name for group ID 1003 1003'Try to login as the new user, after removing the group Success, could still login
Try to execute sudo command with the new user Failed as expected: 'testuser is not in the sudoers file. This incident will be reported'
Log back in as privileged account (which does have sudo rights)
Give the group name removed in step 4 sudoer rights in the sudoers file:
sudo nano /etc/sudoers
Then add this to the file:%testuser ALL=(ALL:ALL) ALL
Login as new user and execute sudo command again Still failed: 'testuser is not in the sudoers file. This incident will be reported'
Give the group id removed in step 4 sudoer rights in the sudoers file:
sudo nano /etc/sudoers
Then add this to the file:%#1003 ALL=(ALL:ALL) ALL
Login as new user and execute sudo command again Success, user now has SUDO rights (I had really hoped this not to be the case)
Create a new group:
sudo groupadd testforid
New group created with ID 1003Check groups of new user again:
groups testuser
Result: 'testuser : testforid'