managedobserve

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLaunchdLabel = "security.kontext.managed-observe"

	// EnvExpectedConfigScope marks which managed-config scope a daemon was
	// installed for. The self-serve LaunchAgent sets it to "user"; the daemon
	// parks instead of running when the resolved scope differs, so an MDM
	// config appearing later is never served by the leftover self-serve agent.
	EnvExpectedConfigScope = "KONTEXT_EXPECTED_CONFIG_SCOPE"
)

Variables

This section is empty.

Functions

func Active

func Active() bool

func AuthErrorPath

func AuthErrorPath(dbPath string) string

AuthErrorPath puts the breadcrumb next to the observe database — the one directory both the daemon and doctor can always derive.

func ClearAuthError

func ClearAuthError(dbPath string) error

func DaemonStatusPath added in v0.15.1

func DaemonStatusPath(dbPath string) string

DaemonStatusPath puts the breadcrumb next to the observe database — the one directory both the daemon and doctor can always derive.

func DefaultDBPath

func DefaultDBPath() string

func DefaultIdleTimeout

func DefaultIdleTimeout() time.Duration

func DefaultLabel

func DefaultLabel() string

func DefaultSocketPath

func DefaultSocketPath() string

func EnsureSocketDir

func EnsureSocketDir(socketPath string) error

func KickstartLaunchd

func KickstartLaunchd(ctx context.Context, label string) error

func KickstartLaunchdKill added in v0.15.1

func KickstartLaunchdKill(ctx context.Context, label string) error

KickstartLaunchdKill runs launchctl kickstart with -k, which kills the running instance first; used to replace a daemon still running a stale binary.

func PrintStatus

func PrintStatus(out io.Writer, installedVersion string) (staleDaemon bool)

PrintStatus reports the managed-observe state for `kontext doctor`: which managed config (if any) this machine resolves, the installation identity, whether the daemon is reachable, the self-serve LaunchAgent, and any token-rejection breadcrumb the daemon left behind.

func RunDaemon

func RunDaemon(ctx context.Context, opts DaemonOptions) error

func WriteAuthError

func WriteAuthError(dbPath string, status int) error

func WriteDaemonStatus added in v0.15.1

func WriteDaemonStatus(dbPath, version string) error

func WriteStartupError

func WriteStartupError(dbPath string, message string) error

WriteStartupError records that the daemon exited before streaming — e.g. the keychain item was unreadable under launchd. Without it, doctor can only say "daemon: not running" with no cause.

Types

type AuthError

type AuthError struct {
	Kind    string `json:"kind"`
	Status  int    `json:"status,omitempty"`
	Message string `json:"message,omitempty"`
	At      string `json:"at"`
}

AuthError is the on-disk breadcrumb a daemon leaves when it cannot authenticate: kind "auth" for hosted-ledger rejections (revoked token), kind "startup" when the install token could not even be resolved (locked keychain, missing item). The daemon's stderr goes to a log file nobody watches, so `kontext doctor` reads this file to give the user the actual next step.

func LoadAuthError

func LoadAuthError(dbPath string) *AuthError

LoadAuthError returns the breadcrumb, or nil when none exists. Unreadable or corrupt files are returned as a distinct diagnostic kind so doctor never turns a local breadcrumb problem into a false revoked-token warning.

type DaemonOptions

type DaemonOptions struct {
	SocketPath             string
	DBPath                 string
	IdleTimeout            time.Duration
	StreamStatePath        string
	StreamInterval         time.Duration
	StreamHTTPClient       *http.Client
	GithubPolicyCachePath  string
	HubspotPolicyCachePath string
	// PolicyRefreshInterval and PolicyHTTPClient apply to every provider's
	// snapshot refresh loop (test knobs; zero values use defaults).
	PolicyRefreshInterval time.Duration
	PolicyHTTPClient      *http.Client
	Diagnostic            diagnostic.Logger
	// BinaryVersion is the CLI binary version, for startup logging and future
	// status reporting.
	BinaryVersion string
	// FallbackDeploymentVersion is reported to the ledger when no MDM
	// deployment-version marker exists (self-serve brew installs).
	FallbackDeploymentVersion string
	HomebrewUpdater           func(context.Context, managedconfig.LoadedConfig, diagnostic.Logger) <-chan struct{}
	BinaryWatchdog            func(context.Context, diagnostic.Logger) <-chan struct{}
}

type DaemonStatus added in v0.15.1

type DaemonStatus struct {
	Version   string `json:"version"`
	PID       int    `json:"pid"`
	StartedAt string `json:"started_at"`
}

DaemonStatus is the on-disk breadcrumb a daemon leaves after its socket is serving. It is written once at daemon startup; readers must verify the PID is alive before trusting it. A stale file from a dead daemon is expected and harmless.

func LoadDaemonStatus added in v0.15.1

func LoadDaemonStatus(dbPath string) *DaemonStatus

func WaitForDaemonRestart added in v0.15.1

func WaitForDaemonRestart(ctx context.Context, dbPath, socketPath, wantVersion string) (*DaemonStatus, error)

WaitForDaemonRestart polls until the socket is serving AND the status breadcrumb reports a live daemon on wantVersion (any live daemon when the version is not comparable, e.g. dev builds). `doctor --fix` uses it so "restarted" is only printed for a verified comeback — launchd can accept a kickstart and still have the new daemon exit immediately (unreadable token, missing Cellar path).

type Lifecycle

type Lifecycle struct {
	SocketPath string
	Label      string
	Kickstart  func(context.Context, string) error
	Diagnostic diagnostic.Logger
}

func NewLifecycle

func NewLifecycle() Lifecycle

func (Lifecycle) Process

func (l Lifecycle) Process(ctx context.Context, event hook.Event) hook.Result

Jump to

Keyboard shortcuts

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