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
- Variables
- func Action(a pipeline.Action) enginev1.Action
- func AddStats(p, d *eventsv1.PolicyStats)
- func DiffStats(cur, prev *eventsv1.PolicyStats) *eventsv1.PolicyStats
- func LatencyBounds() []float64
- func New(src Source, req *request.Request, path string, v pipeline.Verdict, ...) *eventsv1.SecurityEvent
- func NewID(now time.Time) string
- func Reason(r pipeline.Reason) enginev1.Reason
- func Split(batch *eventsv1.EventBatch, maxBytes int) []*eventsv1.EventBatch
- func SplitStats(policies []*eventsv1.PolicyStats, maxBytes int) []*eventsv1.RequestStats
- type Buffer
- type Counter
- type Recorder
- type Source
- type Stats
Constants ¶
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 ¶
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 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 ¶
func New(src Source, req *request.Request, path string, v pipeline.Verdict, now time.Time) *eventsv1.SecurityEvent
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 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 (*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) Next ¶
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.
type Recorder ¶
Recorder turns verdicts into events in a Buffer. A nil Recorder records nothing: an engine without an operator only logs its events.
type Source ¶
type Source struct {
EngineID string
PodNamespace string
PodName string
// BundleVersion returns the bundle being enforced (nil: 0).
BundleVersion func() uint64
}
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 (*Stats) Counter ¶ added in v0.3.0
Counter returns the policy's counter, the same one for every bundle that has the policy.
func (*Stats) Retain ¶ added in v0.3.0
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.