Skip to content

Fix owner removal for duplicate logins #9930

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

Merged
merged 3 commits into from
Nov 15, 2024
Merged

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Nov 14, 2024

When users or teams on GitHub are deleted and recreated they might exist multiple times within our own database with the same login. When owners are deleted, only the newest matching login is considered for deletion though, which makes it impossible to delete older users/teams.

This commit fixes the problem by deleting all owners with a matching login instead.

Unfortunately, diesel does not support UPDATE queries with JOINs, so this has to be a "raw" SQL query with bindings instead…

Fixes #2736, and AFAICT also fixes #1205

Related:

@Turbo87 Turbo87 assigned Turbo87 and unassigned Turbo87 Nov 14, 2024
@Turbo87 Turbo87 added C-bug 🐞 Category: unintended, undesired behavior A-backend ⚙️ labels Nov 14, 2024
@Turbo87 Turbo87 requested a review from a team November 14, 2024 11:16
@Turbo87 Turbo87 force-pushed the issue-2736 branch 2 times, most recently from 5d8277a to 431026d Compare November 14, 2024 12:04
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.08%. Comparing base (1765dd1) to head (431026d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9930      +/-   ##
==========================================
+ Coverage   89.07%   89.08%   +0.01%     
==========================================
  Files         290      290              
  Lines       30060    30145      +85     
==========================================
+ Hits        26776    26855      +79     
- Misses       3284     3290       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@carols10cents
Copy link
Member

Wait, what about this case:

  • User foo, github ID 1 that is Person A has logged in to crates.io
  • Person A renames their github account to bar but does NOT log in to crates.io
  • Person B creates a new github account named foo with github ID 2 and logs in to crates.io
  • Person A logs in to crates.io with their account that's now named bar but still has github ID 1, I believe the current behavior is crates.io updates the gh_login and everything Just Works because the gh_id matches

I think what you're saying is this PR would delete the record for Person A when Person B logs in??? So when Person A logs in again, their account/ownership stuff would be gone?

@carols10cents
Copy link
Member

OH WAIT I think I'm confused. I read this line:

which makes it impossible to delete older users/teams.

and thought the records in the users table were being deleteed, but you're talking about the crate_owners table. Carry on, I think.

@Turbo87
Copy link
Member Author

Turbo87 commented Nov 14, 2024

and thought the records in the users table were being deleted, but you're talking about the crate_owners table

yep, exactly :)

Copy link
Contributor

@eth3lbert eth3lbert left a comment

Choose a reason for hiding this comment

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

LGTM on first glance :)

@eth3lbert
Copy link
Contributor

Ah, and should we add some tests for the team-related parts?

@Turbo87
Copy link
Member Author

Turbo87 commented Nov 14, 2024

should we add some tests for the team-related parts?

I've added #9943 just now, but it looks like there is no fix needed for that issue since it already works as intended.

@eth3lbert
Copy link
Contributor

Wait, what about this case:

* User `foo`, github ID 1 that is Person A has logged in to crates.io

* Person A renames their github account to `bar` but does NOT log in to crates.io

* Person B creates a new github account named `foo` with github ID 2 and logs in to crates.io

* Person A logs in to crates.io with their account that's now named `bar` but still has github ID 1, I believe the current behavior is crates.io updates the gh_login and everything Just Works because the gh_id matches

I think what you're saying is this PR would delete the record for Person A when Person B logs in??? So when Person A logs in again, their account/ownership stuff would be gone?

If I understand correctly, in this case, Person B is not the owner of the crate, and they also do not have permission to change the owner. So, there should not be an issue here.

When users or teams on GitHub are deleted and recreated they might exist multiple times within our own database with the same `login`. When owners are deleted, only the newest matching `login` is considered for deletion though, which makes it impossible to delete older users/teams.

This commit fixes the problem by deleting **all** owners with a matching `login` instead.

Unfortunately, `diesel` does not support `UPDATE` queries with `JOINs`, so this has to be a "raw" SQL query with bindings instead…
Copy link
Contributor

@eth3lbert eth3lbert left a comment

Choose a reason for hiding this comment

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

The regression test confirms that the issue has been fixed as expected. The SQL part leverages bind, which should prevent any injection attacks.
Nice work, thanks 👍

@Turbo87 Turbo87 merged commit 6f9226b into rust-lang:main Nov 15, 2024
8 checks passed
@Turbo87 Turbo87 deleted the issue-2736 branch November 15, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-bug 🐞 Category: unintended, undesired behavior
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Can't remove invalid users from crate owners Bad gateway error when wanting to remove access for a team
3 participants