Fix group transfer failing and wedging on 2FA
What does this MR do and why?
Fixes two bugs that together leave a failed group transfer unable to cancel.
-
The 2FA check reads the wrong group.
Groups::TransferServicereads "Allow more restrictive 2FA enforcement for subgroups" from the immediate new parent, but theGroupvalidation reads it from the top-level ancestor. When the new parent is a subgroup, its column has the defaulttrue, so the service keeps the group's 2FA requirement andsave!fails. The service now reads the setting from the new parent's root ancestor, the same group the validation reads. -
cancel_transfer!runs on the failed transfer's in-memory group. When the service fails beforeGroup.transactioncommits, the transaction rolls back, but the changes stay on the in-memory group, such as the newparent_id. The worker then callscancel_transfer!on that object, and the state machine saves the whole record:- If the changes are invalid, the cancel fails with
StateMachines::InvalidTransition, and the job retries until it dies. - If they are valid, the cancel saves them, such as the new
parent_id, without the rest of the transfer. The rest includes the project authorization refresh.
The worker now reloads the group and clears its memoized
root_ancestorbefore cancelling, in both theelseandrescuepaths. The memo matters too: after a validation failure insave!, it still points at the new parent's root.This MR doesn't change failures after
Group.transactioncommits. By then the newparent_idis saved, so the reload keeps it, and the cancel only resets the transfer state, as before. - If the changes are invalid, the cancel fails with
There's no feature flag. These are small fixes to failure paths, and both restore the intended behavior.
Customer impact: severity1. A customer's group transfer failed this way, and their work is blocked until the group can be moved. The workaround is to transfer into the destination top-level group first, then into the subgroup. This fix stops it from happening again.
The fix was first reviewed as a security MR. AppSec triaged it as a functional bug, not a vulnerability, so it moved here.
References
Resolves https://gitlab.com/gitlab-org/gitlab/-/work_items/639600
Screenshots or screen recordings
Not applicable. There is no UI change.
How to set up and validate locally
- Create a top-level group
r. In Settings > General > Permissions and group features, turn off Allow more restrictive 2FA enforcement for subgroups. - Create a subgroup
r/s. - Create a top-level group
g, and turn on Require all users in this group to set up 2FA. - In
g, go to Settings > General > Advanced > Transfer group, and transfer it tor/s. - On
master, the transfer fails, andlog/sidekiq.logshowsStateMachines::InvalidTransitionfromcancel_transfer. With this branch,gmoves underr/s, and its 2FA requirement is turned off.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.