Audit events for package deletion
-
Review changes -
-
Download -
Patches
-
Plain diff
Context
GitLab provides audit events, which allow users to track a variety of different actions within GitLab. In Add the Package Registry to the list of audited... (#329588), it was proposed to implement audit events for the package registry. The scope of the implementation is detailed in this comment. This MR is the 2nd part of the implementation: Add audit logs for Package destruction.
What does this MR do and why?
-
When a package of any format is deleted from the package registry, an audit event is created. The audit events is a GitLab Premium feature, so its code lives in the
ee
folder. -
In the package registry, packages are destroyed in two fashions:
- Single package destruction through the
Packages::MarkPackageForDestructionService
. - Bulk package destruction through the
Packages::MarkPackagesForDestructionService
.
In those two services, the packages'
status
is updated topending_destruction
, and then a background job should pick them up and call.destroy!
on each package.So, in order to be able to send the audit event, we have to hook into each service's
execute
method instead of using a model's callback for two main reasons:- The user who is performing the destruction is a very important piece of info in the audit event, and we can have access to the
current_user
only in the services. - In the
Packages::MarkPackagesForDestructionService
bulk action, the packages'status
update is done using.update_all
, which doesn't trigger any model callbacks.
- Single package destruction through the
-
To send audit events for the
Packages::MarkPackagesForDestructionService
bulk destruction, I needed to apply some changes on how we could utilizeAuditable#push_audit_event
to store multiple events in the::Gitlab::Audit::EventQueue
and create them in bulk. This is faster and more efficient than iterating over destroyed packages and create events one by one. -
The audit events are saved on the direct parent group. So when a package is destroyed in a project, the event will be available/visible in the parent group of the project. In case the project doesn't have a parent group (belongs to a user namespace), the events will be available in the project.
-
The feature is behind a
WIP
feature flagpackage_registry_audit_events
, so that we can add the rest of the implementation behind the same feature flag. -
The implementation is guided by this documentation page: https://docs.gitlab.com/ee/development/audit_event_guide/#how-to-instrument-new-audit-events.
References
Please include cross-links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Make sure the feature flag
package_registry_audit_events
is enabled. - Make sure your GDK has an enterprise licence: https://gitlab.com/gitlab-org/gitlab-development-kit/blob/main/doc/index.md#use-gitlab-enterprise-features
- Create a couple of packages from rails console:
# stub file upload def fixture_file_upload(*args, **kwargs) Rack::Test::UploadedFile.new(*args, **kwargs) end FactoryBot.create(:npm_package, project: Project.find(<project_id>)) FactoryBot.create(:generic_package, project: Project.find(<project_id>)) FactoryBot.create(:nuget_package, project: Project.find(<project_id>))
- Navigate to the group or project package registry UI page, and delete packages in bulk.
- Navigate to the group audit events page in the UI. Each destroyed package should have an audit event on the page.
Related to #329588
Merge request reports
- version 24fcf3a1a5
- version 235b75d390
- version 22ca9be5a7
- version 214ce7f593
- version 20abb8d618
- version 1995d0d09f
- version 1895d0d09f
- version 1795d0d09f
- version 16a2c2e03b
- version 15a2c2e03b
- version 14ba054b65
- version 13ba054b65
- version 12ba054b65
- version 11060d402c
- version 10a67b49b4
- version 9a67b49b4
- version 8a67b49b4
- version 7bac9e34a
- version 6bac9e34a
- version 5bac9e34a
- version 4bac9e34a
- version 3bac9e34a
- version 2bac9e34a
- version 1bac9e34a
- master (base)
- latest version8de8e9819 commits,
- version 24fcf3a1a59 commits,
- version 235b75d3909 commits,
- version 22ca9be5a79 commits,
- version 214ce7f5938 commits,
- version 20abb8d6188 commits,
- version 1995d0d09f8 commits,
- version 1895d0d09f8 commits,
- version 1795d0d09f2 commits,
- version 16a2c2e03b7 commits,
- version 15a2c2e03b1 commit,
- version 14ba054b656 commits,
- version 13ba054b656 commits,
- version 12ba054b651 commit,
- version 11060d402c1 commit,
- version 10a67b49b46 commits,
- version 9a67b49b42 commits,
- version 8a67b49b41 commit,
- version 7bac9e34a5 commits,
- version 6bac9e34a5 commits,
- version 5bac9e34a5 commits,
- version 4bac9e34a5 commits,
- version 3bac9e34a5 commits,
- version 2bac9e34a1 commit,
- version 1bac9e34a5 commits,
- Side-by-side
- Inline
There are no changes yet
No changes between version 12 and version 12