Accept dependency settings on dependency scanning scanners

What does this MR do and why?

Merge request approval policies block on dependency scanning findings that the merge request did not introduce. The common case is a new advisory for a dependency that already exists, unchanged, on the target branch. The target branch was scanned before the advisory was published, so the finding is newly detected.

This MR is the first of a stack. It lets dependency_scanning scanner entries in scan_finding rules carry two settings, and adds the feature flag that gates them:

scanners:
  - type: dependency_scanning
    dependency_change: introduced   # introduced | unchanged | any (default)
    dependency_type: direct         # direct | transitive | any (default)
  • Both JSON schemas accept dependency_change and dependency_type, only on dependency_scanning entries. Plain string scanners and policies without the settings behave as before. The schema isn't gated, the same as for is_malicious.
  • Rule and ScannerConfig carry the settings. any is the default and is treated as unset.
  • The settings sit behind the beta feature flag approval_policy_dependency_scanning_filters, which is disabled by default. With the flag disabled, ApprovalPolicySource#scanner_configurations drops the settings, so rules follow today's evaluation path.

No behavior changes yet: nothing evaluates the settings until the wiring MR in this stack lands. The filtering semantics are described in that MR and in the docs MR.

Approach: the plan was reviewed and agreed on the issue (revision 2): #635482 (comment 4070943000)

References

Screenshots or screen recordings

Not applicable: backend only. The settings can be set in YAML mode only (#635633).

How to set up and validate locally

  1. Run the new specs:
    bundle exec rspec ee/spec/lib/security/scan_result_policies/rule_spec.rb ee/spec/lib/security/scan_result_policies/scanner_config_spec.rb ee/spec/models/security/approval_policy_source_spec.rb ee/spec/models/security/orchestration_policy_configuration_spec.rb
  2. In the Rails console, check that the flag gates the settings for a project with a policy that sets dependency_change: introduced:
    Feature.disable(:approval_policy_dependency_scanning_filters)
    # ApprovalPolicySource#scanner_configurations omits dependency_change and dependency_type
    Feature.enable(:approval_policy_dependency_scanning_filters)
    # ApprovalPolicySource#scanner_configurations includes them
  3. Save a policy in YAML mode with dependency_change: introduced on a dependency_scanning scanner. It is accepted. The same setting on sast is rejected.

MR stack

This MR is part of a stack of 4 that replaces one 760-line MR. Each MR targets the previous branch (linear chain), so every diff only shows its own change. Merge in order; retarget each MR to master after the one below it merges.

  1. This MR: 635482-ds-dependency-change-filter (!264451 (merged)): schemas, config plumbing, feature flag. Targets master.
  2. 635482-ds-dependency-filter-class (!267117 (merged)): DependencyFilter and the Security::Finding scope, unreferenced. Targets the branch above.
  3. 635482-ds-dependency-filter-wiring (!267118 (merged)): wires the filter into evaluation. Targets the branch above.
  4. 635482-ds-dependency-filter-docs (!267119 (merged)): documentation. Targets the branch above.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alan (Maciej) Paruszewski

Merge request reports

Loading
Loading