device

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 30 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

Index

Constants

View Source
const (
	IdentitySourceEnv    = "env"
	IdentitySourceConfig = "config"
	IdentitySourceSerial = "serial"
)

Identity sources, reported to the backend as device_id_source so support can answer "why does this device have this id" from the row alone. "serial" covers every machine-derived id (hardware serial, the machine-wide id file, a generated fallback).

View Source
const (
	TokenSerial   = "{serial}"
	TokenHostname = "{hostname}"
)

Identity template tokens. The template is a literal, or any mix of literal text and these tokens; it is expanded then sanitized (SanitizeDeviceID). A device is always a machine: there is no user token, because the users of a shared host are reported inside its device (user_identity and user_token on every upload), not as devices of their own.

View Source
const (
	VirtVendorAzure      = "azure"
	VirtVendorAWS        = "aws"
	VirtVendorGCP        = "gcp"
	VirtVendorHyperV     = "hyperv"
	VirtVendorVMware     = "vmware"
	VirtVendorKVM        = "kvm"
	VirtVendorQEMU       = "qemu"
	VirtVendorXen        = "xen"
	VirtVendorParallels  = "parallels"
	VirtVendorVirtualBox = "virtualbox"
	VirtVendorApple      = "apple"
	VirtVendorOther      = "other"
)

Vendor labels (model.Virtualization.Vendor).

View Source
const (
	VirtSourceIMDS    = "imds"
	VirtSourceSMBIOS  = "smbios"
	VirtSourceDMI     = "dmi"
	VirtSourceSysctl  = "sysctl"
	VirtSourceCPUInfo = "cpuinfo"
	VirtSourceSystemd = "systemd"
)

Evidence sources (model.Virtualization.Source).

View Source
const EnvDeviceID = "STEPSEC_DEVICE_ID"

EnvDeviceID is the environment variable that overrides the device identity template. It beats the config.json `device_id` key, which in turn beats the machine identity resolved by SerialNumber (id.go). Fleets that provision machines from a script (a VDI host pool, an image pipeline) set it machine-wide at bootstrap.

View Source
const SystemProbeTimeout = 60 * time.Second

SystemProbeTimeout bounds the hardware probe (the WMI subprocess) for the update task, which isn't latency-sensitive.

View Source
const (

	// UserTokenFingerprintLen is the length of the sha256 hex fingerprint of
	// the full principal appended to a user token (see userToken): 48 bits,
	// so two accounts sharing a short name on one host cannot be made to
	// collide by chance or by choosing a domain name.
	UserTokenFingerprintLen = 12
)

maxDeviceIDLen bounds a configured id. Longer ids keep a readable prefix and gain a deterministic hash suffix so two long templates never collide.

Variables

This section is empty.

Functions

func AttachIdentity added in v1.19.0

func AttachIdentity(exec executor.Executor, dev *model.Device)

AttachIdentity resolves the identity for a gathered Device and records it on the struct (DeviceID, DeviceIDSource, DeviceIDTemplate, IdentityIncomplete, UserToken, PerSessionScanning), which is what ID reads. Gather calls it; telemetry calls it again after a late serial resolve.

func DetectVirtualization added in v1.19.0

func DetectVirtualization(_ context.Context, exec executor.Executor) *model.Virtualization

DetectVirtualization classifies the machine once per process (the answer cannot change while the agent runs) on its own bounded context, so a caller's expiring ctx can never poison the cache. Gather calls it.

func FormatVirtualization added in v1.19.0

func FormatVirtualization(v *model.Virtualization) string

FormatVirtualization renders a classification for logs and the pretty output: "virtual (azure, imds)" / "physical" / "unknown".

func Gather

func Gather(ctx context.Context, exec executor.Executor) model.Device

Gather collects device information (hostname, serial, OS version, user identity) and resolves the device identity (DeviceID) from the configured template or, by default, the machine identity. See identity.go. It does not probe virtualization: hooks and policy lanes call Gather on a budget of a second and never report it; the scan paths attach DetectVirtualization.

func GatherWSL added in v1.17.0

func GatherWSL(ctx context.Context, exec executor.Executor) *model.WSLInfo

GatherWSL detects Windows Subsystem for Linux on the host. It returns nil on non-Windows platforms — WSL detection is host-side only; the Linux binary runs inside a distro and identifies itself separately. It never errors: every failure degrades to WSLPresenceUnknown so a partial probe can't read as a confident "no WSL".

func HasIdentityTemplate added in v1.19.0

func HasIdentityTemplate(exec executor.Executor) bool

HasIdentityTemplate reports whether the device identity is configured rather than derived from the machine identity.

func ID added in v1.18.0

func ID(dev model.Device) string

