Blame SOURCES/sos-bz1767445-interim-sysroot-forbidden-paths.patch

d1980b
From 9a0ab16793a8388b2c3d3909fd3a087c5b6296d4 Mon Sep 17 00:00:00 2001
d1980b
From: Pavel Moravec <pmoravec@redhat.com>
d1980b
Date: Fri, 1 Nov 2019 12:13:23 -0400
d1980b
Subject: [PATCH 01/10] [Plugin] remove invalid {strip/join}_sysroot()
d1980b
d1980b
Do not strip the sysroot path prefix when calling _do_copy_path()
d1980b
for a symlink target and do not add the sysroot prefix when
d1980b
testing for a forbidden path.
d1980b
d1980b
Related: #1842
d1980b
d1980b
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/__init__.py | 4 +---
d1980b
 1 file changed, 1 insertion(+), 3 deletions(-)
d1980b
d1980b
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
d1980b
index e75ec82e..4f1b73ce 100644
d1980b
--- a/sos/plugins/__init__.py
d1980b
+++ b/sos/plugins/__init__.py
d1980b
@@ -731,7 +731,7 @@ class Plugin(object):
d1980b
 
d1980b
         # skip recursive copying of symlink pointing to itself.
d1980b
         if (absdest != srcpath):
d1980b
-            self._do_copy_path(self.strip_sysroot(absdest))
d1980b
+            self._do_copy_path(absdest)
d1980b
         else:
d1980b
             self._log_debug("link '%s' points to itself, skipping target..."
d1980b
                             % linkdest)
d1980b
@@ -758,8 +758,6 @@ class Plugin(object):
d1980b
         return None
d1980b
 
d1980b
     def _is_forbidden_path(self, path):
d1980b
-        if self.use_sysroot():
d1980b
-            path = self.join_sysroot(path)
d1980b
         return _path_in_path_list(path, self.forbidden_paths)
d1980b
 
d1980b
     def _copy_node(self, path, st):
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
d1980b
From aeeebf126fc9fdb0fd8c3b01418bef742bce78c3 Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Fri, 1 Nov 2019 12:22:51 -0400
d1980b
Subject: [PATCH 02/10] [Plugin] fix destination paths in _do_copy_path()
d1980b
d1980b
The path used to copy special device nodes and directories in
d1980b
_do_copy_path() should be the destination path in the archive
d1980b
(without sysroot prefix), and not the source path in the host
d1980b
file system that includes this prefix.
d1980b
d1980b
Related: #1842
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/__init__.py | 6 +++---
d1980b
 1 file changed, 3 insertions(+), 3 deletions(-)
d1980b
d1980b
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
d1980b
index 4f1b73ce..60fbeaf7 100644
d1980b
--- a/sos/plugins/__init__.py
d1980b
+++ b/sos/plugins/__init__.py
d1980b
@@ -721,8 +721,12 @@ class Plugin(object):
d1980b
             return
d1980b
         else:
d1980b
             if stat.S_ISDIR(st.st_mode) and os.access(srcpath, os.R_OK):
d1980b
-                self._copy_dir(srcpath)
d1980b
-                return
d1980b
+                 # copy empty directory
d1980b
+                 if not os.listdir(srcpath):
d1980b
+                     self.archive.add_dir(dest)
d1980b
+                     return
d1980b
+                 self._copy_dir(dest)
d1980b
+                 return
d1980b
 
d1980b
         # handle special nodes (block, char, fifo, socket)
d1980b
         if not (stat.S_ISREG(st.st_mode) or stat.S_ISDIR(st.st_mode)):
d1980b
@@ -808,7 +808,7 @@ class Plugin(object):
d1980b
             ntype = _node_type(st)
d1980b
             self._log_debug("creating %s node at archive:'%s'"
d1980b
                             % (ntype, dest))
d1980b
-            self._copy_node(srcpath, st)
d1980b
+            self._copy_node(dest, st)
d1980b
             return
d1980b
 
