Blame SOURCES/sos-bz1665947-rhui-plugin.patch

ba407d
From 94b9b90c818eb18f0ca8d78fe063dc5b0677c885 Mon Sep 17 00:00:00 2001
ba407d
From: Pavel Moravec <pmoravec@redhat.com>
ba407d
Date: Tue, 22 Jun 2021 12:58:03 +0200
ba407d
Subject: [PATCH] [rhui] add plugin to RHUI
ba407d
ba407d
Add a new/revoked plugin for RHUI (newly based on python3 and pulp-3).
ba407d
ba407d
Edditionally, collect /etc/pki/pulp certificates except for RSA keys.
ba407d
ba407d
Resolves: #2590
ba407d
ba407d
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ba407d
---
ba407d
 sos/report/plugins/pulpcore.py |  7 ++++-
ba407d
 sos/report/plugins/rhui.py     | 49 ++++++++++++++++++++++++++++++++++
ba407d
 2 files changed, 55 insertions(+), 1 deletion(-)
ba407d
 create mode 100644 sos/report/plugins/rhui.py
ba407d
ba407d
diff --git a/sos/report/plugins/pulpcore.py b/sos/report/plugins/pulpcore.py
ba407d
index ccaac3185..77ceacb92 100644
ba407d
--- a/sos/report/plugins/pulpcore.py
ba407d
+++ b/sos/report/plugins/pulpcore.py
ba407d
@@ -77,7 +77,12 @@ def separate_value(line, sep=':'):
ba407d
     def setup(self):
ba407d
         self.parse_settings_config()
ba407d
 
ba407d
-        self.add_copy_spec("/etc/pulp/settings.py")
ba407d
+        self.add_copy_spec([
ba407d
+            "/etc/pulp/settings.py",
ba407d
+            "/etc/pki/pulp/*"
ba407d
+        ])
ba407d
+        # skip collecting certificate keys
ba407d
+        self.add_forbidden_path("/etc/pki/pulp/*.key")
ba407d
 
ba407d
         self.add_cmd_output("rq info -u redis://localhost:6379/8",
ba407d
                             env={"LC_ALL": "en_US.UTF-8"},
ba407d
diff --git a/sos/report/plugins/rhui.py b/sos/report/plugins/rhui.py
ba407d
new file mode 100644
ba407d
index 000000000..7acd3f49e
ba407d
--- /dev/null
ba407d
+++ b/sos/report/plugins/rhui.py
ba407d
@@ -0,0 +1,49 @@
ba407d
+# Copyright (C) 2021 Red Hat, Inc., Pavel Moravec <pmoravec@redhat.com>
ba407d
+
ba407d
+# This file is part of the sos project: https://github.com/sosreport/sos
ba407d
+#
ba407d
+# This copyrighted material is made available to anyone wishing to use,
ba407d
+# modify, copy, or redistribute it subject to the terms and conditions of
ba407d
+# version 2 of the GNU General Public License.
ba407d
+#
ba407d
+# See the LICENSE file in the source distribution for further information.
ba407d
+
ba407d
+from sos.report.plugins import Plugin, RedHatPlugin
ba407d
+
ba407d
+
ba407d
+class Rhui(Plugin, RedHatPlugin):
ba407d
+
ba407d
+    short_desc = 'Red Hat Update Infrastructure'
ba407d
+
ba407d
+    plugin_name = "rhui"
ba407d
+    commands = ("rhui-manager",)
ba407d
+    files = ("/etc/ansible/facts.d/rhui_auth.fact", "/usr/lib/rhui/cds.py")
ba407d
+
ba407d
+    def setup(self):
ba407d
+        self.add_copy_spec([
ba407d
+            "/etc/rhui/rhui-tools.conf",
ba407d
+            "/etc/rhui/registered_subscriptions.conf",
ba407d
+            "/etc/pki/rhui/*",
ba407d
+            "/var/log/rhui-subscription-sync.log",
ba407d
+            "/var/cache/rhui/*",
ba407d
+            "/root/.rhui/*",
ba407d
+        ])
ba407d
+        # skip collecting certificate keys
ba407d
+        self.add_forbidden_path("/etc/pki/rhui/*.key")
ba407d
+
ba407d
+        self.add_cmd_output([
ba407d
+            "rhui-manager status",
ba407d
+            "rhui-manager cert info",
ba407d
+            "ls -lR /var/lib/rhui/remote_share",
ba407d
+        ])
ba407d
+
ba407d
+    def postproc(self):
ba407d
+        # obfuscate admin_pw and secret_key values
ba407d
+        for prop in ["admin_pw", "secret_key"]:
ba407d
+            self.do_path_regex_sub(
ba407d
+                "/etc/ansible/facts.d/rhui_auth.fact",
ba407d
+                r"(%s\s*=\s*)(.*)" % prop,
ba407d
+                r"\1********")
ba407d
+
ba407d
+
ba407d
+# vim: set et ts=4 sw=4 :
ba407d
From bd15dc764c9d4554d8e8f08163228d65ca099985 Mon Sep 17 00:00:00 2001
ba407d
From: Pavel Moravec <pmoravec@redhat.com>
ba407d
Date: Thu, 24 Jun 2021 17:53:27 +0200
ba407d
Subject: [PATCH 1/4] [plugins] Allow add_forbidden_path to apply glob
ba407d
 recursively
ba407d
ba407d
Add option to apply glob.glob to forbidden path recursively.
ba407d
ba407d
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ba407d
---
ba407d
 sos/report/plugins/__init__.py | 6 ++++--
ba407d
 1 file changed, 4 insertions(+), 2 deletions(-)
ba407d
ba407d
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py
ba407d
index 06923300..6fd1a3b2 100644
ba407d
--- a/sos/report/plugins/__init__.py
ba407d
+++ b/sos/report/plugins/__init__.py
ba407d
@@ -1187,12 +1187,14 @@ class Plugin(object):
ba407d
             'symlink': "no"
ba407d
         })
