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

Merge 3002.6 bugfix changes #59822

Merged
merged 32 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a0db8ff
Pass `CI_RUN` as an environment variable to the test run.
s0undt3ch Dec 28, 2020
2a49ed0
Migrate `unit.setup` to PyTest
s0undt3ch Dec 28, 2020
9caee9e
Backport ae36b15 just for test_install.py
Ch3LL Mar 9, 2021
4091432
Only skip tests on CI runs
s0undt3ch Jan 8, 2021
65e23aa
Always store git sha in _version.py during installation
Dec 14, 2020
1287495
Fix PEP440 compliance.
s0undt3ch Jan 26, 2021
dddcba1
Fix and migrate `tests/unit/test_version.py` to PyTest
s0undt3ch Jan 26, 2021
8d5454c
Skip test if `easy_install` is not available
s0undt3ch Jan 26, 2021
b783b47
We also need to be PEP440 compliant when there's no git history
s0undt3ch Jan 26, 2021
1803fd5
Merge pull request #193 from Ch3LL/3002.6_test_install
Ch3LL Mar 9, 2021
28207d0
Allow extra_filerefs as sanitized kwargs for SSH client
meaksh Mar 1, 2021
071945f
Fix regression on cmd.run when passing tuples as cmd
meaksh Feb 26, 2021
7e2253c
Add unit tests to ensure cmd.run accepts tuples
meaksh Mar 1, 2021
fcfec17
Add unit test to check for extra_filerefs on SSH opts
meaksh Mar 1, 2021
6aa84d3
Add changelog file
meaksh Mar 1, 2021
5aae74e
Fix comment for test case
meaksh Mar 1, 2021
25a4567
Fix unit test to avoid failing on Windows
meaksh Mar 1, 2021
9388d5e
Skip failing test on windows
meaksh Mar 2, 2021
c1488cf
Fix test to work on Windows
meaksh Mar 2, 2021
61d74a7
Add all ssh kwargs to sanitize_kwargs method
Ch3LL Mar 8, 2021
447cc4b
Run pre-commit
Ch3LL Mar 8, 2021
ba6e399
Fix pylint
Ch3LL Mar 9, 2021
1fae89d
Fix cmdmod loglevel and module_names tests
Ch3LL Mar 9, 2021
1a6a2ea
Fix pre-commit
Ch3LL Mar 9, 2021
149153a
Skip ssh tests if binary does not exist
Ch3LL Mar 9, 2021
355fbc2
Use setup_loader for cmdmod test
Ch3LL Mar 10, 2021
4202798
Merge pull request #190 from Ch3LL/3002.6_ssh_kwargs
Ch3LL Mar 10, 2021
777ffe6
Prevent argument injection in restartcheck
dwoz Mar 9, 2021
903cfdc
Add changelog for restartcheck fix
dwoz Mar 10, 2021
027263b
docs_3002.6
Mar 10, 2021
d53ba5e
Merge branch '3002.6' into merge/3002.6/freeze
dwoz Mar 16, 2021
2453064
Add back tests removed in merge
dwoz Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Deprecated