d1980b
         # if we get here, it's definitely a regular file (not a symlink or dir)
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
d1980b
From 05f3d5bda8f548459fabcd38f2d087d6ecef98a2 Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Fri, 1 Nov 2019 12:25:09 -0400
d1980b
Subject: [PATCH 03/10] [kernel] remove trailing directory globs in forbidden
d1980b
 paths
d1980b
d1980b
Since the forbidden path test now uses an exact match the trailing
d1980b
globs ("/some/directory/path/to/exclude/*") used to exclude trace
d1980b
related directories from collection lead to a failure to properly
d1980b
blacklist these files:
d1980b
d1980b
The glob is expanded, for e.g.:
d1980b
d1980b
  "/sys/kernel/debug/tracing/per_cpu/*"
d1980b
d1980b
Expands to unclude a 'cpuN' sub-directory for each CPU present on
d1980b
the machine. These expanded paths are then added to the forbidden
d1980b
paths list for the plugin:
d1980b
d1980b
  /sys/kernel/debug/tracing/per_cpu/cpu0
d1980b
  /sys/kernel/debug/tracing/per_cpu/cpu1
d1980b
  ...
d1980b
d1980b
When an attempt is made to collect the entire "per_cpu" directory
d1980b
a check is made for the full "/sys/kernel/debug/tracing/per_cpu"
d1980b
path against each entry in the forbidden paths list. Since this is
d1980b
a prefix of the actual paths stored no match is returned and the
d1980b
collection is permitted.
d1980b
d1980b
Remove the trailing globs from these directory paths and prevent
d1980b
any collection of the directories they reference by the plugin.
d1980b
d1980b
Related: #1842
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/kernel.py | 6 +++---
d1980b
 1 file changed, 3 insertions(+), 3 deletions(-)
d1980b
d1980b
diff --git a/sos/plugins/kernel.py b/sos/plugins/kernel.py
d1980b
index 88b14689..5c852143 100644
d1980b
--- a/sos/plugins/kernel.py
d1980b
+++ b/sos/plugins/kernel.py
d1980b
@@ -89,9 +89,9 @@ class Kernel(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
d1980b
         self.add_forbidden_path([
d1980b
             '/sys/kernel/debug/tracing/trace_pipe',
d1980b
             '/sys/kernel/debug/tracing/README',
d1980b
-            '/sys/kernel/debug/tracing/trace_stat/*',
d1980b
-            '/sys/kernel/debug/tracing/per_cpu/*',
d1980b
-            '/sys/kernel/debug/tracing/events/*',
d1980b
+            '/sys/kernel/debug/tracing/trace_stat',
d1980b
+            '/sys/kernel/debug/tracing/per_cpu',
d1980b
+            '/sys/kernel/debug/tracing/events',
d1980b
             '/sys/kernel/debug/tracing/free_buffer',
d1980b
             '/sys/kernel/debug/tracing/trace_marker',
d1980b
             '/sys/kernel/debug/tracing/trace_marker_raw',
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
d1980b
From 801c71b33dcfeaa980baa9f377b721bdd26aa5e8 Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Fri, 1 Nov 2019 16:53:29 +0000
d1980b
Subject: [PATCH 04/10] [tests] fix test_copy_dir_forbidden_path
d1980b
d1980b
Rather than call just Plugin.setup() and Plugin._do_copy_path(),
d1980b
add an add_copy_spec() call to the mock plugin setup() method,
d1980b
and invoke copying by calling the Plugin.collect() method.
d1980b
d1980b
Related: #1845
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 tests/plugin_tests.py | 3 ++-
d1980b
 1 file changed, 2 insertions(+), 1 deletion(-)
d1980b
d1980b
diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py
d1980b
index b8760429..6522fe14 100644
d1980b
--- a/tests/plugin_tests.py
d1980b
+++ b/tests/plugin_tests.py
d1980b
@@ -81,6 +81,7 @@ class ForbiddenMockPlugin(Plugin):
d1980b
     plugin_name = "forbidden"
d1980b
 
d1980b
     def setup(self):
d1980b
+        self.add_copy_spec("tests")
d1980b
         self.add_forbidden_path("tests")
d1980b
 
d1980b
 
d1980b
@@ -235,7 +236,7 @@ class PluginTests(unittest.TestCase):
d1980b
         })
d1980b
         p.archive = MockArchive()
d1980b
         p.setup()
d1980b
-        p._do_copy_path("tests")
d1980b
+        p.collect()
d1980b
         self.assertEquals(p.archive.m, {})
d1980b
 
d1980b
 
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
d1980b
d1980b
From 68f4d7cc7adde00171af842b5bc808f41d888a87 Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Mon, 4 Nov 2019 10:48:01 +0000
d1980b
Subject: [PATCH 06/10] [Plugin] improve _copy_dir() variable naming
d1980b
d1980b
Directory entries found in _copy_dir() may be either files or
d1980b
sub-directories: reflect this in the names of local variables.
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/__init__.py | 7 ++++---
d1980b
 1 file changed, 4 insertions(+), 3 deletions(-)
d1980b
d1980b
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
d1980b
index 240fe9f1..1a1464c1 100644
d1980b
--- a/sos/plugins/__init__.py
d1980b
+++ b/sos/plugins/__init__.py
d1980b
@@ -738,10 +738,11 @@ class Plugin(object):
d1980b
 
d1980b
     def _copy_dir(self, srcpath):
d1980b
         try:
d1980b
-            for afile in os.listdir(srcpath):
d1980b
+            for name in os.listdir(srcpath):
d1980b
                 self._log_debug("recursively adding '%s' from '%s'"
d1980b
-                                % (afile, srcpath))
d1980b
-                self._do_copy_path(os.path.join(srcpath, afile), dest=None)
d1980b
+                                % (name, srcpath))
d1980b
+                path = os.path.join(srcpath, name)
d1980b
+                self._do_copy_path(path)
d1980b
         except OSError as e:
