Audit conflicting settings policy demands for each policy
What does this MR do and why?
This MR adds govern_policy_conflict_detected so policy authors can see why the engine left a project setting unchanged. Until now, the engine only logged the conflict.
The engine records one event per conflicting policy in its group or instance scope. Each event lists the setting, the policies, and their required values. The engine records conflicts without a Log Audit Trail action.
This MR does not store conflicts on policy evaluations. No changelog entry because security_policies_v2 defaults to off.
Implementation details
Daily checks can repeat the event for each project, so GitLab streams it without saving it to the database. Streaming sends events one at a time, so batching would not reduce sends. Separate audit calls let the service handle failures one policy at a time.
References
Screenshots or screen recordings
No UI changes.
How to set up and validate locally
-
Enable the Policy Store experiment for a top-level group and configure a group audit streaming destination.
-
Create two enforce policies with the
project.scheduled_settings_drift_checktrigger and aset_settingaction. Usesetting_validationto requirerequest_access_enabled: truein one policy andfalsein the other. -
Run the policy check for a project in the group from the Rails console:
project = Project.find_by_full_path('my-group/my-project') Govern::PolicyEngine::EvaluateService.new( subject: project, actor: Users::Internal.admin_bot, trigger: 'project.scheduled_settings_drift_check' ).execute -
Check that the destination received two
govern_policy_conflict_detectedevents and thatrequest_access_enableddid not change.
MR acceptance checklist
Review the MR acceptance checklist.