Add a per user rate limit to deleting labels

What does this MR do and why?

This MR adds a rate limit of 120 label deletes per minute per user, behind the label_delete_rate_limit feature flag (disabled by default). The limit is the label_delete_limit application setting, labeled beta in the docs, following the convention agreed in https://gitlab.com/groups/gitlab-org/-/work_items/24176#note_4152547896.

The check lives in Labels::DestroyService, the one point shared by every path that deletes a label, so one key covers:

  • REST API: DELETE /projects/:id/labels/:label_id and DELETE /groups/:id/labels/:label_id, including the deprecated forms that take name
  • The project and group label pages in the UI

When throttled, the API returns 429 Too Many Requests and the UI shows a plain 429 response. Label promotion is intentionally not limited: it moves all links with a single set-based update, so its cost does not grow with the number of linked items.

This is the Phase 1 protect step for https://gitlab.com/gitlab-org/gitlab/-/work_items/637478. It bounds how often one user can replay a delete, but it does not change the cost of a single delete: destroying a label still removes one label_links row per linked issuable inside one transaction. The batched label_links delete that the work item describes as the mitigation is a separate follow-up.

References

How to set up and validate locally

  1. Enable the feature flag in the Rails console:

    Feature.enable(:label_delete_rate_limit)
  2. Lower the limit with the application settings API, as an administrator:

    curl --request PUT --header "PRIVATE-TOKEN: <admin token>" "http://gdk.test:3000/api/v4/application/settings?label_delete_limit=2"
  3. Delete two labels in a project, with the API or from the labels page. Both succeed.

  4. Delete a third label within the minute. The API returns 429, and the UI shows a 429 response.

  5. Delete a group label as the same user. It is also throttled, because the key is shared.

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.

Edited by Matt D'Angelo

Merge request reports

Loading
Loading