[BUG] modules.mac_brew_pkg incorrectly uses sudo -i
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
modules.mac_brew_pkg._call_brew invokes sudo with -i. That tells sudo to execute an interactive session - it triggers loading .bash_profile. This is not intended for non-interactive uses.
The symptom: if .bash_profile produces anything on stdout, it breaks pkg.installed on mac. Since ~/.bash_profile is used for interactive use-cases, it's often useful to produce output there.
Setup
-
brew install salt -
on-prem machine
-
VM (Virtualbox, KVM, etc. please specify)
-
VM running on a cloud service, please be explicit and add details
-
container (Kubernetes, Docker, containerd, etc. please specify)
-
or a combination, please be explicit
-
jails if it is FreeBSD
Steps to Reproduce the behavior
$ cat /srv/salt/packages.sls
install mac stuff:
pkg.installed:
- pkgs:
- iproute2mac
$ cat ~/.bash_profile
#!/bin/bash
date
$ sudo salt-call --local state.apply packages
local:
----------
ID: install mac stuff
Function: pkg.installed
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/state.py", line 2179, in call
ret = self.states[cdata["full"]](
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1249, in wrapper
return f(*args, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/states/pkg.py", line 1722, in installed
result = _find_install_targets(
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/states/pkg.py", line 591, in _find_install_targets
cur_pkgs = __salt__["pkg.list_pkgs"](versions_as_list=True, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/modules/mac_brew_pkg.py", line 166, in list_pkgs
package_info = salt.utils.json.loads(
File "/usr/local/Cellar/salt/3004.2_1/libexec/lib/python3.10/site-packages/salt/utils/json.py", line 89, in loads
return json_module.loads(s, **kwargs)
File "/usr/local/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Started: 11:52:22.176370
Duration: 2684.24 ms
Changes:
Summary for local
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 2.684 s
Expected behavior
pkg.installed should work even if my .bash_profile produces output for me. Probably, salt should never pass -i to sudo since it's all for non-interactive sessions.
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)Salt Version:
Salt: 3004.2
Dependency Versions:
cffi: 1.14.6
cherrypy: 18.6.1
dateutil: 2.8.0
docker-py: Not Installed
gitdb: 4.0.5
gitpython: 3.1.12
Jinja2: 2.11.3
libgit2: 1.4.4
M2Crypto: Not Installed
Mako: 1.1.4
msgpack: 1.0.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.19
pycrypto: 3.15.0
pycryptodome: 3.9.8
pygit2: 1.9.2
Python: 3.10.5 (main, Jun 23 2022, 17:15:32) [Clang 13.0.0 (clang-1300.0.29.30)]
python-gnupg: 0.4.4
PyYAML: 5.4.1
PyZMQ: Not Installed
smmap: 3.0.2
timelib: 0.2.4
Tornado: 4.5.3
ZMQ: Not Installed
System Versions:
dist: darwin 20.6.0
locale: utf-8
machine: x86_64
release: 20.6.0
system: Darwin
version: 11.6.7 x86_64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in salt/modules/mac_brew_pkg.py at _call_brew, then trace how pkg.installed reaches list_pkgs and parses the brew output. Verify the behavior with a .bash_profile that writes to stdout: pkg.installed should complete without the JSONDecodeError shown in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100