ba407d
 
ba407d
-    def add_forbidden_path(self, forbidden):
ba407d
+    def add_forbidden_path(self, forbidden, recursive=False):
ba407d
         """Specify a path, or list of paths, to not copy, even if it's part of
ba407d
         an ``add_copy_spec()`` call
ba407d
 
ba407d
         :param forbidden: A filepath to forbid collection from
ba407d
         :type forbidden: ``str`` or a ``list`` of strings
ba407d
+
ba407d
+        :param recursive: Should forbidden glob be applied recursively
ba407d
         """
ba407d
         if isinstance(forbidden, str):
ba407d
             forbidden = [forbidden]
ba407d
@@ -1202,7 +1204,7 @@ class Plugin(object):
ba407d
 
ba407d
         for forbid in forbidden:
ba407d
             self._log_info("adding forbidden path '%s'" % forbid)
ba407d
-            for path in glob.glob(forbid):
ba407d
+            for path in glob.glob(forbid, recursive=recursive):
ba407d
                 self.forbidden_paths.append(path)
ba407d
 
ba407d
     def get_all_options(self):
ba407d
-- 
ba407d
2.31.1
ba407d
ba407d
ba407d
From b695201baeb629a6543445d98dbb04f357670621 Mon Sep 17 00:00:00 2001
ba407d
From: Pavel Moravec <pmoravec@redhat.com>
ba407d
Date: Thu, 24 Jun 2021 17:57:48 +0200
ba407d
Subject: [PATCH 2/4] [pulpcore] improve settings.py parsing
ba407d
ba407d
- deal with /etc/pulp/settings.py as a one-line string
ba407d
- parse dbname from it as well
ba407d
- dont collect any *.key file from whole /etc/pki/pulp dir
ba407d
ba407d
Related: #2593
ba407d
ba407d
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ba407d
---
ba407d
 sos/report/plugins/pulpcore.py | 23 +++++++++++++++--------
ba407d
 1 file changed, 15 insertions(+), 8 deletions(-)
ba407d
ba407d
diff --git a/sos/report/plugins/pulpcore.py b/sos/report/plugins/pulpcore.py
ba407d
index 77ceacb9..be526035 100644
ba407d
--- a/sos/report/plugins/pulpcore.py
ba407d
+++ b/sos/report/plugins/pulpcore.py
ba407d
@@ -28,9 +28,10 @@ class PulpCore(Plugin, IndependentPlugin):
ba407d
         databases_scope = False
ba407d
         self.dbhost = "localhost"
ba407d
         self.dbport = 5432
ba407d
+        self.dbname = "pulpcore"
ba407d
         self.dbpasswd = ""
