sense

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 10 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 sense defines the contract every host sensor implements, the registry sensors register into, and the runner that drives them.

A sensor looks at one kind of thing on the host (a package database, a file tree, a certificate store) and returns only what it saw, as evidence.Batch: observations and coverage. It never builds a CBOM, never asserts what software can do, and never says a fact is stronger than the method that found it. Capability is decided later, from cited knowledge (internal/knowledge and internal/derive); the CBOM is a projection of the result (internal/cbom).

Import rules, enforced by test (arch_test.go): sensors do not import cbom, derive, os/exec or net. That is what keeps operating-system code at the edge.

Index

Constants

This section is empty.

Variables

View Source
var Default = NewRegistry()

Default is the process-wide registry that sensors register into from init.

Functions

func Register

func Register(name string, f Factory)

Register adds a factory to Default. It panics on error: a bad registration is a programming mistake and must fail loudly at start-up (as with database/sql.Register).

Types

type Env

type Env struct {
	// FS is the host's root filesystem, addressed with unrooted slash-separated
	// paths ("var/lib/dpkg/status"). Natively it is os.DirFS of the root; in a
	// container with the host mounted at /host it is os.DirFS("/host"); in tests
	// it is an fstest.MapFS. A sensor must read the host only through it.
	FS fs.FS
	// OS is the host's operating system family: "linux" or "windows".
	OS string
	// Tier is the privilege tier this run has: "user" or "admin". It is recorded on
	// every observation; a sensor never escalates.
	Tier string
	// Live is true only when FS is the running machine's own root, so the operating
	// system itself may be asked about it. It is false for a mounted disk, a container
	// image, a `--root` override or a test fixture. A sensor that asks the OS (native
	// APIs) must run only when Live: otherwise it would describe the wrong machine.
	Live bool
}

Env is what a sensor may use to look at the host. Everything a sensor reads comes through it, so a sensor is testable with a fake filesystem and the platform layer is the only place that touches the operating system.

type Factory

type Factory func(Env) (Sensor, error)

Factory constructs a Sensor for a host. Constructors must be cheap and side-effect free: all I/O belongs in Detect and Collect.

type Info

type Info struct {
	// Name is the registry key and the name used in configuration: lowercase
	// kebab-case, e.g. "apt".
	Name string
	// Version is the sensor's own version (semver).
	Version string
	// Methods lists the method IDs the sensor uses (see evidence.Methods).
	Methods []string
}

Info describes a sensor.

func (Info) Validate

func (i Info) Validate() error

Validate reports whether the info is well formed and its methods are declared.

type Options

type Options struct {
	Env      Env
	Enabled  []string      // run only these sensors; empty means all registered
	Disabled []string      // never run these
	Timeout  time.Duration // per-sensor budget for Detect plus Collect; 0 means none
}

Options configures a run.

type Registry

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

Registry maps sensor names to factories.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry. Tests use their own; production code uses Default, filled by sensor packages' init functions.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the registered sensor names, sorted.

func (*Registry) New

func (r *Registry) New(name string, env Env) (Sensor, error)

New builds the named sensor for env. It verifies that the sensor's Info is valid and carries the name it was registered under, which catches copy-paste registration mistakes at start-up.

func (*Registry) Register

func (r *Registry) Register(name string, f Factory) error

Register adds a factory under name. It fails on an invalid or duplicate name or a nil factory.

type Result

type Result struct {
	Runs    []Run
	Batches []evidence.Batch
}

Result is the outcome of a run.

func Sensors

func Sensors(ctx context.Context, reg *Registry, opts Options) (Result, error)

Sensors executes the selected sensors one after another, in name order.

A sensor that fails, times out or panics is recorded and the rest still run: one broken sensor must not blank the inventory. It returns an error only for a request that cannot be honoured, such as naming a sensor that does not exist, which is nearly always a typo in configuration.

func (Result) Denied

func (r Result) Denied() int

Denied is the total number of locations sensors could not read for lack of permission.

func (Result) Incomplete

func (r Result) Incomplete() bool

