Skip to content

Fix mac_brew_pkg.homebrew_prefix triggering su on every invocation (#69027)#69674

Merged
dwoz merged 1 commit into
saltstack:3006.xfrom
dwoz:fix/issue-69027
Jul 14, 2026
Merged

Fix mac_brew_pkg.homebrew_prefix triggering su on every invocation (#69027)#69674
dwoz merged 1 commit into
saltstack:3006.xfrom
dwoz:fix/issue-69027

Conversation

@dwoz

@dwoz dwoz commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes mac_brew_pkg.homebrew_prefix() triggering a su password prompt
(or su: Sorry error on non-tty invocations) on every salt-ssh startup as
a non-root user whose Homebrew is owned by themselves. The probe now only
forwards runas= to cmdmod.run when the brew binary owner differs from
the current process user.

What issues does this PR fix or reference?

Fixes #69027

Previous Behavior

Every invocation of salt-ssh (or any Salt process that loads
mac_brew_pkg) on macOS as a non-root user prints:

[ERROR   ] Command 'su' failed with return code: 1
[ERROR   ] stdout: Password:su: Sorry
[ERROR   ] retcode: 1
[ERROR   ] Command 'brew' failed with return code: 1

On a TTY, the user is prompted for their password before the wrapped
command fails. Root cause: homebrew_prefix() passes
runas=<brew binary owner> to salt.modules.cmdmod.run unconditionally.
On Darwin, cmdmod.run wraps the command in su -l <user> -c ...
whenever runas is truthy, even when <user> is the current process
user — and non-root invocations of su require a password regardless of
whether the source and target identities match.

New Behavior

homebrew_prefix() calls getpass.getuser() and short-circuits runas
to None when the brew binary owner is the current user. The su -l
wrap is skipped in the common single-user macOS setup; behavior when the
brew binary is owned by a different user (shared multi-user installs)
is unchanged. getpass.getuser() failures are tolerated defensively so
we never make things worse than the previous unconditional behavior.

Two regression tests were added to
tests/pytests/unit/modules/test_mac_brew_pkg.py:

  • test_homebrew_prefix_no_su_when_brew_owner_is_current_user
  • test_homebrew_prefix_still_uses_runas_when_brew_owned_by_other_user

Merge requirements satisfied?

  • Docs (no user-facing docs changed; behavior fix only)
  • Changelog (changelog/69027.fixed.md)
  • Tests written/updated

Commits signed with GPG?

Yes

homebrew_prefix() passes runas=<brew binary owner> unconditionally to
cmdmod.run. On macOS, cmdmod.run wraps the command in `su -l <user> -c
...` whenever runas is truthy, even when <user> is the current process
user. On a non-root TTY invocation this prompts for a password; on a
non-TTY invocation it prints `su: Sorry` and a `Command 'brew' failed
with return code: 1` line on every salt-ssh startup.

Only forward runas when the brew binary is owned by a different user
than the current process. When the owner matches the current user,
short-circuit to runas=None so the su wrap is skipped. Defensively
tolerate getpass.getuser() raising in exotic environments (empty passwd
db, some container images) by falling back to the pre-fix behavior.

Fixes saltstack#69027
@dwoz
dwoz merged commit 9d56ab1 into saltstack:3006.x Jul 14, 2026
851 of 861 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants