commit 2e37c179d75f01e4225246145298385221833d4b Author: Bryn M. Reeves Date: Wed Dec 5 14:26:15 2012 +0000 Obscure display passwords in collected libvirt/qemu files diff --git a/sos/plugins/libvirt.py b/sos/plugins/libvirt.py index 001281c..23351c1 100644 --- a/sos/plugins/libvirt.py +++ b/sos/plugins/libvirt.py @@ -13,9 +13,17 @@ ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import sos.plugintools +import glob + class libvirt(sos.plugintools.PluginBase): """libvirt-related information """ def setup(self): self.addCopySpec("/etc/libvirt/") self.addCopySpec("/var/log/libvirt*") + + def postproc(self): + for xmlfile in glob.glob("/etc/libvirt/qemu/*.xml"): + self.doRegexSub(xmlfile, + r"(\s*passwd=\s*')([^']*)('.*$)", + r"\1******\3") commit c22478a91c1e6959c6853b0025faf72bd60f1dd1 Author: Bryn M. Reeves Date: Tue Aug 13 16:47:12 2013 +0100 Add implementation of command output post-processing Backport of commit 3a982ff. Add a doRegexExtOutputSub() function to mirror doRegExSub(). This allows modukes ti apply an arbitrary regular expression substitution to the output collected from external commands. Signed-off-by: Bryn M. Reeves diff --git a/sos/plugintools.py b/sos/plugintools.py index 2419ee4..4bde7e4 100644 --- a/sos/plugintools.py +++ b/sos/plugintools.py @@ -36,6 +36,7 @@ from stat import * from time import time from itertools import * from collections import deque +import fnmatch class PluginException(Exception): pass @@ -109,6 +110,43 @@ class PluginBase: break return False + def doRegexExtOutputSub(self, cmd, regexp, subst): + '''Apply a regexp substitution to command output archived by sosreport. + cmd is the command name from which output is collected (i.e. excluding + parameters). The regexp can be a string or a compiled re object. The + substitution string, subst, is a string that replaces each occurrence + of regexp in each file collected from cmd. Internally 'cmd' is treated + as a glob with a trailing '*' and each matching file from the current + module's command list is subjected to the replacement. + + This function returns the number of replacements made. + ''' + globstr = '*' + cmd + '*' + self.soslog.debug("substituting '%s' for '%s' in commands matching %s" + % (subst, regexp, globstr)) + + if not self.executedCommands: + return 0 + replacements = 0 + try: + for called in self.executedCommands: + if fnmatch.fnmatch(called['exe'], globstr): + path = os.path.join(self.cInfo['cmddir'], called['file']) + self.soslog.debug("applying substitution to %s" % path) + readable = open(path, 'r') + result, replaced = re.subn( + regexp, subst, readable.read()) + readable.close() + if replaced: + fp = open(path, 'w') + fp.write(result) + fp.close() + replacements = replacements + replaced + except Exception, e: + msg = 'regex substitution failed for %s in plugin %s with: "%s"' + self.soslog.error(msg % (path, self.piName, e)) + return replacements + def doRegexFindAll(self, regex, fname): ''' Return a list of all non overlapping matches in the string(s) ''' commit 2287392f69330ba0c15d75ceabdd479b83c8e18c Author: Bryn M. Reeves Date: Tue Aug 13 16:53:49 2013 +0100 Obscure password in corosync-objctl output The corosync-objctl command output may include fence device passwords. Use a command output regex substitution to elide them from generated reports. Signed-off-by: Bryn M. Reeves diff --git a/sos/plugins/cluster.py b/sos/plugins/cluster.py index ee6f51c..13da52c 100644 --- a/sos/plugins/cluster.py +++ b/sos/plugins/cluster.py @@ -130,5 +130,6 @@ class cluster(sos.plugintools.PluginBase): def postproc(self): for cluster_conf in glob("/etc/cluster/cluster.conf*"): self.doRegexSub(cluster_conf, r"(\s*\