Add statistics to the token management for service accounts UI
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
What does this MR do and why?
This Mr adds stats cards to the service accounts
These stats are:-
- Active Tokens
- Tokens expiring in 2 weeks
- Revoked Tokens
- Expired Tokens
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
Screen_Recording_2025-03-14_at_5.39.06_PM
How to set up and validate locally
- Enable the following feature flag:
service_accounts_crud. Tip: use http://127.0.0.1:3000/rails/features/ for a UI to do that. - Enable Ultimate license to group
Flightjs - Create a service account and several tokens in the
gdk rails console:
group = Group.find_by(name: 'Flightjs')
response = Namespaces::ServiceAccounts::CreateService.new(User.first, name: 'My service account', organization_id: group.organization_id, namespace_id: group.id).execute
service_account = response.payload[:user]
(1..5).each do |n|
service_account.personal_access_tokens.create!(name: "Active token #{n}", expires_at: 30.days.since, scopes: ['read_api', 'read_user'])
service_account.personal_access_tokens.create!(name: "Expiring token #{n}", expires_at: 5.days.since, scopes: ['read_api', 'read_user'])
service_account.personal_access_tokens.create!(name: "Expired token #{n}", expires_at: 30.days.ago, scopes: ['read_api', 'read_user'])
service_account.personal_access_tokens.create!(name: "Revoked token #{n}", revoked: true, expires_at: 30.days.since, scopes: ['read_api', 'read_user'])
end
service_account.id
Take note
Write down the id number that comes out of the rails console
- Use your address bar to access the specific page
- In SaaS emulation, go to
https://gdk.test:3443/groups/my_service_account/-/settings/service_accounts/[id (last line from console)]/access_tokens - Without SaaS emulation, go to
https://gdk.test:3443/admin/application_settings/service_accounts/[id (last line from console)]/access_tokens
Edited by Austin Regnery

