Return 429 from the pipeline trigger tokens API when rate limited
What does this MR do and why?
The create, update and delete endpoints in API::Ci::Triggers now map a
ServiceResponse with reason: :rate_limited to 429 Too Many Requests with
a Retry-After header set to the limit's period (one minute), instead of the
generic 400 fallback. The pipeline trigger tokens API reference gains a note
about the shared limit, and the OpenAPI document lists the new response.
The limit itself is enforced in the services by
!267781 (merged), which this MR
targets. Behind the rate_limit_pipeline_trigger_management feature flag, off
by default, so no changelog entry.
Stack
One change split into four MRs:
- !268076 (merged) adds the application setting and rate limit rule.
- !267781 (merged) enforces the limit in the services. This MR targets its branch.
- This MR maps a throttled call to
429in the REST API. - !268078 fixes the controller's update action independently.
References
Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636907
Screenshots or screen recordings
No UI change.
How to set up and validate locally
-
Enable the flag and lower the limit in a Rails console:
Feature.enable(:rate_limit_pipeline_trigger_management) ApplicationSetting.current.update!(pipeline_trigger_management_limit_per_user: 1) -
Create two trigger tokens within a minute. The second call returns
429withRetry-After: 60.curl --request POST --header "PRIVATE-TOKEN: <token>" --data "description=first" \ "http://gdk.test:3000/api/v4/projects/<project_id>/triggers" curl --include --request POST --header "PRIVATE-TOKEN: <token>" --data "description=second" \ "http://gdk.test:3000/api/v4/projects/<project_id>/triggers"
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.