Skip to content

Add audit event emission to CRUD store operations #128

@michaelmcnees

Description

@michaelmcnees

Problem

State-changing operations in CRUD stores do not emit audit events, despite the audit infrastructure being fully built out. This was flagged during PR #127 code review.

Specifically:

  • environment.Store (Create, Delete) emits no audit events
  • secret.Store (Create, Delete, RotateKey) has audit.Action constants defined (ActionCredentialCreated, ActionCredentialDeleted, ActionCredentialRotated) but they are never emitted from the store — only RotateKey emits from the CLI command layer

The project's architecture principle is "audit from day one — every state-changing operation emits an audit event via the AuditEmitter interface." Current stores violate this.

Proposed Approach

Add an optional audit.Emitter field to each store. When set, state-changing methods emit audit events with before/after snapshots. When nil, stores work silently (preserving backward compatibility for tests).

Stores to update

  1. environment.Store — emit on Create, Delete
  2. secret.Store — emit on Create, Delete (using existing ActionCredentialCreated, ActionCredentialDeleted constants)

New audit actions needed

  • ActionEnvironmentCreated
  • ActionEnvironmentDeleted

Pattern

Each store method that mutates state should:

  1. Perform the operation
  2. If Emitter is non-nil, emit an audit.Event with the appropriate action, resource identifier, and before/after state
  3. Return any emit error wrapped alongside the operation result

CLI wiring

CLI commands that construct stores should inject the emitter from the engine or config context, consistent with how cancel.go and rotate_key.go currently emit events.

Acceptance Criteria

  • environment.Store emits audit events on Create and Delete
  • secret.Store emits audit events on Create and Delete
  • New ActionEnvironmentCreated and ActionEnvironmentDeleted constants added
  • Existing ActionCredentialCreated and ActionCredentialDeleted constants are used (not duplicated)
  • Stores remain testable without an emitter (nil-safe)
  • Integration tests verify audit events are emitted
  • All existing tests continue to pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions