audit

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package audit defines the security events IAM emits (logins, logouts, refreshes, refresh-token reuse, revocations, policy denials, sign-ups, invites, throttling, password resets, email verification, MFA) and the Logger interface that receives them.

IAM decides what happened; the Logger decides where it goes. SlogLogger writes to log/slog; Multi and Func compose custom sinks. Events never contain passwords, tokens or session secrets.

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
	Type      EventType
	SubjectID string            // canonical subject ID (if known)
	SessionID string            // public session ID (if known)
	Provider  string            // auth provider involved (if applicable)
	ClientIP  string            // client address as seen by the application
	Message   string            // human-readable description
	Attrs     map[string]string // extensible metadata (reason, count, ...)
}

Event represents a single audit log entry.

Audit events are intentionally generic so they can be:

  • written to logs
  • pushed to SIEM systems
  • stored in databases
  • streamed to Kafka

Events never contain secrets: no passwords, tokens or session secrets. SessionID is the public session identifier.

type EventType

type EventType string

EventType represents the category of an audit event.

These events are security-relevant and should be treated as immutable.

const (
	EventLoginSuccess       EventType = "login_success"
	EventLoginFailure       EventType = "login_failure"
	EventLogout             EventType = "logout"
	EventRefreshSuccess     EventType = "refresh_success"
	EventRefreshFailure     EventType = "refresh_failure"
	EventRefreshReuse       EventType = "refresh_reuse_detected"
	EventSessionRotated     EventType = "session_rotated"
	EventSessionRevoked     EventType = "session_revoked"
	EventSessionsRevokedAll EventType = "sessions_revoked_all"
	EventTokenVerifyFailure EventType = "token_verify_failure"
	EventPolicyDenied       EventType = "policy_denied"
	EventIdentityLinked     EventType = "identity_linked"
	EventSignup             EventType = "signup"
	EventInviteCreated      EventType = "invite_created"
	EventInviteConsumed     EventType = "invite_consumed"
	EventRateLimited        EventType = "rate_limited"
	EventLockout            EventType = "lockout"

	EventPasswordResetRequested     EventType = "password_reset_requested"
	EventPasswordReset              EventType = "password_reset"
	EventEmailVerificationRequested EventType = "email_verification_requested"
	EventEmailVerified              EventType = "email_verified"

	EventMFAChallenge        EventType = "mfa_challenge"
	EventMFASuccess          EventType = "mfa_success"
	EventMFAFailure          EventType = "mfa_failure"
	EventMFAEnrolled         EventType = "mfa_enrolled"
	EventMFADisabled         EventType = "mfa_disabled"
	EventRecoveryCodeUsed    EventType = "mfa_recovery_code_used"
	EventRecoveryCodesIssued EventType = "mfa_recovery_codes_issued"
)

type Func

type Func func(ctx context.Context, event Event) error

Func adapts a function to Logger.

func (Func) Log

func (f Func) Log(ctx context.Context, event Event) error

Log implements Logger.

type Logger

type Logger interface {
	Log(
		ctx context.Context,
		event Event,
	) error
}

Logger defines the contract for recording audit events.

IAM emits audit events but does NOT decide where they go. Log is called synchronously on the request path; slow sinks should buffer internally. Errors are reported to the caller but never fail the operation.

func Multi

func Multi(loggers ...Logger) Logger

Multi fans an event out to several loggers and returns the first error.

type SlogLogger

type SlogLogger struct {
	// Logger receives the events. Nil means slog.Default().
	Logger *slog.Logger
}

SlogLogger writes audit events to a log/slog logger.

Event attributes are written as a group. Callers must never put secrets (tokens, passwords, session secrets) into an Event.

func NewSlogLogger

func NewSlogLogger(l *slog.Logger) *SlogLogger

NewSlogLogger returns an audit logger that writes to l (nil means slog.Default()).

func (*SlogLogger) Log

func (s *SlogLogger) Log(ctx context.Context, event Event) error

Log implements Logger.

Jump to

Keyboard shortcuts

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