gitlab-secret_detection 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23eb987781013adea0ee3eaf3a52f3b7c89e09268a7dfff504d0346efbfeb8e2
4
- data.tar.gz: 9a301fcbdb3b9a2bb76e4dd978a8d574a654a2a65ed4ec3c4f3fd962dfe67c3d
3
+ metadata.gz: b011db6024a9386ec45e091c678b4b4ea43986065f846748f9b646caf2232c86
4
+ data.tar.gz: 9faabaf1da62a2470bc8c569a766f48867b0b59c701076b0c8e3d4fbd6ac7550
5
5
  SHA512:
6
- metadata.gz: 9f2ff05eb818ffeed0a1d1736d59de48822dd8f2d2fb8f56526dd6aa2e36c901eb1592a8372f0999c72c2f8ee6e8fc0b8ac7bf37021f10e2f405aebb2b890a5b
7
- data.tar.gz: 38cdab69b370d7f82784d7e861784cda7a6867341bab08f238ee54aa427c61b5056fced813ab9c9161f8a5b14d8493cc6be29e10779187f76b61980586757b23
6
+ metadata.gz: 7bfb7fcda514e6e5baf4d4aac12208629f9034ffea475d815f95644abf385e3d4983d8640524dd297021e5a441b5b9fd0189b26c2aa8db8e0c38f42d59a0e7fd
7
+ data.tar.gz: 188e1ceb321ed6b92535b704dc962d37d2f4aec6c67ecbddb64316d7ec2503f29975ef416fca3b792613a5a2be1c74fa7175c0f161122e0d5e485423ea4ea7c7
@@ -7,14 +7,18 @@ module Gitlab
7
7
  #
8
8
  # +status+:: One of values from Gitlab::SecretDetection::Core::Status indicating the scan operation's status
9
9
  # +results+:: Array of Gitlab::SecretDetection::Core::Finding values. Default value is nil.
10
- # +metadata+:: Hash object containing additional meta information about the response. It is currently used
11
10
  # to embed more information on error.
11
+ # +applied_exclusions+:: Array of exclusions that were applied during this scan.
12
+ # These can be either GRPC::Exclusions when used as a service, or `Security::ProjectSecurityExclusion
13
+ # object when used as a gem.
14
+ # +metadata+:: Hash object containing additional meta information about the response. It is currently used
12
15
  class Response
13
- attr_reader :status, :results, :metadata
16
+ attr_reader :status, :results, :applied_exclusions, :metadata
14
17
 
15
- def initialize(status, results = [], metadata = {})
18
+ def initialize(status:, results: [], applied_exclusions: [], metadata: {})
16
19
  @status = status
17
20
  @results = results
21
+ @applied_exclusions = applied_exclusions
18
22
  @metadata = metadata
19
23
  end
20
24
 
@@ -25,15 +29,21 @@ module Gitlab
25
29
  def to_h
26
30
  {
27
31
  status:,
28
- metadata:,
29
- results: results&.map(&:to_h)
32
+ results: results&.map(&:to_h),
33
+ applied_exclusions:,
34
+ metadata:
30
35
  }
31
36
  end
32
37
 
33
38
  protected
34
39
 
35
40
  def state
36
- [status, metadata, results]
41
+ [
42
+ status,
43
+ results,
44
+ applied_exclusions,
45
+ metadata
46
+ ]
37
47
  end
38
48
  end
39
49
  end
@@ -32,7 +32,7 @@ module Gitlab
32
32
  rules_data[:rules].freeze
33
33
  rescue StandardError => e
34
34
  logger.error "Failed to parse secret detection ruleset from '#{path}' path: #{e}"
35
- raise Core::Scanner::RulesetParseError
35
+ raise Core::Scanner::RulesetParseError, e
36
36
  end
37
37
  end
38
38
  end
