audit

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package audit provides a durable, append-only audit event log. Events are written as newline-delimited JSON (JSONL) so they can be streamed with `tail -f`, parsed by any JSON tool, or forwarded to a SIEM. Each event is one security-relevant decision: an exec, a recipe run, an approval.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Time       time.Time         `json:"time"`
	Actor      string            `json:"actor,omitempty"`
	Source     string            `json:"source,omitempty"` // "mcp"|"web"|"cli"|"webhook"
	Action     string            `json:"action,omitempty"` // "exec"|"recipe_run"|"approval"
	Target     string            `json:"target,omitempty"`
	Command    string            `json:"command,omitempty"`
	Risk       string            `json:"risk,omitempty"`     // "low"|"medium"|"high"|"critical"
	Decision   string            `json:"decision,omitempty"` // "allow"|"deny"|"require_approval"
	DenyReason string            `json:"deny_reason,omitempty"`
	ApprovalID string            `json:"approval_id,omitempty"`
	ExitCode   *int              `json:"exit_code,omitempty"`
	Extra      map[string]string `json:"extra,omitempty"`
}

Event is one durable record of a security-relevant action. Zero-value fields are omitted from JSON so the log stays compact.

type FileSink

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

FileSink writes events as JSONL to a rotating file managed by lumberjack. Each Log call writes exactly one newline-terminated JSON object. Concurrent calls are serialised by a mutex so lines never interleave.

func NewFileSink

func NewFileSink(path string, opts ...RotateOptions) (*FileSink, error)

NewFileSink opens (or creates) path for writing and returns a FileSink. The caller must call Close when done. An optional RotateOptions enables size- and age-based log rotation; without it sensible defaults apply (100 MB max size, 5 backups, 30-day retention).

func (*FileSink) Close

func (s *FileSink) Close() error

Close flushes and closes the underlying file.

func (*FileSink) Log

func (s *FileSink) Log(_ context.Context, e Event) error

Log serialises e as a JSON line and appends it to the sink file.

type RotateOptions

type RotateOptions struct {
	MaxSizeMB  int  // rotate after this many MB (default 100)
	MaxBackups int  // keep this many old files (default 5)
	MaxAgeDays int  // delete files older than this (default 30)
	Compress   bool // gzip old files
}

RotateOptions controls log rotation for FileSink. All fields are optional; zero values use the defaults listed below.

type Sink

type Sink interface {
	Log(ctx context.Context, e Event) error
	Close() error
}

Sink receives audit events. Implementations must be safe for concurrent use.

func NewNoopSink

func NewNoopSink() Sink

NewNoopSink returns a Sink that silently discards every event.

Jump to

Keyboard shortcuts

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