Let fine-grained tokens read CI configs and CI variables
What does this MR do and why?
A fine-grained personal access token gets no data from the CiLint config, the deprecated ciConfig query and the CI variable types, which declare no authorize_granular_token directive. These 16 types now declare one with an existing permission and leave authorization_todo.txt:
CiConfigV2,CiConfigStageV2,CiConfigGroupV2,CiConfigJobV2,CiConfigInclude,CiConfigJobRestrictionandCiConfigNeeddeclareparent_authorizes: :validate_ci_config, whichCiLintchecks. The deprecatedCiConfig,CiConfigStage,CiConfigGroupandCiConfigJobinherit it as subclasses, soQuery.ciConfignow checksvalidate_ci_configon itsprojectPath, asPOST /projects/:id/ci/lintdoes.CiProjectVariable(and its subclassCiGroupVariable),CiGroupEnvironmentScopeandInheritedCiVariabledeclareparent_authorizes: :read_variable.Project.ciVariables,Project.inheritedCiVariables,Group.ciVariablesandGroup.environmentScopescheck it on their project or group, asGET /projects/:id/variablesandGET /groups/:id/variablesdo. Inherited variables are checked on the project, as theadmin_cicd_variablesuser check is.CiInstanceVariablechecksread_variableon the instance, asGET /admin/ci/variablesdoes.
The issue's other type, CiCatalogResourceComponentUsage, is in !267264 (merged).
References
Closes #638946
- Related to #593878.
I found this while working on gitlab-mcp-server.
Screenshots or screen recordings
No UI change.
How to set up and validate locally
-
As a Maintainer of a private project with a CI/CD variable, create a fine-grained token for the project with Project: Read, CI Config: Validate and Variable: Read, and run:
query { project(fullPath: "<project>") { ciVariables { nodes { key } } } } mutation { ciLint(input: { projectPath: "<project>", content: "test:\n script: echo" }) { config { status stages { name } } } } -
On master the query returns no variables and
configisnull; on this branch they return the variable and the linted config. -
Remove Variable: Read from the token:
ciVariablesisnull, and the lint result stays.
Checks I ran (Ruby 3.3.11)
I ran the steps above as examples of the changed request specs: each new example compares a fine-grained token's answer with what the session of the same user gets, or uses the granular token shared examples.
- With master's types, resolvers and todo list, the changed specs give 110 examples, 17 failures, all of them new examples. On this branch: 110 examples, 0 failures.
gitlab:permissions:validate, bothcompile_docstasks (no change after the committed rows), RuboCop, the commit linter and Danger's linters pass. Left to the pipeline: Ruby 3.4 and the FOSS run.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.