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

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