events

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 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 events turns the engine's security events into SecurityEvents (0002 §5.4) and holds them, bounded, until the agent sends them to the operator. Redaction happens here, before anything leaves the engine (0002 §8.3): no bodies, no query strings, no snippets from credentials, and every field the client controls truncated to its limit.

Index

Constants

View Source
const (
	// DefaultCapacity bounds the events held while the operator is away:
	// about 10 MiB at the contract's field limits.
	DefaultCapacity = 10_000
	// MaxBatch is the contract's limit on a batch.
	MaxBatch = 1_000
)

Defaults of the Buffer.

Variables

View Source
var Redacted = []string{"Authorization", "Cookie", "Set-Cookie", "Proxy-Authorization"}

Redacted are the headers whose values never leave the engine, not even as a snippet (0002 §8.3).

Functions

func Action

func Action(a pipeline.Action) enginev1.Action

Action is a verdict's action in the API's terms.

func AddStats added in v0.3.0

func AddStats(p, d *eventsv1.PolicyStats)

AddStats adds d's counts to p's (same policy). Latency counts of another length (other buckets) are left out.

func DiffStats added in v0.3.0

func DiffStats(cur, prev *eventsv1.PolicyStats) *eventsv1.PolicyStats

DiffStats returns what cur counted since prev, two cumulative reports of one policy (prev nil: none before). A count lower than before means the counts started again from zero: then all of cur is new. Latency in other buckets than prev's is left out.

func LatencyBounds added in v0.3.0

func LatencyBounds() []float64

LatencyBounds returns the latency buckets' upper bounds in seconds, as RequestStats.latency_bounds carries them.

func New

New builds the event for a request and its verdict. path is the request's path without the query string, as the adapter logs it.

func NewID

func NewID(now time.Time) string

NewID returns a ULID for now: sortable by time, unique by its 80 random bits.

func Reason

func Reason(r pipeline.Reason) enginev1.Reason

Reason is a verdict's reason in the API's terms.

func Sensitive added in v0.5.0

func Sensitive(name string) bool

Sensitive reports whether a name looks like a credential's, so that its value never leaves the engine, not even as a snippet: it contains one of sensitiveParts, or "ssn" between non-letters, without regard to case. It errs on the side of redacting ("author" is sensitive).

func Split added in v0.1.4

func Split(batch *eventsv1.EventBatch, maxBytes int) []*eventsv1.EventBatch

Split cuts batch into batches of at most maxBytes encoded each, in order, so each fits a message limit. The first carries batch's dropped count. An event over maxBytes on its own (not one New makes) is left out and counted as dropped.

func SplitStats added in v0.3.0

func SplitStats(policies []*eventsv1.PolicyStats, maxBytes int) []*eventsv1.RequestStats

SplitStats splits policies into RequestStats of at most maxBytes each (one policy per message at least), so a report of many policies never makes a large message.

Types

type Buffer

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

Buffer holds events until the agent sends them, in order of time. Full, it drops the oldest and counts them: events are best effort, inspection never waits for them. Safe for concurrent use.

func NewBuffer

func NewBuffer(capacity int) *Buffer

NewBuffer returns a buffer of capacity events (DefaultCapacity when 0).

func (*Buffer) Add

func (b *Buffer) Add(ev *eventsv1.SecurityEvent)

Add records ev, dropping the oldest event when full. It never blocks.

func (*Buffer) Collectors

func (b *Buffer) Collectors() []prometheus.Collector

Collectors returns the buffer's metrics.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns how many events are held.

func (*Buffer) Next

func (b *Buffer) Next(ctx context.Context, max int) *eventsv1.EventBatch

Next waits for events, then takes up to max of them (MaxBatch when 0 or more) as a batch, with the count dropped since the previous batch. It returns nil when ctx ends first.

func (*Buffer) Return

func (b *Buffer) Return(batch *eventsv1.EventBatch)

Return puts back a batch that couldn't be sent, ahead of newer events, so nothing is lost while the buffer has room: the oldest are dropped first, as Add does.

type Counter added in v0.3.0

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

Counter counts one policy's requests: a few atomic adds per request.

func (*Counter) Observe added in v0.3.0

