Add business_unit scope to security policies
What does this MR do and why?
This change adds support for scoping security policies using security attributes from the business_unit 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 business_unit classification (such as "Engineering").
This addition is similar to the work we did in !228920 (merged), and !229939 (merged). This MR also includes the refactoring suggested in this comment from the MR !229939 (merged).
To avoid making this MR bigger, the policy re-sync trigger for policies using security attributes from the business_unit security category will be added in !232384 (merged).
Database queries
SELECT
"security_categories"."template_type",
"security_attributes"."id"
FROM
"security_attributes"
INNER JOIN "project_to_security_attributes" ON "security_attributes"."id" = "project_to_security_attributes"."security_attribute_id"
INNER JOIN "security_categories" ON "security_categories"."id" = "security_attributes"."security_category_id"
WHERE
"project_to_security_attributes"."project_id" = 80550984
AND "security_attributes"."deleted_at" IS NULL
AND "security_categories"."deleted_at" IS NULL
LIMIT 1000https://postgres.ai/console/gitlab/gitlab-production-sec/sessions/51211/commands/151552
References
Related to: #596631 (closed)
How to set up and validate locally
- Create a new group
- Go to Secure > Security Configuration
- Click in Business Unit
- Click in Create attribute
- Add a name(e.g Engineering) and description(e.g Engineering 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 Engineering)
- 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: "business_unit", namespace: Group.last)
Security::Attribute.where(security_category: category).where(name: "Engineering").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:
business_unit:
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.yml file 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.