provision

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 21 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 provision is the sensor side of sensor provisioning (vdb-site docs/sensor-provisioning-api.md): enrolling a device, as a person or with an MDM key, keeping the credential and the profile's configuration on disk, pulling configuration changes, and rendering the systemd units for the profile's protection level.

Index

Constants

View Source
const (
	Standard = "standard"
	Hardened = "hardened"
	Locked   = "locked"
)

Protection levels.

View Source
const (
	ServiceUnit      = "vulnesis-sensor.service"
	GuardServiceUnit = "vulnesis-sensor-guard.service"
	GuardTimerUnit   = "vulnesis-sensor-guard.timer"
	PolkitRuleName   = "50-vulnesis-sensor.rules"
)

Unit names.

View Source
const DefaultBinPath = "/usr/local/bin/vulnesis-sensor"

DefaultBinPath is where enroll installs the binary.

View Source
const DefaultDir = "/etc/vulnesis-sensor"

DefaultDir is where an enrolled sensor keeps its credential and config.

View Source
const DefaultEndpoint = "https://www.vulnetix.com/api/site"

DefaultEndpoint is the site API.

View Source
const EnrollMessagePrefix = "vulnetix-sensor-enroll/v1"

EnrollMessagePrefix is the first line of the signed MDM enroll message.

View Source
const LegacyEnvFile = "/etc/vulnesis-sensor.env"

LegacyEnvFile is install.sh's credential file, still read when present.

View Source
const WatchdogSec = 30

WatchdogSec is the hardened unit's watchdog; the sensor pings at half of it.

Variables

View Source
var ErrNoCredential = errors.New("not enrolled: no sensor credential")

ErrNoCredential is returned when the device is not enrolled.

View Source
var ErrRevoked = errors.New("the sensor's credential was revoked")

ErrRevoked is returned once the site no longer accepts the device's credential.

View Source
var ErrUninstallRefused = errors.New("the site refused the uninstall code")

ErrUninstallRefused is a 403 from /uninstall: the code is wrong or spent.

View Source
var HTTPClient = &http.Client{Timeout: 60 * time.Second}

HTTPClient is used for every provisioning request.

View Source
var UserAgent = "vulnetix-sensor"

UserAgent is sent on every request.

Functions

func EnrollMessage

func EnrollMessage(integration, kid, profile, sensorKey, mdmDeviceID string, ts int64, nonce string) []byte

EnrollMessage is the exact message an MDM enroll signs.

func NormalizeFleet

func NormalizeFleet(s string) (string, error)

NormalizeFleet lowercases and checks a fleet name. "" is no fleet.

func ParseKey

func ParseKey(raw []byte) ([]byte, error)

ParseKey reads a base64 MDM key file (standard or URL alphabet, padded or not, surrounding whitespace ignored).

func PolkitRule

func PolkitRule(level string) string

PolkitRule refuses anyone but root starting, stopping, masking or enabling the sensor and its guard. systemd names the unit for manage-units; it does not for manage-unit-files (enable, disable, mask act on files), so that action is refused for every unit to anyone but root: on a hardened host, an administrator changes unit files with sudo.

func SaveSnapshotAt

func SaveSnapshotAt(path string, sn Snapshot) error

SaveSnapshotAt writes a config snapshot to path.

func Uninstall

func Uninstall(ctx context.Context, endpoint, authHeader, code, sensorKey string) error

Uninstall records the uninstall; a locked sensor needs a code from the console first. sensorKey is sent when set (an ApiKey credential needs it).

Types

type Config

type Config struct {
	Mode                  string   `json:"mode"`
	Hold                  string   `json:"hold,omitempty"`
	Feeds                 []string `json:"feeds"`
	FeedKey               string   `json:"feedKey"`
	EgressListen          string   `json:"egressListen"`
	DNSListen             string   `json:"dnsListen"`
	Forward               []string `json:"forward"`
	InventoryEvery        string   `json:"inventoryEvery,omitempty"`
	Protection            string   `json:"protection"`
	AllowUserStop         bool     `json:"allowUserStop"`
	HeartbeatAlertMinutes int      `json:"heartbeatAlertMinutes,omitempty"`
	// AutoUpdate lets the guard replace the sensor with the latest release.
	// Absent means on; false pins the fleet to the installed version.
	AutoUpdate *bool `json:"autoUpdate,omitempty"`
	// AllowMajorUpdate lets the guard take a release with a higher major version.
	// Absent or false holds the sensor on its major version: a major release can
	// change the profile format, the units and the protocol.
	AllowMajorUpdate *bool `json:"allowMajorUpdate,omitempty"`
	// UpdateBaseURL is an https mirror of the release layout
	// (<base>/latest, <base>/download/<tag>/checksums.txt and the binaries) for
	// hosts that cannot reach GitHub. Empty means GitHub.
	UpdateBaseURL string `json:"updateBaseUrl,omitempty"`
}

