Add per-user rate limit for badge changes
What does this MR do and why?
Applies a limit of 60 requests per minute per user to creating, updating and deleting project and group badges.
This keeps the limits for these actions consistent with the existing limits on similar actions. Badges are only managed through the REST API (the settings UI uses it too), so the REST check covers every existing path. The limit is fixed, like the existing delete limits. It uses log mode (staged_rule): while the badge_write_rate_limit feature flag is disabled, which is the default, changes over the limit are counted and logged but not blocked. Enabling the flag enforces it.
References
- Rollout issue: #635780
- Closes #635739
Screenshots or screen recordings
Not applicable, there are no UI changes.
How to set up and validate locally
-
In the Rails console, enable the feature flag:
Feature.enable(:badge_write_rate_limit) -
As a user with access, create badges (
POST /api/v4/projects/:id/badges) more than 60 times in a minute. -
Confirm that requests over the limit receive a
429response. -
Disable the feature flag and confirm the requests are no longer limited:
Feature.disable(:badge_write_rate_limit)
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.