Add service to create and sync policy YAML into read model
Why are we doing this work
The security policies are stored as YAML files in the security policy project. This approach has a lot of advantages (like version control for policies using git, auditable etc) but it faces some performance drawbacks. Since reading from the git repository requires calls to Gitaly, it gets difficult to add additional features
This issue focusses on persisting SecurityPolicyRead from policy YAML whenever these events happen:
- Policy project is linked to a development project
- Policy YAML is updated:
PoC that partially covers these changes: Draft: Add initial policies tables and save new... (!139352 - closed)
Relevant links
Non-functional requirements
-
Documentation: -
Feature flag: new sync should be implemented behind a feature flag -
Performance: -
Testing:
Implementation plan
-
Create a new service class Security::SecurityOrchestrationPolicies::Read::SyncServiceto sync the policies from YAML to delete and re-createSecurityPolicyReadby callingSecurity::SecurityOrchestrationPolicies::Read::CreateService. CallSecurity::SecurityOrchestrationPolicies::SyncScanResultPoliciesProjectServiceafter creatingSecurityPolicyRead -
Scan result policy rules should be persisted using Security::ScanResultPolicyRulemodel -
Scan execution policy rules should be persisted using Security::ScanExecutionPolicyRulemodel -
Update UpdateOrchestrationPolicyConfiguration concernto callSecurity::SecurityOrchestrationPolicies::Read::SyncServicefor each policy in YAML
Verification steps
-
Create a group and enable security_policies_sync_groupFF for the group and Create some projects within the group -
Create some policies for the group from Secure->Policies -
Verify from logs that there are Security::PersistSecurityPoliciesWorker,Security::SyncPolicyWorker,Security::SyncProjectPolicyWorkerworkers invoked and completed without failures -
Verify from rails console that there are Security::Policy,Security::ApprovalPolicyRule,Security::ScanExecutionPolicyRuleare created along withSecurity::PolicyProjectLinkandSecurity::ApprovalPolicyRuleProjectLink -
Now update the README.md file (or any file other than policy.yml) in the security policy project and merge the MR. Verify from logs that there are no workers of typeSecurity::PersistSecurityPoliciesWorkerandSecurity::ProcessScanResultPolicyWorkercreated.
Edited by Andy Schoenen