Skip to content

Improve audit event instrumentation with in-memory queue

What does this MR do?

This MR creates a new audit event instrumentation with in-memory queue.

The motivation behind this change was discovered via #213603 (closed). This MR is trying to address two use cases:

  • High-level operation that results in multiple changes to our domain model. For example, the user can add User a and remove Group A in one action and subsequently one method call is dispatched to ApprovalProjectRule model. This triggers 2 audit events: add User and remove Group.
  • High-level operation that involves complex synchronous calls through its abstraction. We need to attribute the audit context (e.g. author, ip_address) which is only available in controller/service layer, to all audit events.

Relates to #213603 (closed)

Implementation approach

We wrap the operation block in a ::Gitlab::Audit::Auditor which captures the initial audit context (i.e. author, scope, target, ip_address) object that are available at the time the operation is initiated.

Extra instrumentation is required in the interacted classes in the chain with Auditable mixin to record audit event to the Audit Event queue via ::Gitlab::Audit::EventQueue.

The EventQueue are stored in Thread via SafeRequestStore and then later extracted when we record an audit event in ::Gitlab::Audit::Auditor via AuditEventService.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Tan Le

Merge request reports