@@ -59,10 +59,13 @@ module Gitlab
59
59
  # +timeout+:: No of seconds(accepts floating point for smaller time values) to limit the total scan duration
60
60
  # +payload_timeout+:: No of seconds(accepts floating point for smaller time values) to limit
61
61
  # the scan duration on each payload
62
- # +raw_value_exclusions:+:: Array of raw values to exclude from the scan.
63
- # +rule_exclusions+:: Array of rules to exclude from the ruleset used for the scan. Each rule is represented
64
- # by its ID. For example: `gitlab_personal_access_token` for representing Gitlab Personal Access
65
- # Token. By default, no rule is excluded from the ruleset.
62
+ # +exclusions+:: Hash with keys: :raw_value, :rule and values of arrays of either
63
+ # GRPC::Exclusion objects (when used as a standalone service)
64
+ # or Security::ProjectSecurityExclusion objects (when used as gem).
65
+ # :raw_value - Exclusions in the :raw array are the raw values to ignore.
66
+ # :rule - Exclusions in the :rule array are the rules to exclude from the ruleset used for the scan.
67
+ # Each rule is represented by its ID. For example: `gitlab_personal_access_token`
68
+ # for representing Gitlab Personal Access Token. By default, no rule is excluded from the ruleset.
66
69
  # +tags+:: Array of tag values to filter from the default ruleset when determining the rules used for the scan.
67
70
  # For example: Add `gitlab_blocking` to include only rules for Push Protection. Defaults to
68
71
  # [`gitlab_blocking`] (+DEFAULT_PATTERN_MATCHER_TAGS+).
@@ -84,13 +87,12 @@ module Gitlab
84
87
  payloads,
85
88
  timeout: DEFAULT_SCAN_TIMEOUT_SECS,
86
89
  payload_timeout: DEFAULT_PAYLOAD_TIMEOUT_SECS,
87
- raw_value_exclusions: [],
88
- rule_exclusions: [],
90
+ exclusions: {},
89
91
  tags: DEFAULT_PATTERN_MATCHER_TAGS,
90
92
  subprocess: RUN_IN_SUBPROCESS
91
93
  )
92
94
 
93
- return Core::Response.new(Core::Status::INPUT_ERROR) unless validate_scan_input(payloads)
95
+ return Core::Response.new(status: Core::Status::INPUT_ERROR) unless validate_scan_input(payloads)
94
96
 
95
97
  # assign defaults since grpc passing zero timeout value to `Timeout.timeout(..)` makes it effectively useless.
96
98
  timeout = DEFAULT_SCAN_TIMEOUT_SECS unless timeout.positive?
@@ -102,24 +104,25 @@ module Gitlab
102
104
 
103
105
  matched_payloads = filter_by_keywords(keyword_matcher, payloads)
104
106
 
105
- next Core::Response.new(Core::Status::NOT_FOUND) if matched_payloads.empty?
107
+ next Core::Response.new(status: Core::Status::NOT_FOUND) if matched_payloads.empty?
106
108
 
107
109
  scan_args = {
108
- payloads: matched_payloads, payload_timeout:,
110
+ payloads: matched_payloads,
111
+ payload_timeout:,
109
112
  pattern_matcher: build_pattern_matcher(tags:),
110
- raw_value_exclusions:, rule_exclusions:
113
+ exclusions:
111
114
  }
112
115
 
113
- secrets = subprocess ? run_scan_within_subprocess(**scan_args) : run_scan(**scan_args)
116
+ secrets, applied_exclusions = subprocess ? run_scan_within_subprocess(**scan_args) : run_scan(**scan_args)
114
117
 
115
118
  scan_status = overall_scan_status(secrets)
116
119
 
117
- Core::Response.new(scan_status, secrets)
120
+ Core::Response.new(status: scan_status, results: secrets, applied_exclusions:)
118
121
  end
119
122
  rescue Timeout::Error => e
120
123
  logger.error "Secret detection operation timed out: #{e}"