d1980b
             if e.errno == errno.ELOOP:
d1980b
                 msg = "Too many levels of symbolic links copying"
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
d1980b
From ad3adef07c32aee5bdd438706c6c1d4590ff8297 Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Mon, 4 Nov 2019 14:13:00 +0000
d1980b
Subject: [PATCH 07/10] [ceph] fix directory blacklist style
d1980b
d1980b
Plugins must use 'path/to/exclude' rather than 'path/to/exclude/*'
d1980b
in order to omit a directory and all its content from the report.
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/ceph.py | 4 ++--
d1980b
 1 file changed, 2 insertions(+), 2 deletions(-)
d1980b
d1980b
diff --git a/sos/plugins/ceph.py b/sos/plugins/ceph.py
d1980b
index 6e340c69..43284bc8 100644
d1980b
--- a/sos/plugins/ceph.py
d1980b
+++ b/sos/plugins/ceph.py
d1980b
@@ -103,8 +103,8 @@ class Ceph(Plugin, RedHatPlugin, UbuntuPlugin):
d1980b
             "/var/lib/ceph/*keyring*",
d1980b
             "/var/lib/ceph/*/*keyring*",
d1980b
             "/var/lib/ceph/*/*/*keyring*",
d1980b
-            "/var/lib/ceph/osd/*",
d1980b
-            "/var/lib/ceph/mon/*",
d1980b
+            "/var/lib/ceph/osd",
d1980b
+            "/var/lib/ceph/mon",
d1980b
             # Excludes temporary ceph-osd mount location like
d1980b
             # /var/lib/ceph/tmp/mnt.XXXX from sos collection.
d1980b
             "/var/lib/ceph/tmp/*mnt*",
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
d1980b
From 4d1576b04d35902ce44d26d6a5b2219e6f9c175a Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Mon, 4 Nov 2019 14:15:55 +0000
d1980b
Subject: [PATCH 09/10] [openstack_octavia] fix directory blacklist style
d1980b
d1980b
Plugins must use 'path/to/exclude' rather than 'path/to/exclude/*'
d1980b
in order to omit a directory and all its content from the report.
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/openstack_octavia.py | 2 +-
d1980b
 1 file changed, 1 insertion(+), 1 deletion(-)
