Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues after CVE fixes #59664

Merged
merged 12 commits into from
Mar 5, 2021
2 changes: 2 additions & 0 deletions changelog/59664.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow "extra_filerefs" as sanitized kwargs for SSH client.
Fix regression on "cmd.run" when passing tuples as cmd.
1 change: 1 addition & 0 deletions salt/client/ssh/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def sanitize_kwargs(self, kwargs):
("rosters", list),
("ignore_host_keys", bool),
("raw_shell", bool),
("extra_filerefs", str),
]
sane_kwargs = {}
for name, kind in roster_vals:
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __virtual__():


def _log_cmd(cmd):
if not isinstance(cmd, list):
if isinstance(cmd, str):
return cmd.split()[0].strip()
return cmd[0].strip()

Expand Down
12 changes: 12 additions & 0 deletions tests/pytests/unit/modules/test_cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ def test_run_runas_with_windows():
cmdmod._run("foo", "bar", runas="baz")


def test_run_with_tuple():
"""
Tests return when cmd is a tuple
"""
mock_true = MagicMock(return_value=True)
with patch("salt.modules.cmdmod._is_valid_shell", mock_true):
with patch("salt.utils.platform.is_windows", MagicMock(return_value=False)):
with patch("os.path.isfile", mock_true):
with patch("os.access", mock_true):
cmdmod._run(("echo", "foo"), python_shell=True)


def test_run_user_not_available():
"""
Tests return when runas user is not available
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/client/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tempfile

import pytest
import salt.client.ssh.client
import salt.config
import salt.roster
import salt.utils.files
Expand Down Expand Up @@ -666,3 +667,26 @@ def test_parse_tgt_no_user(self):
assert client.parse_tgt["hostname"] == host
assert client.parse_tgt["user"] == opts["ssh_user"]
assert self.opts.get("ssh_cli_tgt") == host

def test_extra_filerefs(self):
"""
test "extra_filerefs" are not excluded from kwargs
when preparing the SSH opts
"""
opts = {
"eauth": "auto",
"username": "test",
"password": "test",
"client": "ssh",
"tgt": "localhost",
"fun": "test.ping",
"ssh_port": 22,
"extra_filerefs": "salt://foobar",
}
roster = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "roster")
client = salt.client.ssh.client.SSHClient(
mopts=self.opts, disable_custom_roster=True
)
with patch("salt.roster.get_roster_file", MagicMock(return_value=roster)):
ssh_obj = client._prep_ssh(**opts)
assert ssh_obj.opts.get("extra_filerefs", None) == "salt://foobar"