2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
module Ci
|
|
|
|
class RunnerPolicy < BasePolicy
|
2017-09-10 17:25:29 +05:30
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:locked, scope: :subject) { @subject.locked? }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
condition(:owned_runner) do
|
|
|
|
@user.owns_runner?(@subject)
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:is_instance_runner) do
|
|
|
|
@subject.instance_type?
|
|
|
|
end
|
|
|
|
|
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:is_group_runner) do
|
|
|
|
@subject.group_type?
|
|
|
|
end
|
|
|
|
|
|
|
|
with_options scope: :user, score: 5
|
|
|
|
condition(:any_developer_groups_inheriting_shared_runners) do
|
|
|
|
@user.developer_groups.with_shared_runners_enabled.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
with_options scope: :user, score: 5
|
|
|
|
condition(:any_developer_projects_inheriting_shared_runners) do
|
|
|
|
@user.authorized_projects(Gitlab::Access::DEVELOPER).with_shared_runners_enabled.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
with_options score: 10
|
|
|
|
condition(:any_associated_projects_in_group_runner_inheriting_group_runners) do
|
|
|
|
# Check if any projects where user is a developer are inheriting group runners
|
|
|
|
@subject.groups&.any? do |group|
|
|
|
|
group.all_projects
|
|
|
|
.with_group_runners_enabled
|
|
|
|
.visible_to_user_and_access_level(@user, Gitlab::Access::DEVELOPER)
|
|
|
|
.exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
condition(:belongs_to_multiple_projects, scope: :subject) do
|
2022-05-07 20:08:51 +05:30
|
|
|
@subject.belongs_to_more_than_one_project?
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
rule { anonymous }.prevent_all
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
rule { admin | owned_runner }.policy do
|
2022-04-04 11:22:00 +05:30
|
|
|
enable :read_builds
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
rule { admin | owned_runner }.policy do
|
|
|
|
enable :read_runner
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
rule { is_instance_runner & any_developer_groups_inheriting_shared_runners }.policy do
|
|
|
|
enable :read_runner
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { is_instance_runner & any_developer_projects_inheriting_shared_runners }.policy do
|
|
|
|
enable :read_runner
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { is_group_runner & any_associated_projects_in_group_runner_inheriting_group_runners }.policy do
|
|
|
|
enable :read_runner
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { admin | owned_runner }.policy do
|
|
|
|
enable :assign_runner
|
2018-11-08 19:23:39 +05:30
|
|
|
enable :update_runner
|
|
|
|
enable :delete_runner
|
|
|
|
end
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
rule { ~admin & belongs_to_multiple_projects }.prevent :delete_runner
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
rule { ~admin & locked }.prevent :assign_runner
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
Ci::RunnerPolicy.prepend_mod_with('Ci::RunnerPolicy')
|