Documentation
¶
Overview ¶
Package dbaudit records every database explorer action off the request path. A full queue drops the event and counts it: audit must never block a query, but the loss has to be visible.
Index ¶
- Constants
- func RunSweeper(ctx context.Context, sink Sink, set Settings, ...)
- func Sweep(ctx context.Context, sink Sink, set Settings, now time.Time) (int64, error)
- type Event
- type Options
- type Reservation
- type ServiceSettings
- func (s ServiceSettings) MaxRows(ctx context.Context) int
- func (s ServiceSettings) QueueSize(ctx context.Context) int
- func (s ServiceSettings) RetentionDays(ctx context.Context) int
- func (s ServiceSettings) StoreText(ctx context.Context) bool
- func (s ServiceSettings) TextMaxBytes(ctx context.Context) int
- type Settings
- type Sink
- type Writer
- func (w *Writer) Close()
- func (w *Writer) CountUnauthenticated()
- func (w *Writer) Dropped() uint64
- func (w *Writer) Failed() uint64
- func (w *Writer) Flush(ctx context.Context)
- func (w *Writer) HasRoom(ctx context.Context) bool
- func (w *Writer) Record(ctx context.Context, ev Event)
- func (w *Writer) RecordReserved(ctx context.Context, ev Event, r *Reservation)
- func (w *Writer) Reserve(ctx context.Context) (*Reservation, bool)
- func (w *Writer) Start()
- func (w *Writer) Unauthenticated() uint64
- func (w *Writer) WriteMetrics(out io.Writer, prefix string) error
Constants ¶
const ( OutcomeOK = "ok" OutcomeDenied = "denied" OutcomeRejected = "rejected" OutcomeTimeout = "timeout" OutcomeCancelled = "cancelled" OutcomeError = "error" )
Outcomes and operation kinds the explorer reports.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct {
At time.Time
DatabaseName string
DatabaseID string
Engine string
PrincipalType string
PrincipalID string
PrincipalName string
Ability string
Action string
OpKind string
Fingerprint string
StatementText string
RowsReturned int64
Bytes int64
DurationMs int64
Outcome string
ErrorClass string
ClientIP string
ClientKind string
BranchName string
RequestID string
}
Event is one explorer action. StatementText is dropped unless the setting allows it.
type Options ¶
Options tune the writer; zero values use the defaults below, which callers seed from env.
type Reservation ¶
type Reservation struct {
// contains filtered or unexported fields
}
Reservation is one queue slot held for a request that must be audited.
func (*Reservation) Release ¶
func (r *Reservation) Release()
Release gives the slot back; calling it after RecordReserved or twice is harmless.
type ServiceSettings ¶
type ServiceSettings struct{ Svc *runtimesettings.Service }
ServiceSettings adapts the live settings service.
func (ServiceSettings) MaxRows ¶
func (s ServiceSettings) MaxRows(ctx context.Context) int
MaxRows is the live row cap the sweeper enforces.
func (ServiceSettings) QueueSize ¶
func (s ServiceSettings) QueueSize(ctx context.Context) int
QueueSize is the live queue bound.
func (ServiceSettings) RetentionDays ¶
func (s ServiceSettings) RetentionDays(ctx context.Context) int
RetentionDays is the live retention window.
func (ServiceSettings) StoreText ¶
func (s ServiceSettings) StoreText(ctx context.Context) bool
StoreText reports whether statement text may be stored.
func (ServiceSettings) TextMaxBytes ¶
func (s ServiceSettings) TextMaxBytes(ctx context.Context) int
TextMaxBytes is the live bound on stored statement text.
type Settings ¶
type Settings interface {
StoreText(ctx context.Context) bool
QueueSize(ctx context.Context) int
RetentionDays(ctx context.Context) int
MaxRows(ctx context.Context) int
TextMaxBytes(ctx context.Context) int
}
Settings are read on every call so a live change applies at once.
type Sink ¶
type Sink interface {
InsertDatabaseStatementAudits(ctx context.Context, rows []store.DatabaseStatementAudit) error
PruneDatabaseStatementAudits(ctx context.Context, cutoff time.Time, chunk int) (int64, error)
TrimDatabaseStatementAudits(ctx context.Context, maxRows, chunk int) (int64, error)
}
Sink is the store surface the writer and sweeper need.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer batches events and flushes them on an interval or when enough rows wait.
func (*Writer) CountUnauthenticated ¶
func (w *Writer) CountUnauthenticated()
CountUnauthenticated counts a request that had no principal; no row is written for it.
func (*Writer) Dropped ¶
Dropped counts events lost to a full queue or a failed id; Failed counts rows a flush could not write.
func (*Writer) Flush ¶
Flush writes everything queued now. A failed batch is retried once, then written row by row so one bad row costs only itself; rows that still fail are counted and logged.
func (*Writer) HasRoom ¶
HasRoom reports whether the queue can take one more event; a write path asks before it acts.
func (*Writer) Record ¶
Record queues one event and never blocks. A full queue drops it and counts the drop.
func (*Writer) RecordReserved ¶
func (w *Writer) RecordReserved(ctx context.Context, ev Event, r *Reservation)
RecordReserved queues the event into the slot the reservation holds.
func (*Writer) Reserve ¶
func (w *Writer) Reserve(ctx context.Context) (*Reservation, bool)
Reserve holds one slot so a write that passed the room check cannot lose its event to readers filling the queue meanwhile. Release it when the request ends; RecordReserved consumes it.
func (*Writer) Unauthenticated ¶
Unauthenticated counts explorer requests that carried no principal and wrote no row.