Config is a profile's sensor configuration, as the site sends it.

func (Config) AllowMajorUpdateOn

func (c Config) AllowMajorUpdateOn() bool

AllowMajorUpdateOn reports whether the guard may cross a major version: off unless the profile says true.

func (Config) AutoUpdateOn

func (c Config) AutoUpdateOn() bool

AutoUpdateOn reports whether the sensor keeps itself current: on unless the profile says false.

func (Config) Level

func (c Config) Level() string

Level is the protection level, standard when unset or unknown.

func (Config) UserMayStop

func (c Config) UserMayStop() bool

UserMayStop is whether a manual stop is allowed. A locked sensor never allows one, whatever allowUserStop says.

type Credential

type Credential struct {
	Scheme     string `json:"scheme"` // Sensor | ApiKey
	Value      string `json:"value"`
	DeviceUUID string `json:"deviceUuid"`
	Endpoint   string `json:"endpoint"`
}

Credential is what the device authenticates with.

func (Credential) AuthHeader

func (c Credential) AuthHeader() string

AuthHeader is the Authorization header value for c. A Sensor value is "<deviceUuid>:<secret>" as the site returns it; a bare secret is prefixed with the device uuid.

func (Credential) SensorKeyParam

func (c Credential) SensorKeyParam(sensorKey string) string

SensorKeyParam is the sensor key to name in config pulls and uninstalls: an ApiKey credential (user-key and org-key profiles) does not identify the device, so the site needs the key; a Sensor credential does, so "".

type EnrollRequest

type EnrollRequest struct {
	SensorKey   string `json:"sensorKey"`
	Hostname    string `json:"hostname"`
	ComputeKind string `json:"computeKind"`
	OS          string `json:"os"`
	Arch        string `json:"arch"`
	Version     string `json:"version"`
	// Profile asks for a profile by uuid; it must still match.
	Profile string `json:"profile"`
	// MDMDeviceID is the serial or MDM device id, MDM enrolls only.
	MDMDeviceID string `json:"mdmDeviceId,omitempty"`
	// Fleet names a group of interchangeable short-lived hosts (an autoscaled
	// runner pool). The site files their findings under one repository and
	// retires members that stop reporting. Empty for an ordinary host.
	Fleet string `json:"fleet,omitempty"`
}

EnrollRequest is what the device says about itself when it enrolls.

type EnrollResponse

type EnrollResponse struct {
	DeviceUUID string     `json:"deviceUuid"`
	Profile    ProfileRef `json:"profile"`
	Credential struct {
		Scheme string `json:"scheme"`
		Value  string `json:"value"`
	} `json:"credential"`
	Config     Config `json:"config"`
	ConfigEtag string `json:"configEtag"`
	// Fleet is the fleet the site recorded. A site that predates fleets leaves it
	// empty, which enroll reports.
	Fleet string `json:"fleet"`
}

EnrollResponse is the site's answer to an enroll.

func EnrollWithMDM

func EnrollWithMDM(ctx context.Context, endpoint string, privKeySeed []byte, integration, kid, profile string, req EnrollRequest) (EnrollResponse, error)

EnrollWithMDM enrolls with no person, signing with the key the MDM pushed.

func EnrollWithPerson

func EnrollWithPerson(ctx context.Context, endpoint, authHeader string, req EnrollRequest) (EnrollResponse, error)

EnrollWithPerson enrolls with a person's own credential (authHeader is the whole Authorization value: "ApiKey <principal>:<hmac>" or "Bearer <token>").

func (EnrollResponse) Snapshot

func (r EnrollResponse) Snapshot() Snapshot

