Skip to content

Add expired alert to personal access tokens [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Robert Hunt requested to merge 222734-add-alert-to-personal-access-tokens into master

What does this MR do?

This MR adds an expired tokens alert to personal access tokens (PATs) profile page.

This dismissable alert is shown when the user has PATs that have expired but have not been revoked. The alert is configured to be dismissible for one day before it reappears to the user.

This should encourage more users to completely revoke expired PATs and improve the security of their accounts.

The alert is not shown if the user's GitLab instance enforces the revoking of expired tokens as they are handled automatically

Screenshots or Screencasts (strongly suggested)

No expired tokens One expired token Multiple expired tokens Alert dismissed
image image image image

Setup & testing

  1. Run the following in rails c to create the access tokens:
FactoryBot.definition_file_paths = [Rails.root.join('ee', 'spec', 'factories')]
FactoryBot.find_definitions

# Admin user
user = User.find_by_id(1)

# Create tokens
FactoryBot.create(:personal_access_token, user: user, expires_at: 1.days.ago) # Expired token
FactoryBot.create(:personal_access_token, user: user) # Active token
  1. Make sure that the Enforce personal access token expiration setting is disabled in [HOST]/admin/application_settings/general#js-account-settings
  2. View the personal access tokens page at [HOST]/-/profile/personal_access_tokens
  3. Check the alert is shown with the correct number of expired tokens mentioned and is dismissable

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Related to #222734 (closed)

Edited by Robert Hunt

Merge request reports