ba407d
         # TODO: read also redis config (we dont expect much customisations)
ba407d
-        # TODO: read also db user (pulp) and database name (pulpcore)
ba407d
+        # TODO: read also db user (pulp)
ba407d
         self.staticroot = "/var/lib/pulp/assets"
ba407d
         self.uploaddir = "/var/lib/pulp/media/upload"
ba407d
 
ba407d
@@ -44,7 +45,10 @@ class PulpCore(Plugin, IndependentPlugin):
ba407d
             return val
ba407d
 
ba407d
         try:
ba407d
-            for line in open("/etc/pulp/settings.py").read().splitlines():
ba407d
+            # split the lines to "one option per line" format
ba407d
+            for line in open("/etc/pulp/settings.py").read() \
ba407d
+                    .replace(',', ',\n').replace('{', '{\n') \
ba407d
+                    .replace('}', '\n}').splitlines():
ba407d
                 # skip empty lines and lines with comments
ba407d
                 if not line or line[0] == '#':
ba407d
                     continue
ba407d
@@ -53,11 +57,14 @@ class PulpCore(Plugin, IndependentPlugin):
ba407d
                     continue
ba407d
                 # example HOST line to parse:
ba407d
                 #         'HOST': 'localhost',
ba407d
-                if databases_scope and match(r"\s+'HOST'\s*:\s+\S+", line):
ba407d
+                pattern = r"\s*['|\"]%s['|\"]\s*:\s*\S+"
ba407d
+                if databases_scope and match(pattern % 'HOST', line):
ba407d
                     self.dbhost = separate_value(line)
ba407d
-                if databases_scope and match(r"\s+'PORT'\s*:\s+\S+", line):
ba407d
+                if databases_scope and match(pattern % 'PORT', line):
ba407d
                     self.dbport = separate_value(line)
ba407d
-                if databases_scope and match(r"\s+'PASSWORD'\s*:\s+\S+", line):
ba407d
+                if databases_scope and match(pattern % 'NAME', line):
ba407d
+                    self.dbname = separate_value(line)
ba407d
+                if databases_scope and match(pattern % 'PASSWORD', line):
ba407d
                     self.dbpasswd = separate_value(line)
ba407d
                 # if line contains closing '}' database_scope end
ba407d
                 if databases_scope and '}' in line:
ba407d
@@ -82,7 +89,7 @@ class PulpCore(Plugin, IndependentPlugin):
ba407d
             "/etc/pki/pulp/*"
ba407d
         ])
ba407d
         # skip collecting certificate keys
ba407d
-        self.add_forbidden_path("/etc/pki/pulp/*.key")
ba407d
+        self.add_forbidden_path("/etc/pki/pulp/**/*.key", recursive=True)
ba407d
 
ba407d
         self.add_cmd_output("rq info -u redis://localhost:6379/8",
ba407d
                             env={"LC_ALL": "en_US.UTF-8"},
ba407d
@@ -104,8 +111,8 @@ class PulpCore(Plugin, IndependentPlugin):
ba407d
             _query = "select * from %s where pulp_last_updated > NOW() - " \
ba407d
                      "interval '%s days' order by pulp_last_updated" % \
ba407d
                      (table, task_days)
ba407d
-            _cmd = "psql -h %s -p %s -U pulp -d pulpcore -c %s" % \
ba407d
-                   (self.dbhost, self.dbport, quote(_query))
ba407d
+            _cmd = "psql -h %s -p %s -U pulp -d %s -c %s" % \
ba407d
+                   (self.dbhost, self.dbport, self.dbname, quote(_query))
ba407d
             self.add_cmd_output(_cmd, env=self.env, suggest_filename=table)
ba407d
 
ba407d
     def postproc(self):
ba407d
-- 
ba407d
2.31.1
ba407d
ba407d
ba407d
From 0286034da44bce43ab368dfc6815da7d74d60719 Mon Sep 17 00:00:00 2001
ba407d
From: Pavel Moravec <pmoravec@redhat.com>
ba407d
Date: Thu, 24 Jun 2021 17:59:36 +0200
ba407d
Subject: [PATCH 3/4] [rhui] call rhui-* commands with proper env and timeout
ba407d
ba407d
rhui-manager commands timeout when not being logged in, which
ba407d
should be reacted by adding proper cmd timeout.
ba407d
ba407d
Adding the env.variable ensures potentially unaswered "RHUI Username:"
ba407d
is also printed/colected.
ba407d
ba407d
Further, prevent collecting any *.key file from the whole /etc/pki/rhui
ba407d
dir.
ba407d
ba407d
Related: #2593
ba407d
ba407d
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ba407d
---
ba407d
 sos/report/plugins/rhui.py | 7 +++++--
ba407d
 1 file changed, 5 insertions(+), 2 deletions(-)
ba407d
ba407d
diff --git a/sos/report/plugins/rhui.py b/sos/report/plugins/rhui.py
ba407d
index 7acd3f49..5a152427 100644
ba407d
--- a/sos/report/plugins/rhui.py
ba407d
+++ b/sos/report/plugins/rhui.py
ba407d
@@ -29,13 +29,16 @@ class Rhui(Plugin, RedHatPlugin):
ba407d
             "/root/.rhui/*",
ba407d
         ])