func (c *Counter) Observe(v pipeline.Verdict)

Observe counts a verdict. A nil Counter counts nothing.

type LogLimiter added in v0.5.0

type LogLimiter struct {
	// Now is the clock, time.Now when nil (for tests).
	Now func() time.Time
	// contains filtered or unexported fields
}

LogLimiter rate-limits security event log lines per policy and rule with a token bucket, so a scanner or one false positive on a busy route can't flood the logs. It doesn't touch the events sent to the operator. A nil LogLimiter, or one with a rate of 0, allows every line. Safe for concurrent use.

func NewLogLimiter added in v0.5.0

func NewLogLimiter(perSecond int) *LogLimiter

NewLogLimiter allows perSecond lines per policy and rule each second, in bursts of as many; 0 allows every line.

func (*LogLimiter) Allow added in v0.5.0

func (l *LogLimiter) Allow(v pipeline.Verdict) (bool, uint64)

Allow reports whether v's line is logged and, when it is, how many lines of its policy and rule were left out since the last one.

func (*LogLimiter) Collectors added in v0.5.0

func (l *LogLimiter) Collectors() []prometheus.Collector

Collectors returns the limiter's metrics.

func (*LogLimiter) Suppressed added in v0.5.0

func (l *LogLimiter) Suppressed() *prometheus.CounterVec

Suppressed is the counter of lines left out, by policy.

type LogMatch added in v0.5.0

type LogMatch struct {
	RuleID   int    `json:"rule_id"`
	Variable string `json:"variable"`
}

LogMatch is where a rule matched, for logs and the check API: the rule and the variable's name, never the matched value.

func LogMatches added in v0.5.0

func LogMatches(v pipeline.Verdict) []LogMatch

LogMatches returns where v's rules matched, bounded as in events: at most 32 matches, variable names cut to 128 bytes of valid UTF-8.

type Recorder

type Recorder struct {
	Source Source
	Buffer *Buffer
	// Log rate-limits the events' log lines (nil: every one is logged).
	Log *LogLimiter
}

Recorder turns verdicts into events in a Buffer. A nil Recorder records nothing: an engine without an operator only logs its events.

func (*Recorder) AllowLog added in v0.5.0

func (r *Recorder) AllowLog(v pipeline.Verdict) (bool, uint64)

AllowLog reports whether v's log line is written, and how many lines of its policy and rule were left out since the last one.

func (*Recorder) Record

func (r *Recorder) Record(req *request.Request, path string, v pipeline.Verdict)

Record adds the event for req and v.

type Redaction added in v0.5.0

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

Redaction is what a match leaves no snippet for, on top of the fixed redaction: InkwallConfig.spec.events.redact, from the bundle. A nil Redaction adds nothing.

func NewRedaction added in v0.5.0

func NewRedaction(cfg *bundlev1.EventsConfig) *Redaction

NewRedaction returns the redaction a bundle's events config asks for (nil: none beyond the fixed one).

type Source

type Source struct {
	EngineID     string
	PodNamespace string
	PodName      string
	// BundleVersion returns the bundle being enforced (nil: 0).
	BundleVersion func() uint64
	// Redaction returns the bundle's redaction (nil, or nil returned: the
	// fixed one only).
	Redaction func() *Redaction
}

Source is the engine and pod the events come from.

type Stats added in v0.3.0

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

Stats counts the requests each policy decides, for the operator (0002 §5.2). Safe for concurrent use.

func NewStats added in v0.3.0

func NewStats() *Stats

NewStats returns empty counters.

func (*Stats) Counter added in v0.3.0

func (s *Stats) Counter(policy string) *Counter

Counter returns the policy's counter, the same one for every bundle that has the policy.

func (*Stats) Retain added in v0.3.0

func (s *Stats) Retain(keep map[string]bool)

Retain retires the counters of policies not in keep (the new bundle's): Take reports them once more, then drops them.

func (*Stats) Take added in v0.3.0

func (s *Stats) Take() []*eventsv1.PolicyStats

Take returns what each policy counted since the previous Take, sorted by policy, leaving out policies that counted nothing.

Jump to

Keyboard shortcuts

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