121
124
 
122
- Core::Response.new(Core::Status::SCAN_TIMEOUT)
125
+ Core::Response.new(status: Core::Status::SCAN_TIMEOUT)
123
126
  end
124
127
 
125
128
  private
@@ -201,32 +204,46 @@ module Gitlab
201
204
  matched_payloads << payload
202
205
  end
203
206
 
204
- matched_payloads.freeze
207
+ matched_payloads
205
208
  end
206
209
 
207
210
  # Runs the secret detection scan on the given list of payloads. It accepts
208
211
  # literal values to exclude from the input before the scan, also SD rules to exclude during
209
212
  # the scan when performed on the payloads.
210
213
  def run_scan(
211
- payloads:, payload_timeout:, pattern_matcher:, raw_value_exclusions: [], rule_exclusions: [])
212
- payloads.flat_map do |payload|
214
+ payloads:,
215
+ payload_timeout:,
216
+ pattern_matcher:,
217
+ exclusions: {}
218
+ )
219
+ all_applied_exclusions = Set.new
220
+
221
+ all_findings = payloads.flat_map do |payload|
213
222
  Timeout.timeout(payload_timeout) do
214
- find_secrets_in_payload(
223
+ findings, applied_exclusions = find_secrets_in_payload(
215
224
  payload:,
216
225
  pattern_matcher:,
217
- raw_value_exclusions:, rule_exclusions:
226
+ exclusions:
218
227
  )
228
+ all_applied_exclusions.merge(applied_exclusions)
229
+ findings
219
230
  end
220
231
  rescue Timeout::Error => e
221
232
  logger.error "Secret Detection scan timed out on the payload(id:#{payload.id}): #{e}"
233
+
222
234
  Core::Finding.new(payload.id,
223
235
  Core::Status::PAYLOAD_TIMEOUT)
224
236
  end
237
+ [all_findings, all_applied_exclusions.to_a]
225
238
  end
226
239
 
227
240
  def run_scan_within_subprocess(
228
- payloads:, payload_timeout:, pattern_matcher:, raw_value_exclusions: [],
229
- rule_exclusions: [])
241
+ payloads:,
242
+ payload_timeout:,
243
+ pattern_matcher:,
244
+ exclusions: {}
245
+ )
246
+ all_applied_exclusions = Set.new
230
247
  payload_sizes = payloads.map(&:size)
231
248
  grouped_payload_indices = group_by_chunk_size(payload_sizes)
232
249
 
@@ -239,35 +256,43 @@ module Gitlab
239
256
  ) do |grouped_payload|
240
257
  grouped_payload.flat_map do |payload|
241
258
  Timeout.timeout(payload_timeout) do
