Add exposure scope to security policies
What does this MR do and why?
This change adds support for scoping security policies using security attributes from the exposure category.
Previously, security policies could be scoped to specific projects, groups, and compliance frameworks. Now policies can also be configured to include or exclude projects based on their exposure classification (such as "Internet Facing").
This addition is similar to the work we did in !228920 (merged), !229939 (merged), and !232179 (merged).
To avoid making this MR bigger, the policy re-sync trigger for policies using security attributes from the exposure security category will be added in !232384 (merged).
References
Related to: #596631 (closed)
How to set up and validate locally
- Create a new group
- Go to Secure > Security Configuration
- Click in Exposure level
- Click in Create attribute
- Add a name(e.g Internet Facing) and description(e.g Internet Facing)
- Click in Add attribute
- Click in Save changes
- Create a new project
- Add a
.gitlab-ci.ymlfile with the content:
include:
- template: Jobs/SAST.gitlab-ci.yml- Go to Secure > Security Configuration
- Select Security attributes
- Click on Edit project security attributes
- Select the Application security attribute created in step 6(e.g Internet Facing)
- Click in save changes
- Go back to the group created in step 1
- Go to Secure > Policies
- Click on New policy
- Select Merge request approval policy
- Create a policy to block new vulnerabilities on
Internet Facingprojects - Get the
security_attributeid
category = Security::Category.where(template_type: "exposure", namespace: Group.last)
Security::Attribute.where(security_category: category).where(name: "Internet Facing").first- Create a policy like
approval_policy:
- name: Test
description: ''
enabled: true
rules:
- type: scan_finding
branches: []
vulnerabilities_allowed: 0
severity_levels: []
vulnerability_states: []
scanners:
- type: sast
vulnerabilities_allowed: 0
severity_levels:
- critical
- high
vulnerability_states:
- new_needs_triage
vulnerability_attributes:
false_positive: false
policy_scope:
exposure:
including:
- id: <security_attribute_id>
actions:
- type: require_approval
approvals_required: 1
role_approvers:
- developer- Click on Create new project with the new policy
- Merge the MR to add the policy
- Go back to the project created in step 8
- Create a MR adding the file
vuln.rbwith the content
class RunScript
def run_script
system("cat #{params[:path]}")
end
end- Verify the MR is blocked
- Create another project
- Add a
.gitlab-ci.ymlfile with the content:
include:
- template: Jobs/SAST.gitlab-ci.yml- Create a MR with the same
vuln.rband verify the MR is not blocked.
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.