mdm

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mdm defines the pluggable MDM provider interface and registry used by the Netmaker MDM posture-check feature. Concrete providers (Intune, Jamf, future Iru/JumpCloud/etc.) live in sibling packages and self-register via init().

Index

Constants

View Source
const (
	ProviderIntune    = "intune"
	ProviderJamf      = "jamf"
	ProviderJumpCloud = "jumpcloud"
	ProviderIru       = "iru"
)

Variables

View Source
var (
	ErrDeviceNotRegisteredInEntra = errors.New("device_not_registered_in_entra")
	ErrDeviceNotEnrolledInIntune  = errors.New("device_not_enrolled_in_intune")
	ErrDeviceNotFoundInMDM        = errors.New("device_not_found_in_mdm")
)

Posture-facing error codes returned by Entra-keyed MDM lookups.

Functions

func ActiveProviderID

func ActiveProviderID(ctx context.Context) (string, error)

ActiveProviderID returns the provider id of the active MDM integration, or "" if none.

func GetActive

func GetActive(ctx context.Context) (*schema.Integration, error)

GetActive returns the configured MDM integration row, or nil if none exists.

func LookupErrorCode

func LookupErrorCode(err error) string

LookupErrorCode maps a lookup error to a stable posture violation code. Returns "" for non-lookup failures (e.g. network errors).

func MatchHostToMDMDeviceBySerial

func MatchHostToMDMDeviceBySerial(h schema.Host, d ManagedDevice) bool

MatchHostToMDMDeviceBySerial matches a host to an MDM device by serial number only.

func RedactConfig

func RedactConfig(providerID string, configJSON json.RawMessage) (json.RawMessage, error)

RedactConfig returns config JSON with secrets masked for API responses.

func RefreshHostMDMState

func RefreshHostMDMState(ctx context.Context, h schema.Host) error

RefreshHostMDMState syncs MDM posture state for a single host before join or registration posture evaluation. It does not honour the global sync rate limit.

func Register

func Register(name, display string, f Factory)

Register binds a provider implementation to its stable name.

func RegisterCapabilities

func RegisterCapabilities(name string, c Capabilities)

RegisterCapabilities records the static capability profile of a provider.

func RunMDMSync

func RunMDMSync(ctx context.Context) error

RunMDMSync refreshes DeviceMDMState for hosts via the active provider. Intune prefers Entra-keyed lookup and falls back to serial_number when entra_device_id is absent; other providers list devices and match serial_number. Honours sync_interval_minutes from integration config as an optional per-tick rate-limit hint. Returns nil (no-op) if MDM is not configured.

func RunMDMSyncForce

func RunMDMSyncForce(ctx context.Context) error

RunMDMSyncForce ignores the rate-limit hint and triggers a fresh sync.

func SyncHostMDMState

func SyncHostMDMState(ctx context.Context, hostID string) error

SyncHostMDMState refreshes MDM posture state for one host. When the active provider supports Entra-keyed lookup, Graph is queried by entra_device_id or, when that is absent, the host is matched by serial_number.

func ValidateConfig

func ValidateConfig(providerID string, configJSON json.RawMessage) error

ValidateConfig validates provider config JSON for the given provider id.

Types

type Capabilities

type Capabilities struct {
	// ReportsCompliant is true if the provider populates ManagedDevice.Compliant
	// with a meaningful value derived from upstream compliance state. When
	// false, callers should treat Compliant as "unknown" rather than "false".
	ReportsCompliant bool
}

Capabilities advertises optional provider features so callers (UI / API) know what to surface.

func CapabilitiesFor

func CapabilitiesFor(name string) Capabilities

CapabilitiesFor returns the registered capability profile for a provider id.

type EntraDeviceLookup

type EntraDeviceLookup interface {
	LookupByEntraDeviceID(ctx context.Context, entraDeviceID string) (ManagedDevice, error)
}

EntraDeviceLookup is implemented by MDM providers that resolve a host using host.entra_device_id as Graph devices.deviceId. Intune queries GET /v1.0/devices first, then GET /deviceManagement/managedDevices when /devices returns no match. When entra_device_id is absent, Intune falls back to serial_number matching via ListManagedDevices.

type Factory

type Factory func(config json.RawMessage) (Provider, error)

Factory builds a Provider instance from integration config JSON.

type IntuneConfig

type IntuneConfig struct {
	SyncSettings
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	TenantID     string `json:"tenant_id"`
}

IntuneConfig is stored in integrations_v1.config for the intune provider.

type IruConfig

type IruConfig struct {
	SyncSettings
	APIURL                   string   `json:"api_url"`
	APIToken                 string   `json:"api_token"`
	ComplianceLibraryItemIDs []string `json:"compliance_library_item_ids,omitempty"`
}

