gitlab-secret_detection 0.19.0 → 0.21.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.
@@ -32,6 +32,7 @@ module Gitlab
32
32
  module GRPC
33
33
  class ScannerService < Scanner::Service
34
34
  include SDLogger
35
+ include IntegratedErrorTracking
35
36
 
36
37
  # Maximum timeout value that can be given as the input. This guards
37
38
  # against the misuse of timeouts.
@@ -45,19 +46,34 @@ module Gitlab
45
46
  }.freeze
46
47
 
47
48
  # Implementation for /Scan RPC method
48
- def scan(request, _call)
49
- scan_request_action(request)
49
+ def scan(request, call)
50
+ scan_request_action(request, call)
50
51
  end
51
52
 
52
53
  # Implementation for /ScanStream RPC method
53
- def scan_stream(requests, _call)
54
- request_action = ->(r) { scan_request_action(r) }
54
+ def scan_stream(requests, call)
55
+ request_action = ->(r) { scan_request_action(r, call) }
55
56
  StreamEnumerator.new(requests, request_action).each_item
56
57
  end
57
58
 
58
59
  private
59
60
 
60
- def scan_request_action(request)
61
+ def scan_request_action(request, call)
62
+ if request.nil?
63
+ logger.error(
64
+ message: "FATAL: Secret Detection gRPC scan request is `nil`",
65
+ deadline: call.deadline,
66
+ cancelled: call.cancelled?
67
+ )
68
+ return Gitlab::SecretDetection::GRPC::ScanResponse.new(
69
+ results: [],
70
+ status: Gitlab::SecretDetection::GRPC::ScanResponse::Status::STATUS_INPUT_ERROR,
71
+ applied_exclusions: []
72
+ )
73
+ end
74
+
75
+ logger.info(message: "Secret Detection gRPC scan request received")
76
+
61
77
  validate_request(request)
62
78
 
63
79
  payloads = request.payloads.to_a
@@ -66,7 +82,7 @@ module Gitlab
66
82
  request.exclusions.each do |exclusion|
67
83
  case exclusion.exclusion_type
68
84
  when :EXCLUSION_TYPE_RAW_VALUE
69
- exclusions[:raw] << exclusion
85
+ exclusions[:raw_value] << exclusion
70
86
  when :EXCLUSION_TYPE_RULE
71
87
  exclusions[:rule] << exclusion
72
88
  when :EXCLUSION_TYPE_PATH
@@ -85,7 +101,8 @@ module Gitlab
85
101
  payload_timeout: request.payload_timeout_secs
86
102
  )
87
103
  rescue StandardError => e
88
- logger.error("Failed to run the scan: #{e}")
104
+ logger.error(message: "Failed to run the secret detection scan", exception: e.message)
105
+ track_exception(e)
89
106
  raise ::GRPC::Unknown, e.message
90
107
  end
91
108
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'grpc/integrated_error_tracking'
3
4
  require_relative 'grpc/scanner_service'
4
5
  require_relative 'grpc/client/stream_request_enumerator'
5
6
  require_relative 'grpc/client/grpc_client'
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module SecretDetection
5
+ module Utils
6
+ class Masker
7
+ DEFAULT_VISIBLE_CHAR_COUNT = 3
8
+ DEFAULT_MASK_CHAR_COUNT = 5
9
+ DEFAULT_MASK_CHAR = '*'
10
+
11
+ class << self
12
+ def mask_secret(
13
+ raw_secret_value,
14
+ mask_char: DEFAULT_MASK_CHAR,
15
+ visible_chars_count: DEFAULT_VISIBLE_CHAR_COUNT,
16
+ mask_chars_count: DEFAULT_MASK_CHAR_COUNT
17
+ )
18
+ return '' if raw_secret_value.nil? || raw_secret_value.empty?
19
+ return raw_secret_value if raw_secret_value.length <= visible_chars_count # Too short to mask
20
+
21
+ chars = raw_secret_value.chars
22
+ position = 0
23
+
24
+ while position < chars.length
25
+ # Show 'visible_chars_count' characters
26
+ position += visible_chars_count
27
+
28
+ # Mask next 'mask_chars' characters if available
29
+ mask_chars_count.times do
30
+ break if position >= chars.length
31
+
32
+ chars[position] = mask_char
33
+ position += 1
34
+ end
35
+ end
36
+
37
+ chars.join
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'utils/certificate'
4
4
  require_relative 'utils/memoize'
5
+ require_relative 'utils/masker'
5
6
 
6
7
  module Gitlab
7
8
  module SecretDetection
@@ -3,12 +3,9 @@
3
3
  module Gitlab
4
4
  module SecretDetection
5
5
  class Gem
6
- # TODO: This is a temporary fix to avoid runtime issues
7
- # More details are available here:
8
- # https://gitlab.com/gitlab-org/gitlab/-/issues/514015
9
- #
10
6
  # Ensure to maintain the same version in CHANGELOG file.
11
- VERSION = "0.19.0"
7
+ # More details available under 'Release Process' section in the README.md file.
8
+ VERSION = "0.21.0"
12
9
 
13
10
  # SD_ENV env var is used to determine which environment the
14
11
  # server is running. This var is defined in `.runway/env-<env>.yml` files.
@@ -18,6 +18,7 @@ enum ExclusionType {
18
18
  EXCLUSION_TYPE_RULE = 1; // Rule ID to exclude
19
19
  EXCLUSION_TYPE_RAW_VALUE = 2; // Raw value to exclude
20
20
  EXCLUSION_TYPE_PATH = 3; // Specific file path to exclude
21
+ EXCLUSION_TYPE_REGEX_PATTERN = 4; // Regular expression to exclude
21
22
  }
22
23
 
23
24
  /* Request arg for triggering Scan/ScanStream method */
@@ -40,6 +41,7 @@ message ScanRequest {
40
41
  }
41
42
 
42
43
  /* Response from Scan/ScanStream method */
44
+ /* Any changes to these definitions must be matched by changes in the Core classes that correspond to them */
43
45
  message ScanResponse {
44
46
  // Represents a secret finding identified within a payload
45
47
  message Finding {
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.19.0
4
+ version: 0.21.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: 2025-02-13 00:00:00.000000000 Z
13
+ date: 2025-03-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grpc
@@ -82,6 +82,34 @@ dependencies:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
84
  version: '2.7'
85
+ - !ruby/object:Gem::Dependency
86
+ name: sentry-ruby
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '5.22'
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '5.22'
99
+ - !ruby/object:Gem::Dependency
100
+ name: stackprof
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: 0.2.27
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: 0.2.27
85
113
  - !ruby/object:Gem::Dependency
86
114
  name: toml-rb
87
115
  requirement: !ruby/object:Gem::Requirement
@@ -124,9 +152,11 @@ files:
124
152
  - lib/gitlab/secret_detection/grpc/generated/.gitkeep
125
153
  - lib/gitlab/secret_detection/grpc/generated/secret_detection_pb.rb
126
154
  - lib/gitlab/secret_detection/grpc/generated/secret_detection_services_pb.rb
155
+ - lib/gitlab/secret_detection/grpc/integrated_error_tracking.rb
127
156
  - lib/gitlab/secret_detection/grpc/scanner_service.rb
128
157
  - lib/gitlab/secret_detection/utils.rb
129
158
  - lib/gitlab/secret_detection/utils/certificate.rb
159
+ - lib/gitlab/secret_detection/utils/masker.rb
130
160
  - lib/gitlab/secret_detection/utils/memoize.rb
131
161
  - lib/gitlab/secret_detection/version.rb
132
162
  - proto/secret_detection.proto