d1980b
d1980b
diff --git a/sos/plugins/openstack_octavia.py b/sos/plugins/openstack_octavia.py
d1980b
index b97c83fa..ccdcd4c9 100644
d1980b
--- a/sos/plugins/openstack_octavia.py
d1980b
+++ b/sos/plugins/openstack_octavia.py
d1980b
@@ -30,7 +30,7 @@ class OpenStackOctavia(Plugin):
d1980b
         ])
d1980b
 
d1980b
         # don't collect certificates
d1980b
-        self.add_forbidden_path("/etc/octavia/certs/")
d1980b
+        self.add_forbidden_path("/etc/octavia/certs")
d1980b
 
d1980b
         # logs
d1980b
         if self.get_option("all_logs"):
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
d1980b
From 1fd194191a56c51052f0c24ddeb3bbf9088ae0ca Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Mon, 4 Nov 2019 14:16:13 +0000
d1980b
Subject: [PATCH 10/10] [vdsm] fix directory blacklist style
d1980b
d1980b
Plugins must use 'path/to/exclude' rather than 'path/to/exclude/*'
d1980b
in order to omit a directory and all its content from the report.
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/vdsm.py | 4 ++--
d1980b
 1 file changed, 2 insertions(+), 2 deletions(-)
d1980b
d1980b
diff --git a/sos/plugins/vdsm.py b/sos/plugins/vdsm.py
d1980b
index b2a1ca58..69672643 100644
d1980b
--- a/sos/plugins/vdsm.py
d1980b
+++ b/sos/plugins/vdsm.py
d1980b
@@ -60,9 +60,9 @@ class Vdsm(Plugin, RedHatPlugin):
d1980b
     plugin_name = 'vdsm'
d1980b
 
d1980b
     def setup(self):
d1980b
-        self.add_forbidden_path('/etc/pki/vdsm/keys/*')
d1980b
+        self.add_forbidden_path('/etc/pki/vdsm/keys')
d1980b
         self.add_forbidden_path('/etc/pki/vdsm/libvirt-spice/*-key.*')
d1980b
-        self.add_forbidden_path('/etc/pki/libvirt/private/*')
d1980b
+        self.add_forbidden_path('/etc/pki/libvirt/private')
d1980b
 
d1980b
         self.add_cmd_output('service vdsmd status')
d1980b
         self.add_cmd_output('service supervdsmd status')
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b
From 87dbc4d961d9e98f4e8b7b54010800ff3bdb5a73 Mon Sep 17 00:00:00 2001
d1980b
From: Jake Hunsaker <jhunsake@redhat.com>
d1980b
Date: Mon, 11 Nov 2019 12:43:01 -0500
d1980b
Subject: [PATCH] [Plugin|Policy] Only call lsmod once and standardize kmod
d1980b
 checks
d1980b
d1980b
This commit makes two changes to how sos deals with kernel modules and
d1980b
their state during a run of sosreport.
d1980b
d1980b
First, no longer call `lsmod` for every individual plugin during its
d1980b
enablement check. Instead, call `lsmod` only once during `Policy`
d1980b
initialization, and cache the output for later checks.
d1980b
d1980b
Second, have `Plugin.is_module_loaded()` check for kmod presence in the
d1980b
saved policy class attr for kernel_mods, rather than checking through
d1980b
`/proc/modules`. Have the plugin enablement checks now also use
d1980b
`is_module_loaded()` to standardize with how `SoSPredicate`s are
d1980b
checked.
d1980b
d1980b
Note that this change results in a significant performance increase for
d1980b
sos initialization times in a RHEL 7 container.
d1980b
d1980b
Resolves: #1854
d1980b
d1980b
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
d1980b
---
d1980b
 sos/plugins/__init__.py  | 13 +++----------
d1980b
 sos/policies/__init__.py |  8 +++++---
d1980b
 2 files changed, 8 insertions(+), 13 deletions(-)
d1980b
d1980b
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
d1980b
index 1a1464c11..b7a47b6a4 100644
d1980b
--- a/sos/plugins/__init__.py
d1980b
+++ b/sos/plugins/__init__.py
d1980b
@@ -1170,11 +1170,8 @@
d1980b
                                         sizelimit=sizelimit)
d1980b
 
d1980b
     def is_module_loaded(self, module_name):
