Compute policy diff before persisting security policies
What does this MR do and why?
This change computes policy diff before persisting the security policies so that the diff can be used to update the associated resources conditionally. The changes related to updating the associated resources is done in Draft: Add events for policy changes (!163945 - closed) using EventStore.
security_policies_sync feature flag.
In this MR:
-
Security::SecurityOrchestrationPolicies::PolicyChangesis a data-model that computes the policy diff along with the rules diff inRuleChangedata-model. - Uses policy
nameas an identifier to query the existing policies as policy name is unique for a policy project - Outdated policies are not deleted but rather set an negative
policy_indexand processed for deletion asynchronously to avoid cascading deletes due toapproval_policy_rule_idin many other tables (approval_merge_request_rules,approval_project_rules,software_license_policesetc) -
rulesin policy YAML are persisted correctly when one or many rule(s) is/are removed/added/updated. Outdated rules (approval_policy_rules&scan_execution_policy_rules) are also marked with a negativerule_indexto process the deletion asynchronously to avoid cascading deletes
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Addresses #416262 (closed)
Edited by Sashi Kumar Kumaresan