Codesigned and notarized app cannot directly write files inside the app bundle (neither in my.app/Contents/Resources/ nor my.app/Contents/MacOS/).
Are there any restrictions regarding this? Is there a way to bypass these restrictions?
Here is the situation I encountered:
The main app contains several sub-apps and sub-executables. When the main app calls the sub-apps or sub-executables, it can write files within the app bundle, but when executed directly, it cannot write files. The app is usually opened using the GUI, and when using the command line, neither the main app nor the sub-apps/sub-executables can write files within the app bundle.
My codesigning environment is:
- Sonoma 14.0 on mac mini M1.
- I manually sign the app directly using the
codesigncommand in CI instead of using Xcode. The process will traverse all of the files and sub-apps in the app folder and sign them from the deepest paths to the shallowest paths. I also tried applying this process to other applications, but all of them encountered the same issue of failing to write files. - The app should not be sandboxed (I did not add sandbox entitlements).
I have tried adding the entitlement com.apple.security.files.user-selected.read-write, but this has not resolved the issue.
Are there any restrictions regarding this?
Yes.
Is there a way to bypass these restrictions?
No.
App bundles are read-only by design. This isn’t a new requirement [1], but recent changes in macOS’s trusted execution system mean that it’s more important to follow the rules. To quote Embedding nonstandard code structures in a bundle:
A bundle is a read-only structure. All Apple platforms except the Mac enforce this requirement at runtime. On iOS, for example, any attempt to modify your app’s bundle at runtime will fail with an error. The Mac may or may not enforce this requirement at runtime, depending on the context, but modifying your app’s bundle isn’t supported because it breaks the seal on the app’s code signature.
So your current goal, having the app modify itself, is unsupported, likely to cause problems today, and even more likely to cause problems in the future.
If you can explain more about why you’re trying to modify your own app, I may be able to offer an alternative path forward.
I manually sign the app directly using the codesign command in CI instead of using Xcode.
Based on your description it sounds like you’re doing the right thing here, but I’d be remiss not to mention Creating distribution-signed code for macOS, which contains detailed instructions on how to sign Mac products.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Indeed, you can trace it all the way back to the mid 80s. See here.