Support deleting users and groups via authctl#1372
Support deleting users and groups via authctl#1372shiv-tyagi wants to merge 4 commits intocanonical:mainfrom
Conversation
32db18f to
935182f
Compare
Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>
Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>
Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>
Signed-off-by: Shiv Tyagi <shivtyagi3015@gmail.com>
935182f to
2922411
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1372 +/- ##
==========================================
- Coverage 86.24% 85.85% -0.40%
==========================================
Files 99 101 +2
Lines 6690 6785 +95
Branches 111 111
==========================================
+ Hits 5770 5825 +55
- Misses 860 904 +44
+ Partials 60 56 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nooreldeenmansour
left a comment
There was a problem hiding this comment.
Thanks for the PR! I did some experimentation and found a few issues worth addressing:
1. Home directory cleanup on user deletion
When a user is deleted, their home directory is left behind. We should either add a -r/--remove flag (similar to userdel ) to optionally clean it up, or at minimum make the warning message explicit that the home directory is preserved and requires manual cleanup.
2. Deleting a user's primary group should be blocked
We shouldn't allow deletion of a group that is the primary group of an existing user. This mirrors groupdel's behavior:
You may not remove the primary group of any existing user. You must remove the user before you remove the group.
It breaks the user's next login with: failed to update user "<username>": another system user exists with "<username>" name.
3. Deleting a user orphans their primary group
When a user is deleted, their primary group isn't cleaned up, leaving the database in an inconsistent state.
=== users query ===
<username>|10001|10001|<name>|/home/<username>
=== groups query ===
10000|<username>
The user can re-login, but is assigned a different GID 10001 (non-existent), while GID 10000 is orphaned. This also causes errors in id and groups:
<username>@authd-dev:~$ id
id: cannot find name for group ID 10001
uid=10001(<username>) gid=10001(10001) groups=10001(10001),24(cdrom),10000(<username>)
<username>@authd-dev:~$ groups
groups: cannot find name for group ID 10001
10001 cdrom <username>
4. Re-login after deletion assigns a new UID, breaking home directory ownership
If a deleted user logs back in and gets the same home directory, there is a chance they receive a different UID, meaning they will no longer own their home directory. checkHomeDirOwner detects UID/GID mismatch but only logs a warning in the jounal
|
Thanks for taking a look @nooreldeenmansour. I will work on closing #830 as well in the same PR. Regarding the issues you have highlighted,
Adding a flag to optionally delete the home directory makes sense.
Makes sense. I will take care of this.
I intentionally did it that way because I was unsure about the scenarios where some other user is also manually made part of another users primary group. I would like to hear your thoughts on how do we handle this situation? Should we implement it in a way that the user's primary group deletion happens only when only that user was part of it's group?
This is similar to the warning we show with the delete command. Once a user is deleted, its UID can be assigned to another user. Similarly when it is recreated, it might get a new UID. I think we can add the wordings for later in the warning message. Other than that, I couldn't figure out an easy way to handle that. Our warning message already suggests to lock user instead of deleting to make sure the UID stays reserved. Anything else you have in mind to handle this? |
I think it makes sense to handle this the standard UNIX way. As detailed in the userdel:
The warning message is likely sufficient, since it clearly states the UID drift as a potential consequence. I'll wait on @adombeck's suggestion regarding this |
That sounds reasonable. For the scenario where a user's primary group has other members as well - as far as I understand, authd can only determine whether some other user belongs to a users primary group if the other user itself is managed by authd (please correct me if that’s not accurate). Based on that, we could safely delete a user’s primary group when it has no other members, while also issuing a warning that any manually added users in that group would lose their group membership. @nooreldeenmansour @adombeck WDYT? P.S. I know you’re busy with the upcoming release, so feel free to respond whenever convenient. |
|
Thank you, @shiv-tyagi, for the PR and thank you @nooreldeenmansour for the excellent review!
I agree that we should handle the deletion of the broker's user data before merging this PR, because it would be confusing if we still kept user data after running
I agree that we should handle it the same way
I agree, a warning message explaining the issue with file ownership and suggesting to disable the user instead is the best we can do. |
We don't have to worry about that, because the primary groups only exist in the authd database, not |

Closes #640
This adds subcommands to authctl to allow deleting a user/group using CLI.
This also contains relevant tests to verify the functionality.