- Added deprecation warning for grains.get_or_set_hash (#59425)

Salt 3002.6 (2021-03-10)
========================

Changed
-------
Expand All @@ -30,6 +32,7 @@ Changed
- Store git sha in salt/_version.py when installing from a tag so it can be found if needed later. (#59137)
- Changed package manager detection in yumpkg module (#59201)
- Updating the pkg beacon to fire the events when there are upgrades to packages, but also when watched packages are installed or removed. Breaking out the logic for listing pkgs from context into a separate function to aid in testing. Updating tests to ensure context is not used when use_context option to list_pkgs is False. (#59463)
- Store git sha in salt/_version.py when installing from a tag so it can be found if needed later. (#59137)


Fixed
Expand Down Expand Up @@ -167,6 +170,11 @@ Added
- Add -B flag to FreeBSD pkgng.check() to regenerate the library dependency
metadata for a package by extracting library requirement information from the
binary ELF files in the package. (#59569)
- Fix argument injection bug in restartcheck.restartcheck. This change hardens
the fix for CVE-2020-28243. (#200)
- Allow "extra_filerefs" as sanitized kwargs for SSH client.
Fix regression on "cmd.run" when passing tuples as cmd. (#59664)
- Allow all ssh kwargs as sanitized kwargs for SSH client. (#59748)


Salt 3002.5 (2021-02-25)
Expand Down Expand Up @@ -480,6 +488,18 @@ Added
This flag will be deprecated in the Phosphorus release when this functionality
becomes the default. (#58652)

Salt 3001.7 (2021-03-10)
========================

Fixed
-----

- Fix argument injection bug in restartcheck.restartcheck. This change hardens
the fix for CVE-2020-28243. (#200)
- Allow "extra_filerefs" as sanitized kwargs for SSH client.
Fix regression on "cmd.run" when passing tuples as cmd. (#59664)
- Allow all ssh kwargs as sanitized kwargs for SSH client. (#59748)

Salt 3001.6 (2021-02-09)
========================

Expand Down Expand Up @@ -971,6 +991,18 @@ Added
- [#56637](https://github.com/saltstack/salt/pull/56637) - Add ``win_wua.installed`` to the ``win_wua`` execution module
- Clarify how to get the master fingerprint (#54699)

Salt 3000.9 (2021-03-10)
========================

Fixed
-----

- Allow "extra_filerefs" as sanitized kwargs for SSH client.
Fix regression on "cmd.run" when passing tuples as cmd. (#59664)
- Allow all ssh kwargs as sanitized kwargs for SSH client. (#59748)
- Fix argument injection bug in restartcheck.restartcheck. This change hardens
the fix for CVE-2020-28243.

Salt 3000.8 (2021-02-09)
========================

Expand Down
17 changes: 17 additions & 0 deletions doc/topics/releases/3000.9.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _release-3000-9:

===========================
Salt 3000.9 Release Notes
===========================

Version 3000.9 is a bug fix release for :ref:`3000 <release-3000>`.


Fixed
-----

- Allow "extra_filerefs" as sanitized kwargs for SSH client.
Fix regression on "cmd.run" when passing tuples as cmd. (#59664)
- Allow all ssh kwargs as sanitized kwargs for SSH client. (#59748)
- Fix argument injection bug in restartcheck.restartcheck. This change hardens
the fix for CVE-2020-28243.
17 changes: 17 additions & 0 deletions doc/topics/releases/3001.7.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _release-3001-7:

=========================
Salt 3001.7 Release Notes
=========================

Version 3001.7 is a bug fix release for :ref:`3001 <release-3001>`.


Fixed
-----

- Allow "extra_filerefs" as sanitized kwargs for SSH client.
Fix regression on "cmd.run" when passing tuples as cmd. (#59664)
- Allow all ssh kwargs as sanitized kwargs for SSH client. (#59748)
- Fix argument injection bug in restartcheck.restartcheck. This change hardens
the fix for CVE-2020-28243.
24 changes: 24 additions & 0 deletions doc/topics/releases/3002.6.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _release-3002-6:

=========================
Salt 3002.6 Release Notes
=========================

Version 3002.6 is a bug fix release for :ref:`3002 <release-3002>`.


Changed
-------

- Store git sha in salt/_version.py when installing from a tag so it can be found if needed later. (#59137)


Fixed
-----

- Fix argument injection bug in restartcheck.restartcheck. This change hardens
the fix for CVE-2020-28243. (#200)
- Allow "extra_filerefs" as sanitized kwargs for SSH client.
Fix regression on "cmd.run" when passing tuples as cmd. (#59664)
- Allow all ssh kwargs as sanitized kwargs for SSH client. (#59748)

23 changes: 23 additions & 0 deletions salt/client/ssh/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,34 @@ def sanitize_kwargs(self, kwargs):
("ssh_identities_only", bool),
("ssh_remote_port_forwards", str),
("ssh_options", list),
("ssh_max_procs", int),
("ssh_askpass", bool),
("ssh_key_deploy", bool),
("ssh_update_roster", bool),
("ssh_scan_ports", str),
("ssh_scan_timeout", int),
("ssh_timeout", int),
("ssh_log_file", str),
("raw_shell", bool),
("refresh_cache", bool),
("roster", str),
("roster_file", str),
("rosters", list),
("ignore_host_keys", bool),
("raw_shell", bool),
("extra_filerefs", str),
("min_extra_mods", str),
("thin_extra_mods", str),
("verbose", bool),
("static", bool),
("ssh_wipe", bool),
("rand_thin_dir", bool),
("regen_thin", bool),
("python2_bin", str),
("python3_bin", str),
("ssh_run_pre_flight", bool),
("no_host_keys", bool),
("saltfile", str),
]
sane_kwargs = {}
for name, kind in roster_vals:
Expand Down
11 changes: 5 additions & 6 deletions salt/modules/restartcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""
import os
import re
import shlex
import subprocess
import sys
import time
Expand Down Expand Up @@ -495,17 +494,17 @@ def restartcheck(ignorelist=None, blacklist=None, excludepid=None, **kwargs):
verbose = kwargs.pop("verbose", True)
timeout = kwargs.pop("timeout", 5)
if __grains__.get("os_family") == "Debian":
cmd_pkg_query = "dpkg-query --listfiles "
cmd_pkg_query = ["dpkg-query", "--listfiles"]
systemd_folder = "/lib/systemd/system/"
systemd = "/bin/systemd"
kernel_versions = _kernel_versions_debian()
elif __grains__.get("os_family") == "RedHat":
cmd_pkg_query = "repoquery -l "
cmd_pkg_query = ["repoquery", "-l"]
systemd_folder = "/usr/lib/systemd/system/"
systemd = "/usr/bin/systemctl"
kernel_versions = _kernel_versions_redhat()
elif __grains__.get("os_family") == NILRT_FAMILY_NAME:
cmd_pkg_query = "opkg files "
cmd_pkg_query = ["opkg", "files"]
systemd = ""
kernel_versions = _kernel_versions_nilrt()
else:
Expand Down Expand Up @@ -613,8 +612,8 @@ def restartcheck(ignorelist=None, blacklist=None, excludepid=None, **kwargs):

for package in packages:
_check_timeout(start_time, timeout)
cmd = cmd_pkg_query + package
cmd = shlex.split(cmd)
cmd = cmd_pkg_query[:]
cmd.append(package)
paths = subprocess.Popen(cmd, stdout=subprocess.PIPE)

while True:
Expand Down
76 changes: 76 additions & 0 deletions tests/pytests/unit/client/test_ssh.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pytest
import salt.client.ssh.client
import salt.utils.msgpack
from salt.client import ssh
from tests.support.mock import MagicMock, patch

pytestmark = [pytest.mark.skip_if_binaries_missing("ssh", "ssh-keygen", check_all=True)]


@pytest.fixture
def ssh_target(tmpdir):
Expand Down Expand Up @@ -57,3 +60,76 @@ def test_cmd_block_python_version_error(ssh_target):
with patch_shim:
ret = single.cmd_block()
assert "ERROR: Python version error. Recommendation(s) follow:" in ret[0]


@pytest.mark.parametrize(
"test_opts",
[
("extra_filerefs", "salt://foobar", True),
("host", "testhost", False),
("ssh_user", "testuser", True),
("ssh_passwd", "testpasswd", True),
("ssh_port", 23, False),
("ssh_sudo", True, True),
("ssh_sudo_user", "sudouser", False),
("ssh_priv", "test_priv", True),
("ssh_priv_passwd", "sshpasswd", True),
("ssh_identities_only", True, True),
("ssh_remote_port_forwards", "test", True),
("ssh_options", ["test1", "test2"], True),
("ssh_max_procs", 2, True),
("ssh_askpass", True, True),
("ssh_key_deploy", True, True),
("ssh_update_roster", True, True),
("ssh_scan_ports", "test", True),
("ssh_scan_timeout", 1.0, True),
("ssh_timeout", 1, False),
("ssh_log_file", "/tmp/test", True),
("raw_shell", True, True),
("refresh_cache", True, True),
("roster", "/test", True),
("roster_file", "/test1", True),
("rosters", ["test1"], False),
("ignore_host_keys", True, True),
("min_extra_mods", "test", True),
("thin_extra_mods", "test1", True),
("verbose", True, True),
("static", True, True),
("ssh_wipe", True, True),
("rand_thin_dir", True, True),
("regen_thin", True, True),
("python2_bin", "python2", True),
("python3_bin", "python3", True),
("ssh_run_pre_flight", True, True),
("no_host_keys", True, True),
("saltfile", "/tmp/test", True),
("doesnotexist", None, False),
],
)
def test_ssh_kwargs(test_opts):
"""
test all ssh kwargs are not excluded from kwargs
when preparing the SSH opts
"""
opt_key = test_opts[0]
opt_value = test_opts[1]
# Is the kwarg in salt.utils.parsers?
in_parser = test_opts[2]

opts = {
"eauth": "auto",
"username": "test",
"password": "test",
"client": "ssh",
"tgt": "localhost",
"fun": "test.ping",
opt_key: opt_value,
}
client = salt.client.ssh.client.SSHClient(disable_custom_roster=True)
if in_parser:
ssh_kwargs = salt.utils.parsers.SaltSSHOptionParser().defaults
assert opt_key in ssh_kwargs

with patch("salt.roster.get_roster_file", MagicMock(return_value="")):
ssh_obj = client._prep_ssh(**opts)
assert ssh_obj.opts.get(opt_key, None) == opt_value
47 changes: 47 additions & 0 deletions tests/unit/modules/test_restartcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,50 @@ def test_valid_command(self):
"Found 1 processes using old versions of upgraded files", ret
)
self.assertFalse(os.path.exists(create_file))

def test_valid_command_b(self):
"""
test for CVE-2020-28243
"""
create_file = os.path.join(RUNTIME_VARS.TMP, "created_file")

patch_kernel = patch(
"salt.modules.restartcheck._kernel_versions_redhat",
return_value=["3.10.0-1127.el7.x86_64"],
)
services = {
"NetworkManager": {"ExecMainPID": 123},
"auditd": {"ExecMainPID": 456},
"crond": {"ExecMainPID": 789},
}

patch_salt = patch.dict(
restartcheck.__salt__,
{
"cmd.run": MagicMock(
return_value="Linux localhost.localdomain 3.10.0-1127.el7.x86_64"
),
"service.get_running": MagicMock(return_value=list(services.keys())),
"service.show": MagicMock(side_effect=list(services.values())),
"pkg.owner": MagicMock(return_value=""),
"service.available": MagicMock(return_value=True),
},
)

patch_deleted = patch(
"salt.modules.restartcheck._deleted_files",
MagicMock(return_value=[("--admindir tmp dpkg", 123, "/root/ (deleted)")]),
)

patch_readlink = patch("os.readlink", return_value="--admindir tmp dpkg")

popen_mock = MagicMock()
popen_mock.return_value.stdout.readline.side_effect = ["/usr/bin\n", ""]
patch_popen = patch("subprocess.Popen", popen_mock)

patch_grains = patch.dict(restartcheck.__grains__, {"os_family": "RedHat"})
with patch_kernel, patch_salt, patch_deleted, patch_readlink, patch_grains, patch_popen:
ret = restartcheck.restartcheck()
self.assertIn("Found 1 processes using old versions of upgraded files", ret)
args, kwargs = popen_mock.call_args
assert args[0] == ["repoquery", "-l", "--admindir tmp dpkg"]
1 change: 1 addition & 0 deletions tests/unit/test_module_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def test_module_name_source_match(self):
"unit.utils.scheduler.test_run_job",
"unit.utils.scheduler.test_schedule",
"unit.utils.scheduler.test_skip",
"unit.auth.test_auth",
)
errors = []

Expand Down