anomaly

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 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 anomaly provides a lightweight, in-process behavioural anomaly detector that plugs into the audit-sink chain. It watches the stream of ledger events and emits structured slog warnings when a session's activity crosses configurable thresholds: contacting too many distinct network destinations, bursting shell executions, or accumulating denials. It keeps only small per-session summaries in memory and never blocks the caller, so it is safe to drop into auditsink.NewMulti alongside the real sinks.

Index

Constants

View Source
const (
	// EnvMaxHosts caps distinct network destinations per session before a
	// novel-host anomaly fires. Default 20.
	EnvMaxHosts = "RUNEWARD_ANOMALY_MAX_HOSTS"
	// EnvExecBurst is the number of shell execs within Window that trips an
	// exec-burst anomaly. Default 30.
	EnvExecBurst = "RUNEWARD_ANOMALY_EXEC_BURST"
	// EnvWindow is the sliding window for exec-burst detection. Default 1m.
	EnvWindow = "RUNEWARD_ANOMALY_WINDOW"
	// EnvMaxDenies caps deny verdicts per session before a denial-spike
	// anomaly fires. Default 10.
	EnvMaxDenies = "RUNEWARD_ANOMALY_MAX_DENIES"
)

Environment variables recognised by New, with their defaults.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counts

type Counts struct {
	NovelHost   int
	ExecBurst   int
	DenialSpike int
}

Counts is a snapshot of how many times each anomaly kind has fired (after rate limiting) since the detector was created.

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector inspects audit events and warns on anomalous per-session behaviour. It implements auditsink.Sink so it can be composed into auditsink.NewMulti. It is safe for concurrent use.

func New

func New(logger *slog.Logger) *Detector

New returns a Detector with thresholds read from the environment, falling back to the documented defaults. A nil logger uses slog.Default.

func (*Detector) Close

func (d *Detector) Close() error

Close is a no-op flush; the detector holds no external resources.

func (*Detector) Counts

func (d *Detector) Counts() Counts

Counts returns a snapshot of the anomaly counters.

func (*Detector) Emit

func (d *Detector) Emit(ev ledger.Event)

Emit inspects a single event and raises anomaly warnings as needed. It never blocks and never fails, matching the auditsink.Sink contract.

Jump to

Keyboard shortcuts

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