Documentation
¶
Overview ¶
Package audit records kafui operations (state-changing by default, optionally all) to a local JSONL file for accountability and review. It is the audit half of the enforcement seam: the guarded datasource emits one Record per audited operation with its classified result.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
func DefaultPath() string
DefaultPath returns the default audit log path (~/.kafui/audit.log).
func ResolveUser ¶
func ResolveUser() string
ResolveUser returns the acting local identity: the OS user, falling back to "Unknown". (A SASL-username fallback is a future refinement.)
Types ¶
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter appends one JSON line per record to a file. It is safe for concurrent use.
ponytail: no rotation here — audit volume for a single-user local tool is small. If it ever needs capping, reuse pkg/ui/shared's rotatingWriter rather than adding a size check inline.
func NewFileWriter ¶
func NewFileWriter(path string) (*FileWriter, error)
NewFileWriter opens (creating parent dirs and the file if needed) path for append with 0600 permissions.
func (*FileWriter) Write ¶
func (w *FileWriter) Write(rec Record) error
Write appends rec as a single JSON line.
type Record ¶
type Record struct {
Timestamp string `json:"timestamp"` // ISO-8601 UTC
User string `json:"user"`
Cluster string `json:"cluster,omitempty"`
Resources []Resource `json:"resources"`
Operation string `json:"operation"`
Params map[string]any `json:"params,omitempty"`
Result Result `json:"result"`
Error string `json:"error,omitempty"`
}
Record is one audit-log line.
type Resource ¶
type Resource struct {
Type string `json:"type"`
ID string `json:"id,omitempty"`
Alter bool `json:"alter"`
Actions []string `json:"actions"`
}
Resource is one resource an operation touched.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service records audit entries subject to the enabled flag and level. When disabled it is a no-op, so call sites are unconditional. Write failures are logged and never propagated: auditing must never fail or delay the operation.
func NewService ¶
NewService builds an audit service. A nil writer or logger is tolerated (logger falls back to slog.Default). Pass enabled=false for a no-op service.