ba407d
         # skip collecting certificate keys
ba407d
-        self.add_forbidden_path("/etc/pki/rhui/*.key")
ba407d
+        self.add_forbidden_path("/etc/pki/rhui/**/*.key", recursive=True)
ba407d
 
ba407d
+        # call rhui-manager commands with 1m timeout and
ba407d
+        # with an env. variable ensuring that "RHUI Username:"
ba407d
+        # even unanswered prompt gets collected
ba407d
         self.add_cmd_output([
ba407d
             "rhui-manager status",
ba407d
             "rhui-manager cert info",
ba407d
             "ls -lR /var/lib/rhui/remote_share",
ba407d
-        ])
ba407d
+        ], timeout=60, env={'PYTHONUNBUFFERED': '1'})
ba407d
 
ba407d
     def postproc(self):
ba407d
         # obfuscate admin_pw and secret_key values
ba407d
-- 
ba407d
2.31.1
ba407d
ba407d
ba407d
From a656bd239ab86dfd8973f733ae2c0fbd0c57d416 Mon Sep 17 00:00:00 2001
ba407d
From: Pavel Moravec <pmoravec@redhat.com>
ba407d
Date: Thu, 24 Jun 2021 18:01:14 +0200
ba407d
Subject: [PATCH 4/4] [rhui] fix broken obfuscation
ba407d
ba407d
- /etc/ansible/facts.d/rhui_*.fact must be collected by
ba407d
rhui plugin to let some file to be obfuscated there
ba407d
- obfuscate also cookies values that can grant login access
ba407d
ba407d
Resolves: #2593
ba407d
ba407d
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ba407d
---
ba407d
 sos/report/plugins/ansible.py | 3 +++
ba407d
 sos/report/plugins/rhui.py    | 7 +++++++
ba407d
 2 files changed, 10 insertions(+)
ba407d
ba407d
diff --git a/sos/report/plugins/ansible.py b/sos/report/plugins/ansible.py
ba407d
index 3e5d3d37..5991b786 100644
ba407d
--- a/sos/report/plugins/ansible.py
ba407d
+++ b/sos/report/plugins/ansible.py
ba407d
@@ -29,4 +29,7 @@ class Ansible(Plugin, RedHatPlugin, UbuntuPlugin):
ba407d
             "ansible --version"
ba407d
         ])
ba407d
 
ba407d
+        # let rhui plugin collects the RHUI specific files
ba407d
+        self.add_forbidden_path("/etc/ansible/facts.d/rhui_*.fact")
ba407d
+
ba407d
 # vim: set et ts=4 sw=4 :
ba407d
diff --git a/sos/report/plugins/rhui.py b/sos/report/plugins/rhui.py
ba407d
index 5a152427..1d479f85 100644
ba407d
--- a/sos/report/plugins/rhui.py
ba407d
+++ b/sos/report/plugins/rhui.py
ba407d
@@ -27,6 +27,7 @@ class Rhui(Plugin, RedHatPlugin):
ba407d
             "/var/log/rhui-subscription-sync.log",
ba407d
             "/var/cache/rhui/*",
ba407d
             "/root/.rhui/*",
ba407d
+            "/etc/ansible/facts.d/rhui_*.fact",
ba407d
         ])
ba407d
         # skip collecting certificate keys
ba407d
         self.add_forbidden_path("/etc/pki/rhui/**/*.key", recursive=True)
