Add audit events to profile create and update services

What does this MR do and why?

Adds audit events to the security scan profile create and update flows. The create path now records a single security_scan_profile_create event. The update path snapshots the profile before and after the transaction and records a single security_scan_profile_update event that summarises every changed property: name, description, trigger add/remove, and per-key trigger configuration, with list values reported as added/removed deltas.

Changelog: added
EE: true

[Backend] Add audit event for creating/modifyin... (#606347 - closed) • Gal Katz • 19.3

How to set up and validate locally

  1. Enable the FF:

    Feature.enable(:configurable_security_scan_profiles)
  2. Create and update a profile from the console and inspect the resulting audit events:

    group = Group.first
    user  = group.owners.first
    
    created = Security::ScanProfiles::CreateScanProfileService.new(
      group,
      { scan_type: 'secret_detection', name: 'My profile', description: 'v1',
        triggers: [{ trigger_type: 'default_branch_pipeline' }] },
      user
    ).execute
    profile = created.payload[:scan_profile]
    
    Security::ScanProfiles::UpdateService.new(
      profile,
      { name: 'Renamed profile', triggers: [{ trigger_type: 'git_push_event' }] },
      user
    ).execute
    
    AuditEvents::GroupAuditEvent.last(2).map { |e| e.details[:custom_message] }
    # => ["Created security scan profile 'My profile'",
    #     "Updated security scan profile: Changed name from My profile to Renamed profile; " \
    #     "Set trigger git_push_event to enabled; Removed trigger default_branch_pipeline (was enabled)"]

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.

Edited by rossfuhrman

Merge request reports

Loading