Rate limit pipeline trigger token management actions

What does this MR do and why?

Adds a per-user rate limit to pipeline trigger token management, counted inside the services so the REST API, the GraphQL mutations and the project settings page share it:

Key Scope Limit
pipeline_trigger_management user pipeline_trigger_management_limit_per_user setting, default 300 per minute

Creating, updating and deleting a trigger token all count toward the same allowance, so alternating actions cannot multiply it. There is no per-project limit: with an equal default it could never fire before the per-user one, as found in review of the pipeline schedule limit in !267727 (comment 4204326151). The setting and rule come from the MR this one targets.

The check is a shared concern, Ci::PipelineTriggerRateLimitable, used by CreateService, UpdateService and DestroyService. As in Ci::RetryPipelineService, the attempt is counted before the permission check so a rejected call still costs an attempt, but a caller without permission gets the access error, not the throttle. A throttled call returns a ServiceResponse with reason: :rate_limited: the mutations return the message in errors (the create mutation now falls back to the service message when there is no trigger to read errors from) and the project settings page shows it as a flash alert.

ExpireService, reached only from the admin token revocation API, is deliberately outside this limit.

This mirrors the pipeline schedule limit in !267727 (merged); once both merge, a follow-up can extract the shared concern and shared examples.

Behind the rate_limit_pipeline_trigger_management feature flag, off by default, so no changelog entry. Rollout issue: #638456.

Stack

One change split into four MRs:

  1. !268076 (merged) adds the application setting and rate limit rule. This MR targets its branch.
  2. This MR enforces the limit in the services.
  3. !268082 (merged), stacked on this one, returns 429 with Retry-After from the REST API when a call is throttled. Until it merges a throttled REST call returns 400 with the message.
  4. !268078 fixes the controller's update action independently.

References

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636907

Pipeline retry precedent: !254367 (merged)

Screenshots or screen recordings

No UI change beyond the flash message when a change is throttled.

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. On Settings > CI/CD > Pipeline trigger tokens, add a token and then revoke one within a minute. The second action shows the "requested too many times" message.

  3. log/application_json.log records Pipeline trigger token management rate limit exceeded.

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