Contents

GitLab: BackfillAdminModeScopeForPersonalAccessTokens

Problem with the background migration BackfillAdminModeScopeForPersonalAccessTokens: personal_access_tokens that fails after updating GitLab from version 15.4.6 to 15.8.1.

At the moment, Google doesn’t return anything for "BackfillAdminModeScopeForPersonalAccessTokens", but searching directly on GitLab.com I found an issue. Interestingly, bing.com and duckduckgo.com find it.

Problem

/posts/2023-02-11-gitlab-backfilladminmodescopeforpersonalaccesstokens/problema.png

Cause of the problem

On the GitLab machine, in the command line, go to the GitLab DB prompt

gitlab-rails db

And execute

SELECT t.id,u.name,t.name,t.revoked,t.scopes
FROM personal_access_tokens t
JOIN users u ON t.user_id = u.id;

The problem is the scopes starting with :

/posts/2023-02-11-gitlab-backfilladminmodescopeforpersonalaccesstokens/causa-do-prolema.png

Solutions

Remove the : from the scopes

I prefer this. Remove the : from the scopes (replace only removes the first occurrence of the string, great!)

UPDATE personal_access_tokens
SET scopes = replace(scopes, ':', '');

Or you can revoke the tokens, as below.

Revoke the tokens

Revoke the tokens that have : in the scope, something like

UPDATE personal_access_tokens
SET revoked = 't'
WHERE id in (4, 2 ,6);

Manually run the background migration

/posts/2023-02-11-gitlab-backfilladminmodescopeforpersonalaccesstokens/executar-background-migration.png

Which should run successfully 🎉🎉🎉

References