Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c41bc571
Commit
c41bc571
authored
Oct 07, 2021
by
Grzegorz Bizon
Committed by
Kamil Trzciński
Oct 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow database cross-joins in RegisterJobService
parent
0af85c4f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
35 deletions
+98
-35
app/services/ci/register_job_service.rb
app/services/ci/register_job_service.rb
+26
-28
ee/spec/services/ci/register_job_service_spec.rb
ee/spec/services/ci/register_job_service_spec.rb
+24
-0
lib/gitlab/application_context.rb
lib/gitlab/application_context.rb
+4
-1
spec/services/ci/register_job_service_spec.rb
spec/services/ci/register_job_service_spec.rb
+40
-4
spec/support/database/cross-join-allowlist.yml
spec/support/database/cross-join-allowlist.yml
+0
-2
spec/support/database/prevent_cross_joins.rb
spec/support/database/prevent_cross_joins.rb
+4
-0
No files found.
app/services/ci/register_job_service.rb
View file @
c41bc571
...
@@ -103,42 +103,40 @@ module Ci
...
@@ -103,42 +103,40 @@ module Ci
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
each_build
(
params
,
&
blk
)
def
each_build
(
params
,
&
blk
)
::
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/339429'
)
do
queue
=
::
Ci
::
Queue
::
BuildQueueService
.
new
(
runner
)
queue
=
::
Ci
::
Queue
::
BuildQueueService
.
new
(
runner
)
builds
=
begin
if
runner
.
instance_type?
queue
.
builds_for_shared_runner
elsif
runner
.
group_type?
queue
.
builds_for_group_runner
else
queue
.
builds_for_project_runner
end
end
if
runner
.
ref_protected?
builds
=
begin
builds
=
queue
.
builds_for_protected_runner
(
builds
)
if
runner
.
instance_type?
queue
.
builds_for_shared_runner
elsif
runner
.
group_type?
queue
.
builds_for_group_runner
else
queue
.
builds_for_project_runner
end
end
end
# pick builds that does not have other tags than runner's one
if
runner
.
ref_protected?
builds
=
queue
.
builds_matching_tag_ids
(
builds
,
runner
.
tags
.
ids
)
builds
=
queue
.
builds_for_protected_runner
(
builds
)
end
# pick builds that have at least one tag
# pick builds that does not have other tags than runner's one
unless
runner
.
run_untagged?
builds
=
queue
.
builds_matching_tag_ids
(
builds
,
runner
.
tags
.
ids
)
builds
=
queue
.
builds_with_any_tags
(
builds
)
end
# pick builds that older than specified age
# pick builds that have at least one tag
if
params
.
key?
(
:job_age
)
unless
runner
.
run_untagged?
builds
=
queue
.
builds_queued_before
(
builds
,
params
[
:job_age
].
seconds
.
ago
)
builds
=
queue
.
builds_with_any_tags
(
builds
)
end
end
build_ids
=
retrieve_queue
(
->
{
queue
.
execute
(
builds
)
})
# pick builds that older than specified age
if
params
.
key?
(
:job_age
)
builds
=
queue
.
builds_queued_before
(
builds
,
params
[
:job_age
].
seconds
.
ago
)
end
@metrics
.
observe_queue_size
(
->
{
build_ids
.
size
},
@runner
.
runner_type
)
build_ids
=
retrieve_queue
(
->
{
queue
.
execute
(
builds
)
}
)
build_ids
.
each
{
|
build_id
|
yield
Ci
::
Build
.
find
(
build_id
)
}
@metrics
.
observe_queue_size
(
->
{
build_ids
.
size
},
@runner
.
runner_type
)
end
build_ids
.
each
{
|
build_id
|
yield
Ci
::
Build
.
find
(
build_id
)
}
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
...
ee/spec/services/ci/register_job_service_spec.rb
View file @
c41bc571
...
@@ -55,6 +55,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
...
@@ -55,6 +55,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags
(
ci_queueing_denormalize_ci_minutes_information:
false
)
stub_feature_flags
(
ci_queueing_denormalize_ci_minutes_information:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
it
{
is_expected
.
to
be_kind_of
(
Ci
::
Build
)
}
it
{
is_expected
.
to
be_kind_of
(
Ci
::
Build
)
}
end
end
end
end
...
@@ -103,6 +109,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
...
@@ -103,6 +109,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags
(
ci_queueing_denormalize_ci_minutes_information:
false
)
stub_feature_flags
(
ci_queueing_denormalize_ci_minutes_information:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
it
{
is_expected
.
to
be_nil
}
it
{
is_expected
.
to
be_nil
}
end
end
end
end
...
@@ -307,6 +319,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
...
@@ -307,6 +319,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags
(
ci_pending_builds_queue_source:
false
)
stub_feature_flags
(
ci_pending_builds_queue_source:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
include_examples
'namespace minutes quota'
include_examples
'namespace minutes quota'
end
end
...
@@ -328,6 +346,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
...
@@ -328,6 +346,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags
(
ci_queueing_denormalize_shared_runners_information:
false
)
stub_feature_flags
(
ci_queueing_denormalize_shared_runners_information:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
include_examples
'namespace minutes quota'
include_examples
'namespace minutes quota'
end
end
end
end
...
...
lib/gitlab/application_context.rb
View file @
c41bc571
...
@@ -124,7 +124,10 @@ module Gitlab
...
@@ -124,7 +124,10 @@ module Gitlab
strong_memoize
(
:runner_project
)
do
strong_memoize
(
:runner_project
)
do
next
unless
runner
&
.
project_type?
next
unless
runner
&
.
project_type?
projects
=
runner
.
projects
.
take
(
2
)
# rubocop: disable CodeReuse/ActiveRecord
projects
=
::
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/342147'
)
do
runner
.
projects
.
take
(
2
)
# rubocop: disable CodeReuse/ActiveRecord
end
projects
.
first
if
projects
.
one?
projects
.
first
if
projects
.
one?
end
end
end
end
...
...
spec/services/ci/register_job_service_spec.rb
View file @
c41bc571
...
@@ -87,19 +87,25 @@ module Ci
...
@@ -87,19 +87,25 @@ module Ci
end
end
context
'for specific runner'
do
context
'for specific runner'
do
context
'with
FF
disabled'
do
context
'with
tables decoupling
disabled'
do
before
do
before
do
stub_feature_flags
(
stub_feature_flags
(
ci_pending_builds_project_runners_decoupling:
false
,
ci_pending_builds_project_runners_decoupling:
false
,
ci_queueing_builds_enabled_checks:
false
)
ci_queueing_builds_enabled_checks:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
it
'does not pick a build'
do
it
'does not pick a build'
do
expect
(
execute
(
specific_runner
)).
to
be_nil
expect
(
execute
(
specific_runner
)).
to
be_nil
end
end
end
end
context
'with
FF
enabled'
do
context
'with
tables decoupling
enabled'
do
before
do
before
do
stub_feature_flags
(
stub_feature_flags
(
ci_pending_builds_project_runners_decoupling:
true
,
ci_pending_builds_project_runners_decoupling:
true
,
...
@@ -266,17 +272,23 @@ module Ci
...
@@ -266,17 +272,23 @@ module Ci
context
'and uses project runner'
do
context
'and uses project runner'
do
let
(
:build
)
{
execute
(
specific_runner
)
}
let
(
:build
)
{
execute
(
specific_runner
)
}
context
'with
FF
disabled'
do
context
'with
tables decoupling
disabled'
do
before
do
before
do
stub_feature_flags
(
stub_feature_flags
(
ci_pending_builds_project_runners_decoupling:
false
,
ci_pending_builds_project_runners_decoupling:
false
,
ci_queueing_builds_enabled_checks:
false
)
ci_queueing_builds_enabled_checks:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
it
{
expect
(
build
).
to
be_nil
}
it
{
expect
(
build
).
to
be_nil
}
end
end
context
'with
FF
enabled'
do
context
'with
tables decoupling
enabled'
do
before
do
before
do
stub_feature_flags
(
stub_feature_flags
(
ci_pending_builds_project_runners_decoupling:
true
,
ci_pending_builds_project_runners_decoupling:
true
,
...
@@ -791,6 +803,12 @@ module Ci
...
@@ -791,6 +803,12 @@ module Ci
stub_feature_flags
(
ci_queueing_denormalize_shared_runners_information:
false
)
stub_feature_flags
(
ci_queueing_denormalize_shared_runners_information:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
include_examples
'handles runner assignment'
include_examples
'handles runner assignment'
end
end
...
@@ -807,6 +825,12 @@ module Ci
...
@@ -807,6 +825,12 @@ module Ci
stub_feature_flags
(
ci_queueing_denormalize_tags_information:
false
)
stub_feature_flags
(
ci_queueing_denormalize_tags_information:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
include_examples
'handles runner assignment'
include_examples
'handles runner assignment'
end
end
...
@@ -815,6 +839,12 @@ module Ci
...
@@ -815,6 +839,12 @@ module Ci
stub_feature_flags
(
ci_queueing_denormalize_namespace_traversal_ids:
false
)
stub_feature_flags
(
ci_queueing_denormalize_namespace_traversal_ids:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
include_examples
'handles runner assignment'
include_examples
'handles runner assignment'
end
end
end
end
...
@@ -824,6 +854,12 @@ module Ci
...
@@ -824,6 +854,12 @@ module Ci
stub_feature_flags
(
ci_pending_builds_queue_source:
false
)
stub_feature_flags
(
ci_pending_builds_queue_source:
false
)
end
end
around
do
|
example
|
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/332952'
)
do
example
.
run
end
end
include_examples
'handles runner assignment'
include_examples
'handles runner assignment'
end
end
end
end
...
...
spec/support/database/cross-join-allowlist.yml
View file @
c41bc571
...
@@ -81,7 +81,6 @@
...
@@ -81,7 +81,6 @@
-
"
./spec/presenters/ci/build_runner_presenter_spec.rb"
-
"
./spec/presenters/ci/build_runner_presenter_spec.rb"
-
"
./spec/presenters/ci/pipeline_presenter_spec.rb"
-
"
./spec/presenters/ci/pipeline_presenter_spec.rb"
-
"
./spec/presenters/packages/detail/package_presenter_spec.rb"
-
"
./spec/presenters/packages/detail/package_presenter_spec.rb"
-
"
./spec/requests/api/ci/runner/jobs_request_post_spec.rb"
-
"
./spec/requests/api/ci/runner/runners_post_spec.rb"
-
"
./spec/requests/api/ci/runner/runners_post_spec.rb"
-
"
./spec/requests/api/ci/runners_spec.rb"
-
"
./spec/requests/api/ci/runners_spec.rb"
-
"
./spec/requests/api/commit_statuses_spec.rb"
-
"
./spec/requests/api/commit_statuses_spec.rb"
...
@@ -105,7 +104,6 @@
...
@@ -105,7 +104,6 @@
-
"
./spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb"
-
"
./spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb"
-
"
./spec/services/ci/job_artifacts/destroy_associations_service_spec.rb"
-
"
./spec/services/ci/job_artifacts/destroy_associations_service_spec.rb"
-
"
./spec/services/ci/job_artifacts/destroy_batch_service_spec.rb"
-
"
./spec/services/ci/job_artifacts/destroy_batch_service_spec.rb"
-
"
./spec/services/ci/register_job_service_spec.rb"
-
"
./spec/services/deployments/older_deployments_drop_service_spec.rb"
-
"
./spec/services/deployments/older_deployments_drop_service_spec.rb"
-
"
./spec/services/environments/stop_service_spec.rb"
-
"
./spec/services/environments/stop_service_spec.rb"
-
"
./spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb"
-
"
./spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb"
...
...
spec/support/database/prevent_cross_joins.rb
View file @
c41bc571
...
@@ -64,6 +64,10 @@ module Database
...
@@ -64,6 +64,10 @@ module Database
ensure
ensure
ActiveSupport
::
Notifications
.
unsubscribe
(
subscriber
)
if
subscriber
ActiveSupport
::
Notifications
.
unsubscribe
(
subscriber
)
if
subscriber
end
end
def
allow_cross_joins_across_databases
(
url
:,
&
block
)
::
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
url
,
&
block
)
end
end
end
module
GitlabDatabaseMixin
module
GitlabDatabaseMixin
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment