I've already added a "reveal" probe alongside the existing raw-read and open -g probes, using open -g -R <path>, which goes through the same Finder-reveal service you described rather than opening the file's content.
Unfortunately, I'm not sure this will work or not. While "open -g -R <path>" does eventually call activateFileViewerSelectingURLs, what it actually does is:
-
Perform its own existence checks (which could conceivably fail).
-
Calls NSWorkspace.selectFile(_:inFileViewerRootedAtPath:), which does its own existence checks.
...and then calls activateFileViewerSelectingURLs. Depending on the process state, it's possible that 1 or 2 might fail, even though the Finder might actually still be able to access the file. What's different about "activateFileViewerSelectingURLs" itself is that it doesn't actually implement ANY checks, but just sends the input directly to the Finder.
There's no Finder interaction anywhere in that path; a human isn't browsing these files.
One minor clarification here. The Finder itself isn't necessarily "special" here, as you'd actually see the same basic results across any user interact app that was working "correctly". It's relevant here because it’s an easy way to test what's going on, not because it's unique.
That leads to a question about the File Access Temporary Exceptions suggestion: those are App Sandbox entitlements, which apply to code-signed apps that have opted into App Sandbox. The processes actually hitting this (the launchd daemon, shell scripts, Terminal-invoked tools) aren't sandboxed apps at all — they're plain CLI processes.
Processes inherit the access of their children, so what's actually happening here is that your processes are "constraining" what our tools can do. FYI, that's why fully sandboxed apps (even on the App Store) are free to use command line tools like cp or rm. Sandbox inheritance means that the tools won't do anything the app couldn't do anyway.
Is the temporary-exception entitlement applicable outside of App Sandbox in any form, or is there a different mechanism?
Two different answers to this:
(1)
Our actual entitlement implementation isn't that clear cut, as many of our checks just ask "does this process have the entitlement" regardless of sandbox state. I haven't specifically checked, but I'd expect that to be the case here.
(2)
Unfortunately, the history of how the sandbox was introduced alongside the Mac App Store has made the meaning of "sandbox" less clear than it really should be. In common usage, "sandboxed" basically means something like "an app that has enabled the app sandbox and configured itself such that it operates within the limitations expected of an app store app". Implicitly, that means "sandboxed apps" are inherently more limited than "non-sandboxed apps".
The problem is that, in the context of the broader system, that ISN'T how the "sandbox" actually works. What the sandbox actually means to the system is basically "an app that's declared what we should allow it to do", with the system then enforcing those limitations. The critical difference in that second definition is that it DOESN'T actually impose artificial limits on what your process can do. Case in point, the Mac App Store may not allow your app to define arbitrary paths your app has access to, but the entitlement I just sent you sure will.
More importantly, VERY few apps ACTUALLY need to do so "everything" that's allowed with the app sandbox disabled. Some apps may need file system access, some IOKit access, and while other apps need low-level accessibility access. VERY few need all of those. In that context, enabling the sandbox is basically just a matter of formalizing what your process actually needs to do, then declaring it so your process can't be subverted into doing things it shouldn't.
Moving to here:
(e.g. something at the launchd/daemon level, or a signed helper tool) that would be the right analog for a non-sandboxed background process needing the same kind of "hard-coded" path exception?
So, one thing to clarify here is that focusing too much on the "App Sandbox" can be very misleading. Quinn has a full post about this here, but the summary is that there are multiple different file access systems (Quinn lists 5), any one of which can block access.
In terms of turning all of this into a stable solution, my approach would probably be along these lines:
(A)
Move your mount point out of /Users/Shared/ and into a fixed location outside of the system’s "managed" hierarchy. My personal inclination would be to create a new APFS volume within the same APFS container, but it could pretty much be anywhere outside of a user’s home directory and/or a designated directory.
One thing to understand here is that the goal of this step ISN'T to give your app access to the object, it's to stabilize the systems handling so that you don't have to worry about behavior shifting dynamically. Jumping back to your earlier message as an example, I believe "test_pi_root" failed because it was inside your home directory, but that consistent failure means that once it's working, you'll know it won't break again.
(B)
Enable the App Sandbox and then guarantee access by adding on the "right" entitlements and/or configurations. I know that's a bit vague, but unfortunately, over time, the systems become complex enough that the overlapping layers make it difficult to know exactly what's rejecting you and why. Keep in mind that, from the systems’ perspective, the "normal" way apps gain access to a file system object is that the user directly GAVE them access to that file/object, so this kind of hard-coded access isn't considered the primary approach.
That leads to the other option I overlooked, which is to give your process Full Disk Access. For testing purposes, you can do that through the UI, but in a more "production" configuration, I would probably use Apple Configurator to create a config profile you could use to enable it more "automagically".
I'll also say that throwing FDA into your testing mix would be worthwhile. My assumption is that it would "just work", but if it doesn't work, then that implies something weirder/more complex.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware