Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFabio Pitino <fpitino@gitlab.com>2019-09-13 09:40:00 +0300
committerFabio Pitino <fpitino@gitlab.com>2019-09-24 12:24:38 +0300
commit9ce103af0b974b71321d4e0e9937ee82e10c740f (patch)
tree3fa2f61051eb65362f16228babb28090b7e57e71 /app
parent39381519f294742e4083dfd6a50c0c8ceddecd5d (diff)
Cancel all running CI jobs when user is blocked
This prevents a MITM attack where attacker could still access Git repository if any jobs were running long enough.
Diffstat (limited to 'app')
-rw-r--r--app/models/user.rb10
-rw-r--r--app/services/ci/cancel_user_pipelines_service.rb13
2 files changed, 23 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 909f5f3873d..9aad9b5f51e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -265,6 +265,16 @@ class User < ApplicationRecord
BLOCKED_MESSAGE
end
end
+
+ # rubocop: disable CodeReuse/ServiceClass
+ # Ideally we should not call a service object here but user.block
+ # is also bcalled by Users::MigrateToGhostUserService which references
+ # this state transition object in order to do a rollback.
+ # For this reason the tradeoff is to disable this cop.
+ after_transition any => :blocked do |user|
+ Ci::CancelUserPipelinesService.new.execute(user)
+ end
+ # rubocop: enable CodeReuse/ServiceClass
end
# Scopes
diff --git a/app/services/ci/cancel_user_pipelines_service.rb b/app/services/ci/cancel_user_pipelines_service.rb
new file mode 100644
index 00000000000..bcafb6b4a35
--- /dev/null
+++ b/app/services/ci/cancel_user_pipelines_service.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module Ci
+ class CancelUserPipelinesService
+ # rubocop: disable CodeReuse/ActiveRecord
+ # This is a bug with CodeReuse/ActiveRecord cop
+ # https://gitlab.com/gitlab-org/gitlab/issues/32332
+ def execute(user)
+ user.pipelines.cancelable.find_each(&:cancel_running)
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+ end
+end