Documentation
¶
Overview ¶
Package audit provides structured audit logging for token exchange events.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TruncateJTI ¶
TruncateJTI truncates a JTI string to the given maximum length.
func TruncateUserAgent ¶
TruncateUserAgent truncates a user agent string to the given maximum length.
Types ¶
type Event ¶
type Event struct {
Timestamp time.Time `json:"timestamp"`
TraceID string `json:"trace_id"`
Scope string `json:"scope"`
AppName string `json:"app"`
Identity string `json:"identity"`
Issuer string `json:"issuer"`
Subject string `json:"subject"`
JTI string `json:"jti,omitempty"`
Result ExchangeResult `json:"result"`
ErrorReason string `json:"error_reason,omitempty"`
DurationMS int64 `json:"duration_ms"`
UserAgent string `json:"user_agent,omitempty"`
RemoteIP string `json:"remote_ip,omitempty"`
}
Event represents a single token exchange audit event.
type ExchangeResult ¶
type ExchangeResult string
ExchangeResult represents the outcome of a token exchange attempt.
const ( ResultSuccess ExchangeResult = "success" ResultPolicyDenied ExchangeResult = "policy_denied" ResultOIDCInvalid ExchangeResult = "oidc_invalid" ResultJTIReplay ExchangeResult = "jti_replay" ResultNotFound ExchangeResult = "policy_not_found" ResultCacheError ExchangeResult = "cache_error" ResultGitHubError ExchangeResult = "github_error" ResultUnknownError ExchangeResult = "unknown_error" )
type FileLogger ¶
type FileLogger struct {
// contains filtered or unexported fields
}
FileLogger writes audit events as JSON lines to a file using a buffered channel for non-blocking writes.
func NewFileLogger ¶
NewFileLogger creates a FileLogger that writes to the given path. If path is empty, events are only emitted to the slog logger.
func (*FileLogger) Close ¶
func (fl *FileLogger) Close() error
Close drains remaining events and closes the file. Waits up to 5 seconds.
func (*FileLogger) Log ¶
func (fl *FileLogger) Log(event Event)
Log queues an audit event for writing. Non-blocking — if the channel is full, the event is dropped and a warning is logged.