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

[82599] prevents new user verification creation for locked CSPs #16770

Merged
merged 8 commits into from
Jun 4, 2024

Conversation

bramleyjl
Copy link
Contributor

@bramleyjl bramleyjl commented May 15, 2024

Summary

  • Runs validation on new UserVerification creation, checking for an existing UserVerification with the same CSP type that is locked
  • If a locked UserVerification is found the new UserVerification will still be created, but locked as well to prevent successful authentication.

Related issue(s)

Testing done

  • New code is covered by unit tests

To test, select the (Login.gov) user you wish to use and locate its corresponding UserAccount. Then delete the existing UserVerification if it exists and create a linked UserVerification that is locked.

UserCredentialEmail.delete_all
UserVerification.delete_all
UserVerification.new(user_account_id: <account id>, logingov_uuid: SecureRandom.hex, verified_at: Time.now, locked:true).save
  • During SiS callback the user_verifier class will detect the linked UserVerification of the same CSP type & locked status and will set locked to true for the new UserVerification, as well as log the event.
    Rails -- [Login::UserVerifier] Locked UserVerification created for type=logingov_uuid identifier=e444837a-e88b-4f59-87da-10d3c74c787b
  • Attempt to authenticate via /token with the selected user - login should be prevented by the existing credential lock behavior and Rails will throw an error:
    [SignInService] [V0::SignInController] token error -- { :errors => "Credential is locked" }

What areas of the site does it impact?

Authentication, new user creation

Acceptance criteria

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No error nor warning in the console.
  • Events are being sent to the appropriate logging solution
  • Documentation has been updated (link to documentation)
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • Feature/bug has a monitor built into Datadog or Grafana (if applicable)
  • If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected

@bramleyjl bramleyjl added identity identity-backend Identity team backend label labels May 15, 2024
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 15, 2024 18:06 Inactive
@bramleyjl bramleyjl force-pushed the 82599_logingov_account_lock branch from b07901c to 2019ecd Compare May 16, 2024 14:39
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 16, 2024 14:40 Inactive
@bramleyjl bramleyjl force-pushed the 82599_logingov_account_lock branch from 2019ecd to abd1ced Compare May 16, 2024 15:20
@bramleyjl bramleyjl marked this pull request as ready for review May 16, 2024 15:20
@bramleyjl bramleyjl requested a review from a team as a code owner May 16, 2024 15:20
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 16, 2024 15:45 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 16, 2024 16:26 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 16, 2024 19:12 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 16, 2024 20:20 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 17, 2024 14:10 Inactive
Copy link
Contributor

@bosawt bosawt left a comment

Choose a reason for hiding this comment

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

Few comments for some small updates, otherwise looks good!

app/services/login/user_verifier.rb Outdated Show resolved Hide resolved
app/services/login/user_verifier.rb Outdated Show resolved Hide resolved
spec/services/login/user_verifier_spec.rb Outdated Show resolved Hide resolved
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 20, 2024 18:16 Inactive
@bramleyjl bramleyjl changed the title [882599] prevents new user verification creation for locked CSPs [82599] prevents new user verification creation for locked CSPs May 23, 2024
@bramleyjl bramleyjl force-pushed the 82599_logingov_account_lock branch from bcef8be to af9b8f9 Compare May 23, 2024 20:53
@bramleyjl bramleyjl requested a review from bosawt May 23, 2024 21:01
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 23, 2024 21:39 Inactive
Copy link
Contributor

@bosawt bosawt left a comment

Choose a reason for hiding this comment

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

sorry, couple more changes, I realized this was in a transaction so we can't have the log directly in there

app/services/login/user_verifier.rb Outdated Show resolved Hide resolved
app/services/login/user_verifier.rb Outdated Show resolved Hide resolved
@bramleyjl bramleyjl force-pushed the 82599_logingov_account_lock branch from 187fcc2 to b956d26 Compare May 28, 2024 17:10
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 28, 2024 17:12 Inactive
@bramleyjl bramleyjl requested a review from bosawt May 28, 2024 17:21
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 28, 2024 19:39 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 28, 2024 20:11 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 29, 2024 01:27 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 29, 2024 14:43 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main May 29, 2024 19:50 Inactive
Copy link
Contributor

@bosawt bosawt left a comment

Choose a reason for hiding this comment

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

Just one tiny comment that I found, otherwise looks good

end

def locked
@locked ||= existing_user_account&.user_verifications&.send(login_type)&.where(locked: true).present?
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you start with function with return false unless existing_user_account?

This way you can remove all of the safety &. operators here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it from the user_account & user_verification since we know they'll be there with the guard clause, but the last one I think needs to stay because most times the existing account won't have a user_verification of the CSP type so it will be trying to call .where on a nil value.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, you don't have to worry about nil, this is the beauty of ActiveRecord chaining:

UserAccount.last.user_verifications.send(:dslogon)
=> []

And then if you call .where on the result of this:

UserAccount.last.user_verifications.send(:dslogon).where(locked: true)
=> []

How is that possible? It's because ActiveRecord queries actually return an ActiveRecord_AssociationRelation, which you can still chain queries off of even if it's empty:

UserAccount.last.user_verifications.send(:dslogon).class
=> UserVerification::ActiveRecord_AssociationRelation

@bramleyjl bramleyjl force-pushed the 82599_logingov_account_lock branch from 5cd3b58 to 8b1d0bc Compare June 3, 2024 15:34
@va-vfs-bot va-vfs-bot temporarily deployed to 82599_logingov_account_lock/main/main June 3, 2024 15:36 Inactive
Copy link
Contributor

@bosawt bosawt left a comment

Choose a reason for hiding this comment

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

Created a new user verification, confirmed that locked: false, as expected. Set the user_verification.locked: true, then created yet another user verification but with the same ICN as the old one. Confirmed a new user verification was created with user_verification.locked: true

@bramleyjl bramleyjl merged commit 4959ecb into master Jun 4, 2024
19 checks passed
@bramleyjl bramleyjl deleted the 82599_logingov_account_lock branch June 4, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
identity identity-backend Identity team backend label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants