Homebrew / homebrew-cask

🍻 A CLI workflow for the administration of macOS applications distributed as binaries
https://brew.sh
BSD 2-Clause "Simplified" License
20.94k stars 10.72k forks source link

brew-cask does not elevate permissions on uninstall/upgrade/reinstall #42681

Closed matkozak closed 6 years ago

matkozak commented 6 years ago

General troubleshooting steps

Description of issue

Apologies for another permissions issue, but I cannot figure out why the uninstallation process would cause a problem when the installation does not.

I run Homebrew as a non-admin user with sudo privileges and write access to Homebrew directories in /usr/local/. As a non-admin, I do not have write permissions for /Applications, but I get asked for password when it's time to move an app there during installation. This works perfectly fine.

However, when trying to uninstall, reinstall or upgrade an app, the password prompt does not appear, and the process crashes with a permission error.

I do not have write access to /Applications, but own the directory created during cask installation. For example:

drwxrwxr-x+ 51 root  admin   1.7K Jan 10 13:30 /Applications
drwxr-xr-x  3 kozak  ISIS\Domain Users   102B Jan 10 13:45 /Applications/RStudio.app/
drwxr-xr-x  2 kozak  brew    68B Apr 27  2017 /usr/local/Caskroom/rstudio/1.0.143/

Output of your command with --verbose --debug

