Commit c3696602 authored by Stan Hu's avatar Stan Hu

Fix Error 500 when deleting a pipeline via the API

GitLab EE has an admin audit log that attempts to call `full_path` on
the entity for metadata. Unlike a project or a group, a CI pipeline
doesn't have this; the best we could do is delegate the project path.
For now, set the value to empty but fill in details of the destroyed
pipeline.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/55481
parent 1a20f683
...@@ -5,9 +5,15 @@ module Ci ...@@ -5,9 +5,15 @@ module Ci
def execute(pipeline) def execute(pipeline)
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline)
AuditEventService.new(current_user, pipeline).security_event AuditEventService.new(current_user, pipeline, audit_details).security_event
pipeline.destroy! pipeline.destroy!
end end
def audit_details
{
custom_message: 'Destroyed pipeline'
}
end
end end
end end
...@@ -181,8 +181,12 @@ module EE ...@@ -181,8 +181,12 @@ module EE
end end
def add_security_event_admin_details! def add_security_event_admin_details!
# TODO: Entities such as projects and groups have a full path that
# we can log. However, objects such as CI pipelines do not have
# this. We could delegate this to the project path in the future, but
# for now, just set it to empty.
@details.merge!(ip_address: ip_address, @details.merge!(ip_address: ip_address,
entity_path: @entity.full_path) entity_path: @entity.try(:full_path))
end end
def custom_project_link_group_attributes(group_link) def custom_project_link_group_attributes(group_link)
......
---
title: Fix Error 500 when deleting a pipeline via the API
merge_request: 9104
author:
type: fixed
...@@ -19,11 +19,16 @@ describe ::Ci::DestroyPipelineService do ...@@ -19,11 +19,16 @@ describe ::Ci::DestroyPipelineService do
context 'when audit events is enabled' do context 'when audit events is enabled' do
before do before do
stub_licensed_features(extended_audit_events: true) stub_licensed_features(extended_audit_events: true, admin_audit_log: true)
end end
it 'logs an audit event' do it 'logs an audit event' do
expect { subject }.to change { SecurityEvent.count }.by(1) expect { subject }.to change { SecurityEvent.count }.by(1)
event = SecurityEvent.first
expect(event.entity_type).to eq('Ci::Pipeline')
expect(event.entity_id).to eq(pipeline.id)
expect(event.details[:custom_message]).to eq('Destroyed pipeline')
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment