Fine-grained token refusals name deprecated permissions, such as Webhook: Test, that the token form does not offer
Summary
When a fine-grained personal access token is missing a permission, the insufficient_granular_scope refusal tells the user what to grant as Resource: Action labels. AuthorizeGranularScopesService#access_denied_error builds each label from Authz::PermissionGroups::Assignable.for_permission(permission).first (line 147).
for_permission searches every definition, deprecated ones included, and the definitions are loaded in Dir.glob order. So when a raw permission moved to a new assignable permission and the old file is still there with deprecated: true, the refusal can name the old one.
The token form lists only live definitions (PermissionsResolver reads available_definitions), and the generated fine-grained permissions reference looks each route up with available_for_permission. The refusal therefore asks for an option the form does not have, and disagrees with the reference.
The webhook test routes are an example. They declare test_webhook (project and group, instance). Two definitions hold it: integrations/webhook/test.yml, deprecated by !231454 (merged) in 19.0, and integrations/webhook/trigger.yml, added by the same merge request. test.yml sorts first, so the refusal asks for [Webhook: Test]. The form offers Webhook: Trigger, and the reference lists all three webhook test routes under Trigger. The RenameGranularScopePermission background migration, which runs over granular_scopes with a map from test_webhook to trigger_webhook, was finalized in 19.4 by !250991 (merged).
On master at f967fc7d877 the same thing happens for 16 raw permissions, listed below.
Steps to reproduce
- As the owner of a project that has a webhook, create a fine-grained personal access token that holds only Project: Read for that project.
- Call the test route with it:
curl --request POST --header "PRIVATE-TOKEN: <token>" "https://gitlab.example.com/api/v4/projects/<id>/hooks/<hook_id>/test/push_events". - As an administrator, create a fine-grained personal access token that holds only Metadata: Read on the instance, and call
POST /api/v4/hooks/<system_hook_id>with it.
Example Project
Not needed: any project with a webhook shows it. I reproduced it on a local gitlab/gitlab-ee:19.4.1-ee.0 instance without a license.
What is the current bug behavior?
Both calls are answered 403 Forbidden. The project route:
{"error":"insufficient_granular_scope","error_description":"Access denied: This operation requires a fine-grained personal access token with the following project permissions: [Webhook: Test]."}The system hook route says ... with the following instance permissions: [Webhook: Test]., although test.yml does not even list the instance boundary.
On the same instance, the accessTokenPermissions query that the token form reads lists Webhook create, delete, read, trigger and update, and nothing for test.
What is the expected correct behavior?
The refusal names [Webhook: Trigger], which is what the form offers and what the reference lists for these routes. Granting it is also what lets the call through: on the same instance, a token holding Project: Read and Webhook: Trigger passed the permission check on the project route (GitLab ran the hook and answered with the hook endpoint's reply).
Relevant logs and/or screenshots
The 16 raw permissions whose first definition is deprecated while a live one exists. I computed the labels with GitLab's own Assignable class, loaded unchanged from master at f967fc7d877, building each label as line 148 does:
| Raw permission | Refusal names today | Live definition |
|---|---|---|
cancel_bulk_import |
Bulk Import: Cancel | Import: Cancel |
cancel_github_import |
GitHub Import: Cancel | Import: Cancel |
create_bitbucket_import |
Bitbucket Import: Create | Import: Create |
create_bitbucket_server_import |
Bitbucket Server Import: Create | Import: Create |
create_bulk_import |
Bulk Import: Create | Import: Create |
create_github_gist_import |
GitHub Gist Import: Create | Import: Create |
create_github_import |
GitHub Import: Create | Import: Create |
create_group_import |
Group Import: Create | Import: Create |
increment_usage_data_metric |
Usage Data Metric: Increment | Usage Data Metric: Update |
read_bulk_import |
Bulk Import: Read | Import: Read |
read_bulk_import_entity |
Bulk Import: Read | Import: Read |
read_bulk_import_entity_failure |
Bulk Import: Read | Import: Read |
read_epic_label_event |
Epic Label Event: Read | Work Item: Read |
read_issue_label_event |
Issue Label Event: Read | Work Item: Read |
read_user_project_deploy_key |
User Project Deploy Key: Read | Deploy Key: Read |
test_webhook |
Webhook: Test | Webhook: Trigger |
Every one of them is declared by at least one REST route. Two more raw permissions, execute_orbit_mcp_tool and read_knowledge_graph, are held only by deprecated definitions, and no route declares either of them.
The request specs agree with the service because the shared example authorizing granular token permissions builds its expected message with the same lookup.
From reading the code (I have not tested this): creating a token through the API still accepts a deprecated name while its file exists, because known_assignable_permissions checks Assignable.defined?, which counts deprecated definitions. So a caller using the API could follow the message until the file is removed. Someone using the token form cannot.
Output of checks
Results of GitLab environment info
Reproduced on gitlab/gitlab-ee:19.4.1-ee.0 (26212baacad), unlicensed, with the granular_personal_access_tokens flag enabled. The service line and the two webhook definitions are the same on master at f967fc7d877, and in every release since 19.0.0: v19.0.0-ee already has test.yml deprecated beside trigger.yml, and v18.11.0-ee does not.
Possible fixes
Look the label up among the live definitions first, as the route documentation and validation tasks already do, and fall back to any definition when no live one holds the permission:
assignable = Authz::PermissionGroups::Assignable.available_for_permission(permission).first ||
Authz::PermissionGroups::Assignable.for_permission(permission).firstWithout the fallback, a permission held only by deprecated definitions would raise NoMethodError on nil. The shared example should build its expected message with the same lookup, so the request specs follow the service.
Running gitlab:permissions:assignable:cleanup_deprecated would also hide this on master today: the names of all 14 deprecated files behind this list are keys of RenameGranularScopePermission::RENAMES, finalized in 19.4, so the task should be able to delete them. I still think the lookup is worth fixing, because every future rename reopens the window between the rename and the cleanup, and this one has been open since 19.0.
I found this while mapping what each action of gitlab-mcp-server needs from a fine-grained token. The server passes this refusal on to the model, which then sends its user looking for an option the form does not have.
I'd like to work on this.