-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Enable quarantining of Homebrew-Cask's downloads #4656
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
Conversation
Not quite, as it’d still need the |
This needs some tests. |
@vitorgalvao: which commands should |
Yes, that's what the tests should be checking.
How? Everytime you download something with a browser it will also “pollute” the system database, so I don't think that is a reason not to have tests. |
Anything that downloads, so |
Although this should probably be a global option, so you can set it in |
I've found that after #4401's changes, the extended attributes are not preserved between |
I thought it had been decided that there will not be any swift code added to Homebrew. Someone added a swift script once and it was quickly (and correctly) removed. @MikeMcQuaid is this ringing a bell? |
Can this be done without a Swift script? If so, what are the other options (Objective-C, AppleScript, Ruby, Bash, etc.)? If it cannot be done without Swift or a compiled alternative (e.g. Objective-C) I'd like to propose that literally every line of the Swift script that can be instead moved into Ruby is done that way. For example, printing human readable errors can be done in the Ruby instead based on the exit code. |
@MikeMcQuaid , @chdiza: as I explained in Homebrew/homebrew-cask#48862, the Swift approach enables us to quickly access MacOS's APIs without having to worry about compilation, FFI, etc. The only drawback comes (as you noticed) from having to detect errors based on the exit code. If you want to use pure Ruby, you can, but the drawbacks outweigh the benefits IMO. There are two approaches:
|
(Just a PSA, I’m only catching up on previous discussions, no strong opinion.) Points I’ve seen made against using Swift in Homebrew:
|
Also, and correct me if I'm wrong here, but doesn't the user have to have Xcode or the CLT installed in order to run a swift script? My impression is that lots of cask users won't have those installed because they're only looking to install |
It’s my understanding that from Mojave on, Swift will be (finally) included as part of macOS. That will remove the need for further software installation (Xcode/CLT) and (presumably, I’m guessing on this one) backward-incompatibility will start to be handled more carefully. |
I still don't understand that argument when AppleScript is the alternative. There is much more documentation for Swift than for AppleScript, whose syntax is also much more convoluted. |
I'd be interested at looking at an AppleScript version of these scripts. I think adding Xcode/CLT and/or Swift as a hard dependency for all of |
Well documented or not, people need to practise for a language to be useful to them. I could probably churn out an IOKit driver in AppleScript for you in a day.1 I’d still barely manage to write a Hello World in Swift to save my life.
Absolutely. 1 Dramatization |
True. But as someone who writes a bunch of AppleScript regularly (and loathes every second of it) and close to no Swift, I still feel that if I needed to do something a bit more advanced, I’d more easily find information on the latter than the former. AppleScript’s (and JXA’s) documentation is terrible and code you find online is typically bad (as in, it does the job but it’s longer and less optimal than it could be). All that said, if we’re going to try to rewrite the scripts in AppleScript, we should at least do it in JXA. Not only is the syntax saner, it can do some things AppleScript can’t, and it should be more auditable by more people (being JavaScript). |
I'd argue it's harder to practise without good documentation. |
Very much so! Learning AppleScript was a royal pain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see a sample AppleScript implementation, more logic removed from the Swift implementation and handling the absence of Swift on the system before this is merged.
@MikeMcQuaid, I'll try and port the Swift script to AppleScript (I'll need to switch to the original Objective-C classes first). |
@amyspark Already done. PR incoming. |
Thanks for your review @MikeMcQuaid! Please let me know if everything is OK for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny nit but otherwise 👍 from me. Nice work, particularly on simplifying and better handling the Swift script.
Every nitpick is an opportunity to improve. Thanks again for your comments @MikeMcQuaid. |
Don’t auto-close Homebrew/homebrew-cask#48862, since we may have to revise the policy depending on the installed artifact instead of scraping it completely. After this change is live, I’ll likely replace that issue with a new one. |
@reitermarkus, I've completed all your requests. As regards performance - the bottleneck is in According to the existing Cask
My tests show that none of them preserve quarantine by themselves; in particular, Would it be a better option to issue a single |
I don't think this matters, because the only time we use naked archives is as a workaround.
Forking is definitely the bottleneck here, so yes. |
@reitermarkus, done. Thanks for the review. |
Heads up: I found that some Casks ship with the wrong permissions (tried to install Fritzing for a course and quarantine failed on an internal |
FileUtils.chmod "u+w", Pathname.glob(unpack_dir/"**/*").reject(&:symlink?) So it seems this is only missing the |
Everyone, please let me know if this is ready for merging. Do tell me too if I should merge/rebase on master, as I forked this over two weeks ago. (edited for English redundancy. sorry!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amyspark Yes, a rebase would be awesome so we can test out an up-to-date version of the PR one last time.
@MikeMcQuaid @reitermarkus, please let me know if I should merge, rebase, or rebase+squash this. |
@amyspark I'm fine with any once @claui and @reitermarkus are ✅ |
@claui, @reitermarkus -- I've rebased+squashed on my side. Before cleaning this pull, let me know if the current state is OK with you. |
I ran a final smoke test on a clean VM (30-ish casks). Everything seems to work great so far. |
@amyspark Ready for cleanup 😉 |
Ok everyone, incoming rebase+squash! 🚀 |
Thanks a lot @amyspark ✨ for tackling this! This feature was much needed. |
brew style
with your changes locally?brew tests
with your changes locally?This pull requests adds an additional step to the
Hbc::Download
class that quarantines all downloaded files.The original proposal by @reitermarkus tinkered with Gatekeeper's download database (
~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2
, see #3526), which I found really prone to breaking the main Gatekeeper policy database (i.e./private/var/db/SystemPolicy
).Inspired in Transmission's source code, I implemented download quarantining through the use of a Swift script. In this way, we can add Gatekeeper support while keeping the code completely visible to the user.
As regards the metadata, I added a modicum of fields:
Homebrew-Cask
WEB_DOWNLOAD
(see a list of the possible types here)url
fieldThis also includes:
install
,fetch
, andaudit
, across multiple types of containers--no-quarantine
If merged, this pull request closes Homebrew/homebrew-cask#22388.
Please review, and thanks for your comments!