-
Notifications
You must be signed in to change notification settings - Fork 495
Add missing token scopes to all scope enums #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jschneider
wants to merge
1
commit into
gitlab4j:main
Choose a base branch
from
Neckar-IT:add-missing-token-scopes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "dev": { | ||
| "token": "glpat-xxxxxxxxxxxxxxxxxxxx", | ||
| "project_id": "12345", | ||
| "group_id": "6789" | ||
| } | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer not include this file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| ### Verify that the added scopes exist in GitLab | ||
| ### | ||
| ### Prerequisites: | ||
| ### Copy http-client.private.env.json.example to http-client.private.env.json | ||
| ### and fill in your gitlab.com token, project_id, and group_id. | ||
| ### Then select the "dev" environment in IntelliJ before running. | ||
| ### | ||
| ### How the proof works: | ||
| ### GitLab validates scopes AFTER authentication. If a scope is valid, | ||
| ### the request succeeds (or fails for permission reasons: 403/404). | ||
| ### If a scope is INVALID, GitLab returns 400 with | ||
| ### "scopes does not have a valid value". | ||
| ### | ||
| ### Each section includes a negative test with a deliberately invalid | ||
| ### scope to demonstrate that GitLab does reject unknown scopes. | ||
|
|
||
|
|
||
| ### --- ApplicationScope: self_rotate --- | ||
| ### | ||
| ### The self-service PAT endpoint (POST /api/v4/user/personal_access_tokens) | ||
| ### only accepts k8s_proxy and self_rotate scopes (by design, GitLab 16.5+). | ||
| ### The other ApplicationScope scopes (read_registry, write_registry, etc.) | ||
| ### are valid PAT scopes but can only be set via the admin endpoint or the UI. | ||
| ### | ||
| ### Reference: https://docs.gitlab.com/user/profile/personal_access_tokens/#personal-access-token-scopes | ||
|
|
||
| ### Positive: self_rotate scope (should return 201) | ||
| POST https://gitlab.com/api/v4/user/personal_access_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-self-rotate", | ||
| "scopes": ["self_rotate"], | ||
| "expires_at": "2026-12-31" | ||
| } | ||
|
|
||
| ### Negative: invalid scope (should return 400) | ||
| POST https://gitlab.com/api/v4/user/personal_access_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-invalid-scope", | ||
| "scopes": ["THIS_SCOPE_DOES_NOT_EXIST"], | ||
| "expires_at": "2026-12-31" | ||
| } | ||
|
|
||
| ### --- ProjectAccessTokenScope scopes --- | ||
| ### | ||
| ### Requires Maintainer access on the project. | ||
| ### Reference: https://docs.gitlab.com/user/project/settings/project_access_tokens/#scopes-for-a-project-access-token | ||
|
|
||
| ### Positive: newly added scopes (should return 201, NOT 400) | ||
| POST https://gitlab.com/api/v4/projects/{{project_id}}/access_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-project-scopes-valid", | ||
| "scopes": ["manage_runner", "ai_features", "k8s_proxy", "self_rotate"], | ||
| "expires_at": "2026-12-31", | ||
| "access_level": 30 | ||
| } | ||
|
|
||
| ### Negative: invalid scope (should return 400) | ||
| POST https://gitlab.com/api/v4/projects/{{project_id}}/access_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-project-scopes-invalid", | ||
| "scopes": ["manage_runner", "THIS_SCOPE_DOES_NOT_EXIST"], | ||
| "expires_at": "2026-12-31", | ||
| "access_level": 30 | ||
| } | ||
|
|
||
| ### --- ImpersonationToken.Scope (Group Access Token) scopes --- | ||
| ### | ||
| ### Requires Owner access on the group. | ||
| ### Reference: https://docs.gitlab.com/user/group/settings/group_access_tokens/#scopes-for-a-group-access-token | ||
|
|
||
| ### Positive: newly added scopes (should return 400 Bad request - User does not have permission to create group access token) | ||
| POST https://gitlab.com/api/v4/groups/{{group_id}}/access_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-group-scopes-valid", | ||
| "scopes": ["create_runner", "manage_runner", "ai_features", "self_rotate", "read_virtual_registry", "write_virtual_registry"], | ||
| "expires_at": "2026-12-31", | ||
| "access_level": 30 | ||
| } | ||
|
|
||
| ### Negative: invalid scope (should return 400 scopes does not have a valid value) | ||
| POST https://gitlab.com/api/v4/groups/{{group_id}}/access_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-group-scopes-invalid", | ||
| "scopes": ["create_runner", "THIS_SCOPE_DOES_NOT_EXIST"], | ||
| "expires_at": "2026-12-31", | ||
| "access_level": 30 | ||
| } | ||
|
|
||
| ### --- DeployTokenScope scopes --- | ||
| ### | ||
| ### Requires Maintainer access on the project. | ||
| ### Reference: https://docs.gitlab.com/user/project/deploy_tokens/#scope | ||
|
|
||
| ### Positive: newly added scopes (should return 201, NOT 400) | ||
| POST https://gitlab.com/api/v4/projects/{{project_id}}/deploy_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-deploy-scopes-valid", | ||
| "scopes": ["write_registry", "read_virtual_registry", "write_virtual_registry", "read_package_registry", "write_package_registry"], | ||
| "expires_at": "2026-12-31" | ||
| } | ||
|
|
||
| ### Negative: invalid scope (should return 400 scopes does not have a valid value) | ||
| POST https://gitlab.com/api/v4/projects/{{project_id}}/deploy_tokens | ||
| PRIVATE-TOKEN: {{token}} | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name": "verify-deploy-scopes-invalid", | ||
| "scopes": ["read_repository", "THIS_SCOPE_DOES_NOT_EXIST"], | ||
| "expires_at": "2026-12-31" | ||
| } | ||
|
|
||
| ### --- Cleanup --- | ||
| ### If any tokens were created above, revoke them: | ||
| ### GET https://gitlab.com/api/v4/personal_access_tokens | ||
| ### then DELETE https://gitlab.com/api/v4/personal_access_tokens/:id |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not include this file