gitlab-secret_detection 0.11.1 → 0.39.2
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 +34 -26
- data/lib/gitlab/secret_detection/core/response.rb +16 -6
- data/lib/gitlab/secret_detection/core/ruleset.rb +30 -3
- data/lib/gitlab/secret_detection/core/scanner.rb +308 -77
- data/lib/gitlab/secret_detection/core/secret_push_protection_rules.toml +1072 -0
- data/lib/gitlab/secret_detection/core/status.rb +34 -0
- data/lib/gitlab/secret_detection/grpc/client/grpc_client.rb +50 -19
- 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 +35 -16
- 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 +3 -17
- data/proto/secret_detection.proto +3 -0
- metadata +209 -19
- data/lib/gitlab.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 73f035d35d4ceca23cc77190ee6acb59e8c26e4a473102a9a56da16d3dc23986
|
|
4
|
+
data.tar.gz: c6b85135c9f0bd83268bab359efc0b69f33454c371e397fa77be0e5aea5efcb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b127be2b764b05ae628dadfd0de811fa8d6e893b7d843ce2e60f4fc0af2f247580028350fa970fee5cc6980b71f2882bcc842fb6d5cd50ac3995276112714c6
|
|
7
|
+
data.tar.gz: 4961476f2092a893b11d82c357ea0e2138ddb07490edab4c207f19157f26ec44060f16e744739554bf0e0365cca38fda2813fd7c53dd01c7d8f9956270722e3a
|
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Reference Issue: https://gitlab.com/groups/gitlab-org/-/epics/13792
|
|
|
7
7
|
|
|
8
8
|
#### Tools and Framework
|
|
9
9
|
|
|
10
|
-
- Ruby `3.
|
|
10
|
+
- Ruby `3.3.X`
|
|
11
11
|
- gRPC framework for serving RPC requests
|
|
12
12
|
|
|
13
13
|
## Feature Distribution
|
|
@@ -62,20 +62,21 @@ the approach:
|
|
|
62
62
|
|
|
63
63
|
Usage `make <command>`
|
|
64
64
|
|
|
65
|
-
| Command
|
|
66
|
-
|
|
67
|
-
| `install_secret_detection_rules` | Downloads secret-detection-rules based on package version defined in RULES_VERSION
|
|
68
|
-
| `install`
|
|
69
|
-
| `lint_fix`
|
|
70
|
-
| `gem_clean`
|
|
71
|
-
| `gem_build`
|
|
72
|
-
| `generate_proto`
|
|
73
|
-
| `grpc_docker_build`
|
|
74
|
-
| `grpc_docker_serve`
|
|
75
|
-
| `grpc_serve`
|
|
76
|
-
| `run_core_tests`
|
|
77
|
-
| `run_grpc_tests`
|
|
78
|
-
| `
|
|
65
|
+
| Command | Description |
|
|
66
|
+
|----------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
|
|
67
|
+
| `install_secret_detection_rules` | Downloads secret-detection-rules based on package version defined in RULES_VERSION |
|
|
68
|
+
| `install` | Installs ruby gems in the project using Ruby bundler |
|
|
69
|
+
| `lint_fix` | Fixes all the fixable Rubocop lint offenses |
|
|
70
|
+
| `gem_clean` | Cleans existing gem file(if any) generated through gem build process |
|
|
71
|
+
| `gem_build` | Builds Ruby gem file wrapping secret detection logic (lib directory) |
|
|
72
|
+
| `generate_proto` | Generates ruby(.rb) files for the Protobud Service Definition files(.proto) |
|
|
73
|
+
| `grpc_docker_build` | Builds a docker container image for gRPC server |
|
|
74
|
+
| `grpc_docker_serve` | Runs gRPC server via docker container listening on port 8080. Run `grpc_docker_build` make command before running this command. |
|
|
75
|
+
| `grpc_serve` | Runs gRPC server on the CLI listening on port 50001. Run `install` make command before running this command. |
|
|
76
|
+
| `run_core_tests` | Runs RSpec tests for Secret Detection core logic |
|
|
77
|
+
| `run_grpc_tests` | Runs RSpec tests for Secret Detection gRPC endpoints |
|
|
78
|
+
| `run_utils_tests` | Runs RSpec tests for Secret Detection utilities |
|
|
79
|
+
| `run_all_tests` | Runs all the RSpec tests in the project |
|
|
79
80
|
|
|
80
81
|
|
|
81
82
|
## Secret Detection Rules
|
|
@@ -166,9 +167,9 @@ You should see the following response as a result:
|
|
|
166
167
|
|
|
167
168
|
|
|
168
169
|
```shell
|
|
169
|
-
|
|
170
|
-
localhost:50001 \
|
|
170
|
+
grpcurl -plaintext -d @ \
|
|
171
171
|
-rpc-header 'x-sd-auth:12345' \
|
|
172
|
+
localhost:50001 \
|
|
172
173
|
gitlab.secret_detection.Scanner/Scan <<EOM
|
|
173
174
|
{
|
|
174
175
|
"payloads": [
|
|
@@ -335,15 +336,22 @@ Run `ruby examples/sample-client/sample_client.rb` on your terminal to run the s
|
|
|
335
336
|
|
|
336
337
|
RPC service is benchmarked using [`ghz`](https://ghz.sh), a powerful CLI-based tool for load testing and benchmarking gRPC services. More details added [here](https://gitlab.com/gitlab-org/gitlab/-/work_items/468107).
|
|
337
338
|
|
|
338
|
-
##
|
|
339
|
+
## Release Process
|
|
340
|
+
|
|
341
|
+
We do three primary actions for every merge to `main` branch:
|
|
342
|
+
|
|
343
|
+
- **Build and Publish SD ruby gem to RubyGems.org**:
|
|
344
|
+
- The latest version for releasing Secret Detection gem is pulled from `Gitlab::SecretDetection::Gem::VERSION` (located at`lib/gitlab/secret_detection/version.rb`).
|
|
345
|
+
- We build a ruby gem for the code snapshot and tag it to the extract release version.
|
|
346
|
+
- The script for publising the gem to RubyGems.org is available [here](ci/scripts/publish_ruby_gem.sh).
|
|
339
347
|
|
|
340
|
-
|
|
348
|
+
- **Deploy SD gRPC server to GCP using Runway**:
|
|
349
|
+
- We build a docker container for the current code snapshot and tag it under `$CI_REGISTRY_IMAGE/image:$CI_COMMIT_SHORT_SHA` container registry path.
|
|
350
|
+
- The same container registry path is given as input to the Runway CI downstream which takes it forward for deploying in Staging and Production environments.
|
|
341
351
|
|
|
342
|
-
|
|
352
|
+
- **Make a GitLab Release**:
|
|
353
|
+
- We use a modified version of [`upsert git tag`](https://gitlab.com/gitlab-org/security-products/ci-templates/-/blob/master/includes-dev/upsert-git-tag.ym) job where instead of fetching the version from the first changelog entry, we fetch it from `Gitlab::SecretDetection::Gem::VERSION`. The rest of the behaviour is retained i.e., creating a tag from the version and then creating a new GitLab release against that tag.
|
|
354
|
+
- The job pulls the description of the latest version entry from the [`CHANGELOG.md`](CHANGELOG.md) and uses it for the Release description.
|
|
355
|
+
- The script for creating a git tag and making GitLab release is available [here](ci/scripts/make_gitlab_release.sh).
|
|
343
356
|
|
|
344
|
-
|
|
345
|
-
the `initialize()` method now accepts parsed rules instead of ruleset file path
|
|
346
|
-
- [Gitlab::SecretDetection::Core::Status](lib/gitlab/secret_detection/core/status.rb): `NOT_FOUND` status moved from `0` to `7` since
|
|
347
|
-
gRPC reserves `0` for enums. We need to reflect this change on the Rails side too
|
|
348
|
-
- [Gitlab::SecretDetection::Core::Scanner#scan(...)](lib/gitlab/secret_detection/core/scanner.rb): Introduced `rule_exclusions`, `raw_value_exclusions` and `tags` args to `scan(..)`
|
|
349
|
-
method to suport [exclusions](https://gitlab.com/groups/gitlab-org/-/epics/14315) feature.
|
|
357
|
+
*NOTE: There is no logical requirement for the versions defined in `Gitlab::SecretDetection::Gem::VERSION` and latest entry of `CHANGELOG.md` to be the same. However, we expect them to be the same to keep it consistent. We've added a CI job([`validate version sync`](ci/templates/validate.yml)) that ensures the version sync between them.*
|
|
@@ -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
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
[
|
|
41
|
+
[
|
|
42
|
+
status,
|
|
43
|
+
results,
|
|
44
|
+
applied_exclusions,
|
|
45
|
+
metadata
|
|
46
|
+
]
|
|
37
47
|
end
|
|
38
48
|
end
|
|
39
49
|
end
|
|
@@ -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,18 +29,37 @@ 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
|
|
27
44
|
|
|
28
45
|
# parses given ruleset file and returns the parsed rules
|
|
29
46
|
def parse_ruleset
|
|
30
|
-
|
|
47
|
+
logger.info(
|
|
48
|
+
message: "Parsing local ruleset file",
|
|
49
|
+
ruleset_path: RULESET_FILE_PATH
|
|
50
|
+
)
|
|
31
51
|
rules_data = TomlRB.load_file(path, symbolize_keys: true).freeze
|
|
52
|
+
ruleset_version = extract_ruleset_version
|
|
53
|
+
|
|
54
|
+
logger.info(
|
|
55
|
+
message: "Ruleset details fetched for running Secret Detection scan",
|
|
56
|
+
total_rules: rules_data[:rules]&.length,
|
|
57
|
+
ruleset_version:
|
|
58
|
+
)
|
|
32
59
|
rules_data[:rules].freeze
|
|
33
60
|
rescue StandardError => e
|
|
34
|
-
logger.error "Failed to parse secret detection ruleset
|
|
35
|
-
raise
|
|
61
|
+
logger.error(message: "Failed to parse local secret detection ruleset: #{e.message}")
|
|
62
|
+
raise RulesetParseError, e
|
|
36
63
|
end
|
|
37
64
|
end
|
|
38
65
|
end
|