Backport of 'Make git exclusions in rate limit rules unconditional again' into 19-4-stable-ee

What does this MR do and why?

Backport of !257711 (merged) into 19-4-stable-ee. Fixes gitlab-org/gitlab#630787.

Rack::Attack throttles carry unconditional exclusions, like !git_path?. Labkit re-expressed them as claim rules that reuse the counting rule's match, and that match carries a setting fact. When the claiming throttle is off, which is the default, the claim never fires. The request then reaches the general web throttle and is counted per IP. Rack::Attack never did that at any setting.

This caused a Severity 1 regression on a GitLab Dedicated tenant. CI job token Git and LFS requests received HTTP 429: over 588,000 rejected, 69% of CI Git requests in the 90 minutes before mitigation. A CI job token has no requester_id at the rack layer, so the request looks unauthenticated, and CI runners share egress IPs.

Three rules were affected and 19.4 carries all three:

rule missing exclusion
throttle_unauthenticated_web !git_path?
throttle_authenticated_web !(git_path? && !git_lfs_path?)
throttle_authenticated_git_http !git_lfs_path?

The fix adds a git_http_non_lfs fact and states each exclusion in the rule itself instead of relying on another rule's claim. A labkit match is an AND of positive conditions, so "git and not LFS" cannot be built from two independent boolean facts.

Conflict resolution

Two hunks did not apply cleanly.

  • classified_request.rb: 19.4 has no git_http fact, so this adds two facts rather than one. git_path? is computed once and shared between them, because the route regex is unanchored and #matches? memoizes nothing.
  • ee/spec/requests/labkit_rack_rate_limit_spec.rb: left out on purpose. On the default branch that change corrects an existing assertion which had the old behaviour written into it. That block does not exist on this branch, and it depends on a labkit_counts_for helper and an unauthenticated_traffic_per_ip_log rule that arrived after 19.4 was cut.

limiters_spec.rb applied cleanly, so the six regression examples, one pair per affected rule, are unchanged from the default branch.

Verification

spec/lib/gitlab/rack_attack/labkit_rate_limit/: 133 examples, 0 failures. RuboCop clean on all changed files.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • 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 (not applicable for documentation or spec changes).
  • 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
  • This MR has been approved by a maintainer (only one approval is required).
  • Ensure the E2E Omnibus GitLab EE pipeline (triggered by thee2e:test-on-omnibus-ee job) has succeeded. If it has failed (or shows warnings), investigate the failures. If you determine the failures are unrelated, you may proceed. If you need assistance investigating, request help in the #s_developer_experience Slack channel to confirm the failures are unrelated to the merge request.

Note to the merge request author and maintainer

If you have questions about the patch release process, please:

Edited by Bob Van Landuyt

Merge request reports

Loading
Loading