Add setting to require authentication for the CI Lint API
What does this MR do and why?
Unauthenticated users can call GET /projects/:id/ci/lint on any public project. The UI doesn't allow this: unauthenticated users can't open the pipeline editor.
This MR:
- Adds the
ci_lint_api_require_authenticationapplication setting (Admin > Settings > CI/CD > Continuous Integration and Deployment, and the settings API). Disabled by default. When enabled, unauthenticatedGETrequests get401 Unauthorized. - Adds the
ci_lint_allow_unauthenticated_overrideops flag, checked against the project's root namespace, to keep unauthenticated access for namespaces that still depend on it. Same pattern asci_pipeline_variable_limits_overrideandci_pipeline_seed_timeout_override. - Keeps
404for unauthenticated requests to private or missing projects, also when the setting is enabled. The new check runs afterauthorize_read_code!, and a spec covers this case. - Updates the API docs, the admin docs, and the OpenAPI spec.
Because the setting is disabled by default, existing instances are not affected. Enabling it on GitLab.com is a separate step, tracked in #638411: we enable the override for the namespaces that use the endpoint without authentication today, then enable the setting.
Note: this endpoint does not accept CI/CD job tokens, so requests with CI_JOB_TOKEN are treated as unauthenticated today. When the setting is enabled, they get 401. This is documented in the API and admin docs. Accepting job tokens on this endpoint is out of scope for this MR.
References
Screenshots or screen recordings
The new checkbox in Admin > Settings > CI/CD > Continuous Integration and Deployment: Require authentication for the CI Lint API.
How to set up and validate locally
-
Pick a public project with a
.gitlab-ci.yml, for examplegitlab-org/gitlab-test, and note its ID. -
Call the endpoint without a token. It returns
200:curl --include "http://gdk.test:3000/api/v4/projects/<project_id>/ci/lint" -
Go to Admin > Settings > CI/CD > Continuous Integration and Deployment, select Require authentication for the CI Lint API, and save.
-
Call the endpoint again without a token. It returns
401withThis endpoint requires an API authentication. With a personal access token, it returns200. -
In the Rails console, enable the override for the project's root namespace:
Feature.enable(:ci_lint_allow_unauthenticated_override, Project.find(<project_id>).root_namespace) -
Call the endpoint without a token. It returns
200again.
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.