diff --git a/sos-bz2125499-yum-legacy-links.patch b/sos-bz2125499-yum-legacy-links.patch new file mode 100644 index 0000000..ad8cc50 --- /dev/null +++ b/sos-bz2125499-yum-legacy-links.patch @@ -0,0 +1,73 @@ +From 0b81b7ef780171af4431db656809f10d1683bc4c Mon Sep 17 00:00:00 2001 +From: Pavel Moravec +Date: Tue, 20 Sep 2022 22:11:48 +0200 +Subject: [PATCH 1/2] [dnf] Collect legacy yum config and dnf global vars + +Some systems might rely on legacy yum config with default symlinks to +dnf config - sos should collect the symlinks. + +Additionally, collect dnf global vars. + +Related: #3031 + +Signed-off-by: Pavel Moravec +--- + sos/report/plugins/dnf.py | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/sos/report/plugins/dnf.py b/sos/report/plugins/dnf.py +index 59b8de6c..82078faf 100644 +--- a/sos/report/plugins/dnf.py ++++ b/sos/report/plugins/dnf.py +@@ -55,7 +55,12 @@ class DNFPlugin(Plugin, RedHatPlugin): + '/etc/dnf/modules.d/.*.module': 'dnf_modules' + }) + +- self.add_copy_spec("/etc/dnf/") ++ self.add_copy_spec([ ++ "/etc/dnf/", ++ "/etc/yum.conf", ++ "/etc/yum/pluginconf.d/", ++ "/etc/yum/vars/", ++ ]) + self.add_copy_spec("/etc/yum.repos.d/", + tags=['yum_repos_d', 'dnf_repos_d', 'dnf_repo']) + +-- +2.37.3 + + +From ff17d6486f349dcdc115e898cc50c3845578aef3 Mon Sep 17 00:00:00 2001 +From: Pavel Moravec +Date: Tue, 20 Sep 2022 22:20:51 +0200 +Subject: [PATCH 2/2] [dnf] Obfuscate all passwords from all vars + +- obfuscate also "password=.." variable values +- apply the obfuscation also to global vars dir + +Resolves: #3031 + +Signed-off-by: Pavel Moravec +--- + sos/report/plugins/dnf.py | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/sos/report/plugins/dnf.py b/sos/report/plugins/dnf.py +index 82078faf..6efc9cac 100644 +--- a/sos/report/plugins/dnf.py ++++ b/sos/report/plugins/dnf.py +@@ -125,8 +125,9 @@ class DNFPlugin(Plugin, RedHatPlugin): + self.get_modules_info(modules['output']) + + def postproc(self): +- regexp = r"(proxy_password(\s)*=(\s)*)(\S+)\n" ++ regexp = r"(password(\s)*=(\s)*)(\S+)\n" + repl = r"\1********\n" +- self.do_path_regex_sub("/etc/yum.repos.d/*", regexp, repl) ++ for f in ["/etc/yum.repos.d/*", "/etc/dnf/vars/*"]: ++ self.do_path_regex_sub(f, regexp, repl) + + # vim: set et ts=4 sw=4 : +-- +2.37.3 + diff --git a/sos-bz2126089-relax-magic-dep.patch b/sos-bz2126089-relax-magic-dep.patch new file mode 100644 index 0000000..00bb604 --- /dev/null +++ b/sos-bz2126089-relax-magic-dep.patch @@ -0,0 +1,131 @@ +From 4245de0b978a4d28bb8c833c2f2f5a15a260bd22 Mon Sep 17 00:00:00 2001 +From: Pavel Moravec +Date: Mon, 12 Sep 2022 15:30:16 +0200 +Subject: [PATCH] [utilities] Relax from hard dependency of python3-magic + +For compatibility reasons on some distros, sos should not have a hard +dependency on 'magic' python library. It should attempt to use it for +detection of binary file content, but should fall back to previous "read +the very first byte" method otherwise. + +Resolves: #3025 +Relates: #3021 + +Signed-off-by: Pavel Moravec +--- + requirements.txt | 1 - + setup.py | 2 +- + sos.spec | 2 +- + sos/utilities.py | 50 +++++++++++++++++++++++++++++++++++------------- + 4 files changed, 39 insertions(+), 16 deletions(-) + +diff --git a/requirements.txt b/requirements.txt +index c6ba1162..39f42161 100644 +--- a/requirements.txt ++++ b/requirements.txt +@@ -2,5 +2,4 @@ pycodestyle>=2.4.0 + coverage>=4.0.3 + Sphinx>=1.3.5 + pexpect>=4.0.0 +-python_magic>=0.4.20 + pyyaml +diff --git a/setup.py b/setup.py +index 2a70802d..f2f9ecbe 100644 +--- a/setup.py ++++ b/setup.py +@@ -107,7 +107,7 @@ setup( + ], + cmdclass=cmdclass, + command_options=command_options, +- requires=['pexpect', 'python_magic', 'pyyaml'] ++ requires=['pexpect', 'pyyaml'] + ) + + +diff --git a/sos.spec b/sos.spec +index 748b9fd5..08499816 100644 +--- a/sos.spec ++++ b/sos.spec +@@ -16,7 +16,7 @@ Requires: python3-rpm + Requires: tar + Requires: xz + Requires: python3-pexpect +-Requires: python3-magic ++Recommends: python3-magic + Recommends: python3-pyyaml + Obsoletes: sos-collector <= 1.9 + +diff --git a/sos/utilities.py b/sos/utilities.py +index 2046c8fd..21c815d9 100644 +--- a/sos/utilities.py ++++ b/sos/utilities.py +@@ -19,11 +19,26 @@ import tempfile + import threading + import time + import io +-import magic +- + from contextlib import closing + from collections import deque + ++# try loading magic>=0.4.20 which implements detect_from_filename method ++magic_mod = False ++try: ++ import magic ++ magic.detect_from_filename(__file__) ++ magic_mod = True ++except (ImportError, AttributeError): ++ log = logging.getLogger('sos') ++ from textwrap import fill ++ msg = ("""\ ++WARNING: Failed to load 'magic' module version >= 0.4.20 which sos aims to \ ++use for detecting binary files. A less effective method will be used. It is \ ++recommended to install proper python3-magic package with the module. ++""") ++ log.warn('\n' + fill(msg, 72, replace_whitespace=False) + '\n') ++ ++ + TIMEOUT_DEFAULT = 300 + + +@@ -75,17 +90,26 @@ def file_is_binary(fname): + :returns: True if binary, else False + :rtype: ``bool`` + """ +- try: +- _ftup = magic.detect_from_filename(fname) +- _mimes = ['text/', 'inode/'] +- return ( +- _ftup.encoding == 'binary' and not +- any(_ftup.mime_type.startswith(_mt) for _mt in _mimes) +- ) +- except Exception: +- # if for some reason this check fails, don't blindly remove all files +- # but instead rely on other checks done by the component +- return False ++ if magic_mod: ++ try: ++ _ftup = magic.detect_from_filename(fname) ++ _mimes = ['text/', 'inode/'] ++ return ( ++ _ftup.encoding == 'binary' and not ++ any(_ftup.mime_type.startswith(_mt) for _mt in _mimes) ++ ) ++ except Exception: ++ pass ++ # if for some reason the above check fails or magic>=0.4.20 is not present, ++ # fail over to checking the very first byte of the file content ++ with open(fname, 'tr') as tfile: ++ try: ++ # when opened as above (tr), reading binary content will raise ++ # an exception ++ tfile.read(1) ++ return False ++ except UnicodeDecodeError: ++ return True + + + def find(file_pattern, top_dir, max_depth=None, path_pattern=None): +-- +2.37.3 + diff --git a/sos.spec b/sos.spec index 9e4838a..5a06067 100644 --- a/sos.spec +++ b/sos.spec @@ -5,7 +5,7 @@ Summary: A set of tools to gather troubleshooting information from a system Name: sos Version: 4.4 -Release: 1%{?dist} +Release: 2%{?dist} Group: Applications/System Source0: https://github.com/sosreport/sos/archive/%{version}/sos-%{version}.tar.gz Source1: sos-audit-%{auditversion}.tgz @@ -17,11 +17,13 @@ BuildRequires: gettext Requires: tar Requires: bzip2 Requires: xz -Requires: python3-magic Requires: python3-requests +Recommends: python3-magic Recommends: python3-pexpect Conflicts: vdsm < 4.40 Obsoletes: sos-collector <= 1.9 +Patch1: sos-bz2126089-relax-magic-dep.patch +Patch2: sos-bz2125499-yum-legacy-links.patch %description @@ -33,6 +35,8 @@ support technicians and developers. %prep %setup -qn %{name}-%{version} %setup -T -D -a1 -q +%patch1 -p1 +%patch2 -p1 %build %py3_build @@ -100,6 +104,12 @@ of the system. Currently storage and filesystem commands are audited. %changelog +* Thu Sep 22 2022 Pavel Moravec = 4.4-2 +- [utilities] Relax from hard dependency of python3-magic + Resolves: bz2126089 +- [dnf] Collect legacy yum config symlinks, properly obfuscate pwds + Resolves: bz2125499 + * Fri Sep 09 2022 Pavel Moravec = 4.4-1 - Rebase on upstream 4.4 Resolves: bz2082615