brew cask upgrade rstudio --verbose --debug
==> Upgrading 1 outdated package, with result:
rstudio 1.1.383
==> Started upgrade process for Cask rstudio
==> Hbc::Installer#fetch
==> Satisfying dependencies
==> Downloading
==> Downloading https://download1.rstudio.org/RStudio-1.1.383.dmg
Already downloaded: /Users/kozak/Library/Caches/Homebrew/Cask/rstudio--1.1.383.dmg
==> Downloaded to -> /Users/kozak/Library/Caches/Homebrew/Cask/rstudio--1.1.383.dmg
==> Verifying download
==> Determining which verifications to run for Cask rstudio
==> Checking for verification class Hbc::Verify::Checksum
==> 1 verifications defined
Hbc::Verify::Checksum
==> Running verification of class Hbc::Verify::Checksum
==> Verifying checksum for Cask rstudio
==> SHA256 checksums match
==> Starting upgrade for Cask rstudio
==> Un-installing artifacts
==> 2 artifact/s defined
#<SortedSet:0x00000101ad57a8>
==> Un-installing artifact of class Hbc::Artifact::App
==> Moving App 'RStudio.app' back to '/usr/local/Caskroom/rstudio/1.0.143/RStudio.app'.
Error: Permission denied @ rb_file_s_rename - (/Applications/RStudio.app, /usr/local/Caskroom/rstudio/1.0.143/RStudio.app)
Follow the instructions here:
  https://github.com/caskroom/homebrew-cask#reporting-bugs
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/fileutils.rb:528:in `rename'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/fileutils.rb:528:in `block in mv'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/fileutils.rb:1571:in `block in fu_each_src_dest'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/fileutils.rb:1587:in `fu_each_src_dest0'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/fileutils.rb:1569:in `fu_each_src_dest'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/fileutils.rb:517:in `mv'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/moved.rb:69:in `move_back'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/moved.rb:15:in `uninstall_phase'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:403:in `block in uninstall_artifacts'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/set.rb:674:in `each'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/set.rb:674:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:400:in `uninstall_artifacts'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:362:in `start_upgrade'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:59:in `block in run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:29:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:29:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb:35:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:98:in `run_command'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:168:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:132:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:8:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:100:in `<main>'
Error: Kernel.exit
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:179:in `exit'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:179:in `rescue in run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:156:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:132:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:8:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:100:in `<main>'

Output of brew cask doctor

brew cask doctor
==> Homebrew-Cask Version
Homebrew-Cask 1.4.3-16-gb29213a
caskroom/homebrew-cask (git revision dbfb1; last commit 2018-01-10)
==> macOS
10.12.6
==> Java
N/A
==> Homebrew-Cask Install Location
<NONE>
==> Homebrew-Cask Staging Location
/usr/local/Caskroom
==> Homebrew-Cask Cached Downloads
~/Library/Caches/Homebrew/Cask (2 files, 138.0MB)
==> Homebrew-Cask Taps:
/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask (3897 casks)
==> Contents of $LOAD_PATH
/usr/local/Homebrew/Library/Homebrew/cask/lib
/usr/local/Homebrew/Library/Homebrew
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0/lib
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/site_ruby/2.3.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/site_ruby/2.3.0/x86_64-darwin9.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/site_ruby/2.3.0/universal-darwin9.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/site_ruby
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/vendor_ruby/2.3.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/vendor_ruby/2.3.0/x86_64-darwin9.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/vendor_ruby/2.3.0/universal-darwin9.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/vendor_ruby
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/x86_64-darwin9.0
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/universal-darwin9.0
==> Environment Variables
LC_ALL="en_US.UTF-8"
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Homebrew/Library/Homebrew/shims/scm"
SHELL="/bin/bash"
vitorgalvao commented 6 years ago

Seems reasonable. We should either not ask for a password to install to /Applications (which is what I thought we did), or ask for it on uninstall if we see it’s necessary.

cc @reitermarkus

commitay commented 6 years ago

Looks like currently we're checking permissions on the source (/Caskroom) instead of the target (appdir) during the move_back phase (target -> source) .

Tested with the same configuration as reported. https://github.com/Homebrew/brew/pull/3680

RickyRomero commented 6 years ago

Is this issue fixed? I'm having the same exact error in 1.5.4...

Sentinel:~ admin$ brew cask upgrade coda --verbose --debug                        
==> Upgrading 1 outdated package, with result:
coda 2.6.9
==> Started upgrade process for Cask coda
==> Hbc::Installer#fetch
==> Satisfying dependencies
==> Downloading
==> Downloading https://download.panic.com/coda/Coda%202.6.9.zip
Already downloaded: /Users/admin/Library/Caches/Homebrew/Cask/coda--2.6.9.zip
==> Downloaded to -> /Users/admin/Library/Caches/Homebrew/Cask/coda--2.6.9.zip
==> Verifying download
==> Determining which verifications to run for Cask coda
==> Checking for verification class Hbc::Verify::Checksum
==> 1 verifications defined
Hbc::Verify::Checksum
==> Running verification of class Hbc::Verify::Checksum
==> Verifying checksum for Cask coda
==> SHA256 checksums match
==> Starting upgrade for Cask coda
==> Un-installing artifacts
==> 2 artifact/s defined
#<SortedSet:0x007f934d35c248>
==> Un-installing artifact of class Hbc::Artifact::App
==> Moving App 'Coda 2.app' back to '/usr/local/Caskroom/coda/2.6/Coda 2.app'.
Error: Permission denied @ rb_file_s_rename - (/Applications/Coda 2.app, /usr/local/Caskroom/coda/2.6/Coda 2.app)
Follow the instructions here:
  https://github.com/caskroom/homebrew-cask#reporting-bugs
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:528:in `rename'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:528:in `block in mv'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1571:in `block in fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1587:in `fu_each_src_dest0'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1569:in `fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:517:in `mv'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/moved.rb:69:in `move_back'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/artifact/moved.rb:15:in `uninstall_phase'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:403:in `block in uninstall_artifacts'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/set.rb:674:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/set.rb:674:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:400:in `uninstall_artifacts'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/installer.rb:362:in `start_upgrade'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:59:in `block in run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:29:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:29:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb:35:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:98:in `run_command'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:168:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:132:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:8:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:100:in `<main>'
Error: Kernel.exit
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:179:in `exit'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:179:in `rescue in run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:156:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:132:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:8:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:100:in `<main>'
Sentinel:~ admin$ brew cask doctor
==> Homebrew-Cask Version
Homebrew-Cask 1.5.4
caskroom/homebrew-cask (git revision 87e5af; last commit 2018-02-12)
==> macOS
10.13.3
==> SIP
Enabled
==> Java
N/A
==> Homebrew-Cask Install Location
<NONE>
==> Homebrew-Cask Staging Location
/usr/local/Caskroom
==> Homebrew-Cask Cached Downloads
~/Library/Caches/Homebrew/Cask (15 files, 961.6MB)
==> Homebrew-Cask Taps:
/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask (3913 casks)
==> Contents of $LOAD_PATH
/usr/local/Homebrew/Library/Homebrew/cask/lib
/usr/local/Homebrew/Library/Homebrew
/Library/Ruby/Gems/2.3.0/gems/did_you_mean-1.0.0/lib
/Library/Ruby/Site/2.3.0
/Library/Ruby/Site/2.3.0/x86_64-darwin17
/Library/Ruby/Site/2.3.0/universal-darwin17
/Library/Ruby/Site
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby/2.3.0
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby/2.3.0/x86_64-darwin17
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby/2.3.0/universal-darwin17
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/x86_64-darwin17
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin17
==> Environment Variables
LC_ALL="en_US.UTF-8"
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Homebrew/Library/Homebrew/shims/scm"
SHELL="/bin/bash"
matkozak commented 6 years ago

I can't check with the latest version right now so all I can say is that 1.5.0 fixed it for me personally.