Rate limit trial creation per user

What does this MR do and why?

POST /-/trials calls CustomersDot for the lead, the trial and eligibility, and nothing limits how often one user can submit it.

  • Adds a trial_create ApplicationRateLimiter key: 10 requests per hour per user, checked before the eligibility lookups in TrialsController#create.
  • Requests over the limit are logged to auth.log (Application_Rate_Limiter_Request, env: trial_create_request_limit). They are rejected with 429 only when the enforce_trial_create_rate_limit flag (gitlab_com_derisk, default off) is enabled, so we can check real traffic before enforcing.
  • Memoises eligible_namespaces in the controller. Both before_actions called it, so a request could look up eligibility twice.

The limit applies per user only. The route requires sign-in, and a per-IP limit would also count users behind a shared NAT.

The limit will be added to the GitLab.com rate limits docs once it is enforced.

References

How to set up and validate locally

  1. As the owner of a Free group, submit the trial form at /-/trials/new 11 times within an hour.
  2. The 11th request is logged in log/auth_json.log with "env":"trial_create_request_limit" and still goes through.
  3. Enable the flag in a Rails console with Feature.enable(:enforce_trial_create_rate_limit), then submit again. The response is 429 Too Many Requests.

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

Merge request reports

Loading
Loading