Skip to content

Draft: Limit unverified users to ownership of 2 groups

Ian Anderson requested to merge limit-user-group-creates into master

What does this MR do and why?

Related to: !149622

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.

  1. 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
  1. With a new user, fake their created_at date to be after IdentityVerifiable::GROUP_LIMIT_RELEASE_DAY
[29] pry(main)> u = User.last
[30] pry(main)> u.created_at = IdentityVerifiable::GROUP_LIMIT_RELEASE_DAY + 1.day
  1. Create two groups with the new user. These creates should be successful.
[31] pry(main)> Groups::CreateService.new(u, {name: "test-limit-1", path: "test-limit-1", visibility_level: 0, request_access_enabled: "1"}).execute
[32] pry(main)> Groups::CreateService.new(u, {name: "test-limit-2", path: "test-limit-2", visibility_level: 0, request_access_enabled: "1"}).execute
  1. Create an third group. This creation should failed due reaching the unverified user limit.
[34] pry(main)> response = Groups::CreateService.new(u, {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

Merge request reports