Repository navigation
[client] mobile MDM bridge — iOS + Android setMDMPolicyFetcher entrypoint #6435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,375
−591
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
db2c9b6
MDM Android mobile wiring
riccardomanfrin bec26d5
Removes dead code
riccardomanfrin 8741954
Removes static vars
riccardomanfrin 0340893
Now we need to apply MDM in the GetConfig
riccardomanfrin b2c5732
You now need to explicitly call these around
riccardomanfrin 7715c38
Adds iOS wiring
riccardomanfrin e1ffb16
Merge branch 'main' into mdm_integration (with unresolved conflict ma…
riccardomanfrin e92aa7d
Resolve merge conflicts from main
riccardomanfrin f91f9fc
Convey MDM overlay config to Debug Bundle output
riccardomanfrin 76fd144
Merge remote-tracking branch 'origin/main' into mdm_integration
riccardomanfrin 982626c
Solved conflict in client.go
riccardomanfrin faa1962
Fixup helper withMDMPolicy -> configWithMDM
riccardomanfrin e4d4b44
Fixup after merge
riccardomanfrin 12789d1
Merge branch 'main' into mdm_integration
riccardomanfrin c41d439
Resolve merge conflicts
riccardomanfrin c281b15
[client] Move MDM enforcement logic into a shared Go layer (#7319)
pappz ec4b99b
Merge branch 'main' into mdm_integration
pappz 116e1d3
Merge branch 'main' into mdm_integration
riccardomanfrin 5d15ac0
[client] Resolve the main merge conflicts in the MDM integration
riccardomanfrin d96d22a
[client] Reject explicit empty PSK when MDM enforces a pre-shared key
pappz 47238e0
[client] Apply MDM overlay on the preloaded iOS config in Run
pappz 42f0a63
[client] Gate non-active profile logout behind the MDM profiles switch
pappz 3234ce7
[client] Resolve the managed management URL through the MDM overlay o…
pappz 047715a
[client] Clean up MDM review leftovers
pappz c1e2e20
[client] Check remote jobs and local metrics keys in the mobile MDM c…
pappz a52c7ba
[client] Silence the deprecated PreSharedKey lint in the login confli…
pappz 86d6f7d
[client] Publish the mobile MDM loader and detector atomically
pappz a2b1c99
[client] Report the MDM-overlaid remote jobs value from mobile Prefer…
pappz 1b0dd66
[client] Stop persisting the MDM-overlaid config after mobile logins
pappz ca548ea
[client] Document that the MDM overlay on Config is not reversible
pappz cb5efcd
[client] Re-resolve the tvOS preloaded config before every MDM overlay
pappz c019700
[client] Serve the MDM-managed management URL without touching the co…
pappz 204360e
[client] Align the MDM loader docs with the fetcher precedence and ma…
pappz 9364512
[client] Clean up MDM review nits
pappz b65f493
[client] Fix int policy values coercing to bool in the MDM test helper
pappz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| //go:build android | ||
|
|
||
| package android | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/netbirdio/netbird/client/mdm" | ||
| ) | ||
|
|
||
| // PolicyFetcher is the mobile-side bridge for the MDM managed-config | ||
| // snapshot. The native layer (Kotlin) implements this and registers | ||
| // the instance via SetMobilePolicyFetcher at app start. Every | ||
| // invocation must read the current RestrictionsManager state and | ||
| // return the result as a JSON-encoded map[string]any string. | ||
| // | ||
| // JSON is used because gomobile does not support map[string]any | ||
| // crossing the JNI boundary — the adapter on the Go side parses the | ||
| // string back into the map[string]any expected by mdm.LoadPolicy. | ||
| // | ||
| // Return value contract: | ||
| // - "" (empty) : interpreted as "no MDM source / no managed keys" | ||
| // - "{}" : managed config explicitly empty | ||
| // - "{...}" : JSON object with key/value pairs | ||
| // - malformed JSON : logged and treated as empty | ||
| type PolicyFetcher interface { | ||
| FetchJSON() string | ||
| } | ||
|
|
||
| // jsonFetcherAdapter wraps a gomobile-exposed PolicyFetcher into the | ||
| // internal mdm.PolicyFetcher interface, taking care of JSON decoding | ||
| // on every Fetch. | ||
| type jsonFetcherAdapter struct { | ||
| inner PolicyFetcher | ||
| } | ||
|
|
||
| func (a *jsonFetcherAdapter) Fetch() map[string]any { | ||
| raw := a.inner.FetchJSON() | ||
| if raw == "" { | ||
| return nil | ||
| } | ||
| var out map[string]any | ||
| if err := json.Unmarshal([]byte(raw), &out); err != nil { | ||
| log.Warnf("MDM mobile fetcher: invalid JSON payload from native: %v", err) | ||
| return nil | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // SetMobilePolicyFetcher registers the native-provided MDM policy | ||
| // fetcher. Call exactly once from the gomobile-init code (Kotlin | ||
| // Application.onCreate) before the daemon starts. Passing nil | ||
| // effectively disables MDM enforcement on this build. | ||
| func SetMobilePolicyFetcher(p PolicyFetcher) { | ||
| if p == nil { | ||
| mdm.SetMobilePolicyFetcher(nil) | ||
| return | ||
| } | ||
| mdm.SetMobilePolicyFetcher(&jsonFetcherAdapter{inner: p}) | ||
| } | ||
|
|
||
| // OnMDMPolicyChanged is the mobile entry point the native layer calls | ||
| // when the OS broadcasts a managed-config change | ||
| // (ACTION_APPLICATION_RESTRICTIONS_CHANGED on Android, | ||
| // UserDefaults.didChangeNotification on iOS). The hook cancels the | ||
| // current engine context so the current Run() returns; the native | ||
| // loop is expected to re-invoke Run() afterwards, which re-reads | ||
| // the config (including the fresh MDM overlay via the registered | ||
| // PolicyFetcher). | ||
| // | ||
| // No payload is passed — the OS notification only signals "something | ||
| // changed"; the actual values are read on-demand by the next | ||
| // loadPlatformPolicy call inside Config.apply. | ||
| func (c *Client) OnMDMPolicyChanged() { | ||
| log.Info("MDM policy change signaled by native; stopping engine to restart with fresh config") | ||
| c.Stop() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.