audithook

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package audithook bridges Keysmith lifecycle events to an audit trail backend. It defines a local Recorder interface so the package does not import Chronicle directly.

Index

Constants

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

Severity constants.

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

Outcome constants.

View Source
const (
	ActionKeyCreated          = "keysmith.key.created"
	ActionKeyCreateFailed     = "keysmith.key.create_failed"
	ActionKeyValidated        = "keysmith.key.validated"
	ActionKeyValidationFailed = "keysmith.key.validation_failed"
	ActionKeyRotated          = "keysmith.key.rotated"
	ActionKeyRevoked          = "keysmith.key.revoked"
	ActionKeySuspended        = "keysmith.key.suspended"
	ActionKeyReactivated      = "keysmith.key.reactivated"
	ActionKeyExpired          = "keysmith.key.expired"
	ActionKeyRateLimited      = "keysmith.key.rate_limited"
	ActionPolicyCreated       = "keysmith.policy.created"
	ActionPolicyUpdated       = "keysmith.policy.updated"
	ActionPolicyDeleted       = "keysmith.policy.deleted"
)

Action constants.

View Source
const (
	ResourceKey    = "key"
	ResourcePolicy = "policy"
)

Resource constants.

View Source
const (
	CategoryKeyLifecycle    = "key_lifecycle"
	CategoryKeyValidation   = "key_validation"
	CategoryKeySecurity     = "key_security"
	CategoryPolicyLifecycle = "policy_lifecycle"
)

Category constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEvent

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

AuditEvent is a local representation of an audit event.

type Extension

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

Extension bridges Keysmith lifecycle events to an audit trail backend.

func New

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

New creates an Extension that emits audit events.

func (*Extension) Name

func (e *Extension) Name() string

Name implements plugin.Plugin.

func (*Extension) OnKeyCreateFailed

func (e *Extension) OnKeyCreateFailed(ctx context.Context, k *key.Key, createErr error) error

OnKeyCreateFailed implements plugin.KeyCreateFailed.

func (*Extension) OnKeyCreated

func (e *Extension) OnKeyCreated(ctx context.Context, k *key.Key) error

OnKeyCreated implements plugin.KeyCreated.

func (*Extension) OnKeyExpired

func (e *Extension) OnKeyExpired(ctx context.Context, k *key.Key) error

OnKeyExpired implements plugin.KeyExpired.

func (*Extension) OnKeyRateLimited

func (e *Extension) OnKeyRateLimited(ctx context.Context, k *key.Key) error

OnKeyRateLimited implements plugin.KeyRateLimited.

func (*Extension) OnKeyReactivated

func (e *Extension) OnKeyReactivated(ctx context.Context, k *key.Key) error

OnKeyReactivated implements plugin.KeyReactivated.

func (*Extension) OnKeyRevoked

func (e *Extension) OnKeyRevoked(ctx context.Context, k *key.Key, reason string) error

OnKeyRevoked implements plugin.KeyRevoked.

func (*Extension) OnKeyRotated

func (e *Extension) OnKeyRotated(ctx context.Context, k *key.Key, rec *rotation.Record) error

OnKeyRotated implements plugin.KeyRotated.

func (*Extension) OnKeySuspended

func (e *Extension) OnKeySuspended(ctx context.Context, k *key.Key) error

OnKeySuspended implements plugin.KeySuspended.

func (*Extension) OnKeyValidated

func (e *Extension) OnKeyValidated(ctx context.Context, k *key.Key) error

OnKeyValidated implements plugin.KeyValidated.

func (*Extension) OnKeyValidationFailed

func (e *Extension) OnKeyValidationFailed(ctx context.Context, _ string, validationErr error) error

OnKeyValidationFailed implements plugin.KeyValidationFailed.

func (*Extension) OnPolicyCreated

func (e *Extension) OnPolicyCreated(ctx context.Context, pol *policy.Policy) error

OnPolicyCreated implements plugin.PolicyCreated.

func (*Extension) OnPolicyDeleted

func (e *Extension) OnPolicyDeleted(ctx context.Context, polID id.PolicyID) error

OnPolicyDeleted implements plugin.PolicyDeleted.

func (*Extension) OnPolicyUpdated

func (e *Extension) OnPolicyUpdated(ctx context.Context, pol *policy.Policy) error

OnPolicyUpdated implements plugin.PolicyUpdated.

type Option

type Option func(*Extension)

Option configures an Extension.

func WithEnabled

func WithEnabled(actions ...string) Option

WithEnabled restricts audit recording to the specified actions only. If not called, all actions are recorded.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger for recording errors.

type Recorder

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

Recorder is the interface that audit backends must implement.

type RecorderFunc

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

RecorderFunc is an adapter to use a plain function as a 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