242
- find_secrets_in_payload(
259
+ findings, applied_exclusions = find_secrets_in_payload(
243
260
  payload:,
244
261
  pattern_matcher:,
245
- raw_value_exclusions:, rule_exclusions:
262
+ exclusions:
246
263
  )
264
+ all_applied_exclusions.merge(applied_exclusions)
265
+ findings
247
266
  end
248
267
  rescue Timeout::Error => e
249
268
  logger.error "Secret Detection scan timed out on the payload(id:#{payload.id}): #{e}"
269
+
250
270
  Core::Finding.new(payload.id, Core::Status::PAYLOAD_TIMEOUT)
251
271
  end
252
272
  end
253
273
 
254
- found_secrets.freeze
274
+ [found_secrets, all_applied_exclusions.to_a]
255
275
  end
256
276
 
257
277
  # Finds secrets in the given payload guarded with a timeout as a circuit breaker. It accepts
258
278
  # literal values to exclude from the input before the scan, also SD rules to exclude during
259
279
  # the scan.
260
- def find_secrets_in_payload(payload:, pattern_matcher:, raw_value_exclusions: [], rule_exclusions: [])
280
+ def find_secrets_in_payload(payload:, pattern_matcher:, exclusions: {})
261
281
  findings = []
282
+ applied_exclusions = Set.new
262
283
 
263
284
  payload_offset = payload.respond_to?(:offset) ? payload.offset : 0
264
285
 
286
+ raw_value_exclusions = exclusions.fetch(:raw_value, [])
287
+ rule_exclusions = exclusions.fetch(:rule, [])
288
+
265
289
  payload.data
266
290
  .each_line($INPUT_RECORD_SEPARATOR, chomp: true)
267
291
  .each_with_index do |line, index|
268
292
  unless raw_value_exclusions.empty?
269
- raw_value_exclusions.each do |value|
270
- line.gsub!(value, '') # replace input that doesn't contain allowed value in it
293
+ raw_value_exclusions.each do |exclusion|
294
+ line.gsub!(exclusion.value, '') # replace input that doesn't contain allowed value in it
295
+ applied_exclusions << exclusion
271
296
  end
272
297
  end
273
298
 
@@ -284,19 +309,30 @@ module Gitlab
284
309
  matches.each do |match_idx|
285
310
  rule = rules[match_idx]
286
311
 
287
- next if rule_exclusions.include?(rule[:id])
312
+ next if applied_rule_exclusion?(rule[:id], rule_exclusions, applied_exclusions)
288
313
 
289
314
  title = rule[:title].nil? ? rule[:description] : rule[:title]
290
- findings << Core::Finding.new(payload.id, Core::Status::FOUND, line_no, rule[:id],
291
- title)
315
+
316
+ findings << Core::Finding.new(
317
+ payload.id,
318
+ Core::Status::FOUND,
319
+ line_no,
320
+ rule[:id],
321
+ title
322
+ )
292
323
  end
293
324
  end
294
325
 
295
- findings.freeze
326
+ [findings, applied_exclusions]
296
327
  rescue StandardError => e
297
328
  logger.error "Secret Detection scan failed on the payload(id:#{payload.id}): #{e}"
298
329
 
299
- Core::Finding.new(payload.id, Core::Status::SCAN_ERROR)
330
+ [[Core::Finding.new(payload.id, Core::Status::SCAN_ERROR)], []]
331
+ end
332
+
333
+ def applied_rule_exclusion?(type, rule_exclusions, applied_exclusions)
334
+ applied_exclusion = rule_exclusions&.find { |rule_exclusion| rule_exclusion.value == type }
335
+ applied_exclusion && (applied_exclusions << applied_exclusion)
300
336
  end
301
337
 
302
338
  # Validates the given payloads by verifying the type and
@@ -17,10 +17,11 @@ module Gitlab
17
17
  # Time to wait for the response from the service
18
18
  REQUEST_TIMEOUT_SECONDS = 10 # 10 seconds
19
19
 
20
- def initialize(host, secure: false, compression: true)
20
+ def initialize(host, secure: false, compression: true, logger: nil)
21
21
  @host = host
22
22
  @secure = secure
23
23
  @compression = compression
24
+ @logger = logger.nil? ? LOGGER : logger
24
25
  end
25
26
 
26
27
  # Triggers Secret Detection service's `/Scan` gRPC endpoint. To keep it consistent with SDS gem interface,
@@ -116,14 +117,18 @@ module Gitlab
116
117
  def with_rescued_errors
117
118
  yield
118
119
  rescue ::GRPC::Unauthenticated
119
- SecretDetection::Core::Response.new(SecretDetection::Core::Status::AUTH_ERROR)
120
+ SecretDetection::Core::Response.new(status: SecretDetection::Core::Status::AUTH_ERROR)
120
121
  rescue ::GRPC::InvalidArgument => e
121
122
  SecretDetection::Core::Response.new(
122
- SecretDetection::Core::Status::INPUT_ERROR, nil, { message: e.details, **e.metadata }
123
+ status: SecretDetection::Core::Status::INPUT_ERROR,
124
+ results: nil,
125
+ metadata: { message: e.details, **e.metadata }
123
126
  )
124
127
  rescue ::GRPC::Unknown, ::GRPC::BadStatus => e
125
128
  SecretDetection::Core::Response.new(
126
- SecretDetection::Core::Status::SCAN_ERROR, nil, { message: e.details }
129
+ status: SecretDetection::Core::Status::SCAN_ERROR,
130
+ results: nil,
131
+ metadata: { message: e.details }
127
132
  )
128
133
  end
129
134
 
@@ -131,13 +136,13 @@ module Gitlab
131
136
  response = grpc_response.to_h
132
137
 
133
138
  SecretDetection::Core::Response.new(
134
- response[:status],
135
- response[:results],
136
- response[:metadata]
139
+ status: response[:status],
140
+ results: response[:results],
141
+ metadata: response[:metadata]
137
142
  )
138
143
  rescue StandardError => e
139
- logger.error("Failed to convert to core response: #{e}")
140
- SecretDetection::Core::Response.new(SecretDetection::Core::Status::SCAN_ERROR)
144
+ @logger.error("Failed to convert to core response: #{e}")
145
+ SecretDetection::Core::Response.new(status: SecretDetection::Core::Status::SCAN_ERROR)
141
146
  end
142
147
  end
143
148
  end
@@ -5,7 +5,7 @@
5
5
  require 'google/protobuf'
6
6
 
7
7
 
8
- descriptor_data = "\n\x16secret_detection.proto\x12\x17gitlab.secret_detection\"Z\n\tExclusion\x12>\n\x0e\x65xclusion_type\x18\x01 \x01(\x0e\x32&.gitlab.secret_detection.ExclusionType\x12\r\n\x05value\x18\x02 \x01(\t\"\xc0\x02\n\x0bScanRequest\x12>\n\x08payloads\x18\x01 \x03(\x0b\x32,.gitlab.secret_detection.ScanRequest.Payload\x12\x19\n\x0ctimeout_secs\x18\x02 \x01(\x02H\x00\x88\x01\x01\x12!\n\x14payload_timeout_secs\x18\x03 \x01(\x02H\x01\x88\x01\x01\x12\x36\n\nexclusions\x18\x04 \x03(\x0b\x32\".gitlab.secret_detection.Exclusion\x12\x0c\n\x04tags\x18\x05 \x03(\t\x1a\x43\n\x07Payload\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\t\x12\x13\n\x06offset\x18\x03 \x01(\x05H\x00\x88\x01\x01\x42\t\n\x07_offsetB\x0f\n\r_timeout_secsB\x17\n\x15_payload_timeout_secs\"\xa2\x04\n\x0cScanResponse\x12>\n\x07results\x18\x01 \x03(\x0b\x32-.gitlab.secret_detection.ScanResponse.Finding\x12\x0e\n\x06status\x18\x02 \x01(\x05\x12>\n\x12\x61pplied_exclusions\x18\x03 \x03(\x0b\x32\".gitlab.secret_detection.Exclusion\x1a\x9d\x01\n\x07\x46inding\x12\x12\n\npayload_id\x18\x01 \x01(\t\x12\x0e\n\x06status\x18\x02 \x01(\x05\x12\x11\n\x04type\x18\x03 \x01(\tH\x00\x88\x01\x01\x12\x18\n\x0b\x64\x65scription\x18\x04 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bline_number\x18\x05 \x01(\x05H\x02\x88\x01\x01\x42\x07\n\x05_typeB\x0e\n\x0c_descriptionB\x0e\n\x0c_line_number\"\xe1\x01\n\x06Status\x12\x16\n\x12STATUS_UNSPECIFIED\x10\x00\x12\x10\n\x0cSTATUS_FOUND\x10\x01\x12\x1c\n\x18STATUS_FOUND_WITH_ERRORS\x10\x02\x12\x17\n\x13STATUS_SCAN_TIMEOUT\x10\x03\x12\x1a\n\x16STATUS_PAYLOAD_TIMEOUT\x10\x04\x12\x15\n\x11STATUS_SCAN_ERROR\x10\x05\x12\x16\n\x12STATUS_INPUT_ERROR\x10\x06\x12\x14\n\x10STATUS_NOT_FOUND\x10\x07\x12\x15\n\x11STATUS_AUTH_ERROR\x10\x08*f\n\rExclusionType\x12\x1e\n\x1a\x45XCLUSION_TYPE_UNSPECIFIED\x10\x00\x12\x17\n\x13\x45XCLUSION_TYPE_RULE\x10\x01\x12\x1c\n\x18\x45XCLUSION_TYPE_RAW_VALUE\x10\x02\x32\xc1\x01\n\x07Scanner\x12U\n\x04Scan\x12$.gitlab.secret_detection.ScanRequest\x1a%.gitlab.secret_detection.ScanResponse\"\x00\x12_\n\nScanStream\x12$.gitlab.secret_detection.ScanRequest\x1a%.gitlab.secret_detection.ScanResponse\"\x00(\x01\x30\x01\x42 \xea\x02\x1dGitlab::SecretDetection::GRPCb\x06proto3"
8
+ descriptor_data = "\n\x16secret_detection.proto\x12\x17gitlab.secret_detection\"Z\n\tExclusion\x12>\n\x0e\x65xclusion_type\x18\x01 \x01(\x0e\x32&.gitlab.secret_detection.ExclusionType\x12\r\n\x05value\x18\x02 \x01(\t\"\xc0\x02\n\x0bScanRequest\x12>\n\x08payloads\x18\x01 \x03(\x0b\x32,.gitlab.secret_detection.ScanRequest.Payload\x12\x19\n\x0ctimeout_secs\x18\x02 \x01(\x02H\x00\x88\x01\x01\x12!\n\x14payload_timeout_secs\x18\x03 \x01(\x02H\x01\x88\x01\x01\x12\x36\n\nexclusions\x18\x04 \x03(\x0b\x32\".gitlab.secret_detection.Exclusion\x12\x0c\n\x04tags\x18\x05 \x03(\t\x1a\x43\n\x07Payload\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\t\x12\x13\n\x06offset\x18\x03 \x01(\x05H\x00\x88\x01\x01\x42\t\n\x07_offsetB\x0f\n\r_timeout_secsB\x17\n\x15_payload_timeout_secs\"\xa2\x04\n\x0cScanResponse\x12>\n\x07results\x18\x01 \x03(\x0b\x32-.gitlab.secret_detection.ScanResponse.Finding\x12\x0e\n\x06status\x18\x02 \x01(\x05\x12>\n\x12\x61pplied_exclusions\x18\x03 \x03(\x0b\x32\".gitlab.secret_detection.Exclusion\x1a\x9d\x01\n\x07\x46inding\x12\x12\n\npayload_id\x18\x01 \x01(\t\x12\x0e\n\x06status\x18\x02 \x01(\x05\x12\x11\n\x04type\x18\x03 \x01(\tH\x00\x88\x01\x01\x12\x18\n\x0b\x64\x65scription\x18\x04 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0bline_number\x18\x05 \x01(\x05H\x02\x88\x01\x01\x42\x07\n\x05_typeB\x0e\n\x0c_descriptionB\x0e\n\x0c_line_number\"\xe1\x01\n\x06Status\x12\x16\n\x12STATUS_UNSPECIFIED\x10\x00\x12\x10\n\x0cSTATUS_FOUND\x10\x01\x12\x1c\n\x18STATUS_FOUND_WITH_ERRORS\x10\x02\x12\x17\n\x13STATUS_SCAN_TIMEOUT\x10\x03\x12\x1a\n\x16STATUS_PAYLOAD_TIMEOUT\x10\x04\x12\x15\n\x11STATUS_SCAN_ERROR\x10\x05\x12\x16\n\x12STATUS_INPUT_ERROR\x10\x06\x12\x14\n\x10STATUS_NOT_FOUND\x10\x07\x12\x15\n\x11STATUS_AUTH_ERROR\x10\x08*\x7f\n\rExclusionType\x12\x1e\n\x1a\x45XCLUSION_TYPE_UNSPECIFIED\x10\x00\x12\x17\n\x13\x45XCLUSION_TYPE_RULE\x10\x01\x12\x1c\n\x18\x45XCLUSION_TYPE_RAW_VALUE\x10\x02\x12\x17\n\x13\x45XCLUSION_TYPE_PATH\x10\x03\x32\xc1\x01\n\x07Scanner\x12U\n\x04Scan\x12$.gitlab.secret_detection.ScanRequest\x1a%.gitlab.secret_detection.ScanResponse\"\x00\x12_\n\nScanStream\x12$.gitlab.secret_detection.ScanRequest\x1a%.gitlab.secret_detection.ScanResponse\"\x00(\x01\x30\x01\x42 \xea\x02\x1dGitlab::SecretDetection::GRPCb\x06proto3"
9
9
 
10
10
  pool = Google::Protobuf::DescriptorPool.generated_pool
11
11
  pool.add_serialized_file(descriptor_data)
@@ -61,24 +61,25 @@ module Gitlab
61
61
  validate_request(request)
62
62
 
63
63
  payloads = request.payloads.to_a
64
+ exclusions = { raw_value: [], rule: [], path: [] }
64
65
 
65
- raw_value_exclusions = []
66
- rule_exclusions = []
67
-
68
- request.exclusions&.each do |exclusion|
69
- case exclusion.type
66
+ request.exclusions.each do |exclusion|
67
+ case exclusion.exclusion_type
70
68
  when :EXCLUSION_TYPE_RAW_VALUE
71
- raw_value_exclusions << exclusion.value
69
+ exclusions[:raw] << exclusion
72
70
  when :EXCLUSION_TYPE_RULE
73
- rule_exclusions << exclusion.value
71
+ exclusions[:rule] << exclusion
72
+ when :EXCLUSION_TYPE_PATH
73
+ exclusions[:path] << exclusion
74
+ else
75
+ logger.warn("Unknown exclusion type #{exclusion.exclusion_type}")
74
76
  end
75
77
  end
76
78
 
77
79
  begin
78
80
  result = scanner.secrets_scan(
79
81
  payloads,
80
- raw_value_exclusions:,
81
- rule_exclusions:,
82
+ exclusions:,
82
83
  tags: request.tags.to_a,
83
84
  timeout: request.timeout_secs,
84
85
  payload_timeout: request.payload_timeout_secs
@@ -94,7 +95,8 @@ module Gitlab
94
95
 
95
96
  Gitlab::SecretDetection::GRPC::ScanResponse.new(
96
97
  results: findings,
97
- status: result.status
98
+ status: result.status,
99
+ applied_exclusions: result.applied_exclusions
98
100
  )
99
101
  end
100
102
 
@@ -17,6 +17,7 @@ enum ExclusionType {
17
17
  EXCLUSION_TYPE_UNSPECIFIED = 0;
18
18
  EXCLUSION_TYPE_RULE = 1; // Rule ID to exclude
19
19
  EXCLUSION_TYPE_RAW_VALUE = 2; // Raw value to exclude
20
+ EXCLUSION_TYPE_PATH = 3; // Specific file path to exclude
20
21
  }
21
22
 
22
23
  /* Request arg for triggering Scan/ScanStream method */
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-secret_detection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - group::secret detection
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-12-11 00:00:00.000000000 Z
13
+ date: 2024-12-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grpc