ba407d
@@ -47,6 +48,12 @@ class Rhui(Plugin, RedHatPlugin):
ba407d
                 "/etc/ansible/facts.d/rhui_auth.fact",
ba407d
                 r"(%s\s*=\s*)(.*)" % prop,
ba407d
                 r"\1********")
ba407d
+        # obfuscate twoo cookies for login session
ba407d
+        for cookie in ["csrftoken", "sessionid"]:
ba407d
+            self.do_path_regex_sub(
ba407d
+                r"/root/\.rhui/.*/cookies.txt",
ba407d
+                r"(%s\s+)(\S+)" % cookie,
ba407d
+                r"\1********")
ba407d
 
ba407d
 
ba407d
 # vim: set et ts=4 sw=4 :
ba407d
-- 
ba407d
2.31.1
ba407d
ba407d
From 4e5bebffca9936bcdf4d38aad9989970a15dd72b Mon Sep 17 00:00:00 2001
ba407d
From: Pavel Moravec <pmoravec@redhat.com>
ba407d
Date: Tue, 3 Aug 2021 21:54:33 +0200
ba407d
Subject: [PATCH] [rhui] Update the plugin on several places
ba407d
ba407d
- obfuscate "rhui_manager_password: xxx" in /root/.rhui/answers.yaml*
ba407d
- no need to collect or obfuscate anything from /etc/ansible/facts.d
ba407d
- newly detect the plugin via /etc/rhui/rhui-tools.conf file or rhui-manager
ba407d
  command (only)
ba407d
ba407d
Resolves: #2637
ba407d
ba407d
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
ba407d
---
ba407d
 sos/report/plugins/rhui.py | 14 ++++++--------
ba407d
 1 file changed, 6 insertions(+), 8 deletions(-)
ba407d
ba407d
diff --git a/sos/report/plugins/rhui.py b/sos/report/plugins/rhui.py
ba407d
index 1d479f85..52065fb4 100644
ba407d
--- a/sos/report/plugins/rhui.py
ba407d
+++ b/sos/report/plugins/rhui.py
ba407d
@@ -16,8 +16,8 @@ class Rhui(Plugin, RedHatPlugin):
ba407d
     short_desc = 'Red Hat Update Infrastructure'
ba407d
 
ba407d
     plugin_name = "rhui"
ba407d
-    commands = ("rhui-manager",)
ba407d
-    files = ("/etc/ansible/facts.d/rhui_auth.fact", "/usr/lib/rhui/cds.py")
ba407d
+    commands = ("rhui-manager", )
ba407d
+    files = ("/etc/rhui/rhui-tools.conf", )
ba407d
 
ba407d
     def setup(self):
ba407d
         self.add_copy_spec([
ba407d
@@ -27,7 +27,6 @@ class Rhui(Plugin, RedHatPlugin):
ba407d
             "/var/log/rhui-subscription-sync.log",
ba407d
             "/var/cache/rhui/*",
ba407d
             "/root/.rhui/*",
ba407d
-            "/etc/ansible/facts.d/rhui_*.fact",
ba407d
         ])
ba407d
         # skip collecting certificate keys
ba407d
         self.add_forbidden_path("/etc/pki/rhui/**/*.key", recursive=True)
ba407d
@@ -42,11 +41,10 @@ class Rhui(Plugin, RedHatPlugin):
ba407d
         ], timeout=60, env={'PYTHONUNBUFFERED': '1'})
ba407d
 
ba407d
     def postproc(self):
ba407d
-        # obfuscate admin_pw and secret_key values
ba407d
-        for prop in ["admin_pw", "secret_key"]:
ba407d
-            self.do_path_regex_sub(
ba407d
-                "/etc/ansible/facts.d/rhui_auth.fact",
ba407d
-                r"(%s\s*=\s*)(.*)" % prop,
ba407d
+        # hide rhui_manager_password value in (also rotated) answers file
ba407d
+        self.do_path_regex_sub(
ba407d
+                r"/root/\.rhui/answers.yaml.*",
ba407d
+                r"(\s*rhui_manager_password\s*:)\s*(\S+)",
ba407d
                 r"\1********")
ba407d
         # obfuscate twoo cookies for login session
ba407d
         for cookie in ["csrftoken", "sessionid"]:
ba407d
-- 
ba407d
2.31.1
ba407d