gitlab-secret_detection 0.19.1 → 0.20.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/lib/gitlab/secret_detection/core/ruleset.rb +17 -9
- data/lib/gitlab/secret_detection/core/scanner.rb +3 -12
- data/lib/gitlab/secret_detection/grpc/integrated_error_tracking.rb +64 -0
- data/lib/gitlab/secret_detection/grpc/scanner_service.rb +3 -2
- data/lib/gitlab/secret_detection/grpc.rb +1 -0
- data/lib/gitlab/secret_detection/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cd95dc817999bb641642ef12f37c72cdf877e417caf728752e5d61cbae1bcd2
|
4
|
+
data.tar.gz: 42d9ce659069690870f07310bc35d8e41aab5accc23f2d8a5eac094bac9e6bbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed2fc3c749afe3be21fe16d1f05fd1d16511dd20a7bd77594b707bd99248ee96ed3c2fafc2e0ade16cbad99f7265ea0b8941d3021547b4c4d9f4363bfad31965
|
7
|
+
data.tar.gz: f2a8d9e25d2ccf3a1f35afa23dffd01a21871d895f9bd0f7a4daffd430391067eabe305db230a575cdda41975eb926fa8c50a84914ab3d26b33d2703e58f597a
|
@@ -7,6 +7,14 @@ module Gitlab
|
|
7
7
|
module SecretDetection
|
8
8
|
module Core
|
9
9
|
class Ruleset
|
10
|
+
# RulesetParseError is thrown when the code fails to parse the
|
11
|
+
# ruleset file from the given path
|
12
|
+
RulesetParseError = Class.new(StandardError)
|
13
|
+
|
14
|
+
# RulesetCompilationError is thrown when the code fails to compile
|
15
|
+
# the predefined rulesets
|
16
|
+
RulesetCompilationError = Class.new(StandardError)
|
17
|
+
|
10
18
|
# file path where the secrets ruleset file is located
|
11
19
|
RULESET_FILE_PATH = File.expand_path('secret_push_protection_rules.toml', __dir__)
|
12
20
|
|
@@ -21,6 +29,15 @@ module Gitlab
|
|
21
29
|
@rule_data = parse_ruleset
|
22
30
|
end
|
23
31
|
|
32
|
+
def extract_ruleset_version
|
33
|
+
@ruleset_version ||= if File.readable?(RULESET_FILE_PATH)
|
34
|
+
first_line = File.open(RULESET_FILE_PATH, &:gets)
|
35
|
+
first_line&.split(":")&.[](1)&.strip
|
36
|
+
end
|
37
|
+
rescue StandardError => e
|
38
|
+
logger.error(message: "Failed to extract Secret Detection Ruleset version from ruleset file: #{e.message}")
|
39
|
+
end
|
40
|
+
|
24
41
|
private
|
25
42
|
|
26
43
|
attr_reader :path, :logger
|
@@ -44,15 +61,6 @@ module Gitlab
|
|
44
61
|
logger.error(message: "Failed to parse local secret detection ruleset: #{e.message}")
|
45
62
|
raise Core::Scanner::RulesetParseError, e
|
46
63
|
end
|
47
|
-
|
48
|
-
def extract_ruleset_version
|
49
|
-
@ruleset_version ||= if File.readable?(RULESET_FILE_PATH)
|
50
|
-
first_line = File.open(RULESET_FILE_PATH, &:gets)
|
51
|
-
first_line&.split(":")&.[](1)&.strip
|
52
|
-
end
|
53
|
-
rescue StandardError => e
|
54
|
-
logger.error(message: "Failed to extract Secret Detection Ruleset version from ruleset file: #{e.message}")
|
55
|
-
end
|
56
64
|
end
|
57
65
|
end
|
58
66
|
end
|
@@ -11,14 +11,6 @@ module Gitlab
|
|
11
11
|
module Core
|
12
12
|
# Scan is responsible for running Secret Detection scan operation
|
13
13
|
class Scanner
|
14
|
-
# RulesetParseError is thrown when the code fails to parse the
|
15
|
-
# ruleset file from the given path
|
16
|
-
RulesetParseError = Class.new(StandardError)
|
17
|
-
|
18
|
-
# RulesetCompilationError is thrown when the code fails to compile
|
19
|
-
# the predefined rulesets
|
20
|
-
RulesetCompilationError = Class.new(StandardError)
|
21
|
-
|
22
14
|
# default time limit(in seconds) for running the scan operation per invocation
|
23
15
|
DEFAULT_SCAN_TIMEOUT_SECS = 180 # 3 minutes
|
24
16
|
# default time limit(in seconds) for running the scan operation on a single payload
|
@@ -91,7 +83,6 @@ module Gitlab
|
|
91
83
|
tags: DEFAULT_PATTERN_MATCHER_TAGS,
|
92
84
|
subprocess: RUN_IN_SUBPROCESS
|
93
85
|
)
|
94
|
-
|
95
86
|
return Core::Response.new(status: Core::Status::INPUT_ERROR) unless validate_scan_input(payloads)
|
96
87
|
|
97
88
|
# assign defaults since grpc passing zero timeout value to `Timeout.timeout(..)` makes it effectively useless.
|
@@ -184,7 +175,7 @@ module Gitlab
|
|
184
175
|
unless matcher.compile
|
185
176
|
logger.error "Failed to compile secret detection ruleset in RE::Set"
|
186
177
|
|
187
|
-
raise RulesetCompilationError
|
178
|
+
raise Core::Ruleset::RulesetCompilationError
|
188
179
|
end
|
189
180
|
|
190
181
|
matcher
|
@@ -300,7 +291,7 @@ module Gitlab
|
|
300
291
|
findings
|
301
292
|
end
|
302
293
|
rescue Timeout::Error => e
|
303
|
-
logger.
|
294
|
+
logger.warn "Secret Detection scan timed out on the payload(id:#{payload.id}): #{e}"
|
304
295
|
|
305
296
|
Core::Finding.new(payload.id,
|
306
297
|
Core::Status::PAYLOAD_TIMEOUT)
|
@@ -342,7 +333,7 @@ module Gitlab
|
|
342
333
|
findings
|
343
334
|
end
|
344
335
|
rescue Timeout::Error => e
|
345
|
-
logger.
|
336
|
+
logger.warn "Secret Detection scan timed out on the payload(id:#{payload.id}): #{e}"
|
346
337
|
|
347
338
|
Core::Finding.new(payload.id, Core::Status::PAYLOAD_TIMEOUT)
|
348
339
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sentry-ruby'
|
4
|
+
|
5
|
+
require_relative '../../../../lib/gitlab/secret_detection/core/ruleset'
|
6
|
+
|
7
|
+
module Gitlab
|
8
|
+
module SecretDetection
|
9
|
+
module GRPC
|
10
|
+
module IntegratedErrorTracking
|
11
|
+
extend self
|
12
|
+
|
13
|
+
def track_exception(exception, args = {})
|
14
|
+
unless Sentry.initialized?
|
15
|
+
logger.warn(message: "Cannot track exception in Error Tracking as Sentry is not initialized")
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
args[:ruleset_version] = ruleset_version
|
20
|
+
|
21
|
+
Sentry.capture_exception(exception, **args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup(logger: Logger.new($stdout))
|
25
|
+
if Sentry.initialized?
|
26
|
+
logger.warn(message: "Sentry is already initialized, skipping re-setup")
|
27
|
+
return
|
28
|
+
end
|
29
|
+
|
30
|
+
logger.info(message: "Initializing Sentry SDK for Integrated Error Tracking..")
|
31
|
+
|
32
|
+
unless can_setup_sentry?
|
33
|
+
logger.warn(message: "Integrated Error Tracking not available, skipping Sentry SDK initialization")
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
Sentry.init do |config|
|
38
|
+
config.dsn = ENV.fetch('SD_TRACKING_DSN')
|
39
|
+
config.environment = ENV.fetch('SD_ENV')
|
40
|
+
config.release = Gitlab::SecretDetection::Gem::VERSION
|
41
|
+
config.send_default_pii = true
|
42
|
+
config.send_modules = false
|
43
|
+
config.traces_sample_rate = 0.2 if ENV.fetch('ENABLE_SENTRY_PERFORMANCE_MONITORING', 'false') == 'true'
|
44
|
+
end
|
45
|
+
|
46
|
+
Sentry.set_context('ruleset', { version: ruleset_version })
|
47
|
+
|
48
|
+
true
|
49
|
+
rescue StandardError => e
|
50
|
+
logger.error(message: "Failed to initialize Sentry SDK for Integrated Error Tracking: #{e}")
|
51
|
+
raise e
|
52
|
+
end
|
53
|
+
|
54
|
+
def ruleset_version
|
55
|
+
@ruleset_version ||= Gitlab::SecretDetection::Core::Ruleset.new.extract_ruleset_version || 'unknown'
|
56
|
+
end
|
57
|
+
|
58
|
+
def can_setup_sentry?
|
59
|
+
ENV.fetch('SD_ENV', '') == 'production' && ENV.fetch('SD_TRACKING_DSN', '') != ''
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -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.
|
@@ -100,8 +101,8 @@ module Gitlab
|
|
100
101
|
payload_timeout: request.payload_timeout_secs
|
101
102
|
)
|
102
103
|
rescue StandardError => e
|
103
|
-
logger.error(message: "Failed to run the secret detection scan", exception: e)
|
104
|
-
|
104
|
+
logger.error(message: "Failed to run the secret detection scan", exception: e.message)
|
105
|
+
track_exception(e)
|
105
106
|
raise ::GRPC::Unknown, e.message
|
106
107
|
end
|
107
108
|
|
@@ -8,7 +8,7 @@ module Gitlab
|
|
8
8
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/514015
|
9
9
|
#
|
10
10
|
# Ensure to maintain the same version in CHANGELOG file.
|
11
|
-
VERSION = "0.
|
11
|
+
VERSION = "0.20.0"
|
12
12
|
|
13
13
|
# SD_ENV env var is used to determine which environment the
|
14
14
|
# server is running. This var is defined in `.runway/env-<env>.yml` files.
|
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.20.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
|
+
date: 2025-02-25 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,6 +152,7 @@ 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
|