Use audit event type definition YML file when present
Description
We want to start using the audit event type definition YML files so that these are the single source of truth for audit events. In the next iterations we want to start throwing an exception if an audit event is logged but it doesn't have a corresponding YML definition.
Implementation Plan
- Update the
auditmethod ofGitlab::Audit::Auditorto add a warning if the name of the event being audited doesn't have an associated YML file. This can be done by creating a method like below:
# Inside lib/gitlab/audit/type/definition.rb
def defined?(key)
definitions[key.to_sym].present?
end
# And then use it inside lib/gitlab/audit/auditor.rb
Gitlab::Audit::Type::Definition.defined?('<event_name>') # add warning logs if false
- Update the
initializemethod ofGitlab::Audit::Auditorto read from the YML definition (so that the YML is the single source of truth)
# Inside lib/gitlab/audit/type/definition.rb
def stream_only?(key)
# if saved_to_database if false then stream_only would be true
# since both saved_to_database and stream_only cannot be false together.
!definitions[key.to_sym].saved_to_database
end
# And then use it inside lib/gitlab/audit/auditor.rb
@stream_only = Gitlab::Audit::Type::Definition.stream_only?(name)
- Check the existing YAML definitions and ensure that the
saved_to_databaseandstreamfields matches with the current logic in the codebase and update the existing YAML files in case of mismatch.