Skip to content

fix: use unique ID for linked accounts - #3441

Merged
sreya merged 35 commits into
mainfrom
jon/userauth
Aug 17, 2022
Merged

sreya merged 35 commits into
mainfrom
jon/userauth

Conversation

@sreya

@sreya sreya commented Aug 9, 2022 •

Copy link
Copy Markdown
Collaborator

This PR fixes some of the logic related to OAuth-related logins.

Behavior updates:

  • This PR restricts user to being able to login with only one login type. That means a user that logs in with Github cannot authenticate to the same account with OIDC.
    • This also means if you logged in as a built-in user (aka login_type = password) and your admin configured OIDC or Github you cannot "migrate" your account to these new forms of login
  • We can now process updates to a user's email and username in an upstream OIDC provider! Previously if your email was updated and you attempted to log in it would create a new account.

Schema updates:

  • user_links:
    • Added a new table user_links which hosts OAuth-related fields (rows are not created for password-based login)
    • A user can have at most one row per login_type (even though they cannot take advantage of that for now)
  • api_keys:
    • Dropped all columns related to OAuth (and migrated to user_links)
  • users:
    • Added a login_type column. This column is now duplicated between user_links users and api_keys. We could remove it from api_keys but it's nice to have when trying to refresh auth tokens.
    • The column is necessary in order to determine whether a user is of login_type password so as to prevent them from logging in with an alternative login type.

fixes #3322

@sreya
sreya requested review from a team and removed request for a team August 10, 2022 00:41
@sreya
sreya marked this pull request as ready for review August 10, 2022 23:48
@sreya
sreya requested a review from a team as a code owner August 10, 2022 23:48
@sreya
sreya requested review from kylecarbs and removed request for a team August 10, 2022 23:48
@sreya
sreya requested a review from kylecarbs August 12, 2022 04:56
Comment thread coderd/httpmw/apikey.go Resolved
Comment thread coderd/httpmw/apikey.go Resolved
Comment thread coderd/httpmw/apikey.go Resolved
Comment thread coderd/users.go Resolved
@sreya

sreya commented Aug 13, 2022

Copy link
Copy Markdown
Collaborator Author

@kylecarbs I stood up OIDC and tested all the edge cases. Things seem to be working as expected. I'm going to update the PR with a summary of the updated behavior.

@sreya
sreya requested a review from kylecarbs August 13, 2022 03:15
@ammario

ammario commented Aug 14, 2022

Copy link
Copy Markdown
Member

This PR restricts user to being able to login with only one login type. That means a user that logs in with Github cannot authenticate to the same account with OIDC.

What was your rationale for this decision? Kyle says there are bad security implications with the current implementation. Just confirming that we're aligned.

@sreya

sreya commented Aug 15, 2022

Copy link
Copy Markdown
Collaborator Author

@ammario I think mainly because the emails aren't verified for built-in. There's also some precedent in other services like Gitlab. For example if I sign in using email/password on Gitlab and then try to sign in with Google using the same email I get an error (for what it's worth I wouldn't say that's the standard, LinkedIn let me swap between both although they required email verification). We also didn't allow this in v1 and heard no complaints about that behavior.

I don't know if there's any realistic security implications but if user A is created with email/password, and then User B signs in with OIDC with a matching email, then user B would be logged into user A's account. Is that realistic? Not really but it's just kinda strange that it could happen.

I don't think there are any security implications at all with signing in between OIDC and Github but I know that with this PR we will process upstream updates to a user's email/username in the OIDC provider and reflect those in the product. If we do that with Github as well then you can get in a situation where a user's email and username is flip flopping between two values every time they sign in with a different provider.

I don't feel particularly strongly one way or the other and I do see how it could be useful for existing users to be able to "migrate" their built-in account to OIDC/Github instead of having to create a new account just to take advantage of new forms of login.

@ammario

ammario commented Aug 16, 2022

Copy link
Copy Markdown
Member

@sreya all SGTM

Comment thread coderd/database/queries/users.sql Resolved
Comment thread coderd/userauth.go Resolved
Comment thread coderd/userauth.go Resolved
Comment thread coderd/userauth.go Resolved
Comment thread coderd/userauth.go Resolved
@sreya
sreya merged commit c3eea98 into main Aug 17, 2022
@sreya
sreya deleted the jon/userauth branch August 17, 2022 23:00
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.

Link OIDC accounts by unique identifier

4 participants