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:

  1. !268076 (merged) adds the application setting and rate limit rule.
  2. !267781 (merged) enforces the limit in the services. This MR targets its branch.
  3. This MR maps a throttled call to 429 in the REST API.
  4. !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

  1. 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)
  2. Create two trigger tokens within a minute. The second call returns 429 with Retry-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.

🤖 Generated with Claude Code

Edited by Tiger Watson

Merge request reports

Loading
Loading