ID returns the device identity every backend call uses: the identity Gather resolved (a configured template or literal, else the machine identity), or "" when none is usable (never a placeholder like "unknown"). A Device not produced by Gather falls back to the configured literal (or template, expanded from the Device's own fields) and then its serial. Keep SerialNumber separate so telemetry retains the hardware identity.

func IDForGuest added in v1.18.0

func IDForGuest(dev model.Device, hostDeviceID, distroID string) string

IDForGuest gives the host/distro identity precedence over an inherited host config. Partial guest metadata falls back to the ordinary device identity.

func IdentityTemplate added in v1.19.0

func IdentityTemplate(exec executor.Executor) (template, source string)

IdentityTemplate returns the identity template in force: STEPSEC_DEVICE_ID when set, else config.json's device_id, else "" (machine identity). The source is returned alongside so callers can report it.

func ImageBuilderActive added in v1.19.0

func ImageBuilderActive(exec executor.Executor) bool

ImageBuilderActive reports whether scans are switched off on this machine: the marker exists and names this machine. A marker from another machine (the builder, seen from a clone) or one with no machine id is ignored.

func IsServiceAccount added in v1.19.0

func IsServiceAccount(exec executor.Executor, user string) bool

IsServiceAccount reports whether a user identity names a daemon context rather than a developer: empty or unknown, root when the process is root, and on Windows the well-known service accounts (NT AUTHORITY\SYSTEM, LOCAL SERVICE, NETWORK SERVICE, the NT SERVICE\ virtual accounts) and machine accounts (trailing $). It is the single predicate behind the payload's no_user_logged_in flag and the empty user token.

func MachineStateDir added in v1.19.0

func MachineStateDir() string

MachineStateDir returns the machine-wide state dir in force ("" when the shared-host features are off).

func PerSessionReason added in v1.19.0

func PerSessionReason(exec executor.Executor) string

PerSessionReason returns the human-readable reason per-session scanning is on for this host, or "" when it is not.

func PerSessionScanning added in v1.19.0

func PerSessionScanning(exec executor.Executor) (on bool, reason string)

PerSessionScanning reports whether this host scans every signed-in session separately (false when the host is not shared, the feature is off, or the OS is not Windows) and the display reason. The first positive decision writes the sticky marker; every later call reads it back. The answer is taken once per process (perSession): main evaluates it right after RecordScanUser, and everything else in the run reuses that snapshot.

func ProspectiveScanUser added in v1.19.0

func ProspectiveScanUser(exec executor.Executor)

ProspectiveScanUser makes the per-session decision of this process count the current user's visit today as a scan would, without writing it: for `identity`, which must answer what send-telemetry would do.

func RecordScanUser added in v1.19.0

func RecordScanUser(exec executor.Executor)

RecordScanUser notes the developer running this scan, and the day, in the machine-wide seen-users file so the users rule can switch the host to per-session scanning once two developers have each scanned on two different days. Only with config multi_user_detection = "users"; service accounts are never recorded. No-op where the machine dir is unavailable (non-Windows, per-user installs).

func ResetIDCache added in v1.18.0

func ResetIDCache()

ResetIDCache drops the process-wide identity and the hardware probe result. For tests.

func ResetPerSessionForTest added in v1.19.0

func ResetPerSessionForTest()

ResetPerSessionForTest drops the per-process per-session snapshot so a test can act as the next run. Tests only.

func ResetVirtualizationCache added in v1.19.0

func ResetVirtualizationCache()

ResetVirtualizationCache drops the memoized answer. For tests.

func SanitizeDeviceID added in v1.19.0

func SanitizeDeviceID(s string) string

SanitizeDeviceID makes a configured id safe for every key it is embedded in (DynamoDB composite keys use '#', S3 prefixes use '/'): runes outside [A-Za-z0-9._~-] become '-', runs of '-' collapse, leading and trailing '-' and '.' are trimmed, and an id longer than 128 bytes keeps its first 115 bytes plus a 12-hex-digit sha256 suffix so it stays unique and readable. Returns "" when nothing survives. Applied ONLY to configured ids; the machine-identity path is never touched.

func SerialNumber added in v1.15.0

func SerialNumber(ctx context.Context, exec executor.Executor) string

SerialNumber resolves the machine identity (the device_id absent a configured override) once per process, so the run gate, scan, enforcers and hooks can't disagree. It runs before any network beacon. With no source it generates and persists an ID; an exhausted ctx or an ID that can't be persisted yields "unknown" (not cached, so a later caller retries).

func SessionScope added in v1.19.0

func SessionScope(exec executor.Executor) string

SessionScope returns the per-session state scope for this run: the user token when this host scans every signed-in session separately and the current user is a real developer, else "" (shared state). It probes nothing (no serial, no hostname) so main can call it before any state path is touched.

func SetImageBuilder added in v1.19.0

func SetImageBuilder(exec executor.Executor, on bool) error

SetImageBuilder turns the switch on (write the marker bound to this machine) or off (empty it). Refuses to switch on when this machine has no usable hardware id: an unbound marker could not be told from a clone's own and would stop every host built from the image from scanning.

func SetLogger added in v1.19.0

func SetLogger(l *progress.Logger)

SetLogger routes the package's diagnostics to l.

func SetMachineStateDirForTest added in v1.19.0

func SetMachineStateDirForTest(dir string) (restore func())

SetMachineStateDirForTest overrides the machine-wide state dir and returns a func restoring the previous one. Tests only. Each override starts a fresh per-session snapshot (a test stands for a new process).

func SystemID added in v1.18.0

func SystemID(ctx context.Context, exec executor.Executor, cachePath string, probeTimeout time.Duration) string

SystemID is the device identity for the SYSTEM self-updater. probeTimeout bounds the hardware probe (the self-check passes a short one so its smoke test can't time out on a wedged WMI). It never reads the shared ProgramData device-id file, which users can write (M-9). A configured device_id is resolved the way the scan resolves it: a literal as given; a template expanded with the host name and the machine identity (systemMachineID). A template that still carries the retired {user} token falls back to the machine identity, as the scan does. Only a hardware result or a literal configured id is cached: a template's expansion is recomputed from the hardware cache each time, so a later probe failure never leaves SYSTEM with an id the user scans do not use. "" when nothing is usable.

func TemplateForReport added in v1.19.0

func TemplateForReport(template string) string

TemplateForReport is the template the payload reports as device_id_template: the template in force when it carries a token, "" for the hardware serial and for a literal id, which the backend already sees as device_id.

func UserToken added in v1.19.0

func UserToken(exec executor.Executor, user string) string

UserToken is the token the agent reports for the signed-in user (payload and beacon user_token) and uses as the per-session state scope: "" for a service account, else userToken sanitized for file names and keys.

func UserTokenFingerprint added in v1.19.0

func UserTokenFingerprint(principal string) string

UserTokenFingerprint is the fingerprint part of a user token: the first UserTokenFingerprintLen hex digits of the sha256 of the lowercased full principal (DOMAIN\user, or the whole email).

Types

type Identity added in v1.19.0

type Identity struct {
	DeviceID string
	Serial   string
	Source   string // IdentitySource*
	Template string // the raw env/config value; "" when Source == serial
	// Incomplete is true when a token expanded empty: {serial} on a machine
	// with no usable serial, {hostname} on a nameless host without one. An
	// incomplete identity must not reach the backend, so callers skip the run
	// and say why.
	Incomplete bool
	// Issue is a human-readable note for the log ("" when nothing is wrong):
	// an unknown token, a template that sanitized to nothing, and so on.
	Issue string
	// UserToken names the signed-in user this run scans for: the account's
	// short name plus a fingerprint of the full principal (userToken), "" for
	// a service account. Every upload and beacon carries it as user_token so
	// the backend files the run under the right user of this device.
	UserToken string
	// PerSession is true when this host scans every signed-in session
	// separately (device/multiuser.go): each session's run keeps its own
	// state and lock, all of them reporting under this one device.
	PerSession bool
	// SessionScope names the per-session state directory (paths.StateDir):
	// UserToken when PerSession and a user is signed in, else "".
	SessionScope string
}

Identity is the resolved device identity for this run.

DeviceID is what EVERY backend call uses (through ID / IDForGuest): the run gate, run-status beacons, the rules fetch, the upload bodies, device policy, hooks and the telemetry payload's device_id. Serial is the machine identity SerialNumber resolved and ships as the payload's serial_number regardless of how DeviceID was produced, so a rebuilt virtual desktop that keeps its configured identity still reports the hardware change.

func ResolveIdentity added in v1.19.0

func ResolveIdentity(exec executor.Executor, serial, hostname, user string) Identity

ResolveIdentity turns the configured template (or its absence) plus the probed facts into the identity used for every backend call, and records the session facts (UserToken, PerSession, SessionScope). Pure apart from the env/config read in IdentityTemplate and the per-session snapshot.

The machine-identity path is byte-identical to what the agent always sent: no sanitization is applied when there is no template, so an existing fleet never re-registers after an upgrade (VMware serials with spaces included).

func ResolvedDeviceID added in v1.19.0

func ResolvedDeviceID(ctx context.Context, exec executor.Executor) Identity

ResolvedDeviceID resolves the identity without a full Gather: the machine identity comes from SerialNumber (cached per process, so a second caller pays nothing) and only when the template needs it (the machine identity itself, {serial}, or {hostname} on a host without a usable name); hostname and user are cheap. Used by the run gate ahead of the device_info phase and by `uninstall --retire`.

Jump to

Keyboard shortcuts

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