fix: unquarantine dylib after download #38
Merged
+145
−54
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.
When building Coder Desktop for distribution for the first time, and running the app on a device with System Integrity Protection, we hit a bit of a roadblock:
As a result, the CoderVPN
.dylib
downloaded from the Coder deployment has thecom.apple.quarantine
xattr set, prompting Gatekeeper to check it. Presumably because the.dylib
isn't notarized, it gets blocked. This wasn't noticed during earlier prototyping as the file was never created within the System Extension sandbox, and so it never had the xattr.Unfortunately, System Network Extensions must run in a sandbox. I was also unable to abuse the
com.apple.security.files.user-selected.executable
entitlement to remove the quarantinexattr
from the file - all signs point to theuser-selected
part of the entitlement being very much crucial.Fortunately, we're not required to run the application itself sandboxed. When not sandboxed, an app is able to remove the quarantine xattr.
Of note here is that our System Network Extensions runs as
root
, whilst the applications runs as the logged-in user. This means there is no overlap in files writable by both the Network Extension, and the app [1].Given this, one thing I explored was if we could somehow notarize the
.dylib
, and have Gatekeeper use that notarization ticket to remove the quarantine. Unfortunately, notarizing the dylib alone (or within a framework bundle) had no effect when attempting to open the.dylib
on an internet-connected computer. Furthermore, there's no way to staple a notarization ticket to an unbundled.dylib
. Placing it into a container that can be stapled, such as a.dmg
or a.pkg
would make it unsbale by the sandboxed network extension - it cannot mount the disk image (which was the source of other sandbox escapes), and it cannot work with apkg
installer.I've sent in an Apple Support ticket asking if we've missed anything on this topic, and if there's potentially a better way, though from what I've read online that would appear unlikely - if we were able to execute the dylib without the user's explicit consent, it would constitute a sandbox escape CVE [2].
Employed Workaround
To deal with this issue, this PR removes the app sandbox from the Coder Desktop application, and uses a privileged
AppleScript
command to run/usr/bin/xattr -d com.apple.quarantine /path/to/dylib
- this is requested over XPC, and the Network Extension waits for the user to complete thesudo
prompt before continuing.Some downsides to this workaround are:
.dylib
is downloaded. (This is annoying for us at Coder - our Coder deployment updates on each push tocoder/coder/main
.)