launcher

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 15 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 launcher resolves the child process the GUI-subsystem launcher (cmd/stepsecurity-dev-machine-guard-task) should spawn for a given invocation. The launcher itself lives in cmd/ and is Windows-only because it depends on Job Objects and CREATE_NO_WINDOW; the resolution logic is platform-agnostic and lives here so it can be unit-tested on the macOS CI runners that drive the rest of the test suite.

Index

Constants

View Source
const (
	BootstrapBinary = "stepsecurity-dev-machine-guard-bootstrap.exe"

	// ExitCannotStart is returned when no child could be started (D5). It is
	// outside {0, 1}, so a run record carrying it classifies as bad.
	ExitCannotStart = 70
	// ExitKilled is the exit status given to a child tree the bootstrap
	// terminated at its deadline.
	ExitKilled = 124

	EnvRunRecord         = "STEPSEC_RUN_RECORD"
	EnvRunID             = "STEPSEC_RUN_ID"
	EnvBootstrapVersion  = "STEPSEC_BOOTSTRAP_VERSION"
	EnvBootstrapFallback = "STEPSEC_BOOTSTRAP_FALLBACK"

	// UpdaterFailureThreshold consecutive failures of one updater version
	// make `update` fall back to the seed's updater.
	UpdaterFailureThreshold = 3
)

Bootstrap mode (spec §2, D2). The MSI installs this launcher a second time as BootstrapBinary in the install root; under that name it resolves the state.json pointer and launches the versioned binaries. It must stay tiny and frozen-safe: no network and no crypto, never crash, and read state.json only through the frozen pointer contract.

View Source
const (
	ReasonStateMissing      = updatestate.FallbackStateMissing
	ReasonStateCorrupt      = updatestate.FallbackStateCorrupt
	ReasonStateUnreadable   = updatestate.FallbackStateUnreadable
	ReasonCurrentMissing    = updatestate.FallbackCurrentMissing
	ReasonCurrentIncomplete = updatestate.FallbackCurrentIncomplete
	ReasonStartFailed       = updatestate.FallbackStartFailed
	ReasonUpdaterFailed     = updatestate.FallbackUpdaterFailed
	ReasonNoUpdater         = updatestate.FallbackNoUpdater
)

Fallback reasons passed in EnvBootstrapFallback. Reasons about a named version carry it after a colon (current_missing:1.20.0) so the agent can report update_pointer_invalid with update_from = that version.

View Source
const (
	// AgentBinary is the default child the launcher invokes when no
	// --exec flag is present. Sits next to the launcher in the install
	// directory (MSI: C:\Program Files\StepSecurity\, PowerShell:
	// %USERPROFILE%\.stepsecurity\bin\).
	AgentBinary = "stepsecurity-dev-machine-guard.exe"

	// ExecFlag opts into the generic-target launch mode used by the
	// PowerShell loader. See ResolveTarget for the contract.
	ExecFlag = "--exec"
)

Variables

This section is empty.

Functions

func IsBootstrapBinary added in v1.18.0

func IsBootstrapBinary(exePath string) bool

IsBootstrapBinary reports whether exePath is the bootstrap's file name.

func ResolveTarget

func ResolveTarget(argv []string) (string, []string, error)

ResolveTarget returns the child executable's absolute path and the argv slice to forward to it, derived from the launcher's own argv (i.e. os.Args[1:], not including the program name).

Two modes, dispatched on the first argument:

  • "--exec" mode. argv begins with --exec; the next element is the child binary (resolved via exec.LookPath so bare basenames like "powershell.exe" are accepted alongside fully-qualified paths), and the rest of argv is forwarded to it. Used by the PowerShell loader's scheduled task to wrap `powershell.exe -File loader.ps1 send-telemetry` under the launcher's no-console envelope.

  • Default (legacy / MSI) mode. argv does not begin with --exec; the child is the sibling AgentBinary in the launcher's own directory, and all of argv is forwarded to it. Preserves byte-for-byte compatibility with the launcher's pre-1.11.5 behaviour, which is what the MSI install layout's scheduled task action uses.

Errors (all returned from this function; the caller in cmd/.../main.go is responsible for mapping them to exit codes + stderr output per the contract below):

  • --exec without a target: malformed task action.
  • --exec target not on PATH: visible at install time rather than silently exiting.
  • Default mode with no sibling agent: most commonly indicates the launcher was deployed without its companion.