IruConfig is stored in integrations_v1.config for the iru provider (Iru Endpoint Management, formerly Kandji). APIURL is the tenant API hostname from Settings (e.g. https://acme.api.iru.com or https://acme.api.kandji.io).

ComplianceLibraryItemIDs optionally limits compliance evaluation to specific library item IDs from GET /api/v1/devices/{device_id}/status. When empty, all parameters and library items must report a passing status (PASS, REMEDIATED/EXCLUDED/WARNING for parameters; PASS/success/EXCLUDED/AVAILABLE for library items).

type JamfConfig

type JamfConfig struct {
	SyncSettings
	ClientID          string   `json:"client_id"`
	ClientSecret      string   `json:"client_secret"`
	BaseURL           string   `json:"base_url"`
	ComplianceVendors []string `json:"compliance_vendors,omitempty"`
}

JamfConfig is stored in integrations_v1.config for the jamf provider.

ComplianceVendors optionally limits device-trust evaluation to named complianceVendor values from Jamf Conditional Access (e.g. "Jamf", "Intune"). When empty, every applicable compliance record for the device must be COMPLIANT.

type JumpCloudConfig

type JumpCloudConfig struct {
	SyncSettings
	ClientID            string   `json:"client_id"`
	ClientSecret        string   `json:"client_secret"`
	BaseURL             string   `json:"base_url"`
	CompliancePolicyIDs []string `json:"compliance_policy_ids,omitempty"`
}

JumpCloudConfig is stored in integrations_v1.config for the jumpcloud provider. Auth uses a JumpCloud service account (client_id + client_secret) against admin-oauth.id.jumpcloud.com with Basic auth. BaseURL defaults to https://console.jumpcloud.com.

CompliancePolicyIDs optionally limits device-trust evaluation to specific JumpCloud policy object IDs. When empty, all policy statuses returned for each system must pass.

type ManagedDevice

type ManagedDevice struct {
	// ProviderDeviceID is the primary key in the upstream MDM.
	ProviderDeviceID string
	// AzureADDeviceID is filled by Intune; non-Entra MDMs leave it blank.
	AzureADDeviceID string

	SerialNumber      string
	HardwareUUID      string
	DeviceName        string
	UserPrincipalName string // user email

	Enrolled   bool
	Compliant  bool
	LastSeenAt time.Time
}

ManagedDevice is the normalised, provider-agnostic view of a device that an MDM Provider returns. Fields that a given provider can't fill are left as their zero value.

type Provider

type Provider interface {
	// Name returns the stable identifier of this provider (matches integrations_v1.id).
	Name() string
	// Capabilities advertises optional provider features.
	Capabilities() Capabilities
	// Verify confirms credentials and connectivity against the upstream MDM.
	Verify(ctx context.Context) error
	// ListManagedDevices returns every device known to the upstream MDM.
	ListManagedDevices(ctx context.Context) ([]ManagedDevice, error)
}

Provider is the minimal contract every MDM integration must satisfy.

func Build

func Build(name string, config json.RawMessage) (Provider, error)

Build constructs a provider by explicit name from config JSON.

func BuildActive

func BuildActive(ctx context.Context) (Provider, error)

BuildActive builds the provider for the active MDM integration.

type ProviderType

type ProviderType struct {
	Name             string `json:"name"`
	Display          string `json:"display"`
	ReportsCompliant bool   `json:"reports_compliant"`
}

ProviderType describes a provider implementation available at compile time.

func ListProviderTypes

func ListProviderTypes() []ProviderType

ListProviderTypes returns the registered providers with capability flags.

type SyncSettings

type SyncSettings struct {
	SyncEnabled         bool `json:"sync_enabled"`
	SyncIntervalMinutes int  `json:"sync_interval_minutes"`
}

SyncSettings are shared across MDM provider configs.

func ParseSyncSettings

func ParseSyncSettings(providerID string, configJSON json.RawMessage) (SyncSettings, error)

ParseSyncSettings extracts sync settings from stored integration config.

Directories

Path Synopsis
Package intune implements an MDM provider backed by Microsoft Intune via Microsoft Graph.
Package intune implements an MDM provider backed by Microsoft Intune via Microsoft Graph.
Package iru implements an MDM provider backed by Iru Endpoint Management (formerly Kandji).
Package iru implements an MDM provider backed by Iru Endpoint Management (formerly Kandji).
Package jamf implements an MDM provider backed by Jamf Pro.
Package jamf implements an MDM provider backed by Jamf Pro.
Package jumpcloud implements an MDM provider backed by JumpCloud.
Package jumpcloud implements an MDM provider backed by JumpCloud.

Jump to

Keyboard shortcuts

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