Documentation
¶
Overview ¶
Package uplink is the runtime sensor's client for the vdb-site runtime routes (docs/runtime-sensor-api.md there): register with the rules it compiled, post rule matches and holds, and long-poll decisions.
It authenticates with the org's ApiKey through pkg/auth, so a sensor holds the same credential the CLI does, or with an enrolled device's Sensor credential (Authorization). Neither can make a decision: the site refuses decisions from both.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) AuthHeader() string
- func (c *Client) Base() string
- func (c *Client) Goodbye(ctx context.Context, sensorKey, reason, detail string) error
- func (c *Client) PollDecisionPage(ctx context.Context, sensorKey string, since int64, wait time.Duration) (DecisionPage, error)
- func (c *Client) PollDecisions(ctx context.Context, sensorKey string, since int64, wait time.Duration) ([]Decision, int64, error)
- func (c *Client) PostEvents(ctx context.Context, sensorKey string, events []Event) (int, []string, error)
- func (c *Client) PostInventory(ctx context.Context, sensorKey string, packages []InventoryPackage) (int, error)
- func (c *Client) PostInventoryReport(ctx context.Context, sensorKey string, r InventoryReport) (int, error)
- func (c *Client) Register(ctx context.Context, r Registration) (string, error)
- func (c *Client) Stop()
- func (c *Client) Stopped() bool
- type Decision
- type DecisionPage
- type Event
- type InventoryPackage
- type InventoryReport
- type Metrics
- type PassStat
- type Registration
- type RuleLoad
Constants ¶
const DefaultEndpoint = "https://www.vulnetix.com/api/site"
DefaultEndpoint is the site API.
Variables ¶
var ErrStopped = errors.New("uplink stopped: the sensor no longer reports")
ErrStopped is returned by every call once Stop was called.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Endpoint string
Creds *auth.Credentials
// Authorization, when set, is the whole Authorization header and wins
// over Creds: an enrolled device's "Sensor <deviceUuid>:<secret>".
Authorization func() string
HTTP *http.Client
Version string
// contains filtered or unexported fields
}
Client talks to /v1/runtime.
func (*Client) AuthHeader ¶
AuthHeader is the Authorization header every call sends: the device's Sensor credential, else the ApiKey one. Empty with neither.
func (*Client) Goodbye ¶
Goodbye says the sensor is stopping, so the console shows a stop rather than a silent host. reason is signal, stop, uninstall or upgrade.
func (*Client) PollDecisionPage ¶
func (c *Client) PollDecisionPage(ctx context.Context, sensorKey string, since int64, wait time.Duration) (DecisionPage, error)
PollDecisionPage is PollDecisions with the whole answer. On error the cursor is since.
func (*Client) PollDecisions ¶
func (c *Client) PollDecisions(ctx context.Context, sensorKey string, since int64, wait time.Duration) ([]Decision, int64, error)
PollDecisions waits up to wait for decisions after since, and returns them with the cursor to poll from next.
func (*Client) PostEvents ¶
func (c *Client) PostEvents(ctx context.Context, sensorKey string, events []Event) (int, []string, error)
PostEvents sends at most 500 events. It returns how many the server stored and the ones it refused, by index and reason.
func (*Client) PostInventory ¶
func (c *Client) PostInventory(ctx context.Context, sensorKey string, packages []InventoryPackage) (int, error)
PostInventory replaces the sensor's in-use package report.
func (*Client) PostInventoryReport ¶
func (c *Client) PostInventoryReport(ctx context.Context, sensorKey string, r InventoryReport) (int, error)
PostInventoryReport replaces the sensor's package report and says how complete it is.
type Decision ¶
type Decision struct {
UUID string `json:"uuid"`
RuleTable string `json:"ruleTable"`
RuleUUID string `json:"ruleUuid"`
SensorScope string `json:"sensorScope"`
Subject string `json:"subject"`
Verdict string `json:"verdict"`
Value string `json:"value,omitempty"`
DecidedAt int64 `json:"decidedAt"`
Until int64 `json:"until,omitempty"`
RevokedAt int64 `json:"revokedAt,omitempty"`
}
Decision is what a person decided.
type DecisionPage ¶
type DecisionPage struct {
Decisions []Decision `json:"decisions"`
Cursor int64 `json:"cursor"`
// ConfigEtag is the etag of the device's profile config, for an
// enrolled device; empty for a hand-configured sensor. A sensor running
// another etag pulls its config at once instead of at its next tick.
ConfigEtag string `json:"configEtag,omitempty"`
}
DecisionPage is one long-poll answer.
type Event ¶
type Event struct {
EventKey string `json:"eventKey"`
RuleTable string `json:"ruleTable"`
RuleUUID string `json:"ruleUuid"`
Lane string `json:"lane"`
SubjectKind string `json:"subjectKind"`
Subject string `json:"subject"`
Action string `json:"action"`
HoldExpiresAt int64 `json:"holdExpiresAt,omitempty"`
Detail map[string]any `json:"detail,omitempty"`
ObservedAt int64 `json:"observedAt"`
}
Event is one rule match or hold.
type InventoryPackage ¶
type InventoryPackage struct {
Name string `json:"name"`
Version string `json:"version"`
Ecosystem string `json:"ecosystem"`
State string `json:"state"`
Processes int `json:"processes"`
Examples []string `json:"examples,omitempty"`
// Purl is the package URL carrying the host's real distro, architecture
// and source package, which is what a distro advisory matches on.
Purl string `json:"purl,omitempty"`
// Arch is the package's architecture: a host may carry one package for
// two (libc6 for amd64 and i386).
Arch string `json:"arch,omitempty"`
// Files are up to 5 of the package's files a running process has mapped
// (its shared libraries, not only the executable): where a flaw in it is
// loaded.
Files []string `json:"files,omitempty"`
}
InventoryPackage is one package running processes map.
type InventoryReport ¶
type InventoryReport struct {
Packages []InventoryPackage `json:"packages"`
// Complete is nil when the sensor cannot say (the site then guards on the
// counts), true when every package database present was read, and false
// when one could not be.
Complete *bool `json:"complete,omitempty"`
// Warnings name the databases that could not be read.
Warnings []string `json:"warnings,omitempty"`
// Unsupported is why this host's packages cannot be read at all.
Unsupported string `json:"unsupported,omitempty"`
// Seq orders this sensor's reports: the time the host was read, in ms. The
// site does not apply a report older than the last it applied.
Seq int64 `json:"seq,omitempty"`
}
InventoryReport is one inventory post. Complete, Warnings and Unsupported say how much of the host it describes: the site replaces the stored list with a report only when it can trust it to be the whole host.
type Metrics ¶
type Metrics struct {
StartedAt int64 `json:"startedAt"`
UptimeSec int64 `json:"uptimeSec"`
CPUSec float64 `json:"cpuSec"`
RSSBytes uint64 `json:"rssBytes"`
HeapBytes uint64 `json:"heapBytes"`
SysBytes uint64 `json:"sysBytes"`
Goroutines int `json:"goroutines"`
NumGC uint32 `json:"numGc"`
Passes map[string]PassStat `json:"passes"`
}
Metrics is the sensor's own footprint and the state of its periodic work, sent with every heartbeat.
type PassStat ¶
type PassStat struct {
LastAt int64 `json:"lastAt"`
DurationMs int64 `json:"durationMs"`
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
Runs int `json:"runs"`
Failures int `json:"failures"`
}
PassStat is how one kind of periodic work (inventory, feeds, config, hostchecks, flush) last went.
type Registration ¶
type Registration struct {
SensorKey string `json:"sensorKey"`
ComputeKind string `json:"computeKind"`
ResourceArn string `json:"resourceArn,omitempty"`
Hostname string `json:"hostname"`
Mode string `json:"mode"`
Version string `json:"version"`
KernelVersion string `json:"kernelVersion,omitempty"`
Capabilities map[string]bool `json:"capabilities"`
RulesetEtag string `json:"rulesetEtag,omitempty"`
// Metrics is what the sensor costs the host and how its periodic work went.
Metrics *Metrics `json:"metrics,omitempty"`
// UpdateState is the outcome of the last self-update the guard recorded
// ({"state","from","to","reason","at"}); nil when there is none.
UpdateState json.RawMessage `json:"updateState,omitempty"`
// RuleLoads nil leaves the server's list as it is; an empty slice says
// the sensor loads nothing. Encoded by Register.
RuleLoads []RuleLoad `json:"-"`
}
Registration is what the sensor says about itself.
type RuleLoad ¶
type RuleLoad struct {
RuleTable string `json:"ruleTable"`
RuleUUID string `json:"ruleUuid"`
Status string `json:"status"` // compiled | rejected | no-engine
Reason string `json:"reason,omitempty"`
Mode string `json:"mode"` // block | log
}
RuleLoad is whether the sensor compiled one rule.