Add application scope
What does this MR do and why?
This change adds support for scoping security policies using security attributes from the application 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 application classification (such as "Web" or "Finance").
This addition is similar to the work we did in !228920 (merged). This MR also does some refactoring to avoid duplication in our code and JSON validation, which should make it easier to add support for the remaining security_categories.
To avoid making this MR bigger, the policy re-sync trigger for policies using security attributes from the application 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 Application
- Click in Create attribute
- Add a name(e.g Finance) and description(e.g Finance Applications)
- Click in Add attribute
- Click in Save changes
- Create a new project
- Add a .gitlab-ci.yml file 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 Finance)
- 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
Financeprojects - Get the
security_attributeid
category = Security::Category.where(template_type: "application", namespace: Group.last)
Security::Attribute.where(security_category: category).where(name: "Finance").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:
application:
including:
- id: 33
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 1
- 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
- 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.