Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

createUser: mark emails as unverified on creation#46187

Merged
bobheadxi merged 26 commits into
mainfrom
01-05-email_do_not_send_emails_to_unverified_emails_split
Jan 25, 2023
Merged

createUser: mark emails as unverified on creation#46187
bobheadxi merged 26 commits into
mainfrom
01-05-email_do_not_send_emails_to_unverified_emails_split

Conversation

@bobheadxi

@bobheadxi bobheadxi commented Jan 6, 2023

Copy link
Copy Markdown
Member

Today, users created with mutation { createUser } automatically have their emails marked as verified, even if the email is bogus. This could cause us to automatically send potentially large numbers of emails automatically to nonexistent email addresses (see https://github.com/sourcegraph/customer/issues/1790). To mitigate this, this change marks the emails of created users as unverified if SMTP is configured.

This has implications for Cloud instances, where mutation { createUser } is frequently used to create initial admin users. After this change, these users may receive a more limited set of emails (i.e. https://github.com/sourcegraph/sourcegraph/pull/46184) and have limited capabilities (i.e. unable to link account via external service) until they verify their email by:

  1. using a "set password" or "reset password" link delivered by email (https://github.com/sourcegraph/sourcegraph/pull/46307)
  2. using "verify email" in user settings to send an email verification
  3. a site admin verifying the user email manually via setUserEmailVerified mutation or UI

Test plan

I've added new unit tests that cover the old and new set password behaviour on the mutation.

Manual test:

  1. sg start, configured with SMTP in dev-private
  2. Site admin -> users -> create testuser with email
  3. Site admin -> users -> testuser -> emails -> primary email is unverified
  4. Log out
  5. CLick password reset link in email
  6. Log in
  7. User -> emails -> primary email is verified

@bobheadxi

Copy link
Copy Markdown
Member Author

Comment thread cmd/frontend/graphqlbackend/users_create.go Outdated
@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Jan 6, 2023

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (0.00 kb) 0.00% (+0.34 kb) 0.00% (+0.34 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits c94542c and 40ab277 or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails branch from ab399f9 to 5a20b9f Compare January 6, 2023 01:49
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails_split branch from 5b40d8f to 780de03 Compare January 6, 2023 01:49
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails branch from 5a20b9f to 75e7b2c Compare January 6, 2023 02:09
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails_split branch from 780de03 to 61aa4ed Compare January 6, 2023 02:09
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails branch from 75e7b2c to d1a6bd6 Compare January 6, 2023 04:49
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails_split branch from 61aa4ed to 804ed36 Compare January 6, 2023 04:49
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails branch from d1a6bd6 to 1c50b9a Compare January 6, 2023 04:57
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails_split branch from 804ed36 to adf98a1 Compare January 6, 2023 04:57
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails branch 2 times, most recently from 3ef8164 to 78a3acc Compare January 6, 2023 07:05
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails_split branch from adf98a1 to acdc689 Compare January 6, 2023 07:05
@bobheadxi bobheadxi marked this pull request as ready for review January 6, 2023 07:26
@bobheadxi bobheadxi requested review from a team January 6, 2023 07:28
@unknwon

unknwon commented Jan 6, 2023

Copy link
Copy Markdown
Contributor
  • We could send a verification email on user creation, but these aren't needed if an admin expects a user to sign in via an external service, and would send an extra email on top of the password reset link if needed. This is also awkward because you must sign in before you click the verification.

IIRC, if an account is pre-created with an unverified and the user is expected to sign in via an external service, a brand new account is always created because we only consider account linking by verified emails. Not saying we can't change the current behavior, just want to call out the implication.

  • We could bundle verification into the password reset, but it's unclear how worthwhile this investment is at the moment - I could implement this in a follow-up PR if required.

For a best possible UX, I believe we should. I can't recall another product that wants me to do both when I get an account... If we trust the password reset link being sent to an email, there seems no reason we can't in turn trust the email itself, right?

@unknwon unknwon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor thinking: should we keep the current behavior if SMTP is not configured?

Comment thread client/web/src/site-admin/SiteAdminCreateUserPage.tsx Outdated
@bobheadxi

bobheadxi commented Jan 6, 2023

Copy link
Copy Markdown
Member Author

Minor thinking: should we keep the current behavior if SMTP is not configured?

SMTP configuration is not static - you might not set up SMTP until some time after an instance is stood up, for example. Also, whether the email is verified or not doesn't impact instances that don't have SMTP set up, since we cannot send emails anyway

Update: actually, I think you may be right - a lot of other functionality (login, external accounts) key on validated emails, so retaining the old behaviour is probably best. Instances that care should set up SMTP before onboarding users

IIRC, if an account is pre-created with an unverified and the user is expected to sign in via an external service, a brand new account is always created because we only consider account linking by verified emails. Not saying we can't change the current behavior, just want to call out the implication.

Ah, you are right. I think I'll look harder look at having the password reset also handle email verification before making this change then

Update: see https://github.com/sourcegraph/sourcegraph/pull/46307

@bobheadxi bobheadxi marked this pull request as draft January 6, 2023 17:37
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails branch from 78a3acc to a28f30a Compare January 6, 2023 17:42
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails_split branch 2 times, most recently from 467afd9 to 8bf46d9 Compare January 6, 2023 17:43
@bobheadxi bobheadxi force-pushed the 01-05-email_do_not_send_emails_to_unverified_emails branch from 6611218 to 6cf4633 Compare January 6, 2023 18:48
@bobheadxi bobheadxi requested a review from kopancek January 12, 2023 17:39
@bobheadxi

Copy link
Copy Markdown
Member Author

@kopancek thanks for the first round of reviews - I've addressed your comments and updated the behaviour, would appreciate a review when you get the chance!

@mrnugget mrnugget left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we also need to update docs?

@bobheadxi

Copy link
Copy Markdown
Member Author

@sourcegraph-bot

sourcegraph-bot commented Jan 20, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 40ab277...c94542c.

Notify File(s)
@sourcegraph/delivery doc/admin/auth/index.md
doc/admin/config/email.md

@mrnugget

Copy link
Copy Markdown
Contributor

Thanks!

Comment thread cmd/frontend/graphqlbackend/users_create.go Outdated
Comment thread cmd/frontend/internal/auth/userpasswd/set_password.go Outdated

@kopancek kopancek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Added small suggestions that should not block PR merge.

Comment thread CHANGELOG.md Outdated
Comment thread doc/admin/auth/index.md Outdated
The [`builtin` auth provider](../config/site_config.md#builtin-password-authentication) manages user accounts internally in its own database. It supports user signup, login, and password reset (via email if configured, or else via a site admin).

Password reset links expire after 4 hours.
Password reset links expire after 4 hours by default - this can be configured in site configuration with the `auth.passwordResetLinkExpiry` field.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be better to have a link that points to the site config schema definition here. Not sure how feasible that is though 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a link!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Trick seems to be to view the site_config page in browser, and get the anchor link through there

bobheadxi and others added 2 commits January 24, 2023 16:09
Co-authored-by: Milan Freml <kopancek@users.noreply.github.com>
Co-authored-by: Joe Chen <joe@sourcegraph.com>
@bobheadxi bobheadxi merged commit 4ad221c into main Jan 25, 2023
@bobheadxi bobheadxi deleted the 01-05-email_do_not_send_emails_to_unverified_emails_split branch January 25, 2023 00:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants