Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't delete empty groups from database #758

Merged
merged 6 commits into from
Jan 28, 2025

Conversation

adombeck
Copy link
Contributor

@adombeck adombeck commented Jan 27, 2025

When a user logs in, we fetch the groups from the provider and update
our database accordingly. When this causes a user to be removed from an
authd group and that group doesn't have any other users in it, it's
currently removed from our database. That's an issue for two reasons:

  1. The next time a user who is a member of that group logs in, a new
    random GID is generated for that group, which means that any existing
    files owned by the group won't be accessible to members of the group
    anymore.

  2. Whenever a another group is added, the random GID generated for that
    group can by chance be the same as the GID of the deleted group,
    allowing members access to existing files owned by the deleted group.

With this commit, we don't delete an empty group but just keep it in the
database, so that its GID is still reserved and reused the next time a
user who is a member of that group logs in.

UDENG-5873

It was broken in multiple ways:

* It deletes the user even if it already existed in the database before
  this update.

* It's not protected by a mutex, so a concurrent update could have
  successfully added the user, which is then incorrectly deleted here.

In addition to that, now that we don't automatically delete empty
groups, it still leaves the groups (including the user private group)
which were added.

Fixing all that would require effort which I'm not sure would be
justified. I don't see any issues with users/groups from an
authenticated but erroneous login attempt still being in the database,
except that it might be a bit surprising to users.

Therefore, with this commit we simply leave the updated user and groups
as they are.
When a user logs in, we fetch the groups from the provider and update
our database accordingly. When this causes a user to be removed from an
authd group and that group doesn't have any other users in it, it's
currently removed from our database. That's an issue for two reasons:

1. The next time a user who is a member of that group logs in, a new
   random GID is generated for that group, which means that any existing
   files owned by the group won't be accessible to members of the group
   anymore.

2. Whenever a another group is added, the random GID generated for that
   group can by chance be the same as the GID of the deleted group,
   allowing members access to existing files owned by the deleted group.

With this commit, we don't delete empty groups but just keep them in the
database, so that its GID is still reserved and reused the next time a
user who is a member of that group logs in.
@adombeck adombeck force-pushed the 757-do-not-delete-empty-groups branch from 54e1f1a to a71ad8b Compare January 27, 2025 20:52
@adombeck adombeck marked this pull request as ready for review January 27, 2025 21:37
@adombeck adombeck requested a review from a team as a code owner January 27, 2025 21:37
@adombeck adombeck requested a review from didrocks January 27, 2025 21:37
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

That will be a good et necessary change. Thanks for spotting and raising this!

In addition to my comments, I think there is one test missing (once "Delete existing user" is modified). We should have a dedicated tests for "Deleting last user from a group keeps the group record" or something along that line.
That way, we have the 2 separated tests and logic articulated:

  • ensuring that when we remove a user, we clean up the group and let other members intacts (which is different from "Remove group from user").
  • ensure that removing last user from a group keeps the group record for reusing.

Does it make sense?

internal/users/manager_test.go Show resolved Hide resolved
... as the name suggests. This allows us to test that removing user1
removes it from that group but doesn't remove other members.
To make it clear that it tests keeping other group members intact.
To make it clear that it tests keeping the group record when the last
user of a group is deleted.
@adombeck adombeck requested a review from didrocks January 28, 2025 10:26
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

Thanks for the additional tests!

@adombeck adombeck merged commit b98b25f into main Jan 28, 2025
13 of 16 checks passed
@adombeck adombeck deleted the 757-do-not-delete-empty-groups branch January 28, 2025 13:18
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