aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-02-05 13:16:54 -0500
committerJake Hunsaker <jhunsake@redhat.com>2021-02-22 10:31:23 -0500
commit2d697caef5fa7dc43dea4464ac9d2a49abca4969 (patch)
treec84f8274af0af2819c20639130c13f47c2496ce5
parentd810d4d7aa5dc49044a5fbc665983071f6a03cb5 (diff)
downloadsos-2d697caef5fa7dc43dea4464ac9d2a49abca4969.tar.gz
[clean] Allow specifying keywords in a text file
This commit adds the ability for users to provide a text file with a list of newline-delimited keywords that should be obfuscated, rather than requiring all keywords be specified either by the `--keywords` option or configuration file settings. Files may be provided via the new `--keyword-file` option which is available to `clean`, `collect`, and `report`. Closes: #2401 Resolves: #2408 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--man/en/sos-clean.16
-rw-r--r--sos/cleaner/__init__.py7
-rw-r--r--sos/cleaner/parsers/keyword_parser.py7
-rw-r--r--sos/collector/__init__.py4
-rw-r--r--sos/report/__init__.py4
5 files changed, 26 insertions, 2 deletions
diff --git a/man/en/sos-clean.1 b/man/en/sos-clean.1
index 28ac67f7..0c62ed07 100644
--- a/man/en/sos-clean.1
+++ b/man/en/sos-clean.1
@@ -4,6 +4,8 @@ sos clean - Obfuscate sensitive data from one or more sosreports
.SH SYNOPSIS
.B sos clean TARGET [options]
[\-\-domains]
+ [\-\-keywords]
+ [\-\-keyword-file]
[\-\-map-file]
[\-\-jobs]
[\-\-no-update]
@@ -54,6 +56,10 @@ Keywords provided by this option will be obfuscated as "obfuscatedwordX" where X
integer based on the keyword's index in the parser. Note that keywords will be replaced as
both standalone words and in substring matches.
.TP
+.B \-\-keyword-file FILE
+Provide a file that contains a list of keywords that should be obfuscated. Each word must
+be specified on a newline within the file.
+.TP
.B \-\-map-file FILE
Provide a location to a valid mapping file to use as a reference for existing obfuscation pairs.
If one is found, the contents are loaded before parsing is started. This allows consistency between
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py
index 1bc792b0..b9eb61ef 100644
--- a/sos/cleaner/__init__.py
+++ b/sos/cleaner/__init__.py
@@ -44,6 +44,7 @@ class SoSCleaner(SoSComponent):
'domains': [],
'jobs': 4,
'keywords': [],
+ 'keyword_file': None,
'map_file': '/etc/sos/cleaner/default_mapping',
'no_update': False,
'target': '',
@@ -85,7 +86,8 @@ class SoSCleaner(SoSComponent):
SoSHostnameParser(self.opts.map_file, self.opts.domains),
SoSIPParser(self.opts.map_file),
SoSMacParser(self.opts.map_file),
- SoSKeywordParser(self.opts.map_file, self.opts.keywords),
+ SoSKeywordParser(self.opts.map_file, self.opts.keywords,
+ self.opts.keyword_file),
SoSUsernameParser(self.opts.map_file, self.opts.usernames)
]
@@ -170,6 +172,9 @@ third party.
clean_grp.add_argument('--keywords', action='extend', default=[],
dest='keywords',
help='List of keywords to obfuscate')
+ clean_grp.add_argument('--keyword-file', default=None,
+ dest='keyword_file',
+ help='Provide a file a keywords to obfuscate')
clean_grp.add_argument('--map-file', dest='map_file',
default='/etc/sos/cleaner/default_mapping',
help=('Provide a previously generated mapping '
diff --git a/sos/cleaner/parsers/keyword_parser.py b/sos/cleaner/parsers/keyword_parser.py
index 169ce759..4315f2a4 100644
--- a/sos/cleaner/parsers/keyword_parser.py
+++ b/sos/cleaner/parsers/keyword_parser.py
@@ -8,6 +8,8 @@
#
# See the LICENSE file in the source distribution for further information.
+import os
+
from sos.cleaner.parsers import SoSCleanerParser
from sos.cleaner.mappings.keyword_map import SoSKeywordMap
@@ -20,7 +22,7 @@ class SoSKeywordParser(SoSCleanerParser):
map_file_key = 'keyword_map'
prep_map_file = ''
- def __init__(self, conf_file=None, keywords=None):
+ def __init__(self, conf_file=None, keywords=None, keyword_file=None):
self.mapping = SoSKeywordMap()
self.user_keywords = []
super(SoSKeywordParser, self).__init__(conf_file)
@@ -28,6 +30,9 @@ class SoSKeywordParser(SoSCleanerParser):
self.user_keywords.append(_keyword)
if keywords:
self.user_keywords.extend(keywords)
+ if keyword_file and os.path.exists(keyword_file):
+ with open(keyword_file, 'r') as kwf:
+ self.user_keywords.extend(kwf.read().splitlines())
def parse_line(self, line):
count = 0
diff --git a/sos/collector/__init__.py b/sos/collector/__init__.py
index fb1b119b..406c8f35 100644
--- a/sos/collector/__init__.py
+++ b/sos/collector/__init__.py
@@ -65,6 +65,7 @@ class SoSCollector(SoSComponent):
'image': '',
'jobs': 4,
'keywords': [],
+ 'keyword_file': None,
'label': '',
'list_options': False,
'log_size': 0,
@@ -376,6 +377,9 @@ class SoSCollector(SoSComponent):
cleaner_grp.add_argument('--keywords', action='extend', default=[],
dest='keywords',
help='List of keywords to obfuscate')
+ cleaner_grp.add_argument('--keyword-file', default=None,
+ dest='keyword_file',
+ help='Provide a file a keywords to obfuscate')
cleaner_grp.add_argument('--no-update', action='store_true',
default=False, dest='no_update',
help='Do not update the default cleaner map')
diff --git a/sos/report/__init__.py b/sos/report/__init__.py
index e5a68b2c..25478ba7 100644
--- a/sos/report/__init__.py
+++ b/sos/report/__init__.py
@@ -88,6 +88,7 @@ class SoSReport(SoSComponent):
'experimental': False,
'enable_plugins': [],
'keywords': [],
+ 'keyword_file': None,
'plugopts': [],
'label': '',
'list_plugins': False,
@@ -318,6 +319,9 @@ class SoSReport(SoSComponent):
cleaner_grp.add_argument('--keywords', action='extend', default=[],
dest='keywords',
help='List of keywords to obfuscate')
+ cleaner_grp.add_argument('--keyword-file', default=None,
+ dest='keyword_file',
+ help='Provide a file a keywords to obfuscate')
cleaner_grp.add_argument('--no-update', action='store_true',
default=False, dest='no_update',
help='Do not update the default cleaner map')