The launcher entrypoint distinguishes the two error contexts: --exec errors are written to stderr and the process exits 2, while default-mode errors stay silent and exit 1 (preserving byte-for-byte compatibility with the pre-1.11.5 launcher that MSI installs rely on).

func SetRunningVersion added in v1.18.0

func SetRunningVersion(string) error

SetRunningVersion is a no-op off Windows (no registry inventory).

Types

type Bootstrap added in v1.18.0

type Bootstrap struct {
	Layout   updatestate.Layout
	Spawn    Spawner
	IsSystem func() bool
	Now      func() time.Time
	Sleep    func(time.Duration)
	Getenv   func(string) string
	Environ  func() []string
	Out      io.Writer
	NewRunID func() string
	// SetRunningVersion records the version adopt-seed made current
	// (HKLM RunningVersion on Windows); nil skips it.
	SetRunningVersion func(string) error
	// SelfExe is this bootstrap's own image; adopt-seed copies it to
	// Layout.MSIHelperFile for the MSI's stop-for-msi action. "" skips it.
	SelfExe string
	// VerifySeed checks a seed's executables before adopt-seed copies them
	// (authenticode.SameSeedPublisher in production); nil skips it.
	VerifySeed func(path string) error

	AdoptLockWait  time.Duration // adopt-seed: bounded wait for the update lock
	RecordLockWait time.Duration // update: wait to record the updater result
	LockPoll       time.Duration
	RunLockWait    time.Duration // run-record lock; 0 means defaultRunLockWait
	UpdateDeadline time.Duration
	// contains filtered or unexported fields
}

Bootstrap runs the bootstrap verbs. All fields are injectable for tests; NewBootstrap fills production values.

func NewBootstrap added in v1.18.0

func NewBootstrap(exePath string, isSystem func() bool) *Bootstrap

NewBootstrap returns a production bootstrap rooted at the directory of exePath, with runs under the ProgramData data root.

func (*Bootstrap) AdoptSeed added in v1.18.0

func (b *Bootstrap) AdoptSeed(args []string) int

AdoptSeed is `adopt-seed --seed-dir <dir>` (SYSTEM, MSI custom action): protect versions\ and state\, copy the seed into versions\<seed> if absent, and point current at it when current is unusable or older. It always exits 0: it must never fail the MSI.

func (*Bootstrap) Main added in v1.18.0

func (b *Bootstrap) Main(argv []string) int

Main dispatches a bootstrap command line (argv without the program name).

func (*Bootstrap) Run added in v1.18.0

func (b *Bootstrap) Run(args []string) int

Run is `run <agent args...>`: launch versions\<v>\task.exe with args from the first usable of current → previous → seed, record the run, and return the child's exit code.

func (*Bootstrap) StopForMSI added in v1.18.0

func (b *Bootstrap) StopForMSI(args []string) int

StopForMSI is `stop-for-msi --install-dir <root>`, the MSI's first deferred action (D29): it stops every DMG process under root and waits, bounded, until no process holds any MSI-owned file, so Windows Installer never finds one in use (which needs a reboot). It runs from the helper copy in state\msi\, so its own image is not an MSI file. Always exits 0.

func (*Bootstrap) Update added in v1.18.0

func (b *Bootstrap) Update() int

Update is `update` (SYSTEM): pick the updater binary, run `agent.exe self-update --system`, and record its result in state.updater.

type SpawnResult added in v1.18.0

type SpawnResult struct {
	Started  bool  // false: the child never started (Err says why)
	ExitCode int   // valid when Started
	Killed   bool  // the deadline fired and the child's tree was terminated
	Err      error // start error, or a wait error with no exit status
}

SpawnResult is the outcome of one child run.

func SpawnHidden added in v1.18.0

func SpawnHidden(path string, args, env []string, deadline time.Duration, onStart func()) SpawnResult

SpawnHidden runs the child directly; off Windows there is no console or job object to manage, and only the direct child is killed on deadline.

type Spawner added in v1.18.0

type Spawner func(path string, args, env []string, deadline time.Duration, onStart func()) SpawnResult

Spawner starts path with args and env, calls onStart once the child is running, and waits for it. A positive deadline terminates the child's whole process tree when it expires.

Jump to

Keyboard shortcuts

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