mdm

package
v0.74.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package mdm reads MDM-managed configuration from platform-native sources (plist on macOS, registry on Windows, UserDefaults on iOS, RestrictionsManager on Android). The returned Policy is consumed by profilemanager.Config.apply() as the highest-priority override layer.

An empty Policy (no source present, or source present with zero keys) means no MDM enforcement is active and the client behaves as if the feature did not exist.

Index

Constants

View Source
const (
	KeyManagementURL            = "managementURL"
	KeyDisableUpdateSettings    = "disableUpdateSettings"
	KeyDisableProfiles          = "disableProfiles"
	KeyDisableNetworks          = "disableNetworks"
	KeyDisableClientRoutes      = "disableClientRoutes"
	KeyDisableServerRoutes      = "disableServerRoutes"
	KeyBlockInbound             = "blockInbound"
	KeyDisableMetricsCollection = "disableMetricsCollection"
	KeyAllowServerSSH           = "allowServerSSH"
	KeyDisableAutoConnect       = "disableAutoConnect"
	KeyPreSharedKey             = "preSharedKey"
	KeyRosenpassEnabled         = "rosenpassEnabled"
	KeyRosenpassPermissive      = "rosenpassPermissive"
	KeyWireguardPort            = "wireguardPort"

	// Split tunnel is modeled as a single conceptual policy with two
	// registry/plist values. KeySplitTunnelMode is the discriminator
	// ("allow" or "disallow"); KeySplitTunnelApps is a comma-separated
	// list of package names. The values are mutually exclusive by
	// construction — only one mode can be set at a time.
	KeySplitTunnelMode = "splitTunnelMode"
	KeySplitTunnelApps = "splitTunnelApps"

	// KeyLazyConnection forces the lazy-connection feature on or off, overriding
	// the management feature flag. Read as a bool (native bool, or on/off,
	// true/false, 1/0, yes/no); absent = defer to management.
	KeyLazyConnection = "lazyConnection"
)

Well-known policy keys. Names mirror the corresponding ConfigInput Go field names (lowerCamelCase) so the daemon can map a Policy key directly to a configuration field.

View Source
const (
	SplitTunnelModeAllow    = "allow"
	SplitTunnelModeDisallow = "disallow"
)

Split-tunnel mode literals (KeySplitTunnelMode values).

View Source
const DefaultReloadInterval = 1 * time.Minute

DefaultReloadInterval is the production cadence at which the desktop daemon re-reads the OS-native MDM policy. Picked to balance responsiveness against registry/plist I/O overhead. Mobile builds use OS-side notifications instead, hence anticipating the ticker mechanism entirely.

Variables

View Source
var SecretKeys = map[string]struct{}{
	KeyPreSharedKey: {},
}

SecretKeys lists keys whose values must be redacted in logs.

Functions

This section is empty.

Types

type Policy

type Policy struct {
	// contains filtered or unexported fields
}

Policy holds MDM-managed settings read from the platform source. A nil or empty Policy means no enforcement is active.

func LoadPolicy

func LoadPolicy() *Policy

LoadPolicy reads the platform-native MDM configuration. Returns an empty (but non-nil) Policy when no source is present, the source is empty, or the platform is unsupported.

Diagnostic logging differentiates the three states:

  • source absent / unsupported platform: trace log only
  • source present, zero keys: info "MDM enrolled (no managed keys)"
  • source present, N keys: info "MDM enrolled with N managed keys: [...]"

func NewPolicy

func NewPolicy(values map[string]any) *Policy

NewPolicy constructs a Policy from a key→value map. Pass nil or an empty map to construct an empty (no-enforcement) Policy. The returned *Policy is always non-nil.

func (*Policy) GetBool

func (p *Policy) GetBool(key string) (bool, bool)

GetBool returns the managed value for key coerced to bool, and whether the key was set. Accepts native bool and string literals (true/false, 1/0, yes/no, on/off), case-insensitively and trimmed of surrounding whitespace.

func (*Policy) GetInt

func (p *Policy) GetInt(key string) (int64, bool)

GetInt returns the managed value for key as int64, and whether the key was set. Accepts native int / int64 (as produced by the Windows registry loader for REG_DWORD/REG_QWORD) and numeric strings (decimal).

func (*Policy) GetString

func (p *Policy) GetString(key string) (string, bool)

GetString returns the managed value for key coerced to string, and whether the key was set. A non-string value returns ("", false).

func (*Policy) GetStringSlice

func (p *Policy) GetStringSlice(key string) ([]string, bool)

GetStringSlice returns the managed value for key as []string, and whether the key was set. Accepts []string, []any (of strings), and a single string (treated as a one-element list).

func (*Policy) HasKey

func (p *Policy) HasKey(key string) bool

HasKey reports whether the given key is MDM-managed.

func (*Policy) IsEmpty

func (p *Policy) IsEmpty() bool

IsEmpty reports whether the Policy has no managed keys.

func (*Policy) ManagedKeys

func (p *Policy) ManagedKeys() []string

ManagedKeys returns the sorted list of managed key names. Returns an empty slice (not nil) on an empty Policy.

type Ticker

type Ticker struct {
	// contains filtered or unexported fields
}

Ticker periodically re-reads the OS-native MDM policy via LoadPolicy and invokes the onChange callback (supplied to Run) whenever the observed Policy diverges from the last observation (added / removed / changed keys). Launch with Run from a goroutine; cancel the supplied context to stop.

func NewTicker

func NewTicker(reloadInterval time.Duration) *Ticker

NewTicker constructs a Ticker that will re-read the OS-native policy every reloadInterval once Run is called. The initial snapshot is populated by calling policyLoader at construction time so the first tick only fires onChange when the policy actually changed since boot — without this baseline the first tick would report every currently-managed key as "added" and trigger a spurious engine restart.

func (*Ticker) Run

func (t *Ticker) Run(ctx context.Context, onChange func(prev, curr *Policy) error)

Run blocks until ctx is cancelled, polling the OS-native policy store at the configured cadence and emitting log lines + onChange callback on every observed diff. onChange must be non-nil.

Jump to

Keyboard shortcuts

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