monitor

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BehaviorNetwork  = "network"
	BehaviorOpen     = "open"
	BehaviorExec     = "exec"
	BehaviorProtocol = "protocol"
	BehaviorDNS      = "dns"
)

Behavior names emitted on findings; they match reporter.Finding.Behavior.

Variables

This section is empty.

Functions

This section is empty.

Types

type FindingSink

type FindingSink interface {
	Report(reporter.Finding)
}

FindingSink receives the findings monitor mode produces. *reporter.Reporter satisfies it; tests use a recording fake.

type Monitor

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

Monitor implements events.RuntimePolicyEventHandler (policy tracking), events.NamespaceEventHandler (namespaceSelector input) and runtimeevent.Sink (event evaluation). It is not a pod-event handler: events carry their own attributed pod identity (filled by pkg/attribution), so monitor keeps no pod state at all.

func New

func New(log logr.Logger, findings FindingSink, m *metrics.Metrics) *Monitor

New builds a Monitor. findings and m may each be nil: a daemon without a reporter (or without metrics) still evaluates events, it just has fewer places to put the result.

func (*Monitor) HandleEvent

func (m *Monitor) HandleEvent(ev runtimeevent.Event)

HandleEvent evaluates ev against every tracked policy that selects the event's pod, emitting at most one finding per (policy, pod) for this event. Monitor-mode policies produce counterfactual findings for every violation; enforce-mode policies produce enforced findings only for events the kernel actually denied.

It satisfies runtimeevent.Sink: fast, non-blocking and never panicking outward. The whole body runs behind utils.Guard because the finding sink is an interface supplied by the daemon.

func (*Monitor) Len

func (m *Monitor) Len() int

Len reports how many policies are tracked (test/debug helper).

func (*Monitor) Name

func (m *Monitor) Name() string

Name identifies this sink to the collector.

func (*Monitor) NamespaceEvent

func (m *Monitor) NamespaceEvent(name string, nsLabels map[string]string, evType string)

NamespaceEvent keeps the namespace label cache in step. A delete drops the entry, which leaves an event from a pod in that namespace matching only the policies whose namespaceSelector is empty — the namespace is going away, so no policy should keep selecting into it.

func (*Monitor) RuntimePolicyEvent

func (m *Monitor) RuntimePolicyEvent(rp *compiler.EvaluationResult, rpEventType string) error

RuntimePolicyEvent tracks monitor- AND enforce-mode policies and forgets everything else.

Monitor-mode policies are tracked for the counterfactual ("would this have been denied"). Enforce-mode policies are tracked so a kernel deny can be attributed to the policy whose lists produced it: the kernel maps have no policy dimension, so this userspace re-evaluation is what answers "which policy denied that". A deleted policy is untracked, as is one whose behaviors hold no value at all or whose mode is unknown: none of those can ever produce a finding, and keeping them would only slow the event path down.

Jump to

Keyboard shortcuts

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