-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add support to install as $INSTALL_USER #789
Conversation
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.
Generally this script can't be executed as root unless you're in a CI environment, I'm not sure if this will work for macOS for example.
@@ -107,6 +107,10 @@ then | |||
export USER | |||
fi | |||
|
|||
# Allow delegating installation to a different user (useful for installs by root) | |||
INSTALL_USER="${INSTALL_USER-${USER}}" | |||
INSTALL_HOME=$(eval echo ~"${INSTALL_USER}") |
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.
This will quietly fail if the user does not exist.
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'll add a validation for the INSTALL_USER to exist
I've tested the script to work on MacOS. |
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.
Can you provide more context for why/when this is needed?
I think it's very bad idea for this script to be run as root and even more so to be doing curl | sh
as root. I don't think privileges are being dropped appropriately here and the majority of the script still runs as root. This means a typo or error in a future iteration of this script could have catastrophic results.
Co-authored-by: Mike McQuaid <[email protected]>
Of course! In my case, I need to install and maintain a pool of macs. The macs get set up with an installation script for efficiency / reliability. However, recently I looked at the possibility to have the install script implemented in Swift using I found that there is no way to install homebrew as root, for another user. This PR adds that functionality. |
Do you mean your script or this script here? Have you tried making use of
This is something I'm not 👎🏻 on but would need a few changes:
|
Have you considered using the macOS |
Thanks for the feedback so far! Using SUDO_ASKPASS does not solve my use-case because the remote mac install program (or the program that is specified as SUDO_ASKPASS) will still need to store the password so that it can be provided when needed by sudo. |
It's a trade-off here, really:
If your script is being as root: it could modify systemwide |
Where can I find this pkg build? In the release assets there are only the sources: https://github.com/Homebrew/brew/releases |
Agreed, I considered this option. |
Another perspective on the security impact: It is already possible to run the install as root by adding a Given the above I argue that the |
I’m not sure I understand the security issues of this approach. Does the delegation achieve anything other than who owns the created directories? |
Sorry, I don't see it, personally. Regardless, I'm afraid we have to do what's best for all Homebrew users here and not just your specific case.
Sure, it's possible; it's also pretty obvious that that's a hack built to support Docker specifically.
I don't agree. It's running as |
In our CI we have a setup where we have a user with As such I would personally like to see a change similar to this that makes that possible where you can run the installer as the account with
Can you expand more on this? Most of the downloading appears at the end. One exception is the Xcode Command Line Tools. You can however install this beforehand (and I would suggest in an enterprise environment to do so) and therefore if done that way there should not be any downloading until after all |
Passing on this, sorry @berikv! You may find the Homebrew .pkg installer helpful. |
It's included in here now. |
Allow to install as another user:
This is especially useful in headless installs by root, where passing a sudo password would make the install script insecure and / or needlessly complex.
setup_machine.sh // Run as root
Tested on Intel MacOS 13.4.1: