Skip to content

Add as-console-user command#22358

Merged
MikeMcQuaid merged 1 commit into
mainfrom
as-console-user
May 21, 2026
Merged

Add as-console-user command#22358
MikeMcQuaid merged 1 commit into
mainfrom
as-console-user

Conversation

@MikeMcQuaid
Copy link
Copy Markdown
Member

  • 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.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes. Non-maintainers may only have one AI-assisted/generated PR open at a time.

OpenAI Codex 5.5 xhigh with local review and testing.


Copilot AI review requested due to automatic review settings May 20, 2026 18:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh and update installer preinstall/postinstall scripts to use it for user/home resolution.
  • Update the release workflow to stage macos_user.sh alongside installer scripts for pkgbuild.

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.

Comment thread Library/Homebrew/brew.sh Outdated
Comment thread Library/Homebrew/cmd/as-console-user.sh Outdated
Comment thread Library/Homebrew/cmd/as-console-user.sh Outdated
- 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.
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 21, 2026
Merged via the queue into main with commit 95af20d May 21, 2026
41 checks passed
@MikeMcQuaid MikeMcQuaid deleted the as-console-user branch May 21, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants