mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-02 04:51:29 +02:00
The mobile bridges only carried the policy fetcher, leaving every enforcement decision to the native apps: the desktop derived its UI restrictions in the Wails service layer, the daemon kept the conflict machinery in the server package, and both mobile bridges duplicated the JSON fetch adapter. Anything the native side had to reimplement was a place for iOS and Android to drift apart. Enforcement now lives in client/mdm and is consumed identically by all three platforms: - conflicts.go holds the value-aware conflict checks lifted out of the daemon, so the same normalization (canonical URLs, PSK sentinel echo) applies wherever a config change is validated. - restrictions.go derives the UI enforcement snapshot from a policy and renders it in the JSON shape the desktop frontend already consumes. The service-layer types become aliases, keeping one source of truth. - jsonloader.go replaces the adapter that was copy-pasted into both bridges. - changedetector.go moves change detection off the native side: the caller forwards the OS notification and asks whether the managed configuration actually changed, instead of diffing dictionaries itself. The mobile bridges gain the enforcement the daemon already had. The Preferences getters resolve managed keys from the policy, so a naive UI shows the enforced value; Commit rejects a staged change that diverges from a managed key; NewAuth resolves the managed management URL before persisting the config and overlays the policy on it, so a login can no longer run against a URL the policy forbids. Android's profile mutations fail closed when disableProfiles is set. NewAuth takes the fetcher as a required argument rather than keeping a policy-blind overload: the apps consume this code as a submodule, so a compile error at the bump is the point. The mobile PSK getter is replaced by a presence check — the key has no reason to cross the bridge, and not returning it means the native side needs no redaction sentinel of its own.
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package mdm
|
|
|
|
import (
|
|
"sync"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// ChangeDetector tracks the last observed policy of a Loader so an
|
|
// OS-notification-driven caller can ask whether the managed configuration
|
|
// actually changed before restarting anything.
|
|
type ChangeDetector struct {
|
|
mu sync.Mutex
|
|
loader *Loader
|
|
prev *Policy
|
|
}
|
|
|
|
// NewChangeDetector constructs a ChangeDetector seeded with the loader's
|
|
// current policy, so only a later change reports as changed.
|
|
func NewChangeDetector(loader *Loader) *ChangeDetector {
|
|
return &ChangeDetector{
|
|
loader: loader,
|
|
prev: loader.Load(),
|
|
}
|
|
}
|
|
|
|
// Changed re-reads the policy, logs the per-key diff, and reports whether it
|
|
// diverged from the last observation; the new snapshot becomes the baseline.
|
|
func (d *ChangeDetector) Changed() bool {
|
|
d.mu.Lock()
|
|
defer d.mu.Unlock()
|
|
curr := d.loader.Load()
|
|
if policiesEqual(d.prev, curr) {
|
|
return false
|
|
}
|
|
added, removed, changed := diffPolicies(d.prev, curr)
|
|
log.Infof("MDM policy changed: added=%v removed=%v changed=%v", added, removed, changed)
|
|
d.prev = curr
|
|
return true
|
|
}
|
|
|
|
// Current returns the last observed policy snapshot.
|
|
func (d *ChangeDetector) Current() *Policy {
|
|
d.mu.Lock()
|
|
defer d.mu.Unlock()
|
|
return d.prev
|
|
}
|