Unable to delete project / group / personal access tokens that expire beyond the maximum allowed lifetime for access tokens
Summary
A customer reported that some old tokens that have an expiry date in 4-5 months from current date haven't been revoked after setting the maximum lifetime for access tokens to 30 days.
For personal access tokens that are still visible in the UI, trying to revoke the token gives 422 error.
For group / project access tokens that are still visible in the UI, trying to revoke the token displays error message Could not revoke access token <NAME_OF_TOKEN>
.
Steps to reproduce
- Go to Admin area -
Settings > General
and expandAccount and limit
section. - Scroll down and clear any value set in
Maximum allowable lifetime for access token (days)
. - Save changes
- Go to your project and create a new project access token (
Settings > Access tokens
) - Set expiry date 5 months from today (example: Nov 11, 2024)
- Save token.
- Open a database session (
sudo gitlab-psql
) and change the created_at and updated_at values for this token to mimic a token created in the past:
select * from personal_access_tokens order by id desc; #find the token you just created
update personal_access_tokens set created_at='2022-06-23 19:26:21.023552', updated_at='2022-06-23 19:26:21.023552' where id in(<ID_OF_TOKEN>) and user_id=<USER_ID>;
- Verify token shows correct expiry and creation date on the UI.
- Go to Admin area. Set the value for
Maximum allowable lifetime for access token (days)
to 30. Save changes. - Refresh project access tokens page.
- Revoke token. You will get the error "Could not revoke access token <name_of_your_token>".
Example Project
Since I need access to database to mimic an old token creation, I had to use a self-managed GitLab instance for this test.
What is the current bug behavior?
When we set the maximum allowable lifetime for access tokens, PersonalAccessTokens::Instance::PolicyWorker
is scheduled to run in 3 hours. If for some reason this did not complete successfully or did not run for any reason, the user cannot revoke these tokens through the UI.
What is the expected correct behavior?
If the old tokens that expire beyond allowable lifetime are still showing on the UI, manual revoking should succeed.
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
root@ip-172-31-45-70:/var/log/gitlab/gitlab-rails# gitlab-rake gitlab:env:info System information System: Ubuntu 20.04 Proxy: no Current User: git Using RVM: no Ruby Version: 3.1.4p223 Gem Version: 3.5.7 Bundler Version:2.5.8 Rake Version: 13.0.6 Redis Version: 7.0.15 Sidekiq Version:7.1.6 Go Version: unknown GitLab information Version: 16.11.2-ee Revision: d210b947e3e Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 14.11 URL: https://gitlab-gcp.supermunn.com HTTP Clone URL: https://gitlab-gcp.supermunn.com/some-group/some-project.git SSH Clone URL: git@gitlab-gcp.supermunn.com:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: GitLab Shell Version: 14.35.0 Repository storages: - default: unix:/var/opt/gitlab/gitaly/gitaly.socket GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Gitaly - default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket - default Version: 16.11.2 - default Git Version: 2.43.2 root@ip-172-31-45-70:/var/log/gitlab/gitlab-rails#
Results of GitLab application Check
Expand for output related to the GitLab application check
root@ip-172-31-45-70:/var/log/gitlab/gitlab-rails# gitlab-rake gitlab:check SANITIZE=true Checking GitLab subtasks ...
Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 14.35.0 ? ... OK (14.35.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Checking Reply by email ...
IMAP server credentials are correct? ... Checking elif.guner@gmail.com no Try fixing it: An error occurred: Net::IMAP::NoResponseError: Invalid credentials (Failure) Check that the information in config/gitlab.yml is correct For more information see: doc/administration/reply_by_email.md Please fix the error above and rerun the checks. Mailroom enabled? ... skipped MailRoom running? ... skipped
Checking Reply by email ... Finished
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units) Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units) Projects have namespace: ... 2/1 ... yes 1/5 ... yes 1/6 ... yes 2/7 ... yes 2/10 ... yes 2/11 ... yes 2/12 ... yes 1/17 ... yes 6/19 ... yes 6/20 ... yes 2/21 ... yes 7/22 ... yes 7/23 ... yes 8/24 ... yes 8/25 ... yes 8/26 ... yes 9/27 ... yes 6/28 ... yes 11/29 ... yes 2/30 ... yes 5/31 ... yes 39/32 ... yes 6/33 ... yes 11/36 ... yes 6/37 ... yes 6/39 ... yes 6/40 ... yes 6/44 ... yes 59/45 ... yes 59/46 ... yes 6/47 ... yes 59/48 ... yes 59/49 ... yes 59/50 ... yes 59/51 ... yes 59/52 ... yes 59/53 ... yes 64/54 ... yes 59/55 ... yes 59/56 ... yes 59/57 ... yes Redis version >= 6.2.14? ... yes Ruby version >= 3.0.6 ? ... yes (3.1.4) Git user has default SSH configuration? ... yes Active users: ... 7 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-8.x or OpenSearch version 1.x ... skipped (Advanced Search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
root@ip-172-31-45-70:/var/log/gitlab/gitlab-rails#
Possible fixes
- Start a rails console session (
sudo gitlab-rails console
) - Run:
PersonalAccessTokens::Instance::PolicyWorker.new.perform