Only show warn mode policy selection when active
What does this MR do and why?
Only show warn mode policy selection when active
- currently the bypass selector modal shows if there are any warn mode policies instead of just non-dismissed warn mode policies
- update variable names to be more descriptive
- add tests
EE: true
References
Screenshots or screen recordings
Before | After |
---|---|
![]() |
![]() |
How to set up and validate locally
- Upload a GitLab Ultimate license
- Enable the
security_policy_approval_warn_mode
feature flag in http://gdk.test:3443/rails/features - Create a ruby project (use ruby template) with SAST enabled (easiest scanner to enable)
- Install and run gitlab runners in your gdk (instructions)
- Navigate to the new project => Secure => Policies => New policy => Merge request approval policy
- Create a policy that is enforced and has you user as a bypass exception
Enforce policy
approval_policy:
- name: Prevent Critical Vulnerabilities
description: This is to prevent Critical/High Vulnerabilities from getting merged
enabled: true
actions:
- type: require_approval
approvals_required: 1
role_approvers:
- maintainer
- developer
- owner
rules:
- type: scan_finding
scanners: []
vulnerabilities_allowed: 0
severity_levels: []
vulnerability_states: []
branch_type: protected
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: true
require_password_to_approve: false
fallback_behavior:
fail: open
- Create a policy that is not enforced (warn policy)
Warn policy
approval_policy:
- name: Warn - Prevent SAST vulnerabilities
description: Security Scan
enabled: true
enforcement_type: "warn"
rules:
- type: scan_finding
scanners:
- sast
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
- Create an MR in the new project with vulnerable code
vulnerable_code.rb
input = gets.chomp
eval("puts \#{input}")
job = params[:job]
eval(job)
- Verify the MR widget shows that policies are being violated
- Verify the "Bypass" button appears
- Verify clicking the
Bypass
button brings up a modal that lets you select between the exception policy and the warn mode policy -
Bypass
the warn mode policy - Click the "Bypass" button in the widget
- Verify the modal appears to bypass the exception policy and not the warn policy
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.
Related to #561650 (closed)