debian-mirror-gitlab/app/policies/ci/runner_policy.rb

85 lines
2.4 KiB
Ruby
Raw Normal View History

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
2023-04-23 21:23:45 +05:30
condition(:creator) do
@user == @subject.creator
end
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
2022-11-25 23:54:43 +05:30
condition(:any_developer_maintainer_owned_groups_inheriting_shared_runners) do
@user.developer_maintainer_owned_groups.with_shared_runners_enabled.any?
2022-10-11 01:57:18 +05:30
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
2022-11-25 23:54:43 +05:30
# Check if any projects where user is a developer+ are inheriting group runners
2022-10-11 01:57:18 +05:30
@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
2018-11-08 19:23:39 +05:30
enable :read_runner
2022-10-11 01:57:18 +05:30
end
2022-11-25 23:54:43 +05:30
rule { is_instance_runner & any_developer_maintainer_owned_groups_inheriting_shared_runners }.policy do
2022-10-11 01:57:18 +05:30
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
2023-04-23 21:23:45 +05:30
rule { creator }.enable :read_ephemeral_token
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')