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

  1. Enable the Policy Store experiment for a top-level group and configure a group audit streaming destination.

  2. Create two enforce policies with the project.scheduled_settings_drift_check trigger and a set_setting action. Use setting_validation to require request_access_enabled: true in one policy and false in the other.

  3. 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
  4. Check that the destination received two govern_policy_conflict_detected events and that request_access_enabled did not change.

MR acceptance checklist

Review the MR acceptance checklist.

Edited by Dominic Bauer

Merge request reports

Loading
Loading