Skip to content

feat(protect): audit logging#160

Merged
auxesis merged 2 commits intomainfrom
audit-interface
Jun 16, 2025
Merged

feat(protect): audit logging#160
auxesis merged 2 commits intomainfrom
audit-interface

Conversation

@calvinbrewer
Copy link
Copy Markdown
Contributor

@calvinbrewer calvinbrewer commented Jun 12, 2025

The .audit interface is a method available on all Protect.js operations.
It allows you to attach arbitrary metadata to the operation for ZeroKMS audit logging purposes.

Usage example:

  const plaintext = await protectClient.decrypt(ciphertext.data).audit({
    metadata: {
      user: 'cj@cjb.io',
      action: 'read',
      requestId: 'abc-123',
    },
  })

The metadata object can contain any key-value pairs you wish to associate with the operation.
This metadata will be included in the ZeroKMS audit logs.

The .audit() method is chainable and does not affect the result of the operation itself.

@calvinbrewer calvinbrewer marked this pull request as ready for review June 13, 2025 16:58
@freshtonic
Copy link
Copy Markdown
Contributor

@cj does this mean no auditing happens at all on decryption if .audit is skipped, or is .audit for additional metadata?

Copy link
Copy Markdown

@engineforce engineforce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@auxesis
Copy link
Copy Markdown
Contributor

auxesis commented Jun 16, 2025

does this mean no auditing happens at all on decryption if .audit is skipped, or is .audit for additional metadata?

@freshtonic .audit is only for additional user-supplied metadata.

ZeroKMS will still produce logs for key generation and retrieval operations, regardless of the call to .audit.

@auxesis auxesis merged commit c14dd00 into main Jun 16, 2025
1 check passed
@auxesis auxesis deleted the audit-interface branch June 16, 2025 00:34
@coderdan
Copy link
Copy Markdown
Contributor

coderdan commented Jul 7, 2025

This is great!

I wonder if it might be clearer to name the method auditContext or something? This would communicate that the method is to supply additional information for the audit log rather than it being required for auditing to take place. What do you think @calvinbrewer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants