Backport of 'Count CI job token Git requests against the user's rate limit' to 19.5
What does this MR do and why?
This MR backports !263309 (merged) to 19.5, for https://gitlab.com/gitlab-org/gitlab/-/work_items/634147. The 19.4 backport is !272160 (merged). 19.6 already has the change.
Git over HTTP requests that authenticate with a CI job token (gitlab-ci-token:<token>) skip throttle_authenticated_git_http, so they are only counted per IP. One bot account on a GitLab Dedicated instance drove about 955 req/s this way for weeks (S1, infradev, SLO missed). Gitlab::Auth::RequestAuthenticator now reads job tokens from basic auth on Git paths, so these requests count against the job's user.
Rollout
After this change, job-token Git requests are no longer unauthenticated, so they leave throttle_unauthenticated_git_http and count under throttle_authenticated_git_http for the job's user. An instance that has only the unauthenticated Git HTTP limit enabled loses the limit that applies to these requests today. This applies to GitLab Dedicated and to every 19.5 self-managed instance.
Both Git HTTP rate limits are disabled by default. On an instance where throttle_authenticated_git_http_enabled is off, this change has no effect until an administrator turns it on.
- GitLab Dedicated: confirmed in https://gitlab.com/gitlab-org/gitlab/-/work_items/634147. The affected instance has
throttle_authenticated_git_httpenforced at 6,000 requests per minute, and the limit never fired for this traffic because job-token requests skipped it. With this patch, those requests count against the job user's limit, so the patch does stop the incident traffic on that tenant. No setting change is needed there. - Self-managed instances that want a limit on these requests need
throttle_authenticated_git_http_enabledon. This is the same rollout note as !263309 (merged), for the patch release post. - For the patch release post: on instances that have the authenticated Git HTTP limit enabled, a shared bot or service user that runs many CI Git requests now counts all of them against its own limit and can receive
429responses ongit fetchandgit clone. Administrators can raise the limit or allow that user to bypass authenticated request rate limiting. - Job-token LFS batch and lock requests count toward the job user's limit. With
throttle_authenticated_git_lfs_enabledon, they count toward that limit. With it off, they count toward the user'sthrottle_authenticated_web_enabledlimit, as personal access token LFS requests do. LFS object uploads and downloads stay counted per IP.
Differences from master
Only changes that apply to 19.5 are backported. Code introduced in later releases is not added.
Gitlab::PathRegex.repository_git_http_route_regexandrepository_git_lfs_object_route_regexare added here, because 19.5 does not have them. 19.5'sgit_request?matches.gitanywhere in a path, which would accept job tokens on web paths such as/-/archive/main/x.git.zipor the raw files of a project nameduser.gitlab.io.- API paths keep
%i[request basic_auth], which 19.5 already has from !259720 (merged). Job token resolution on API paths is unchanged, except for one case described in the next bullet. Only Git paths get[:basic_auth]. - On API paths,
can_authenticate_job_token_basic_auth?is true, so the newfind_user_from_job_token_basic_authoverride also runs there. Before this change,gitlab-ci-token:<PAT>on an API path made the base finder raiseUnauthorizedError, so the rate limiter saw no user and counted the request per IP. Now the override returnsnilfor a password that is not a job token, and the personal access token resolves to its user, so the request counts under the authenticated API throttle. This matches master, andrequest_authenticator_spec.rbpins it. It does not apply on 19.4, where API paths havejob_token_allowed: true. find_user_from_job_bearer_tokenexists on 19.5, so it gets the master override that limits Bearer job tokens to API paths. Without it, the Bearer finder would accept job tokens on Git paths.- Job tokens are accepted only where both
git_http_request?and 19.5'sgit_request?match./<repo>/info/refswithout.gitis excluded, because the 19.5 throttles do not class it as Git. Master counts it as Git, so this is a deliberate difference, the same as in the 19.4 backport. - Docs: the "Changed in GitLab 19.6" history entries are left out of
doc/rate_limits/git.md, so the 19.5 docs do not reference a later version. The behavior text is kept.
Not changed on 19.5:
- Throttle classification (
git_path?and the labkit rules):info/refswithout.gitis still not classed as Git by the throttles. - The
git_request?override.
Specs from the master MR are included, including the update to labkit_rack_rate_limit_git_ci_job_token_spec.rb, which exists on 19.5. Left out: info/refs without .git in the throttles, the user.gitlab.io web-throttle spec, and the EE spec context in ee/spec/requests/labkit_rack_rate_limit_spec.rb, whose surrounding examples do not exist on 19.5. request_authenticator_spec.rb pins /<repo>/info/refs as not job-token-eligible.
References
- Issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/634147
- Handoff: https://gitlab.com/gitlab-com/gl-infra/production-engineering/-/work_items/30372
- 19.4 backport: !272160 (merged)
MR acceptance checklist
- This MR is backporting a bug fix, documentation update, or spec fix, previously merged in the default branch.
- The MR that fixed the bug on the default branch has been deployed to GitLab.com. (Merged 2026-11-16: confirm the deploy before merging.)
- The MR title is descriptive (e.g. "Backport of 'title of default branch MR'"). This is important, since the title will be copied to the patch blog post.
- Required labels have been applied to this merge request
- severity label and bug subtype labels (if applicable)
- If this MR fixes a bug that affects customers, the customer label has been applied.
- This MR has been approved by a maintainer (only one approval is required). This touches authentication, so ask an Authentication maintainer.
- Ensure the
e2e:test-on-omnibus-eejob has succeeded, or if it has failed, investigate the failures. If you determine the failures are unrelated, you may proceed.
Note to the merge request author and maintainer
If you have questions about the patch release process, please:
- Refer to the patch release runbook for engineers and maintainers for guidance.
- Ask questions on the
#releasesSlack channel (internal only). - Once the backport has been merged, the commit changes will be automatically deployed to a release environment that can be used for manual validation. See after merging runbook for details.