Documentation
¶
Overview ¶
Package audit records security-relevant events (sign-ins, account and credential changes, administrative changes and, when enabled, read access) in the gk_audit_event table.
Recording never fails the caller's request: a write error is logged and the request carries on. Every recorded event is also written to the application log as one structured "audit" line, for log shippers.
Index ¶
- Constants
- func Changes(before, after map[string]any) map[string]any
- func ID(id int64) string
- func Purge(ctx context.Context, db *sql.DB, cutoff time.Time) (int64, error)
- func Record(ctx context.Context, e Event)
- func RecordDB(ctx context.Context, db *sql.DB, e Event)
- func RecordRequest(c *gin.Context, e Event)
- func Recorded(c *gin.Context) bool
- func Sensitive(field string) bool
- func Snapshot(fields map[string]any) map[string]any
- type Event
Constants ¶
const ( CategoryAuth = "auth" // sign-in, sign-out, 2FA, passwords, tokens, sessions CategoryAdmin = "admin" // changes made through admin pages and admin APIs CategoryAccess = "access" // read access (ticket views, downloads, exports); opt-in CategorySystem = "system" // retention purges and other unattended actions )
Categories group actions in the viewer.
const ( OutcomeSuccess = "success" OutcomeFailure = "failure" // the action was attempted and failed (wrong password, invalid input) OutcomeDenied = "denied" // the caller was not allowed to do it )
Outcomes.
const ( ActorAgent = "agent" ActorCustomer = "customer" ActorAnonymous = "anonymous" // not signed in (failed sign-ins, password reset requests) ActorSystem = "system" ActorPlugin = "plugin" )
Actor types.
const Redacted = "[redacted]"
Redacted replaces the value of a sensitive field in Changes.
Variables ¶
This section is empty.
Functions ¶
func Changes ¶
Changes compares before and after field values and returns the fields that differ as {"field": {"from": old, "to": new}}. Values of sensitive fields are replaced with Redacted, so the log shows that a secret changed but not what it was or became. A field missing on one side counts as nil. It returns nil when nothing changed.
func RecordRequest ¶
RecordRequest records e for the request: an empty actor, IP or user agent is filled from c, and the request is marked as recorded.
Types ¶
type Event ¶
type Event struct {
Time time.Time
Category string
// Action is a dotted name: area.object.verb, e.g. "auth.login",
// "admin.user.update", "access.ticket.view".
Action string
Outcome string
ActorType string
ActorID int64
ActorLogin string
IP string
UserAgent string
TargetType string
TargetID string
TargetLabel string
// Details holds event-specific context: a reason, the request route,
// field changes from Changes. Secrets must not be put here.
Details map[string]any
}
Event is one audit record. Category, Action and Outcome are required; Time defaults to now.