My macOS app is unable to read a Managed Preferences plist unless the App Sandbox is disabled. Is there any solution to read the MDM plist file while the sandbox is still enabled?

I created two sample apps — one sandboxed and one non‑sandboxed. I tested reading Managed Preferences using bash commands, CFPreferencesCopyValue for a domain, and defaults read. Everything works correctly only when the sandbox is disabled in the entitlements.

When the sandbox is enabled, I’m unable to read values from /Library/Managed Preferences/.

Is there any supported way for a sandboxed macOS app to read an MDM-delivered preference plist under /Library/Managed Preferences/?

Any guidance on the correct and Apple‑supported method would be appreciated.

Answered by DTS Engineer in 881412022

Is there any supported way for a sandboxed macOS app to read an MDM-delivered preference plist under /Library/Managed Preferences/?

Any guidance on the correct and Apple‑supported method would be appreciated.

There are basically two ways to make this work:

  1. Have the user select the file or directory using an open panel (or drag and drop).

  2. Use an entitlement that gives you access to the target directory.

In this particular case, that means using one of the "File Access Temporary Exceptions" to hard-code access to "/Library/Managed Preferences/". A few notes on that:

  • The documentation suggests using "Shared Preference Domain Temporary Exceptions". I would certainly try that; however, I suspect it won't work as "Managed Preferences" may not be part of the standard preference system.

  • While there's always an inherent risk in using a "temporary" entitlement, I generally consider this particular entitlement set to be relatively safe. The entitlement’s role is clear and straightforward (it gives access to the target), and there's an obvious benefit for us having some kind of "escape hatch" to enable access, if only as a solution if/when bugs occur.

However, for maximum “safety” you can implement both approaches: include the entitlement and try to directly access the file, but if that fails, then fall back to an open panel.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Is there any supported way for a sandboxed macOS app to read an MDM-delivered preference plist under /Library/Managed Preferences/?

Any guidance on the correct and Apple‑supported method would be appreciated.

There are basically two ways to make this work:

  1. Have the user select the file or directory using an open panel (or drag and drop).

  2. Use an entitlement that gives you access to the target directory.

In this particular case, that means using one of the "File Access Temporary Exceptions" to hard-code access to "/Library/Managed Preferences/". A few notes on that:

  • The documentation suggests using "Shared Preference Domain Temporary Exceptions". I would certainly try that; however, I suspect it won't work as "Managed Preferences" may not be part of the standard preference system.

  • While there's always an inherent risk in using a "temporary" entitlement, I generally consider this particular entitlement set to be relatively safe. The entitlement’s role is clear and straightforward (it gives access to the target), and there's an obvious benefit for us having some kind of "escape hatch" to enable access, if only as a solution if/when bugs occur.

However, for maximum “safety” you can implement both approaches: include the entitlement and try to directly access the file, but if that fails, then fall back to an open panel.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Could you please suggest the recommended approach? In this scenario, the user should not be required to select a file manually (such as through drag-and-drop), since the file must be accessed and read automatically without user interaction. However, I am facing the same issue even when attempting direct access.

Could you please suggest the recommended approach?

First off, as a clarification, what are you actually trying read here? If this is your apps preference file (meaning, it has your apps bundle ID), then NSUserDefaults (or CFPreference) will read automatically without any special code.

Similarly, if this ISN'T your apps data, then what's the relationship between your app and the data you're trying to read?

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

My macOS app is unable to read a Managed Preferences plist unless the App Sandbox is disabled. Is there any solution to read the MDM plist file while the sandbox is still enabled?
 
 
Q