Add as-console-user command#22358
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new brew as-console-user command and shared macOS user-resolution helper to support MDM/Munki/Jamf workflows where the parent process is root but Homebrew operations should run as the logged-in console user. Also refactors the macOS installer package scripts to share the same console-user and home-directory resolution logic, and stages that helper into the pkgbuild scripts bundle.
Changes:
- Add
brew as-console-user(Ruby command definition + shell implementation) to re-dispatch a Homebrew command as the active macOS console user. - Introduce
Library/Homebrew/utils/macos_user.shand update installerpreinstall/postinstallscripts to use it for user/home resolution. - Update the release workflow to stage
macos_user.shalongside installer scripts forpkgbuild.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| package/scripts/preinstall | Sources shared macOS user helper and validates a resolvable install user. |
| package/scripts/postinstall | Uses shared helper to select install user and resolve home directory for cache placement. |
| Library/Homebrew/utils/macos_user.sh | New standalone helper for console user, home directory, and package-user override logic. |
| Library/Homebrew/test/cmd/as-console-user_spec.rb | Adds unit tests for shell dispatch and user-resolution helper behavior. |
| Library/Homebrew/cmd/as-console-user.sh | Implements the shell-side homebrew-as-console-user dispatcher. |
| Library/Homebrew/cmd/as-console-user.rb | Declares the new command and its CLI docs/arg parsing. |
| Library/Homebrew/brew.sh | Exempts as-console-user from the “don’t run as root” guard. |
| .github/workflows/release.yml | Stages installer scripts + macos_user.sh for pkgbuild packaging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Support MDM/Munki/Jamf runs where the parent process is root but Homebrew must execute as the logged-in macOS console user. - Keep the nested operation constrained to `HOMEBREW_BREW_FILE` so this helper cannot become a general-purpose root command launcher. - Share `macos_user.sh` with installer scripts so no-user and package plist fallback behaviour cannot drift between install paths. - Stage `macos_user.sh` for `pkgbuild` because `preinstall` needs the resolver before the Homebrew payload has been installed.
d2f89ab to
af3538d
Compare
p-linnane
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
HOMEBREW_BREW_FILEso this helper cannot become a general-purpose root command launcher.macos_user.shwith installer scripts so no-user and package plist fallback behaviour cannot drift between install paths.macos_user.shforpkgbuildbecausepreinstallneeds the resolver before the Homebrew payload has been installed.brew lgtm(style, typechecking and tests) with your changes locally?OpenAI Codex 5.5 xhigh with local review and testing.