diff options
Diffstat (limited to 'lib/gitlab')
68 files changed, 204 insertions, 37 deletions
diff --git a/lib/gitlab/access.rb b/lib/gitlab/access.rb index 7ef9f7ef630..ed5816482a9 100644 --- a/lib/gitlab/access.rb +++ b/lib/gitlab/access.rb @@ -132,3 +132,5 @@ module Gitlab end end end + +Gitlab::Access.prepend_if_ee('EE::Gitlab::Access') diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb index bdc46abeb9f..53c1398d6ab 100644 --- a/lib/gitlab/auth.rb +++ b/lib/gitlab/auth.rb @@ -26,6 +26,8 @@ module Gitlab DEFAULT_SCOPES = [:api].freeze class << self + prepend_if_ee('EE::Gitlab::Auth') # rubocop: disable Cop/InjectEnterpriseEditionModule + def omniauth_enabled? Gitlab.config.omniauth.enabled end diff --git a/lib/gitlab/auth/ldap/access.rb b/lib/gitlab/auth/ldap/access.rb index c875bba4bcb..b8ed740e08c 100644 --- a/lib/gitlab/auth/ldap/access.rb +++ b/lib/gitlab/auth/ldap/access.rb @@ -8,6 +8,8 @@ module Gitlab module Auth module LDAP class Access + prepend_if_ee('::EE::Gitlab::Auth::LDAP::Access') # rubocop: disable Cop/InjectEnterpriseEditionModule + attr_reader :provider, :user, :ldap_identity def self.open(user, &block) diff --git a/lib/gitlab/auth/ldap/adapter.rb b/lib/gitlab/auth/ldap/adapter.rb index bcb0ecccdf9..356579ef402 100644 --- a/lib/gitlab/auth/ldap/adapter.rb +++ b/lib/gitlab/auth/ldap/adapter.rb @@ -4,6 +4,8 @@ module Gitlab module Auth module LDAP class Adapter + prepend_if_ee('::EE::Gitlab::Auth::LDAP::Adapter') # rubocop: disable Cop/InjectEnterpriseEditionModule + SEARCH_RETRY_FACTOR = [1, 1, 2, 3].freeze MAX_SEARCH_RETRIES = Rails.env.test? ? 1 : SEARCH_RETRY_FACTOR.size.freeze diff --git a/lib/gitlab/auth/ldap/config.rb b/lib/gitlab/auth/ldap/config.rb index 354f91306f9..eb1d0925c55 100644 --- a/lib/gitlab/auth/ldap/config.rb +++ b/lib/gitlab/auth/ldap/config.rb @@ -5,6 +5,8 @@ module Gitlab module Auth module LDAP class Config + prepend_if_ee('::EE::Gitlab::Auth::LDAP::Config') # rubocop: disable Cop/InjectEnterpriseEditionModule + NET_LDAP_ENCRYPTION_METHOD = { simple_tls: :simple_tls, start_tls: :start_tls, diff --git a/lib/gitlab/auth/ldap/person.rb b/lib/gitlab/auth/ldap/person.rb index 11a4052a109..88ec22aa75c 100644 --- a/lib/gitlab/auth/ldap/person.rb +++ b/lib/gitlab/auth/ldap/person.rb @@ -4,6 +4,8 @@ module Gitlab module Auth module LDAP class Person + prepend_if_ee('::EE::Gitlab::Auth::LDAP::Person') # rubocop: disable Cop/InjectEnterpriseEditionModule + # Active Directory-specific LDAP filter that checks if bit 2 of the # userAccountControl attribute is set. # Source: http://ctogonewild.com/2009/09/03/bitmask-searches-in-ldap/ diff --git a/lib/gitlab/auth/ldap/user.rb b/lib/gitlab/auth/ldap/user.rb index 9c71671f409..3b68230e193 100644 --- a/lib/gitlab/auth/ldap/user.rb +++ b/lib/gitlab/auth/ldap/user.rb @@ -11,6 +11,7 @@ module Gitlab module LDAP class User < Gitlab::Auth::OAuth::User extend ::Gitlab::Utils::Override + prepend_if_ee('::EE::Gitlab::Auth::LDAP::User') # rubocop: disable Cop/InjectEnterpriseEditionModule class << self # rubocop: disable CodeReuse/ActiveRecord diff --git a/lib/gitlab/auth/o_auth/auth_hash.rb b/lib/gitlab/auth/o_auth/auth_hash.rb index 91b9ddc0d00..76f2827af1a 100644 --- a/lib/gitlab/auth/o_auth/auth_hash.rb +++ b/lib/gitlab/auth/o_auth/auth_hash.rb @@ -6,6 +6,8 @@ module Gitlab module Auth module OAuth class AuthHash + prepend_if_ee('::EE::Gitlab::Auth::OAuth::AuthHash') # rubocop: disable Cop/InjectEnterpriseEditionModule + attr_reader :auth_hash def initialize(auth_hash) @auth_hash = auth_hash diff --git a/lib/gitlab/auth/o_auth/user.rb b/lib/gitlab/auth/o_auth/user.rb index f121dce4cbb..300181025a4 100644 --- a/lib/gitlab/auth/o_auth/user.rb +++ b/lib/gitlab/auth/o_auth/user.rb @@ -9,6 +9,8 @@ module Gitlab module Auth module OAuth class User + prepend_if_ee('::EE::Gitlab::Auth::OAuth::User') # rubocop: disable Cop/InjectEnterpriseEditionModule + SignupDisabledError = Class.new(StandardError) SigninDisabledForProviderError = Class.new(StandardError) diff --git a/lib/gitlab/auth/result.rb b/lib/gitlab/auth/result.rb index 4ebf2afb9cb..0fe91f9f3c8 100644 --- a/lib/gitlab/auth/result.rb +++ b/lib/gitlab/auth/result.rb @@ -3,6 +3,8 @@ module Gitlab module Auth Result = Struct.new(:actor, :project, :type, :authentication_abilities) do + prepend_if_ee('::EE::Gitlab::Auth::Result') # rubocop: disable Cop/InjectEnterpriseEditionModule + def ci?(for_project) type == :ci && project && diff --git a/lib/gitlab/auth/saml/config.rb b/lib/gitlab/auth/saml/config.rb index 8cb999f50d4..ed2f3f158c1 100644 --- a/lib/gitlab/auth/saml/config.rb +++ b/lib/gitlab/auth/saml/config.rb @@ -4,6 +4,8 @@ module Gitlab module Auth module Saml class Config + prepend_if_ee('::EE::Gitlab::Auth::Saml::Config') # rubocop: disable Cop/InjectEnterpriseEditionModule + class << self def options Gitlab::Auth::OAuth::Provider.config_for('saml') diff --git a/lib/gitlab/auth/saml/user.rb b/lib/gitlab/auth/saml/user.rb index ec95bc46791..1ba36ad95b4 100644 --- a/lib/gitlab/auth/saml/user.rb +++ b/lib/gitlab/auth/saml/user.rb @@ -9,6 +9,8 @@ module Gitlab module Auth module Saml class User < Gitlab::Auth::OAuth::User + prepend_if_ee('::EE::Gitlab::Auth::Saml::User') # rubocop: disable Cop/InjectEnterpriseEditionModule + extend ::Gitlab::Utils::Override def save diff --git a/lib/gitlab/auth/user_auth_finders.rb b/lib/gitlab/auth/user_auth_finders.rb index 76d41eede23..e2f562c0843 100644 --- a/lib/gitlab/auth/user_auth_finders.rb +++ b/lib/gitlab/auth/user_auth_finders.rb @@ -18,6 +18,8 @@ module Gitlab end module UserAuthFinders + prepend_if_ee('::EE::Gitlab::Auth::UserAuthFinders') # rubocop: disable Cop/InjectEnterpriseEditionModule + include Gitlab::Utils::StrongMemoize PRIVATE_TOKEN_HEADER = 'HTTP_PRIVATE_TOKEN' diff --git a/lib/gitlab/checks/base_checker.rb b/lib/gitlab/checks/base_checker.rb index 09b17b5b76b..a14fa02c2a4 100644 --- a/lib/gitlab/checks/base_checker.rb +++ b/lib/gitlab/checks/base_checker.rb @@ -3,6 +3,7 @@ module Gitlab module Checks class BaseChecker + prepend_if_ee('EE::Gitlab::Checks::BaseChecker') # rubocop: disable Cop/InjectEnterpriseEditionModule include Gitlab::Utils::StrongMemoize attr_reader :change_access diff --git a/lib/gitlab/checks/change_access.rb b/lib/gitlab/checks/change_access.rb index 8a57a3a6d9a..14a445fcb96 100644 --- a/lib/gitlab/checks/change_access.rb +++ b/lib/gitlab/checks/change_access.rb @@ -3,6 +3,8 @@ module Gitlab module Checks class ChangeAccess + prepend_if_ee('EE::Gitlab::Checks::ChangeAccess') # rubocop: disable Cop/InjectEnterpriseEditionModule + ATTRIBUTES = %i[user_access project skip_authorization skip_lfs_integrity_check protocol oldrev newrev ref branch_name tag_name logger commits].freeze diff --git a/lib/gitlab/checks/diff_check.rb b/lib/gitlab/checks/diff_check.rb index ea0d8c85a66..6372d96c07d 100644 --- a/lib/gitlab/checks/diff_check.rb +++ b/lib/gitlab/checks/diff_check.rb @@ -4,6 +4,7 @@ module Gitlab module Checks class DiffCheck < BaseChecker include Gitlab::Utils::StrongMemoize + prepend_if_ee('EE::Gitlab::Checks::DiffCheck') # rubocop: disable Cop/InjectEnterpriseEditionModule LOG_MESSAGES = { validate_file_paths: "Validating diffs' file paths...", diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index cde042c5e0a..668e4a5e246 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -82,3 +82,5 @@ module Gitlab end end end + +Gitlab::Ci::Config.prepend_if_ee('EE::Gitlab::Ci::ConfigEE') diff --git a/lib/gitlab/ci/config/entry/jobs.rb b/lib/gitlab/ci/config/entry/jobs.rb index 9d1a1ee8c4b..b517dae4d2e 100644 --- a/lib/gitlab/ci/config/entry/jobs.rb +++ b/lib/gitlab/ci/config/entry/jobs.rb @@ -77,3 +77,5 @@ module Gitlab end end end + +::Gitlab::Ci::Config::Entry::Jobs.prepend_if_ee('::EE::Gitlab::Ci::Config::Entry::Jobs') diff --git a/lib/gitlab/ci/parsers.rb b/lib/gitlab/ci/parsers.rb index eb63e6c8363..c76cd5ff285 100644 --- a/lib/gitlab/ci/parsers.rb +++ b/lib/gitlab/ci/parsers.rb @@ -3,6 +3,8 @@ module Gitlab module Ci module Parsers + prepend_if_ee('::EE::Gitlab::Ci::Parsers') # rubocop: disable Cop/InjectEnterpriseEditionModule + ParserNotFoundError = Class.new(ParserError) def self.parsers diff --git a/lib/gitlab/ci/pipeline/chain/limit/activity.rb b/lib/gitlab/ci/pipeline/chain/limit/activity.rb index 68482cf08a9..3c64278e305 100644 --- a/lib/gitlab/ci/pipeline/chain/limit/activity.rb +++ b/lib/gitlab/ci/pipeline/chain/limit/activity.rb @@ -19,3 +19,5 @@ module Gitlab end end end + +Gitlab::Ci::Pipeline::Chain::Limit::Activity.prepend_if_ee('EE::Gitlab::Ci::Pipeline::Chain::Limit::Activity') diff --git a/lib/gitlab/ci/pipeline/chain/limit/job_activity.rb b/lib/gitlab/ci/pipeline/chain/limit/job_activity.rb index 31c218bf954..2e8b437252f 100644 --- a/lib/gitlab/ci/pipeline/chain/limit/job_activity.rb +++ b/lib/gitlab/ci/pipeline/chain/limit/job_activity.rb @@ -19,3 +19,5 @@ module Gitlab end end end + +Gitlab::Ci::Pipeline::Chain::Limit::JobActivity.prepend_if_ee('EE::Gitlab::Ci::Pipeline::Chain::Limit::JobActivity') diff --git a/lib/gitlab/ci/pipeline/chain/limit/size.rb b/lib/gitlab/ci/pipeline/chain/limit/size.rb index cd330c58406..739648840e9 100644 --- a/lib/gitlab/ci/pipeline/chain/limit/size.rb +++ b/lib/gitlab/ci/pipeline/chain/limit/size.rb @@ -19,3 +19,5 @@ module Gitlab end end end + +Gitlab::Ci::Pipeline::Chain::Limit::Size.prepend_if_ee('EE::Gitlab::Ci::Pipeline::Chain::Limit::Size') diff --git a/lib/gitlab/ci/pipeline/chain/validate/abilities.rb b/lib/gitlab/ci/pipeline/chain/validate/abilities.rb index 357a1d55b3b..f9ed9d91177 100644 --- a/lib/gitlab/ci/pipeline/chain/validate/abilities.rb +++ b/lib/gitlab/ci/pipeline/chain/validate/abilities.rb @@ -60,3 +60,5 @@ module Gitlab end end end + +Gitlab::Ci::Pipeline::Chain::Validate::Abilities.prepend_if_ee('EE::Gitlab::Ci::Pipeline::Chain::Validate::Abilities') diff --git a/lib/gitlab/ci/status/build/failed.rb b/lib/gitlab/ci/status/build/failed.rb index 76dfe7b7639..961012c2cee 100644 --- a/lib/gitlab/ci/status/build/failed.rb +++ b/lib/gitlab/ci/status/build/failed.rb @@ -21,6 +21,8 @@ module Gitlab private_constant :REASONS + prepend_if_ee('::EE::Gitlab::Ci::Status::Build::Failed') # rubocop: disable Cop/InjectEnterpriseEditionModule + def status_tooltip base_message end diff --git a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml index 2afc99d0bf8..56ce33203ad 100644 --- a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml @@ -1,4 +1,4 @@ -# Read more about this feature here: https://docs.gitlab.com/ee/user/project/merge_requests/container_scanning.html +# Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/container_scanning/ container_scanning: stage: test diff --git a/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml index 15b84f1540d..c8930bc6263 100644 --- a/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml @@ -1,4 +1,4 @@ -# Read more about this feature here: https://docs.gitlab.com/ee/user/project/merge_requests/dependency_scanning.html +# Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/ # # Configure the scanning tool through the environment variables. # List of the variables: https://gitlab.com/gitlab-org/security-products/dependency-scanning#settings diff --git a/lib/gitlab/ci/templates/Security/License-Management.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/License-Management.gitlab-ci.yml index b6555e627a1..f10a445f7c9 100644 --- a/lib/gitlab/ci/templates/Security/License-Management.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/License-Management.gitlab-ci.yml @@ -1,4 +1,8 @@ -# Read more about this feature here: https://docs.gitlab.com/ee/user/project/merge_requests/license_management.html +# Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/license_management/ +# +# Configure the scanning tool through the environment variables. +# List of the variables: https://gitlab.com/gitlab-org/security-products/license-management#settings +# How to set: https://docs.gitlab.com/ee/ci/yaml/#variables variables: LICENSE_MANAGEMENT_SETUP_CMD: '' # If needed, specify a command to setup your environment with a custom package manager. diff --git a/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml index 90278122361..a61731a24b7 100644 --- a/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml @@ -1,4 +1,4 @@ -# Read more about this feature here: https://docs.gitlab.com/ee/user/project/merge_requests/sast.html +# Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/sast/ # # Configure the scanning tool through the environment variables. # List of the variables: https://gitlab.com/gitlab-org/security-products/sast#settings diff --git a/lib/gitlab/cleanup/orphan_job_artifact_files.rb b/lib/gitlab/cleanup/orphan_job_artifact_files.rb index 808814c39e0..1b01ca25559 100644 --- a/lib/gitlab/cleanup/orphan_job_artifact_files.rb +++ b/lib/gitlab/cleanup/orphan_job_artifact_files.rb @@ -130,3 +130,5 @@ module Gitlab end end end + +Gitlab::Cleanup::OrphanJobArtifactFiles.prepend_if_ee('EE::Gitlab::Cleanup::OrphanJobArtifactFiles') diff --git a/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb b/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb index 53e0c83046e..6ad05c7b2e4 100644 --- a/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb +++ b/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb @@ -78,3 +78,5 @@ module Gitlab end end end + +Gitlab::Cleanup::OrphanJobArtifactFilesBatch.prepend_if_ee('EE::Gitlab::Cleanup::OrphanJobArtifactFilesBatch') diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 6ecd506d55b..e4e93b59a36 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -309,3 +309,5 @@ module Gitlab end end end + +Gitlab::Database.prepend_if_ee('EE::Gitlab::Database') diff --git a/lib/gitlab/database_importers/common_metrics.rb b/lib/gitlab/database_importers/common_metrics.rb index f964ae8a275..b9d320f2fc7 100644 --- a/lib/gitlab/database_importers/common_metrics.rb +++ b/lib/gitlab/database_importers/common_metrics.rb @@ -6,3 +6,5 @@ module Gitlab end end end + +Gitlab::DatabaseImporters::CommonMetrics.prepend_if_ee('EE::Gitlab::DatabaseImporters::CommonMetrics') diff --git a/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb b/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb index c9e957ec7c0..409a1252da1 100644 --- a/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb +++ b/lib/gitlab/database_importers/common_metrics/prometheus_metric_enums.rb @@ -38,3 +38,5 @@ module Gitlab end end end + +::Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetricEnums.prepend_if_ee('EE::Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetricEnums') diff --git a/lib/gitlab/email/handler.rb b/lib/gitlab/email/handler.rb index cebedb19dcc..e9a7c9bcf5c 100644 --- a/lib/gitlab/email/handler.rb +++ b/lib/gitlab/email/handler.rb @@ -3,6 +3,8 @@ module Gitlab module Email module Handler + prepend_if_ee('::EE::Gitlab::Email::Handler') # rubocop: disable Cop/InjectEnterpriseEditionModule + def self.handlers @handlers ||= load_handlers end diff --git a/lib/gitlab/email/handler/base_handler.rb b/lib/gitlab/email/handler/base_handler.rb index f89d1d15010..2e487c42cb5 100644 --- a/lib/gitlab/email/handler/base_handler.rb +++ b/lib/gitlab/email/handler/base_handler.rb @@ -24,6 +24,14 @@ module Gitlab def metrics_params { handler: self.class.name } end + + # Each handler should use it's own metric event. Otherwise there + # is a possibility that within the same Sidekiq process, that same + # event with different metrics_params will cause Prometheus to + # throw an error + def metrics_event + raise NotImplementedError + end end end end diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb index 78a3a9489ac..22fc8addcd9 100644 --- a/lib/gitlab/email/handler/create_issue_handler.rb +++ b/lib/gitlab/email/handler/create_issue_handler.rb @@ -48,6 +48,10 @@ module Gitlab end # rubocop: enable CodeReuse/ActiveRecord + def metrics_event + :receive_email_create_issue + end + private def create_issue diff --git a/lib/gitlab/email/handler/create_merge_request_handler.rb b/lib/gitlab/email/handler/create_merge_request_handler.rb index b3b5063f2ca..e8071bcafd0 100644 --- a/lib/gitlab/email/handler/create_merge_request_handler.rb +++ b/lib/gitlab/email/handler/create_merge_request_handler.rb @@ -54,6 +54,10 @@ module Gitlab super.merge(includes_patches: patch_attachments.any?) end + def metrics_event + :receive_email_create_merge_request + end + private def build_merge_request diff --git a/lib/gitlab/email/handler/create_note_handler.rb b/lib/gitlab/email/handler/create_note_handler.rb index b00af15364d..28200643296 100644 --- a/lib/gitlab/email/handler/create_note_handler.rb +++ b/lib/gitlab/email/handler/create_note_handler.rb @@ -32,6 +32,10 @@ module Gitlab record_name: 'comment') end + def metrics_event + :receive_email_create_note + end + private def author diff --git a/lib/gitlab/email/handler/unsubscribe_handler.rb b/lib/gitlab/email/handler/unsubscribe_handler.rb index 20e4c125626..528857aff14 100644 --- a/lib/gitlab/email/handler/unsubscribe_handler.rb +++ b/lib/gitlab/email/handler/unsubscribe_handler.rb @@ -36,6 +36,10 @@ module Gitlab noteable.unsubscribe(sent_notification.recipient) end + def metrics_event + :receive_email_unsubscribe + end + private attr_reader :reply_token diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb index d28f6b301fa..7da8b385266 100644 --- a/lib/gitlab/email/receiver.rb +++ b/lib/gitlab/email/receiver.rb @@ -39,9 +39,9 @@ module Gitlab raise UnknownIncomingEmail unless handler - Gitlab::Metrics.add_event(:receive_email, handler.metrics_params) - - handler.execute + handler.execute.tap do + Gitlab::Metrics.add_event(handler.metrics_event, handler.metrics_params) + end end private diff --git a/lib/gitlab/etag_caching/router.rb b/lib/gitlab/etag_caching/router.rb index d09dcdbb337..7b921ab6199 100644 --- a/lib/gitlab/etag_caching/router.rb +++ b/lib/gitlab/etag_caching/router.rb @@ -3,6 +3,8 @@ module Gitlab module EtagCaching class Router + prepend_if_ee('EE::Gitlab::EtagCaching::Router') # rubocop: disable Cop/InjectEnterpriseEditionModule + Route = Struct.new(:regexp, :name) # We enable an ETag for every request matching the regex. # To match a regex the path needs to match the following: diff --git a/lib/gitlab/exclusive_lease.rb b/lib/gitlab/exclusive_lease.rb index d466d2a514c..425ef5d738a 100644 --- a/lib/gitlab/exclusive_lease.rb +++ b/lib/gitlab/exclusive_lease.rb @@ -96,3 +96,5 @@ module Gitlab end end end + +Gitlab::ExclusiveLease.prepend_if_ee('EE::Gitlab::ExclusiveLease') diff --git a/lib/gitlab/fake_application_settings.rb b/lib/gitlab/fake_application_settings.rb index 77f7d9490f3..74b91277dd7 100644 --- a/lib/gitlab/fake_application_settings.rb +++ b/lib/gitlab/fake_application_settings.rb @@ -32,3 +32,5 @@ module Gitlab alias_method :has_attribute?, :[] end end + +Gitlab::FakeApplicationSettings.prepend_if_ee('EE::Gitlab::FakeApplicationSettings') diff --git a/lib/gitlab/favicon.rb b/lib/gitlab/favicon.rb index 519213e143c..b5d308e462c 100644 --- a/lib/gitlab/favicon.rb +++ b/lib/gitlab/favicon.rb @@ -60,3 +60,5 @@ module Gitlab end end end + +Gitlab::Favicon.prepend_if_ee('EE::Gitlab::Favicon') diff --git a/lib/gitlab/git_access.rb b/lib/gitlab/git_access.rb index 4b626509008..7e9ec097ef7 100644 --- a/lib/gitlab/git_access.rb +++ b/lib/gitlab/git_access.rb @@ -408,3 +408,5 @@ module Gitlab end end end + +Gitlab::GitAccess.prepend_if_ee('EE::Gitlab::GitAccess') diff --git a/lib/gitlab/git_access_wiki.rb b/lib/gitlab/git_access_wiki.rb index 0af91957fa8..3d0db753f6e 100644 --- a/lib/gitlab/git_access_wiki.rb +++ b/lib/gitlab/git_access_wiki.rb @@ -2,6 +2,8 @@ module Gitlab class GitAccessWiki < GitAccess + prepend_if_ee('EE::Gitlab::GitAccessWiki') # rubocop: disable Cop/InjectEnterpriseEditionModule + ERROR_MESSAGES = { read_only: "You can't push code to a read-only GitLab instance.", write_to_wiki: "You are not allowed to write to this project's wiki." diff --git a/lib/gitlab/github_import/parallel_importer.rb b/lib/gitlab/github_import/parallel_importer.rb index 1d3541b80c7..cdd2abaeb4c 100644 --- a/lib/gitlab/github_import/parallel_importer.rb +++ b/lib/gitlab/github_import/parallel_importer.rb @@ -5,6 +5,8 @@ module Gitlab # The ParallelImporter schedules the importing of a GitHub project using # Sidekiq. class ParallelImporter + prepend_if_ee('::EE::Gitlab::GithubImport::ParallelImporter') # rubocop: disable Cop/InjectEnterpriseEditionModule + attr_reader :project def self.async? diff --git a/lib/gitlab/gl_repository.rb b/lib/gitlab/gl_repository.rb index 04dabe423e8..99bf4258c07 100644 --- a/lib/gitlab/gl_repository.rb +++ b/lib/gitlab/gl_repository.rb @@ -49,3 +49,5 @@ module Gitlab private_class_method :instance end end + +Gitlab::GlRepository.prepend_if_ee('::EE::Gitlab::GlRepository') diff --git a/lib/gitlab/hook_data/issue_builder.rb b/lib/gitlab/hook_data/issue_builder.rb index e5f86ca02b5..1f64e440141 100644 --- a/lib/gitlab/hook_data/issue_builder.rb +++ b/lib/gitlab/hook_data/issue_builder.rb @@ -24,6 +24,7 @@ module Gitlab last_edited_by_id milestone_id moved_to_id + duplicated_to_id project_id relative_position state @@ -54,3 +55,5 @@ module Gitlab end end end + +Gitlab::HookData::IssueBuilder.prepend_if_ee('EE::Gitlab::HookData::IssueBuilder') diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb index 0be49e27acb..1e9dff405c5 100644 --- a/lib/gitlab/import_export/relation_factory.rb +++ b/lib/gitlab/import_export/relation_factory.rb @@ -3,6 +3,8 @@ module Gitlab module ImportExport class RelationFactory + prepend_if_ee('::EE::Gitlab::ImportExport::RelationFactory') # rubocop: disable Cop/InjectEnterpriseEditionModule + OVERRIDES = { snippets: :project_snippets, ci_pipelines: 'Ci::Pipeline', pipelines: 'Ci::Pipeline', diff --git a/lib/gitlab/import_sources.rb b/lib/gitlab/import_sources.rb index e4d625b5738..58c7744fae0 100644 --- a/lib/gitlab/import_sources.rb +++ b/lib/gitlab/import_sources.rb @@ -25,6 +25,8 @@ module Gitlab ].freeze class << self + prepend_if_ee('EE::Gitlab::ImportSources') # rubocop: disable Cop/InjectEnterpriseEditionModule + def options Hash[import_table.map { |importer| [importer.title, importer.name] }] end diff --git a/lib/gitlab/metrics/dashboard/processor.rb b/lib/gitlab/metrics/dashboard/processor.rb index a33a010ad97..c0fa3bb2f3a 100644 --- a/lib/gitlab/metrics/dashboard/processor.rb +++ b/lib/gitlab/metrics/dashboard/processor.rb @@ -46,3 +46,5 @@ module Gitlab end end end + +Gitlab::Metrics::Dashboard::Processor.prepend_if_ee('EE::Gitlab::Metrics::Dashboard::Processor') diff --git a/lib/gitlab/middleware/read_only/controller.rb b/lib/gitlab/middleware/read_only/controller.rb index 802ff18fc58..a29dc5395f3 100644 --- a/lib/gitlab/middleware/read_only/controller.rb +++ b/lib/gitlab/middleware/read_only/controller.rb @@ -4,6 +4,8 @@ module Gitlab module Middleware class ReadOnly class Controller + prepend_if_ee('EE::Gitlab::Middleware::ReadOnly::Controller') # rubocop: disable Cop/InjectEnterpriseEditionModule + DISALLOWED_METHODS = %w(POST PATCH PUT DELETE).freeze APPLICATION_JSON = 'application/json' APPLICATION_JSON_TYPES = %W{#{APPLICATION_JSON} application/vnd.git-lfs+json}.freeze diff --git a/lib/gitlab/object_hierarchy.rb b/lib/gitlab/object_hierarchy.rb index c06f106ffe1..74057bbc493 100644 --- a/lib/gitlab/object_hierarchy.rb +++ b/lib/gitlab/object_hierarchy.rb @@ -198,3 +198,5 @@ module Gitlab end end end + +Gitlab::ObjectHierarchy.prepend_if_ee('EE::Gitlab::ObjectHierarchy') diff --git a/lib/gitlab/omniauth_initializer.rb b/lib/gitlab/omniauth_initializer.rb index ad1377a0892..c051a581837 100644 --- a/lib/gitlab/omniauth_initializer.rb +++ b/lib/gitlab/omniauth_initializer.rb @@ -2,6 +2,8 @@ module Gitlab class OmniauthInitializer + prepend_if_ee('::EE::Gitlab::OmniauthInitializer') # rubocop: disable Cop/InjectEnterpriseEditionModule + def initialize(devise_config) @devise_config = devise_config end diff --git a/lib/gitlab/patch/draw_route.rb b/lib/gitlab/patch/draw_route.rb index b00244a6e04..4c8ca015974 100644 --- a/lib/gitlab/patch/draw_route.rb +++ b/lib/gitlab/patch/draw_route.rb @@ -5,6 +5,8 @@ module Gitlab module Patch module DrawRoute + prepend_if_ee('EE::Gitlab::Patch::DrawRoute') # rubocop: disable Cop/InjectEnterpriseEditionModule + RoutesNotFound = Class.new(StandardError) def draw(routes_name) diff --git a/lib/gitlab/path_regex.rb b/lib/gitlab/path_regex.rb index ee2ef91c65c..9606e3e134c 100644 --- a/lib/gitlab/path_regex.rb +++ b/lib/gitlab/path_regex.rb @@ -246,3 +246,5 @@ module Gitlab end end end + +Gitlab::PathRegex.prepend_if_ee('EE::Gitlab::PathRegex') diff --git a/lib/gitlab/prometheus/metric_group.rb b/lib/gitlab/prometheus/metric_group.rb index 394556e8708..caf0d453b6f 100644 --- a/lib/gitlab/prometheus/metric_group.rb +++ b/lib/gitlab/prometheus/metric_group.rb @@ -3,6 +3,7 @@ module Gitlab module Prometheus class MetricGroup + prepend_if_ee('EE::Gitlab::Prometheus::MetricGroup') # rubocop: disable Cop/InjectEnterpriseEditionModule include ActiveModel::Model attr_accessor :name, :priority, :metrics diff --git a/lib/gitlab/prometheus/queries/query_additional_metrics.rb b/lib/gitlab/prometheus/queries/query_additional_metrics.rb index 960d3536ec0..1bab2ae7d75 100644 --- a/lib/gitlab/prometheus/queries/query_additional_metrics.rb +++ b/lib/gitlab/prometheus/queries/query_additional_metrics.rb @@ -4,6 +4,8 @@ module Gitlab module Prometheus module Queries module QueryAdditionalMetrics + prepend_if_ee('EE::Gitlab::Prometheus::Queries::QueryAdditionalMetrics') # rubocop: disable Cop/InjectEnterpriseEditionModule + def query_metrics(project, environment, query_context) matched_metrics(project).map(&query_group(query_context)) .select(&method(:group_with_any_metrics)) diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 6636ffa448e..4bfa6f7e9a5 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -121,3 +121,5 @@ module Gitlab end end end + +Gitlab::Regex.prepend_if_ee('EE::Gitlab::Regex') diff --git a/lib/gitlab/repo_path.rb b/lib/gitlab/repo_path.rb index b4f41b9cd9a..030e50dfbf6 100644 --- a/lib/gitlab/repo_path.rb +++ b/lib/gitlab/repo_path.rb @@ -38,3 +38,5 @@ module Gitlab end end end + +Gitlab::RepoPath.singleton_class.prepend_if_ee('EE::Gitlab::RepoPath::ClassMethods') diff --git a/lib/gitlab/search/parsed_query.rb b/lib/gitlab/search/parsed_query.rb index c4fb0199558..f3136fff294 100644 --- a/lib/gitlab/search/parsed_query.rb +++ b/lib/gitlab/search/parsed_query.rb @@ -3,6 +3,8 @@ module Gitlab module Search class ParsedQuery + prepend_if_ee('EE::Gitlab::Search::ParsedQuery') # rubocop: disable Cop/InjectEnterpriseEditionModule + attr_reader :term, :filters def initialize(term, filters) diff --git a/lib/gitlab/slash_commands/presenters/issue_base.rb b/lib/gitlab/slash_commands/presenters/issue_base.rb index 08cb82274fd..0be31e234b5 100644 --- a/lib/gitlab/slash_commands/presenters/issue_base.rb +++ b/lib/gitlab/slash_commands/presenters/issue_base.rb @@ -4,6 +4,8 @@ module Gitlab module SlashCommands module Presenters module IssueBase + prepend_if_ee('EE::Gitlab::SlashCommands::Presenters::IssueBase') # rubocop: disable Cop/InjectEnterpriseEditionModule + def color(issuable) issuable.open? ? '#38ae67' : '#d22852' end diff --git a/lib/gitlab/template/gitlab_ci_yml_template.rb b/lib/gitlab/template/gitlab_ci_yml_template.rb index 3e2bb11c35f..ee91f1200cd 100644 --- a/lib/gitlab/template/gitlab_ci_yml_template.rb +++ b/lib/gitlab/template/gitlab_ci_yml_template.rb @@ -32,3 +32,5 @@ module Gitlab end end end + +Gitlab::Template::GitlabCiYmlTemplate.prepend_if_ee('::EE::Gitlab::Template::GitlabCiYmlTemplate') diff --git a/lib/gitlab/tree_summary.rb b/lib/gitlab/tree_summary.rb index 8518a13cd1c..76018cb23c4 100644 --- a/lib/gitlab/tree_summary.rb +++ b/lib/gitlab/tree_summary.rb @@ -2,6 +2,8 @@ module Gitlab class TreeSummary + prepend_if_ee('::EE::Gitlab::TreeSummary') # rubocop: disable Cop/InjectEnterpriseEditionModule + include ::Gitlab::Utils::StrongMemoize attr_reader :commit, :project, :path, :offset, :limit diff --git a/lib/gitlab/url_blocker.rb b/lib/gitlab/url_blocker.rb index fab504aa603..4285b2675c5 100644 --- a/lib/gitlab/url_blocker.rb +++ b/lib/gitlab/url_blocker.rb @@ -45,21 +45,18 @@ module Gitlab ascii_only: ascii_only ) - normalized_hostname = uri.normalized_host - hostname = uri.hostname - port = get_port(uri) - - address_info = get_address_info(hostname, port, dns_rebind_protection) + address_info = get_address_info(uri, dns_rebind_protection) return [uri, nil] unless address_info ip_address = ip_address(address_info) - protected_uri_with_hostname = enforce_uri_hostname(ip_address, uri, hostname, dns_rebind_protection) + return [uri, nil] if domain_whitelisted?(uri) || ip_whitelisted?(ip_address) + + protected_uri_with_hostname = enforce_uri_hostname(ip_address, uri, dns_rebind_protection) # Allow url from the GitLab instance itself but only for the configured hostname and ports return protected_uri_with_hostname if internal?(uri) validate_local_request( - normalized_hostname: normalized_hostname, address_info: address_info, allow_localhost: allow_localhost, allow_local_network: allow_local_network @@ -86,12 +83,12 @@ module Gitlab # # The original hostname is used to validate the SSL, given in that scenario # we'll be making the request to the IP address, instead of using the hostname. - def enforce_uri_hostname(ip_address, uri, hostname, dns_rebind_protection) - return [uri, nil] unless dns_rebind_protection && ip_address && ip_address != hostname + def enforce_uri_hostname(ip_address, uri, dns_rebind_protection) + return [uri, nil] unless dns_rebind_protection && ip_address && ip_address != uri.hostname - uri = uri.dup - uri.hostname = ip_address - [uri, hostname] + new_uri = uri.dup + new_uri.hostname = ip_address + [new_uri, uri.hostname] end def ip_address(address_info) @@ -110,14 +107,14 @@ module Gitlab validate_unicode_restriction(uri) if ascii_only end - def get_address_info(hostname, port, dns_rebind_protection) - Addrinfo.getaddrinfo(hostname, port, nil, :STREAM).map do |addr| + def get_address_info(uri, dns_rebind_protection) + Addrinfo.getaddrinfo(uri.hostname, get_port(uri), nil, :STREAM).map do |addr| addr.ipv6_v4mapped? ? addr.ipv6_to_ipv4 : addr end rescue SocketError - # If the dns rebinding protection is not enabled, we allow - # urls that can't be resolved at this point. - return unless dns_rebind_protection + # If the dns rebinding protection is not enabled or the domain + # is whitelisted we avoid the dns rebinding checks + return if domain_whitelisted?(uri) || !dns_rebind_protection # In the test suite we use a lot of mocked urls that are either invalid or # don't exist. In order to avoid modifying a ton of tests and factories @@ -131,18 +128,11 @@ module Gitlab end def validate_local_request( - normalized_hostname:, address_info:, allow_localhost:, allow_local_network:) return if allow_local_network && allow_localhost - ip_whitelist, domain_whitelist = - Gitlab::CurrentSettings.outbound_local_requests_whitelist_arrays - - return if local_domain_whitelisted?(domain_whitelist, normalized_hostname) || - local_ip_whitelisted?(ip_whitelist, ip_address(address_info)) - unless allow_localhost validate_localhost(address_info) validate_loopback(address_info) @@ -258,14 +248,12 @@ module Gitlab (uri.port.blank? || uri.port == config.gitlab_shell.ssh_port) end - def local_ip_whitelisted?(ip_whitelist, ip_string) - ip_obj = Gitlab::Utils.string_to_ip_object(ip_string) - - ip_whitelist.any? { |ip| ip.include?(ip_obj) } + def domain_whitelisted?(uri) + Gitlab::UrlBlockers::UrlWhitelist.domain_whitelisted?(uri.normalized_host) end - def local_domain_whitelisted?(domain_whitelist, domain_string) - domain_whitelist.include?(domain_string) + def ip_whitelisted?(ip_address) + Gitlab::UrlBlockers::UrlWhitelist.ip_whitelisted?(ip_address) end def config diff --git a/lib/gitlab/url_blockers/url_whitelist.rb b/lib/gitlab/url_blockers/url_whitelist.rb new file mode 100644 index 00000000000..a0cfcbc49a3 --- /dev/null +++ b/lib/gitlab/url_blockers/url_whitelist.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Gitlab + module UrlBlockers + class UrlWhitelist + class << self + def ip_whitelisted?(ip_string) + return false if ip_string.blank? + + ip_whitelist, _ = outbound_local_requests_whitelist_arrays + ip_obj = Gitlab::Utils.string_to_ip_object(ip_string) + + ip_whitelist.any? { |ip| ip.include?(ip_obj) } + end + + def domain_whitelisted?(domain_string) + return false if domain_string.blank? + + _, domain_whitelist = outbound_local_requests_whitelist_arrays + + domain_whitelist.include?(domain_string) + end + + private + + attr_reader :ip_whitelist, :domain_whitelist + + # We cannot use Gitlab::CurrentSettings as ApplicationSetting itself + # calls this class. This ends up in a cycle where + # Gitlab::CurrentSettings creates an ApplicationSetting which then + # calls this method. + # + # See https://gitlab.com/gitlab-org/gitlab-ee/issues/9833 + def outbound_local_requests_whitelist_arrays + return [[], []] unless ApplicationSetting.current + + ApplicationSetting.current.outbound_local_requests_whitelist_arrays + end + end + end + end +end diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index fb18c7a8554..5cd54c302fc 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -217,3 +217,5 @@ module Gitlab end end end + +Gitlab::UsageData.prepend_if_ee('EE::Gitlab::UsageData') |