summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/config')
-rw-r--r--lib/gitlab/ci/config/entry/processable.rb2
-rw-r--r--lib/gitlab/ci/config/external/context.rb12
-rw-r--r--lib/gitlab/ci/config/external/file/artifact.rb16
-rw-r--r--lib/gitlab/ci/config/external/file/base.rb33
-rw-r--r--lib/gitlab/ci/config/external/file/local.rb8
-rw-r--r--lib/gitlab/ci/config/external/file/project.rb28
-rw-r--r--lib/gitlab/ci/config/external/file/remote.rb8
-rw-r--r--lib/gitlab/ci/config/external/file/template.rb8
-rw-r--r--lib/gitlab/ci/config/external/mapper.rb34
9 files changed, 109 insertions, 40 deletions
diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb
index 43475742214..46afedbcc3a 100644
--- a/lib/gitlab/ci/config/entry/processable.rb
+++ b/lib/gitlab/ci/config/entry/processable.rb
@@ -23,7 +23,7 @@ module Gitlab
validates :config, presence: true
validates :name, presence: true
validates :name, type: Symbol
- validates :name, length: { maximum: 255 }, if: -> { ::Feature.enabled?(:ci_validate_job_length, default_enabled: :yaml) }
+ validates :name, length: { maximum: 255 }
validates :config, disallowed_keys: {
in: %i[only except start_in],
diff --git a/lib/gitlab/ci/config/external/context.rb b/lib/gitlab/ci/config/external/context.rb
index 512cfdde474..2def565bc19 100644
--- a/lib/gitlab/ci/config/external/context.rb
+++ b/lib/gitlab/ci/config/external/context.rb
@@ -70,16 +70,20 @@ module Gitlab
}
end
- def mask_variables_from(location)
- variables.reduce(location.dup) do |loc, variable|
+ def mask_variables_from(string)
+ variables.reduce(string.dup) do |str, variable|
if variable[:masked]
- Gitlab::Ci::MaskSecret.mask!(loc, variable[:value])
+ Gitlab::Ci::MaskSecret.mask!(str, variable[:value])
else
- loc
+ str
end
end
end
+ def includes
+ expandset.map(&:metadata)
+ end
+
protected
attr_writer :expandset, :execution_deadline, :logger
diff --git a/lib/gitlab/ci/config/external/file/artifact.rb b/lib/gitlab/ci/config/external/file/artifact.rb
index 4f79e64ca9a..1244c7f7475 100644
--- a/lib/gitlab/ci/config/external/file/artifact.rb
+++ b/lib/gitlab/ci/config/external/file/artifact.rb
@@ -28,6 +28,14 @@ module Gitlab
end
end
+ def metadata
+ super.merge(
+ type: :artifact,
+ location: masked_location,
+ extra: { job_name: masked_job_name }
+ )
+ end
+
private
def project
@@ -52,7 +60,7 @@ module Gitlab
end
unless artifact_job.present?
- errors.push("Job `#{job_name}` not found in parent pipeline or does not have artifacts!")
+ errors.push("Job `#{masked_job_name}` not found in parent pipeline or does not have artifacts!")
return false
end
@@ -80,6 +88,12 @@ module Gitlab
parent_pipeline: context.parent_pipeline
}
end
+
+ def masked_job_name
+ strong_memoize(:masked_job_name) do
+ context.mask_variables_from(job_name)
+ end
+ end
end
end
end
diff --git a/lib/gitlab/ci/config/external/file/base.rb b/lib/gitlab/ci/config/external/file/base.rb
index a660dd339d8..89da0796906 100644
--- a/lib/gitlab/ci/config/external/file/base.rb
+++ b/lib/gitlab/ci/config/external/file/base.rb
@@ -16,8 +16,6 @@ module Gitlab
@params = params
@context = context
@errors = []
-
- validate!
end
def matching?
@@ -48,6 +46,30 @@ module Gitlab
expanded_content_hash
end
+ def validate!
+ context.logger.instrument(:config_file_validation) do
+ validate_execution_time!
+ validate_location!
+ validate_content! if errors.none?
+ validate_hash! if errors.none?
+ end
+ end
+
+ def metadata
+ {
+ context_project: context.project&.full_path,
+ context_sha: context.sha
+ }
+ end
+
+ def eql?(other)
+ other.hash == hash
+ end
+
+ def hash
+ [params, context.project&.full_path, context.sha].hash
+ end
+
protected
def expanded_content_hash
@@ -66,13 +88,6 @@ module Gitlab
nil
end
- def validate!
- validate_execution_time!
- validate_location!
- validate_content! if errors.none?
- validate_hash! if errors.none?
- end
-
def validate_execution_time!
context.check_execution_time!
end
diff --git a/lib/gitlab/ci/config/external/file/local.rb b/lib/gitlab/ci/config/external/file/local.rb
index 3aa665c7d18..ee9cc1552fe 100644
--- a/lib/gitlab/ci/config/external/file/local.rb
+++ b/lib/gitlab/ci/config/external/file/local.rb
@@ -19,6 +19,14 @@ module Gitlab
strong_memoize(:content) { fetch_local_content }
end
+ def metadata
+ super.merge(
+ type: :local,
+ location: masked_location,
+ extra: {}
+ )
+ end
+
private
def validate_content!
diff --git a/lib/gitlab/ci/config/external/file/project.rb b/lib/gitlab/ci/config/external/file/project.rb
index 27e097ba980..3d4436530a8 100644
--- a/lib/gitlab/ci/config/external/file/project.rb
+++ b/lib/gitlab/ci/config/external/file/project.rb
@@ -27,17 +27,25 @@ module Gitlab
strong_memoize(:content) { fetch_local_content }
end
+ def metadata
+ super.merge(
+ type: :file,
+ location: masked_location,
+ extra: { project: masked_project_name, ref: masked_ref_name }
+ )
+ end
+
private
def validate_content!
if !can_access_local_content?
- errors.push("Project `#{project_name}` not found or access denied!")
+ errors.push("Project `#{masked_project_name}` not found or access denied! Make sure any includes in the pipeline configuration are correctly defined.")
elsif sha.nil?
- errors.push("Project `#{project_name}` reference `#{ref_name}` does not exist!")
+ errors.push("Project `#{masked_project_name}` reference `#{masked_ref_name}` does not exist!")
elsif content.nil?
- errors.push("Project `#{project_name}` file `#{masked_location}` does not exist!")
+ errors.push("Project `#{masked_project_name}` file `#{masked_location}` does not exist!")
elsif content.blank?
- errors.push("Project `#{project_name}` file `#{masked_location}` is empty!")
+ errors.push("Project `#{masked_project_name}` file `#{masked_location}` is empty!")
end
end
@@ -76,6 +84,18 @@ module Gitlab
variables: context.variables
}
end
+
+ def masked_project_name
+ strong_memoize(:masked_project_name) do
+ context.mask_variables_from(project_name)
+ end
+ end
+
+ def masked_ref_name
+ strong_memoize(:masked_ref_name) do
+ context.mask_variables_from(ref_name)
+ end
+ end
end
end
end
diff --git a/lib/gitlab/ci/config/external/file/remote.rb b/lib/gitlab/ci/config/external/file/remote.rb
index 8335a9ef625..e7b007b4d8d 100644
--- a/lib/gitlab/ci/config/external/file/remote.rb
+++ b/lib/gitlab/ci/config/external/file/remote.rb
@@ -18,6 +18,14 @@ module Gitlab
strong_memoize(:content) { fetch_remote_content }
end
+ def metadata
+ super.merge(
+ type: :remote,
+ location: masked_location,
+ extra: {}
+ )
+ end
+
private
def validate_location!
diff --git a/lib/gitlab/ci/config/external/file/template.rb b/lib/gitlab/ci/config/external/file/template.rb
index c3d120dfdce..9469f09ce13 100644
--- a/lib/gitlab/ci/config/external/file/template.rb
+++ b/lib/gitlab/ci/config/external/file/template.rb
@@ -20,6 +20,14 @@ module Gitlab
strong_memoize(:content) { fetch_template_content }
end
+ def metadata
+ super.merge(
+ type: :template,
+ location: masked_location,
+ extra: {}
+ )
+ end
+
private
def validate_location!
diff --git a/lib/gitlab/ci/config/external/mapper.rb b/lib/gitlab/ci/config/external/mapper.rb
index 79a04ad409e..c1250c82750 100644
--- a/lib/gitlab/ci/config/external/mapper.rb
+++ b/lib/gitlab/ci/config/external/mapper.rb
@@ -48,8 +48,8 @@ module Gitlab
.flat_map(&method(:expand_project_files))
.flat_map(&method(:expand_wildcard_paths))
.map(&method(:expand_variables))
- .each(&method(:verify_duplicates!))
.map(&method(:select_first_matching))
+ .each(&method(:verify!))
end
def normalize_location(location)
@@ -111,26 +111,6 @@ module Gitlab
end
end
- def verify_duplicates!(location)
- logger.instrument(:config_mapper_verify) do
- verify_max_includes_and_add_location!(location)
- end
- end
-
- def verify_max_includes_and_add_location!(location)
- if expandset.count >= MAX_INCLUDES
- raise TooManyIncludesError, "Maximum of #{MAX_INCLUDES} nested includes are allowed!"
- end
-
- # Scope location to context to allow support of
- # relative includes
- scoped_location = location.merge(
- context_project: context.project,
- context_sha: context.sha)
-
- expandset.add(scoped_location)
- end
-
def select_first_matching(location)
logger.instrument(:config_mapper_select) do
select_first_matching_without_instrumentation(location)
@@ -147,6 +127,18 @@ module Gitlab
matching.first
end
+ def verify!(location_object)
+ verify_max_includes!
+ location_object.validate!
+ expandset.add(location_object)
+ end
+
+ def verify_max_includes!
+ if expandset.count >= MAX_INCLUDES
+ raise TooManyIncludesError, "Maximum of #{MAX_INCLUDES} nested includes are allowed!"
+ end
+ end
+
def expand_variables(data)
logger.instrument(:config_mapper_variables) do
expand_variables_without_instrumentation(data)