Fix scan result policies for empty severity levels
requested to merge andysoiron/fix-scan_result_policies_findings_finder-with-empty-severity_levels into master
What does this MR do and why?
The policy editor usually fills the severity_levels
field with an empty array. This results in an empty array being provided as an option for
Security::ScanResultPolicies::FindingsFinder. To fix this, we can ignore empty arrays.
How to set up and validate locally
- On the
master
branch. - Create a new policy
- Create a project
- Add a
.gitlab-ci.yml
with secret detection (See.gitlab-ci.yml
with secret detection example). - On the left sidebar, select Security & Compliance and Policies.
- Select New Policy.
- Select Scan result policy.
- For Name choose any name.
- For Rules choose "when Security Scan Secret Detection runs against the All protected branches and find(s). Any vulnerabilities that match all of the following criteria:".
- Select Add new criteria and New severity
- Choose Select all
- In Actions Select "Require 1 approval from:".
- Select any user that is not you.
- Alternatively to steps 5 to 11, you can switch to
.yaml
mode and copy the Policy example below. And replace theuser_approvers_ids
with a valid user ID that has access to the project. - Select Configure with a merge request.
- Merge the MR.
- Produce an MR with a vulnerability finding.
- If you haven't already, set up a runner with docker.
- Go to the project page and select the Web IDE button.
- Create a new file called
.env
. - Add the following line to the file
AWS_TOKEN='AKIAZYONPI3G4JNCCWGA'
. - Commit the changes to a new branch and start an MR.
- The pipelines security tab should show one finding.
- Verify the changes
- The MR should not require an approval regardless of the vulnerability finding.
- Switch to the
andysoiron/fix-scan_result_policies_findings_finder-with-empty-severity_levels
branch. - Reset required approvals by updating the security policy again. For example, add an empty line to the end of
.gitlab/security-policies/policy.yml
. - The MR should now require an approval.
`.gitlab-ci.yml` with secret detection
# .gitlab-ci.yml
include:
- template: Jobs/Secret-Detection.gitlab-ci.yml
test-job:
script:
- echo "Test Job..."
Policy example
type: scan_result_policy
name: sdfsdf
description: ''
enabled: true
rules:
- type: scan_finding
branches: []
scanners:
- secret_detection
vulnerabilities_allowed: 0
severity_levels: []
vulnerability_states: []
actions:
- type: require_approval
approvals_required: 1
user_approvers_ids:
- 82
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Andy Schoenen