Documentation
¶
Overview ¶
Package export sends the engines' security events to SIEMs and log pipelines, from every operator replica, without the control plane (design 0010): each replica exports the events of the engines connected to it, from one bounded buffer with a cursor per sink, as OTLP logs (gRPC or HTTP) or JSON over HTTP.
Index ¶
- Constants
- type AddressRefusedError
- type Exporter
- type Metrics
- type PrometheusMetrics
- func (PrometheusMetrics) BufferBytes(n int64)
- func (PrometheusMetrics) Dropped(sink, reason string, n int)
- func (PrometheusMetrics) Duration(sink string, d time.Duration)
- func (PrometheusMetrics) Exported(sink string, n int)
- func (PrometheusMetrics) Failed(sink, kind string)
- func (PrometheusMetrics) Forget(sink string)
- func (PrometheusMetrics) Pending(sink string, n uint64)
- func (PrometheusMetrics) Start(sink string)
- func (PrometheusMetrics) Succeeded(sink string, at time.Time)
- type SinkStatus
Constants ¶
const ( DefaultBufferBytes = 32 << 20 DefaultDiskBytes = 512 << 20 DefaultFlushTimeout = 15 * time.Second )
Defaults of the Exporter (design 0010 §2.4).
const ( // SchemaVersion is the schema's version: the scope version in OTLP. SchemaVersion = "1" // SchemaName is the "schema" of every JSON event. SchemaName = "inkwall.dev/security-event/v" + SchemaVersion )
The exported event (design 0010 §5): the SecurityEvent, with what the operator adds (the cluster, the time it received the event). Field names are stable within a schema version; the golden tests pin them.
const ( DropBufferFull = "buffer_full" DropRejected = "rejected" DropTooLarge = "too_large" )
Why events were never delivered: the reason label of the dropped metric.
const ( StateConfigInvalid = enginereport.SinkConfigInvalid StateAddressRefused = enginereport.SinkAddressRefused StateFailing = enginereport.SinkFailing StateDropping = enginereport.SinkDropping StateExporting = enginereport.SinkExporting )
The state classes of a sink, in the order of precedence of the EventsExported condition: the first that applies wins.
const DefaultStatusWindow = 5 * time.Minute
DefaultStatusWindow is how long a sink fails without a success to be Failing, and how recently one that dropped for a full buffer is Dropping (design 0010 §8).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddressRefusedError ¶
type AddressRefusedError struct {
// Class is loopback, unspecified, link-local or metadata.
Class string
}
AddressRefusedError is a connection refused by the dialer's guard. Its message names the address class, never the address.
func (*AddressRefusedError) Error ¶
func (e *AddressRefusedError) Error() string
type Exporter ¶
type Exporter struct {
// Client reads the InkwallConfig and the operator's Secrets (cached).
Client client.Reader
// APIReader reads the kube-system Namespace, whose UID is the cluster's
// ID, which the manager doesn't cache.
APIReader client.Reader
// Namespace is the operator's: the Secrets the sinks name are there.
Namespace string
// Dir holds the buffer on disk ("": in memory only); MemoryBytes and
// DiskBytes bound it (defaults DefaultBufferBytes, DefaultDiskBytes).
Dir string
MemoryBytes, DiskBytes int64
// FlushTimeout bounds the flush on Stop (default DefaultFlushTimeout).
FlushTimeout time.Duration
// Poll is how often the configuration and its Secrets are read again
// (default 2 s).
Poll time.Duration
// HasPolicy reports whether the bundle this replica serves has a policy
// (distribution.Store.HasPolicy): an event's policy counts only then.
HasPolicy func(string) bool
// StatusWindow: a sink failing this long without a success is
// Failing; one that dropped for a full buffer within it, Dropping
// (default DefaultStatusWindow; the e2e test shortens it).
StatusWindow time.Duration
Metrics Metrics
Log logr.Logger
// contains filtered or unexported fields
}
Exporter exports the security events this replica receives. It isn't a manager runnable: the distribution server starts it, and stops it once its gRPC server has stopped, so no Add comes after the flush.
func (*Exporter) Add ¶
func (e *Exporter) Add(b *eventsv1.EventBatch)
Add takes a batch from an engine (distribution.Server.Events), read only. It never blocks: it appends the batch under a mutex and returns, and a full buffer drops the oldest.
func (*Exporter) Report ¶
func (e *Exporter) Report() []enginereport.Sink
Report is Status as the replica's engine report carries it, for the leader's EventsExported condition and inkwallctl status.
func (*Exporter) Start ¶
Start opens the buffer (loading what a previous run left on disk) and starts the export. A directory that can't be used is replaced by memory.
func (*Exporter) Status ¶
func (e *Exporter) Status() []SinkStatus
Status is each sink's state on this replica, sorted by name; none without sinks.
type Metrics ¶
type Metrics interface {
Exported(sink string, n int)
Dropped(sink, reason string, n int)
Failed(sink, kind string)
Duration(sink string, d time.Duration)
Succeeded(sink string, at time.Time)
Pending(sink string, n uint64)
BufferBytes(n int64)
Forget(sink string)
// Start makes a new sink's series, at 0.
Start(sink string)
}
Metrics receives what the exporter counts (operator metrics); nil counts nothing.
type PrometheusMetrics ¶
type PrometheusMetrics struct{}
PrometheusMetrics reports to the operator's metrics registry.
func (PrometheusMetrics) BufferBytes ¶
func (PrometheusMetrics) BufferBytes(n int64)
BufferBytes sets the export buffer's size.
func (PrometheusMetrics) Dropped ¶
func (PrometheusMetrics) Dropped(sink, reason string, n int)
Dropped counts the events a sink never got, by reason.
func (PrometheusMetrics) Duration ¶
func (PrometheusMetrics) Duration(sink string, d time.Duration)
Duration observes a request's time.
func (PrometheusMetrics) Exported ¶
func (PrometheusMetrics) Exported(sink string, n int)
Exported counts the events a sink accepted.
func (PrometheusMetrics) Failed ¶
func (PrometheusMetrics) Failed(sink, kind string)
Failed counts a failed request, by kind.
func (PrometheusMetrics) Forget ¶
func (PrometheusMetrics) Forget(sink string)
Forget removes a removed sink's series.
func (PrometheusMetrics) Pending ¶
func (PrometheusMetrics) Pending(sink string, n uint64)
Pending sets the events the sink hasn't had accepted.
func (PrometheusMetrics) Start ¶
func (PrometheusMetrics) Start(sink string)
Start makes a sink's series, at 0.
type SinkStatus ¶
type SinkStatus struct {
Name string `json:"name"`
// State is one of the State constants.
State string `json:"state"`
// Message says why, for every state but Exporting: the error class,
// never a Secret or more than a short, escaped part of a response.
Message string `json:"message,omitempty"`
// Pending counts the events the sink hasn't had answered.
Pending uint64 `json:"pending"`
// Plaintext: the sink's endpoint is http:// or grpc://.
Plaintext bool `json:"plaintext,omitempty"`
LastSuccess time.Time `json:"lastSuccess,omitzero"`
}
SinkStatus is a sink's state on this replica.