Create audit event when policy dismissal is merged
What does this MR do and why?
Creates audit events when a merge request is merged with a dismissed warn-mode security policy.
We want to integrate dismissed policies into the vulnerability report page as well so I added a status field in preparation for this. We only want to show dismissals that are associated with an MR that was merged.
References
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: MR - Security Scan 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 an MR introducing a vulnerability. Add a file
.env
with the following content:AWS_TOKEN='AKIAZYONPI3G4JNCCWGA'
- The MR should be blocked by the new policies
- Dismiss the policy using
/-/graphql-explorer
and the following querymutation DismissPolicyViolations($projectPath: ID!, $mergeRequestIid: String!, $securityPolicyIds: [ID!]!, $dismissalTypes: [DismissalType!]!, $comment: String!) { dismissPolicyViolations(input: { projectPath: $projectPath, iid: $mergeRequestIid, securityPolicyIds: $securityPolicyIds, dismissalTypes: $dismissalTypes, comment: $comment }) { errors } } // variables (replace with own values) { "projectPath": "mr-205857/test-2", "mergeRequestIid": "1", "securityPolicyIds": [91], "dismissalTypes": ["SCANNER_FALSE_POSITIVE"], "comment": "Dismissed this because of false positive" }
- Merge the MR
- On the left sidebar, select Secure and Audit events.
- A new audit event should be added. It may take a while until the background worker finishes and creates the event.
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 #569628
Edited by Andy Schoenen