Skip to content
New issue

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

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

Already on GitHub? # to your account

mfa: prevent the user from deleting the last MFA device #6585

Merged
merged 2 commits into from
Apr 27, 2021

Conversation

awly
Copy link
Contributor

@awly awly commented Apr 23, 2021

When the cluster requires MFA for all users (when second_factor is
on, u2f or totp, and not off or optional), users could lock
themselves out by deleting the last device. Prevent that.

Fixes #5803

When the cluster requires MFA for all users (when `second_factor` is
`on`, `u2f` or `totp`, and not `off` or `optional`), users could lock
themselves out by deleting the last device. Prevent that.

Fixes #5803
@awly awly force-pushed the andrew/delete-last-mfa-device branch from 81ec8b6 to f113536 Compare April 27, 2021 22:20
@awly awly enabled auto-merge (squash) April 27, 2021 22:20
Separate by the type of the device and which type the cluster enforces.
@awly awly force-pushed the andrew/delete-last-mfa-device branch from f113536 to 6257686 Compare April 27, 2021 22:58
@awly awly merged commit 3ff75e2 into master Apr 27, 2021
@awly awly deleted the andrew/delete-last-mfa-device branch April 27, 2021 23:11
awly pushed a commit that referenced this pull request Apr 27, 2021
* mfa: prevent the user from deleting the last MFA device

When the cluster requires MFA for all users (when `second_factor` is
`on`, `u2f` or `totp`, and not `off` or `optional`), users could lock
themselves out by deleting the last device. Prevent that.

Fixes #5803

* Make last MFA device deletion check more strict

Separate by the type of the device and which type the cluster enforces.
Comment on lines +1753 to +1756
case constants.SecondFactorOTP:
if numTOTPDevs == 1 {
return trail.ToGRPC(trace.BadParameter("cannot delete the last OTP device for this user; add a replacement device first to avoid getting locked out"))
}
Copy link
Contributor

@andrejtokarcik andrejtokarcik Apr 28, 2021

Choose a reason for hiding this comment

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

Does SecondFactorOTP mean there can be no U2F devices stored for the user? If a user had a single OTP device but he intended to delete some of the (now unusable) U2F devices, wouldn't this error be incorrectly returned since the type of the device to be deleted doesn't seem to be taken into account?

Analogically for SecondFactorU2F when deleting an OTP device.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This block only returns an error if cluster requires SecondFactorOTP and there is exactly 1 OTP device registered (regardless of how many U2F devices there are).
Same thing for SecondFactorU2F, the error only happens when there's 1 U2F device, regardless of any OTP devices.

Maybe I misunderstand the question?

Copy link
Contributor

@andrejtokarcik andrejtokarcik Apr 28, 2021

Choose a reason for hiding this comment

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

Yes, I understand that.

My worry is that this error would be returned even if a user requested to delete an U2F device and not the last OTP device. In other words, the type of the device to be deleted should be checked and the user should not be prevented from deleting an U2F device even if there is only a single OTP device left.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OTP is a sub-type of MFA, not a separate group.
Each user has multiple MFA devices. Each of those devices is either U2F or OTP.
In the loop above I calculate the number of devices of each type (numTOTPDevs and numU2FDevs).
Does that clarify the logic?

awly pushed a commit that referenced this pull request Apr 28, 2021
* mfa: prevent the user from deleting the last MFA device

When the cluster requires MFA for all users (when `second_factor` is
`on`, `u2f` or `totp`, and not `off` or `optional`), users could lock
themselves out by deleting the last device. Prevent that.

Fixes #5803

* Make last MFA device deletion check more strict

Separate by the type of the device and which type the cluster enforces.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mfa: user can delete the last MFA device when "second_factor: on"
3 participants