Limit AI Catalog flow service accounts per top-level group
What does this MR do and why?
This MR limits how many service accounts GitLab creates for AI Catalog flows in one top-level group. The limit is 50 new service accounts each hour.
When a flow is turned on in a top-level group, GitLab can create a service account user for it. Turning the flow off never deletes that user. Only Free plans have a cap on service accounts, so on trial and paid plans one group can create these users without a limit. Each user adds rows to shared tables for all of GitLab.com.
Over the last 90 days, the highest count for one top-level group in one hour was 20. The limit is 2.5 times that.
When the limit is reached:
- The enable request returns the error "Too many service accounts were created for flows in this group. Try again later."
- The foundational flow sync records the failure with the reason
rate_limitedand runs again after one hour. - GitLab still reuses a free service account with the same name, because reuse creates no user.
The limit is a staged rule. It only logs until the enforce_ai_catalog_service_account_creation_rate_limit feature flag is on.
A second MR will make GitLab reuse the group's earlier service accounts, so that a turn-off and turn-on loop stops creating users.
References
How to set up and validate locally
- Turn on the feature flag:
Feature.enable(:enforce_ai_catalog_service_account_creation_rate_limit). - In the Rails console, set a low limit for the test: stub or edit the
ai_catalog_service_account_creationrule to a limit of 1. - As a group Owner, turn on a custom flow in a top-level group. A service account is created.
- Turn on a second custom flow with a different name. The request fails with the rate limit error, and no new user is created.
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.