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.
- checksums.yaml +4 -4
- data/README.md +33 -25
- data/lib/gitlab/secret_detection/core/ruleset.rb +30 -3
- data/lib/gitlab/secret_detection/core/scanner.rb +214 -42
- data/lib/gitlab/secret_detection/core/secret_push_protection_rules.toml +11 -48
- data/lib/gitlab/secret_detection/core/status.rb +34 -0
- data/lib/gitlab/secret_detection/grpc/client/grpc_client.rb +42 -16
- data/lib/gitlab/secret_detection/grpc/generated/secret_detection_pb.rb +1 -1
- data/lib/gitlab/secret_detection/grpc/integrated_error_tracking.rb +64 -0
- data/lib/gitlab/secret_detection/grpc/scanner_service.rb +24 -7
- data/lib/gitlab/secret_detection/grpc.rb +1 -0
- data/lib/gitlab/secret_detection/utils/masker.rb +43 -0
- data/lib/gitlab/secret_detection/utils.rb +1 -0
- data/lib/gitlab/secret_detection/version.rb +2 -5
- data/proto/secret_detection.proto +2 -0
- metadata +32 -2
@@ -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,
|
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,
|
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[:
|
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:
|
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
|
|
@@ -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
|
@@ -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
|
-
|
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.
|
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-
|
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
|