audit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package audit records an append-only log of every authorized (and denied) operation. Params arrive already redacted; the writer never mutates audit rows after insert.

Package audit provides the audit log and session recording.

Index

Constants

View Source
const (
	SourceHTTP = "http"
	SourceAI   = "ai"
)

Operation sources recorded on every audit event.

Variables

This section is empty.

Functions

func WithRemoteAddr

func WithRemoteAddr(ctx context.Context, addr string) context.Context

WithRemoteAddr stashes the request's client address on the context so every audit event recorded during the request inherits it without each call site having to thread it through.

func WithSource

func WithSource(ctx context.Context, source, turnID string) context.Context

WithSource marks every audit event recorded during ctx with how the operation was initiated ("http" or "ai") and, for AI, the conversation/turn id.

Types

type Event

type Event struct {
	User         models.User
	Event        string // route AuditEvent
	ConnectionID string
	RouteID      string
	Risk         string
	Result       models.AuditResult
	Params       map[string]string
	Err          error
	RemoteAddr   string
	// Source is "http" or "ai"; TurnID correlates AI tool calls to a turn. Both
	// fall back to the request context when left empty (see WithSource).
	Source string
	TurnID string
}

Event is one auditable operation, assembled by the route wrapper. Params must already have secret values redacted before they reach Record.

type Noop

type Noop struct{}

Noop discards events — used by the route wrapper until the real writer is wired.

func (Noop) Record

func (Noop) Record(context.Context, Event)

Record does nothing.

type Sink

type Sink interface {
	Record(ctx context.Context, ev Event)
}

Sink receives audit events. The route wrapper depends on this interface; the store-backed writer and a noop sink both implement it.

type Writer

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

Writer persists events to the append-only AuditStore.

func NewWriter

func NewWriter(s store.AuditStore) *Writer

func (*Writer) Record

func (w *Writer) Record(ctx context.Context, ev Event)

Record appends one audit entry. Append failures are intentionally swallowed here (audit must never break the request path); the store logs its own errors.

Jump to

Keyboard shortcuts

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