Incomplete reports whether the result is known to be incomplete: a sensor failed or was cut short, or a budget was hit. A skipped sensor is not incomplete (absence of an ecosystem is a fact, not a fault), and neither is a scope that merely had unreadable locations: that is reported as a privilege warning, not as an error (ADR-0009).

type Run

type Run struct {
	Name         string
	Info         Info // zero if the sensor could not be constructed
	Status       Status
	Err          error
	Observations int
	Duration     time.Duration
}

Run records what happened to one sensor.

type Sensor

type Sensor interface {
	// Info identifies the sensor. Cheap, side-effect free, the same every time.
	Info() Info

	// Detect reports whether this kind of thing is present on the host.
	//
	//	(true,  nil)  present: Collect will be called.
	//	(false, nil)  absent: the sensor is skipped. The normal outcome of, say, the
	//	              dpkg sensor on a Windows host.
	//	(false, err)  presence could not be determined; recorded as a failure.
	Detect(ctx context.Context) (bool, error)

	// Collect returns what the sensor saw. A non-nil error means the result is
	// INCOMPLETE; the Batch returned alongside is still valid and kept, because a
	// partial inventory beats none.
	Collect(ctx context.Context) (evidence.Batch, error)
}

Sensor inventories one kind of thing on the local host.

One-shot and (later) daemon modes drive sensors through the same calls. A sensor must:

  • be read-only: never modify the host;
  • honour ctx cancellation;
  • be repeatable: Detect and Collect may be called many times on one value;
  • not assume concurrent use: the runner calls a sensor sequentially;
  • report what it could not see as Coverage, never as silence.

type Status

type Status string

Status is the outcome of one sensor in one run.

const (
	StatusOK      Status = "ok"      // collected completely
	StatusSkipped Status = "skipped" // this kind of thing is not on the host (normal)
	StatusPartial Status = "partial" // collection failed part-way; findings so far are kept
	StatusFailed  Status = "failed"  // nothing could be collected
)

The possible statuses.

Directories

Path Synopsis
Package all links in every built-in sensor.
Package all links in every built-in sensor.
Package certfiles is the sensor for X.509 certificates that a Linux host keeps as files: the system trust store, CA anchors, and the certificates of the services that run on it.
Package certfiles is the sensor for X.509 certificates that a Linux host keeps as files: the system trust store, CA anchors, and the certificates of the services that run on it.
Package debian is the sensor for Debian-family hosts (Debian, Ubuntu, Kali and derivatives).
Package debian is the sensor for Debian-family hosts (Debian, Ubuntu, Kali and derivatives).
Package pefiles is the sensor for cryptographic libraries that live as loose files rather than in a package database, which is how most of them exist on Windows (an application bundles its own OpenSSL, NSS or GnuTLS).
Package pefiles is the sensor for cryptographic libraries that live as loose files rather than in a package database, which is how most of them exist on Windows (an application bundles its own OpenSSL, NSS or GnuTLS).
pefilestest
Package pefilestest builds small, valid PE images with a version resource, so the PE parser, the sensor and the pipeline are tested on any OS without shipping real binaries.
Package pefilestest builds small, valid PE images with a version resource, so the PE parser, the sensor and the pipeline are tested on any OS without shipping real binaries.
Package sensetest provides a scriptable fake sensor for testing code that drives sensors (the registry, the runner, the pipeline) without a real host.
Package sensetest provides a scriptable fake sensor for testing code that drives sensors (the registry, the runner, the pipeline) without a real host.
Package wincerts is the sensor for the certificates in the Windows system certificate stores: the machine's own certificates, the trust anchors (root and intermediate authorities), trusted publishers and trusted people, for the machine and for the user the collector runs as.
Package wincerts is the sensor for the certificates in the Windows system certificate stores: the machine's own certificates, the trust anchors (root and intermediate authorities), trusted publishers and trusted people, for the machine and for the user the collector runs as.
Package wincng is the sensor for the cryptography Windows itself provides: the CNG algorithm registry and primitive providers, key storage providers (KSPs) and legacy cryptographic service providers (CSPs).
Package wincng is the sensor for the cryptography Windows itself provides: the CNG algorithm registry and primitive providers, key storage providers (KSPs) and legacy cryptographic service providers (CSPs).

Jump to

Keyboard shortcuts

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