audithook

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package audithook provides an audit event recording extension for Vault. It bridges Vault operations to external audit systems (e.g. Chronicle).

Index

Constants

View Source
const (
	// Secret actions.
	ActionSecretAccessed = "secret.accessed"
	ActionSecretSet      = "secret.set"
	ActionSecretDeleted  = "secret.deleted"
	ActionSecretRotated  = "secret.rotated"

	// Flag actions.
	ActionFlagEvaluated = "flag.evaluated"
	ActionFlagCreated   = "flag.created"
	ActionFlagUpdated   = "flag.updated"
	ActionFlagDeleted   = "flag.deleted"
	ActionFlagToggled   = "flag.toggled"

	// ActionFlagRulesSet records a whole-list replacement of a flag's
	// targeting rules.
	ActionFlagRulesSet = "flag.rules_set"

	// ActionFlagOverrideSet records a per-tenant override being written.
	ActionFlagOverrideSet = "flag.override_set"

	// ActionFlagOverrideDeleted records a per-tenant override being removed.
	ActionFlagOverrideDeleted = "flag.override_deleted"

	// Config actions.
	ActionConfigSet     = "config.set"
	ActionConfigDeleted = "config.deleted"

	// ActionConfigRolledBack records a config entry's value being restored
	// from an earlier version.
	ActionConfigRolledBack = "config.rolled_back"

	// Override actions.
	ActionOverrideSet     = "override.set"
	ActionOverrideDeleted = "override.deleted"

	// ActionRotationPolicySaved records a rotation policy being created or
	// changed. The policy's secret key is the row's key.
	ActionRotationPolicySaved = "rotation.policy_saved"

	// ActionRotationPolicyDeleted records a rotation policy being removed.
	ActionRotationPolicyDeleted = "rotation.policy_deleted"
)

Standard audit actions for Vault operations.

View Source
const (
	CategorySecret   = "vault.secret"
	CategoryFlag     = "vault.flag"
	CategoryConfig   = "vault.config"
	CategoryOverride = "vault.override"
	CategoryRotation = "vault.rotation"
)

Audit event categories.

View Source
const (
	ResourceSecret   = "secret"
	ResourceFlag     = "flag"
	ResourceConfig   = "config"
	ResourceOverride = "override"
	ResourceRotation = "rotation"
)

Resource types.

View Source
const (
	SeverityInfo     = "info"
	SeverityWarning  = "warning"
	SeverityCritical = "critical"
)

Severity levels.

View Source
const (
	OutcomeSuccess = "success"
	OutcomeFailure = "failure"
)

Outcome values.

Variables

This section is empty.

Functions

func AllActions

func AllActions() []string

AllActions returns all registered audit action strings.

Types

type AuditEvent

type AuditEvent struct {
	Action     string         `json:"action"`
	Resource   string         `json:"resource"`
	Category   string         `json:"category"`
	ResourceID string         `json:"resource_id"`
	Key        string         `json:"key"`
	Metadata   map[string]any `json:"metadata,omitempty"`
	Outcome    string         `json:"outcome"`
	Severity   string         `json:"severity"`
	Reason     string         `json:"reason,omitempty"`
}

AuditEvent represents a single audit event emitted by the extension.

type Extension

type Extension struct {
	// contains filtered or unexported fields
}

Extension is an audit recording extension that forwards events to a Recorder. Actions can be filtered so only selected events are recorded.

func New

func New(recorder Recorder, opts ...Option) *Extension

New creates an audit hook extension.

func (*Extension) Name

func (e *Extension) Name() string

Name returns the extension name.

func (*Extension) Record

func (e *Extension) Record(
	ctx context.Context,
	action, severity, outcome, resource, resourceID, category, key string,
	err error,
	kvPairs ...any,
)

Record emits an audit event through the recorder. kvPairs are additional metadata key-value pairs (alternating string key, any value).

type Option

type Option func(*Extension)

Option configures the Extension.

func WithActions

func WithActions(actions ...string) Option

WithActions limits the extension to only record the specified actions. If not set, all actions are recorded.

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger sets the logger for the extension.

type Recorder

type Recorder interface {
	Record(ctx context.Context, event *AuditEvent) error
}

Recorder records audit events to an external system.

type RecorderFunc

type RecorderFunc func(ctx context.Context, event *AuditEvent) error

RecorderFunc is a function adapter for Recorder.

func (RecorderFunc) Record

func (f RecorderFunc) Record(ctx context.Context, event *AuditEvent) error

Record implements Recorder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL