Draft: Add request rate limits to the raw-token validity checks API

Problem

The raw-token validity checks endpoint from !268618 (merged) is synchronous and looks up tokens across the whole instance. Without request limits one scanner could saturate it, and a customer could raise their share by spreading calls across projects.

Changes

I added two Labkit rate-limit rules and check them in the endpoint with check_rate_limit!, right after the project is resolved. Each caller gets 60 requests a minute and each top-level namespace 120, checked in that order so a noisy caller spends its own budget before the namespace's. The namespace rule is keyed on the project's top-level namespace, so creating projects does not raise a customer's total. A throttled request returns 429 with Retry-After and RateLimit-Name, and the helper honours the throttle bypass header and logs the request like every other rate-limited endpoint.

The limits are hardcoded, as https://gitlab.com/gitlab-org/gitlab/-/work_items/637858 asks, and the rule definitions live in the SupportedRateLimits registry so they stay compatible with the Project Bulkhead work. The check runs before the service, so a caller over the limit gets 429 rather than the 404 an unauthorized caller gets; the limit protects capacity, so it applies before any further work.

This is the last MR of a stack of four for https://gitlab.com/gitlab-org/gitlab/-/work_items/637856. It targets the endpoint branch.

Validation

The request spec passes locally (33 examples), including both throttled cases, and RuboCop reports no offenses on the changed files.

Edited by Jennifer Li

Merge request reports

Loading
Loading