audit

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package audit provides structured audit logging for security-sensitive operations. It follows the WHO/WHAT/WHEN pattern for compliance and forensics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Timestamp  time.Time         `json:"timestamp"`
	Type       EventType         `json:"type"`
	Actor      string            `json:"actor"`             // WHO: username, IP, or "system"
	Action     string            `json:"action"`            // WHAT: human-readable action description
	Resource   string            `json:"resource"`          // Resource affected (e.g., endpoint, config file)
	Result     string            `json:"result"`            // success, failure, denied
	RemoteAddr string            `json:"remote_addr"`       // Client IP address
	UserAgent  string            `json:"user_agent"`        // Client user agent
	RequestID  string            `json:"request_id"`        // Correlation ID
	Details    map[string]string `json:"details,omitempty"` // Additional context
}

Event represents a structured audit event.

type EventType

type EventType string

EventType represents the type of audit event.

const (
	// Configuration events
	EventConfigReload      EventType = "config.reload"
	EventConfigReloadError EventType = "config.reload.error"

	// Refresh events
	EventRefreshStart   EventType = "refresh.start"
	EventRefreshSuccess EventType = "refresh.success"
	EventRefreshError   EventType = "refresh.error"

	// Authentication events
	EventAuthSuccess EventType = "auth.success"
	EventAuthFailure EventType = "auth.failure"
	EventAuthMissing EventType = "auth.missing"

	// API access events
	EventAPIAccess    EventType = "api.access"
	EventAPIForbidden EventType = "api.forbidden"
	EventAPIRateLimit EventType = "api.ratelimit"
)

type Logger

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

Logger provides audit logging functionality.

func NewLogger

func NewLogger() *Logger

NewLogger creates a new audit logger with a dedicated "audit" component.

func (*Logger) APIAccess

func (l *Logger) APIAccess(remoteAddr, method, endpoint string, statusCode int)

APIAccess logs API endpoint access.

func (*Logger) AuthFailure

func (l *Logger) AuthFailure(remoteAddr, endpoint, reason string)

AuthFailure logs a failed authentication attempt.

func (*Logger) AuthMissing

func (l *Logger) AuthMissing(remoteAddr, endpoint string)

AuthMissing logs a request without authentication.

func (*Logger) AuthSuccess

func (l *Logger) AuthSuccess(remoteAddr, endpoint string)

AuthSuccess logs a successful authentication.

func (*Logger) ConfigReload

func (l *Logger) ConfigReload(actor, result string, details map[string]string)

ConfigReload logs a configuration reload event.

func (*Logger) Log

func (l *Logger) Log(event Event)

Log writes an audit event to the audit log.

func (*Logger) LogFromContext

func (l *Logger) LogFromContext(ctx context.Context, event Event)

LogFromContext logs an audit event with context information. It automatically extracts request ID, remote addr, and user agent from the context.

func (*Logger) RateLimitExceeded

func (l *Logger) RateLimitExceeded(remoteAddr, endpoint string)

RateLimitExceeded logs rate limit violations.

func (*Logger) RefreshComplete

func (l *Logger) RefreshComplete(actor string, channels, bouquets int, durationMS int64)

RefreshComplete logs a completed refresh operation.

func (*Logger) RefreshError

func (l *Logger) RefreshError(actor, reason string)

RefreshError logs a failed refresh operation.

func (*Logger) RefreshStart

func (l *Logger) RefreshStart(actor string, bouquets []string)

RefreshStart logs the start of a refresh operation.

Jump to

Keyboard shortcuts

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