Skip to content

Commit

Permalink
Merge pull request #47212 from weswhet/fix-macos-runas
Browse files Browse the repository at this point in the history
fix macOS running as user.
  • Loading branch information
Nicole Thomas committed May 16, 2018
2 parents 0c7439a + 8ee11d7 commit 4fe78bb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion salt/modules/cmdmod.py
Expand Up @@ -43,7 +43,7 @@
from salt.exceptions import CommandExecutionError, TimedProcTimeoutError, \
SaltInvocationError
from salt.log import LOG_LEVELS
from salt.ext.six.moves import range, zip
from salt.ext.six.moves import range, zip, map

# Only available on POSIX systems, nonfatal on windows
try:
Expand Down Expand Up @@ -405,6 +405,19 @@ def _get_stripped(cmd):

return win_runas(cmd, runas, password, cwd)

if runas and salt.utils.platform.is_darwin():
# we need to insert the user simulation into the command itself and not
# just run it from the environment on macOS as that
# method doesn't work properly when run as root for certain commands.
if isinstance(cmd, (list, tuple)):
cmd = ' '.join(map(_cmd_quote, cmd))

cmd = 'su -l {0} -c "{1}"'.format(runas, cmd)
# set runas to None, because if you try to run `su -l` as well as
# simulate the environment macOS will prompt for the password of the
# user and will cause salt to hang.
runas = None

if runas:
# Save the original command before munging it
try:
Expand Down

0 comments on commit 4fe78bb

Please sign in to comment.