Limit unverified users to creation of 2 groups
What does this MR do and why?
Related to: https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/625
This MR limits the number of groups a user can create until they verify their phone number or credit card. This limit will help combat crypto mining since each top-level group includes 400 CI minutes for free users.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Enable the feature flag
[28] pry(main)> Feature.enable(:unverified_account_group_creation_limit)
WARNING: Understand the stability and security risks of enabling in-development features with feature flags.
See https://docs.gitlab.com/ee/administration/feature_flags.html#risks-when-enabling-features-still-in-development for more information.
=> true
- With a new user, fake their
created_at
date to be afterIdentityVerifiable::GROUP_LIMIT_RELEASE_DAY
[30] pry(main)> user = FactoryBot.create(:user, created_at: IdentityVerifiable::IDENTITY_VERIFICATION_RELEASE_DATE + 1.day)
- Create two groups with the new user. These creates should be successful.
[31] pry(main)> Groups::CreateService.new(user, {name: "test-limit-1", path: "test-limit-1", visibility_level: 0, request_access_enabled: "1"}).execute
[32] pry(main)> Groups::CreateService.new(user, {name: "test-limit-2", path: "test-limit-2", visibility_level: 0, request_access_enabled: "1"}).execute
- Create a third group. This creation should fail due to reaching the unverified user limit.
[34] pry(main)> response = Groups::CreateService.new(user, {name: "test-limit-3", path: "test-limit-3", visibility_level: 0, request_access_enabled: "1"}).execute
[36] pry(main)> response.payload[:group].errors
=> #<ActiveModel::Errors [#<ActiveModel::Error attribute=identity_verification, type=You have reached the group limit until you verify your account ., options={}>]>
Edited by Ian Anderson