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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a749972fd361e8f84074f6b292f0a244ad5f86dd9d78b046cdd5593fed8ead8e
4
- data.tar.gz: bdbc88f40aa8061577bcc4c618e3fc1691ef3b62276509300f8f2ee5be4c3e52
3
+ metadata.gz: 73f035d35d4ceca23cc77190ee6acb59e8c26e4a473102a9a56da16d3dc23986
4
+ data.tar.gz: c6b85135c9f0bd83268bab359efc0b69f33454c371e397fa77be0e5aea5efcb5
5
5
  SHA512:
6
- metadata.gz: 72af511eae50a715a3c5023302ba3eafe7f7dd25af4a420bcc09b797c36fb924d2d70d074f5877bd5e21527347785b743d90b58e779dd90b43e16926f30351ed
7
- data.tar.gz: 700627072f35b21367e561343f87dce664bf30e6b627194e56a3fbbe421bbd73794cf4e0f1fc3fae69382da92a4ac1067e2f5a842b51b777a9e8ce490cac49f3
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.2.5`
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 | 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_all_tests` | Runs all the RSpec tests in the project |
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
- $ grpcurl -d @ \
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
- ## Project Status
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
- Secret Detection service's status can be tracked here: https://gitlab.com/gitlab-org/gitlab/-/issues/467531
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
- #### Changes made in the secret detection logic that were previously not present in the Gem
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
- - [Gitlab::SecretDetection::Core::Scanner#initialize(...)](lib/gitlab/secret_detection/core/scanner.rb): To reuse the logic of ruleset parsing from a file source, we parse the ruleset file at once and pass the parsed rules around. So,
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, 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
@@ -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
- # rule_file_content = File.read(path)
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 from '#{path}' path: #{e}"
35
- raise Core::Scanner::RulesetParseError
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