Skip to content

Check allowlist of a namespace before banning a user

Eugie Limpin requested to merge pass_allowlist into master

What does this MR do and why?

Implements a part of https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/36

Pass in a group's namespace_setting.unique_project_download_limit_allowlist to ApplicationRateLimiter#throttled? to avoid banning specified users when they exceed unique project download limit set for the group.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Validate via Rails console

# enable the feature flag
> Feature.enable(:auto_ban_user_on_namespace_excessive_projects_download)

# create a test user
> user = FactoryBot.create(:user)

# create a group
> group = FactoryBot.create(:group)

# update unique project download limit settings for the group
> group.namespace_settings.update!({
  unique_project_download_limit: 1,
  unique_project_download_limit_interval_in_seconds: 600,
  unique_project_download_limit_allowlist: [user.username]
})

# create two projects belonging to the group
> project1 = FactoryBot.create(:project, namespace: group)
> project2 = FactoryBot.create(:project, namespace: group)

# simulate downloading the first project
> Users::Abuse::GitAbuse::NamespaceThrottleService.execute(project1, user)
# validate that result is {:banned=>false}
=> {:banned=>false}

# exceed download limit by simulating download of second project
> Users::Abuse::GitAbuse::NamespaceThrottleService.execute(project2, user)
# validate that result is {:banned=>false}
=> {:banned=>false}

# validate that user is not banned from namespace since they are allowlisted
> user.banned_from_namespace?(group)
=> false

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugie Limpin

Merge request reports

Loading