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
- Variables
- func EnrollMessage(integration, kid, profile, sensorKey, mdmDeviceID string, ts int64, ...) []byte
- func NormalizeFleet(s string) (string, error)
- func ParseKey(raw []byte) ([]byte, error)
- func PolkitRule(level string) string
- func SaveSnapshotAt(path string, sn Snapshot) error
- func Uninstall(ctx context.Context, endpoint, authHeader, code, sensorKey string) error
- type Config
- type Credential
- type EnrollRequest
- type EnrollResponse
- type File
- type HTTPError
- type ProfileRef
- type Snapshot
- type Store
- func (s Store) ConfigPath() string
- func (s Store) CredentialPath() string
- func (s Store) HasCredential() bool
- func (s Store) LoadCredential() (Credential, error)
- func (s Store) SaveCredential(c Credential) error
- func (s Store) SaveSnapshot(sn Snapshot) error
- func (s Store) Uninstalling() bool
- func (s Store) UninstallingPath() string
- type UnitOptions
Constants ¶
const ( Standard = "standard" Hardened = "hardened" Locked = "locked" )
Protection levels.
const ( ServiceUnit = "vulnesis-sensor.service" GuardServiceUnit = "vulnesis-sensor-guard.service" GuardTimerUnit = "vulnesis-sensor-guard.timer" PolkitRuleName = "50-vulnesis-sensor.rules" )
Unit names.
const DefaultBinPath = "/usr/local/bin/vulnesis-sensor"
DefaultBinPath is where enroll installs the binary.
const DefaultDir = "/etc/vulnesis-sensor"
DefaultDir is where an enrolled sensor keeps its credential and config.
const DefaultEndpoint = "https://www.vulnetix.com/api/site"
DefaultEndpoint is the site API.
const EnrollMessagePrefix = "vulnetix-sensor-enroll/v1"
EnrollMessagePrefix is the first line of the signed MDM enroll message.
const LegacyEnvFile = "/etc/vulnesis-sensor.env"
LegacyEnvFile is install.sh's credential file, still read when present.
const WatchdogSec = 30
WatchdogSec is the hardened unit's watchdog; the sensor pings at half of it.
Variables ¶
var ErrNoCredential = errors.New("not enrolled: no sensor credential")
ErrNoCredential is returned when the device is not enrolled.
var ErrRevoked = errors.New("the sensor's credential was revoked")
ErrRevoked is returned once the site no longer accepts the device's credential.
var ErrUninstallRefused = errors.New("the site refused the uninstall code")
ErrUninstallRefused is a 403 from /uninstall: the code is wrong or spent.
var HTTPClient = &http.Client{Timeout: 60 * time.Second}
HTTPClient is used for every provisioning request.
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 ¶
NormalizeFleet lowercases and checks a fleet name. "" is no fleet.
func ParseKey ¶
ParseKey reads a base64 MDM key file (standard or URL alphabet, padded or not, surrounding whitespace ignored).
func PolkitRule ¶
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 ¶
SaveSnapshotAt writes a config snapshot to path.
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 ¶
AllowMajorUpdateOn reports whether the guard may cross a major version: off unless the profile says true.
func (Config) AutoUpdateOn ¶
AutoUpdateOn reports whether the sensor keeps itself current: on unless the profile says false.
func (Config) UserMayStop ¶
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 ¶
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.
type ProfileRef ¶
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 ¶
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 ¶
ConfigPath is the config snapshot enroll writes.
func (Store) CredentialPath ¶
CredentialPath is the credential file.
func (Store) HasCredential ¶
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 ¶
SaveSnapshot writes the store's config snapshot. It holds no secret.
func (Store) Uninstalling ¶
Uninstalling is whether an uninstall is in progress.
func (Store) UninstallingPath ¶
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.