Snapshot is the response's config snapshot.

func (EnrollResponse) StoredCredential

func (r EnrollResponse) StoredCredential(endpoint string) Credential

StoredCredential is the response's credential, to store for endpoint.

type File

type File struct {
	Path    string
	Mode    os.FileMode
	Content string
}

File is one file the units consist of.

func RenderUnits

func RenderUnits(cfg Config, binPath string, opts ...UnitOptions) []File

RenderUnits returns the systemd units (and, from hardened up, the polkit rule) for cfg's protection level, running binPath.

Every level gets the sensor service and the guard timer. The guard runs as root once a minute: it keeps the units in step with the profile (so a profile raised to hardened takes effect without a reinstall) and, from hardened up, restores a sensor that was stopped, disabled or masked.

The service runs as a dynamic user, which cannot read the root-only credential, so systemd hands it over with LoadCredential=.

type HTTPError

type HTTPError struct {
	Method, Path string
	Status       int
	Message      string
	// Revoked is the site saying, in so many words, that this device is
	// switched off. A 401 without it is a deploy in flight or a proxy fault.
	Revoked bool
}

HTTPError is a refusal from the site, with its error message.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type ProfileRef

type ProfileRef struct {
	UUID string `json:"uuid"`
	Name string `json:"name"`
}

ProfileRef names the profile a device enrolled under.

type Snapshot

type Snapshot struct {
	Profile    ProfileRef `json:"profile"`
	Config     Config     `json:"config"`
	ConfigEtag string     `json:"configEtag"`
}

Snapshot is the last configuration the device pulled.

func LoadSnapshot

func LoadSnapshot(paths ...string) (Snapshot, string, error)

LoadSnapshot reads the newest of the snapshots at paths: enroll writes one under the store, and the running sensor (which cannot write /etc) writes what it pulls to its state directory. A missing file is skipped.

func PollConfig

func PollConfig(ctx context.Context, endpoint, authHeader, etag, sensorKey string) (Snapshot, bool, error)

PollConfig pulls the profile's config. With etag set it asks for a change only: changed is false on 304. The etag goes as ?etag= as well as If-None-Match, because the worker in front of the site API drops If-None-Match. sensorKey is needed with an ApiKey credential only (see Credential.SensorKeyParam), which names a person or an org, not the device. ErrRevoked only when the site says the device is revoked; any other 401 is an error to retry, since a sensor that wrongly decides it is revoked stops reporting until someone restarts it.

type Store

type Store struct {
	Dir string
}

Store is the on-disk state of an enrolled device.

func (Store) ConfigPath

func (s Store) ConfigPath() string

ConfigPath is the config snapshot enroll writes.

func (Store) CredentialPath

func (s Store) CredentialPath() string

CredentialPath is the credential file.

func (Store) HasCredential

func (s Store) HasCredential() bool

HasCredential is whether a credential is stored, from systemd's credentials directory or the store. It does not need to read the file.

func (Store) LoadCredential

func (s Store) LoadCredential() (Credential, error)

LoadCredential reads the credential.

func (Store) SaveCredential

func (s Store) SaveCredential(c Credential) error

SaveCredential writes the credential, readable by root only.

func (Store) SaveSnapshot

func (s Store) SaveSnapshot(sn Snapshot) error

SaveSnapshot writes the store's config snapshot. It holds no secret.

func (Store) Uninstalling

func (s Store) Uninstalling() bool

Uninstalling is whether an uninstall is in progress.

func (Store) UninstallingPath

func (s Store) UninstallingPath() string

UninstallingPath is the uninstall-in-progress marker.

type UnitOptions

type UnitOptions struct {
	ConfigDir string // default /etc/vulnesis-sensor
	UnitDir   string // default /etc/systemd/system
	PolkitDir string // default /etc/polkit-1/rules.d
}

UnitOptions says where the files go. The zero value is the real system.

func (UnitOptions) PolkitRulePath

func (o UnitOptions) PolkitRulePath() string

PolkitRulePath is where the hardened polkit rule goes.

func (UnitOptions) UnitPaths

func (o UnitOptions) UnitPaths() []string

UnitPaths is every file RenderUnits can write, for removal.

Jump to

Keyboard shortcuts

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