Only preserve policy dismissals if MR targets default branch
What does this MR do and why?
Only preserve policy dismissals if targeting default
We show preserved policy dismissals in the vulnerability report. Vulnerablities are only created for findings on the default branch. If we preserve dismissals for MRs that didn't merge into default, we risk showing them on the vulnerability report even though the dismissal could not be responsible for introducing the vulnerability to the default branch.
How to set up and validate locally
- Enable the feature flag
echo "Feature.enable(:security_policy_approval_warn_mode)" | rails c
- Create a new project.
- On the left sidebar, select Secure and Policies.
- Select New policy.
- Select Scan execution policy.
- Enter a name and select Create new project with the new policy.
- Merge the MR
- Go back to the first project
- On the left sidebar, select Secure and Policies again.
- Select New policy.
- Select Merge request approval policy
- Switch to .yaml mode
- Paste the following config:
approval_policy: - name: warn-mode policy description: Security Scan enabled: true enforcement_type: warn rules: - type: scan_finding scanners: - secret_detection vulnerabilities_allowed: 0 severity_levels: [] vulnerability_states: [] branch_type: protected actions: - type: require_approval approvals_required: 1 role_approvers: - developer - maintainer - owner - type: send_bot_message enabled: true approval_settings: block_branch_modification: false prevent_pushing_and_force_pushing: false prevent_approval_by_author: false prevent_approval_by_commit_author: false remove_approvals_with_new_commit: false require_password_to_approve: false fallback_behavior: fail: open
- Select Configure with a merge request
- Merge the MR
- Back to the first project. Create a new branch
feature-branch
- Go to Settings → Repository → Protected branches
- Select your branch and click Protect
- Create an MR targeting the
feature-branch
and introducing a vulnerability. Add a file.env
with the following content:AWS_TOKEN='AKIAZYONPI3G4JNCCWGA'
- The MR should be blocked by the warn-mode policy after the pipeline finishes
- Dismiss the policy by selecting Bypass next to the policy violation warning on the MR
- Provide a description like
Merge into feature-branch MR
- Merge the MR into
feature-branch
- Now create the same MR targeting the default branch
- Bypass the policy again, this time with reason
Merge into default branch
- Merge the MR
- Wait for the latest branch pipeline to finish
- On the left sidebar select Secure → Vulnerability report
- Select the AWS access token vulnerability
- Only the
Merge into default branch
policy bypass should show up.
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 Andy Schoenen