d1980b
-        """Return whether specified moudle as module_name is loaded or not"""
d1980b
-        if len(grep("^" + module_name + " ", "/proc/modules")) == 0:
d1980b
-            return False
d1980b
-        else:
d1980b
-            return True
d1980b
+        """Return whether specified module as module_name is loaded or not"""
d1980b
+        return module_name in self.policy.kernel_mods
d1980b
 
d1980b
     # For adding output
d1980b
     def add_alert(self, alertstring):
d1980b
@@ -1408,15 +1408,11 @@
d1980b
         return True
d1980b
 
d1980b
     def _check_plugin_triggers(self, files, packages, commands, services):
d1980b
-        kernel_mods = self.policy.lsmod()
d1980b
-
d1980b
-        def have_kmod(kmod):
d1980b
-            return kmod in kernel_mods
d1980b
 
d1980b
         return (any(os.path.exists(fname) for fname in files) or
d1980b
                 any(self.is_installed(pkg) for pkg in packages) or
d1980b
                 any(is_executable(cmd) for cmd in commands) or
d1980b
-                any(have_kmod(kmod) for kmod in self.kernel_mods) or
d1980b
+                any(self.is_module_loaded(mod) for mod in self.kernel_mods) or
d1980b
                 any(self.is_service(svc) for svc in services))
d1980b
 
d1980b
     def default_enabled(self):
d1980b
d1980b
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
d1980b
index a19daf227..f4aa31801 100644
d1980b
--- a/sos/policies/__init__.py
d1980b
+++ b/sos/policies/__init__.py
d1980b
@@ -822,6 +822,7 @@ class LinuxPolicy(Policy):
d1980b
 
d1980b
     def __init__(self, sysroot=None):
d1980b
         super(LinuxPolicy, self).__init__(sysroot=sysroot)
d1980b
+        self.init_kernel_modules()
d1980b
         if self.init == 'systemd':
d1980b
             self.init_system = SystemdInit()
d1980b
         else:
d1980b
@@ -874,11 +875,12 @@ def get_local_name(self):
d1980b
     def sanitize_filename(self, name):
d1980b
         return re.sub(r"[^-a-z,A-Z.0-9]", "", name)
d1980b
 
d1980b
-    def lsmod(self):
d1980b
-        """Return a list of kernel module names as strings.
d1980b
+    def init_kernel_modules(self):
d1980b
+        """Obtain a list of loaded kernel modules to reference later for plugin
d1980b
+        enablement and SoSPredicate checks
d1980b
         """
d1980b
         lines = shell_out("lsmod", timeout=0).splitlines()
d1980b
-        return [line.split()[0].strip() for line in lines]
d1980b
+        self.kernel_mods = [line.split()[0].strip() for line in lines]
d1980b
 
d1980b
     def pre_work(self):
d1980b
         # this method will be called before the gathering begins
d1980b
d1980b
From c4182ebd52af523261d2e7ef75affbb88eaf31fb Mon Sep 17 00:00:00 2001
d1980b
From: "Bryn M. Reeves" <bmr@redhat.com>
d1980b
Date: Mon, 4 Nov 2019 10:45:15 +0000
d1980b
Subject: [PATCH 05/10] [Plugin] use correct source path when copying
d1980b
 directories
d1980b
d1980b
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
d1980b
---
d1980b
 sos/plugins/__init__.py | 2 +-
d1980b
 1 file changed, 1 insertion(+), 1 deletion(-)
d1980b
d1980b
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
d1980b
index 60fbeaf7..240fe9f1 100644
d1980b
--- a/sos/plugins/__init__.py
d1980b
+++ b/sos/plugins/__init__.py
d1980b
@@ -725,7 +725,7 @@ class Plugin(object):
d1980b
                  if not os.listdir(srcpath):
d1980b
                      self.archive.add_dir(dest)
d1980b
                      return
d1980b
-                 self._copy_dir(dest)
d1980b
+                 self._copy_dir(srcpath)
d1980b
                  return
d1980b
 
d1980b
         # handle special nodes (block, char, fifo, socket)
d1980b
-- 
d1980b
2.21.0
d1980b
d1980b