agent

package
v4.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: AGPL-3.0 Imports: 38 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 agent runs the sensor: it loads rules from the feeds, registers with what compiled, serves the proxies, ships events and applies decisions.

Losing the platform does not stop the sensor. Rules already compiled keep running, decisions already applied keep applying, and events wait in a bounded queue until the uplink answers again. If the queue fills, the oldest events are dropped and the count is reported with the next batch, so a gap is visible rather than silent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInventoryReport added in v4.19.0

func BuildInventoryReport(root string) (uplink.InventoryReport, error)

BuildInventoryReport reads the host under root (its processes and package databases) into the report the sensor posts. `vulnetix-sensor inventory --report` prints it, which is how to see what a host would send.

func ToDecision

func ToDecision(d uplink.Decision) decide.Decision

ToDecision converts a platform decision for the verdict engine.

Types

type Agent

type Agent struct {
	Verdicts *decide.Engine
	Rules    *proxy.Rules
	// ExitCode is the guarded workload's exit code, once Run returns.
	ExitCode int
	// Restart is set when Run returned because PollConfig asked for a
	// restart.
	Restart bool
	// contains filtered or unexported fields
}

Agent is a running sensor.

func New

func New(cfg Config) *Agent

New builds an agent. The proxies in cfg are wired to its verdict engine and rule set.

func (*Agent) Enqueue

func (a *Agent) Enqueue(e uplink.Event)

Enqueue adds an event to the outbound queue.

func (*Agent) Flush

func (a *Agent) Flush(ctx context.Context)

Flush posts the queue in batches of 500. A batch that fails goes back to the front of the queue.

func (*Agent) Mode

func (a *Agent) Mode() decide.Mode

Mode is the verdict engine's current mode.

func (*Agent) RefreshRules

func (a *Agent) RefreshRules(ctx context.Context) []uplink.RuleLoad

RefreshRules fetches every feed and, when any changed, compiles and installs the union of every feed's last good rules: a feed that did not change, or failed this round, contributes what it fetched before. It returns the rule loads to report, or nil when nothing changed or nothing could be fetched.

func (*Agent) ReportHostChecks

func (a *Agent) ReportHostChecks(now time.Time) int

ReportHostChecks reads the host's configuration and queues each failing check as an event in the cis lane. The event key includes the day, so a failure that persists is reported once a day, and one that is fixed stops.

func (*Agent) ReportInventory

func (a *Agent) ReportInventory(ctx context.Context) error

ReportInventory reads which installed packages processes map and posts it.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) error

Run serves until ctx ends.

func (*Agent) SetConfigEtag

func (a *Agent) SetConfigEtag(etag string)

SetConfigEtag records the etag of the profile config the sensor now runs.

func (*Agent) SetFeeds

func (a *Agent) SetFeeds(feeds []feed.Fetcher)

SetFeeds replaces the feeds. The next refresh fetches every one of them afresh and rebuilds the rule set from the new list only; a feed still in the list keeps its last good rules until its new source fetches.

func (*Agent) SetHold

func (a *Agent) SetHold(d time.Duration)

SetHold changes how long guard mode holds a new match.

func (*Agent) SetMode

func (a *Agent) SetMode(m decide.Mode)

SetMode changes the mode live, as a profile change does.

func (*Agent) StopReporting

func (a *Agent) StopReporting()

StopReporting stops the uplink: the sensor keeps enforcing what it has and reports nothing more.

type Config

type Config struct {
	SensorKey string
	Version   string
	Mode      decide.Mode
	Hold      time.Duration
	Facts     host.Facts

	Feeds  []feed.Fetcher
	Uplink *uplink.Client

	// Reverse is nil when the sensor does not front a port; Egress is nil
	// when it does not proxy outbound calls.
	Reverse       *proxy.Reverse
	ReverseListen string
	Egress        *proxy.Egress
	EgressListen  string

	// DNSListen is the UDP address the DNS guard answers on, forwarding to
	// DNSUpstream. Empty leaves DNS alone.
	DNSListen   string
	DNSUpstream string

	// OnHealthy is called once, after the first report the server accepts. The
	// self-update treats a new release as sound only after this.
	OnHealthy func()
	// UpdateState returns the last self-update outcome to report with each
	// register; nil when there is none.
	UpdateState func() json.RawMessage

	// TetragonExport is Tetragon's JSON export file. When set, every process
	// start is checked against the feeds' file-hash indicators.
	TetragonExport string
	// HostRoot is where the host's filesystem is visible to the sensor, for
	// hashing what a process ran: "/" on the host, or a mount in a container.
	HostRoot string

	// BPFLSM loads the BPF LSM exec guard (internal/sensor/lsmguard), which
	// refuses execs of the exact paths block-mode rules name, in the kernel.
	// Needs the bpf LSM and root; off by default.
	BPFLSM bool

	// ExecGuard is a workload command the sensor starts under its seccomp exec
	// guard (vulnetix-sensor run -- <command>), for compute with no eBPF such
	// as Fargate. Every exec the workload makes waits for the rules; Run
	// returns when the workload exits, with its code in ExitCode.
	ExecGuard []string

	// InventoryEvery is how often the in-use package inventory is read from
	// HostRoot/proc and reported. Zero turns it off.
	InventoryEvery time.Duration

	// SIEM, when set, gets a copy of every DNS and egress decision, matched
	// or not, for Guardian (--forward siem). Nil forwards nothing.
	SIEM *siem.Forwarder

	// PollConfig, when set, is called every ConfigEvery (default five
	// minutes) for an enrolled sensor's profile changes. It applies what it
	// can to the running agent; returning true stops Run cleanly so the
	// service manager restarts the sensor with the new configuration.
	PollConfig  func(ctx context.Context, a *Agent) (restart bool)
	ConfigEvery time.Duration
	// ConfigEtag is the etag of the profile config the sensor started on. When
	// the decisions long-poll names another one, PollConfig runs at once (at
	// most every ConfigSoonest, default ten seconds) rather than waiting for
	// the tick, which stays as the fallback. PollConfig reports the etag it
	// applies with SetConfigEtag.
	ConfigEtag    string
	ConfigSoonest time.Duration

	// Notify is sd_notify, sdnotify.Notify outside tests. READY=1 is sent
	// when Run starts and WATCHDOG=1 at half the unit's watchdog interval.
	Notify           func(state string) (bool, error)
	WatchdogInterval time.Duration

	FeedEvery      time.Duration
	HeartbeatEvery time.Duration
	FlushEvery     time.Duration
	QueueLimit     int

	Logf func(string, ...any)
}

Config is how the sensor is run.

Jump to

Keyboard shortcuts

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