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

Enable MFA on specific API keys #2846

Merged
merged 3 commits into from
Dec 28, 2021

Conversation

jenshenny
Copy link
Member

@jenshenny jenshenny commented Nov 2, 2021

Part of: #2755

This PR allows users to enable or disable MFA requirement on owners that have MFA enabled for UI and UI and gem signin. Owners cannot disable MFA on keys if they have UI and API and cannot enable MFA if they didn't have MFA setup.

MFA disabled Index Screen Shot 2021-11-02 at 10 39 20 AM
MFA UI only Index Screen Shot 2021-11-02 at 10 38 27 AM

Edit
Screen Shot 2021-11-02 at 10 38 13 AM

Create
Screen Shot 2021-11-02 at 10 37 53 AM

MFA UI and API Index Screen Shot 2021-11-02 at 10 36 29 AM

Edit
Screen Shot 2021-11-02 at 10 36 10 AM

Create
Screen Shot 2021-11-02 at 2 12 19 PM

@jenshenny jenshenny marked this pull request as ready for review November 2, 2021 20:18
app/controllers/api/base_controller.rb Outdated Show resolved Hide resolved
config/locales/es.yml Outdated Show resolved Hide resolved
<%= label_tag :mfa, t("api_keys.index.multifactor_auth"), class: "form__label" %>
<% if current_user.mfa_ui_and_api? %>
<p><%= t("api_keys.index.mfa_api_enabled") %></p>
<%= f.hidden_field :mfa, value: true %>
Copy link
Member

Choose a reason for hiding this comment

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

when a user has mfa_ui_and_api, all keys they create will have mfa enabled. is this desired behavior? this seems inconsistent with existing keys, where mfa is null for user with mfa_ui_and_api. when user enables mfa with ui_only, it may be unexpected that his existing keys are not working without otp.
also, if we really want this to be true, we should set this in the controller and not view (attackers can mess with this logic).

Copy link
Member Author

Choose a reason for hiding this comment

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

My thought process is that a user that has mfa ui and api enabled would downgrade if one of their keys can't work with otp. It would be a pain to downgrade and enable mfa on most of their existing keys if they have many.

I agree that the inconsistencies between new/existing keys isn't great. On the new page, we are communicating this inconsistency by saying mfa will be turned on for that key. One possibility to try to make it more consistent (other than backfilling) is to set mfa to true when updating existing keys if the user has mfa_ui_and_api. But that could make it even more confusing if the user downgrades.

I removed the hidden value that sets this in the view and will add it to the controller if we decide to go this way.

Copy link
Member

Choose a reason for hiding this comment

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

to make it more consistent (other than backfilling) is to set mfa to true when updating existing keys if the user has mfa_ui_and_api.

agreed, we can make this consistent.

My thought process is that a user that has mfa ui and api enabled would downgrade if one of their keys can't work with otp.

got it. thank you for explaining. Perhaps we need more opinion on this, however, I feel if the user is changing their mfa level, they would expect that existing keys would use the default behavior for that level (default mfa false for ui_only). we would preserve api_key.mfa only where it was explicitly enabled.

If we agree on the above proposition, setting api_key.mfa, when user has mfa UI and API enabled, would be redundant. mfa will be enforced anyway for all keys.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps we need more opinion on this, however, I feel if the user is changing their mfa level, they would expect that existing keys would use the default behavior for that level (default mfa false for ui_only). we would preserve api_key.mfa only where it was explicitly enabled.

That makes a lot of sense, I agree with your view now. I’m happy to leave it the way it is right now and not set api_key.mfa unless the user explicitly sets it in the ui only level. I suppose it also isn’t difficult to change the behaviour if we change our minds about this in the future?

Copy link
Member

Choose a reason for hiding this comment

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

yes, I would prefer that we don't set mfa when the user already has MFA UI and api.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I removed the checkbox associated with enabling MFA on the UI and API level.

Screen Shot 2021-11-29 at 9 31 07 AM

config/locales/en.yml Outdated Show resolved Hide resolved
@jenshenny jenshenny force-pushed the mfa-specific-keys branch 2 times, most recently from 3a397bb to 0420b51 Compare November 16, 2021 17:28
@jenshenny
Copy link
Member Author

Apologies for the delay @sonalkr132, I've been away for a while since you last reviewed. I think this PR is ready for another look.

@jenshenny jenshenny requested a review from sonalkr132 November 19, 2021 13:55
aellispierce added a commit to Shopify/rubygems.org that referenced this pull request Dec 2, 2021
What:

A users profile can currently be queried by their id or handle
(`api/v1/profiles/:id|:handle`). This
adds the ability for an authenticated user to also query their own
profile without needing to know their id or pass their handle.

Why:

Once MFA can be [enabled on specific API
keys](rubygems#2846) through the
UI, a user should also be able to enable it on keys that they create
during `gem signin` in the CLI.

However, we only want to ask a user if they would like to enable mfa on
new keys if they have account mfa levels of `ui_only` or
`ui_and_gem_sign`. Users that have MFA disabled or have it enabled for
`ui_and_api ` should not be prompted, as it should be auto enabled or
disabled for those levels.

Once [an owners mfa level can be queried through the
API](rubygems#2837), then enabling
an authed user to pull their profile will return their MFA level and
help us determine if we should ask them to set enable MFA on new keys
created during gem signin.
Copy link
Member

@sonalkr132 sonalkr132 left a comment

Choose a reason for hiding this comment

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

Hi, I have updated the view a bit so that we only show api_key.mfa enabled. Previously, it was showing mfa enabled for all API keys when user has ui_and_api mfa. It may have lead user to belive that they have mfa enabled on all keys even when they downgrade their mfa level.
Thank you so much for working on this. Apologies for the delay in getting this merged.

Please do send the PR for rubygems cli as well.

@sonalkr132 sonalkr132 merged commit 8f32c9f into rubygems:master Dec 28, 2021
@sonalkr132 sonalkr132 temporarily deployed to staging December 28, 2021 09:48 Inactive
@jenshenny
Copy link
Member Author

🎉 Awesome, thank you!

FYI for the rubygems cli PR, I believe we would need to first add an API endpoint to retrieve the user's MFA status to determine whether or not to ask the user to enable MFA on their API key. There's changes for adding an auth endpoint api/v1/profile, and with your suggestion, it makes sense to expose the MFA level for that specific auth endpoint (and not rely on https://github.com/rubygems/rubygems.org/pull/2837/files) and open for review.

@jenshenny
Copy link
Member Author

Here's the open PR for adding the authed endpoint if you want to take a look @sonalkr132

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.

3 participants