Loading
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_createApplicationRateLimiterkey: 10 requests per hour per user, checked before the eligibility lookups inTrialsController#create. - Requests over the limit are logged to
auth.log(Application_Rate_Limiter_Request,env: trial_create_request_limit). They are rejected with429only when theenforce_trial_create_rate_limitflag (gitlab_com_derisk, default off) is enabled, so we can check real traffic before enforcing. - Memoises
eligible_namespacesin the controller. Bothbefore_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
- https://gitlab.com/gitlab-org/gitlab/-/work_items/635543
- Rollout issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/636612
- Related: !265175 (merged)
How to set up and validate locally
- As the owner of a Free group, submit the trial form at
/-/trials/new11 times within an hour. - The 11th request is logged in
log/auth_json.logwith"env":"trial_create_request_limit"and still goes through. - Enable the flag in a Rails console with
Feature.enable(:enforce_trial_create_rate_limit), then submit again. The response is429 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.