forked from sosreport/sos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[archive, component] Obfuscate upload password in sos.log and manifes…
…t.json sos_logs/sos.log and sos_reports/manifest.json tracks command line where we must obfuscate upload passwords like: --upload-pass=PASSWORD --upload-url https://user:[email protected] So let move the do_file_sub functionality into archive class and call that from report before finalizing the archive. Resolves: sosreport#3463 Closes: sosreport#3462 Signed-off-by: Pavel Moravec <[email protected]>
- Loading branch information
1 parent
6c1d4be
commit b9dcb2c
Showing
6 changed files
with
71 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,15 @@ class SoSComponent(): | |
"verbosity": 0 | ||
} | ||
|
||
# files in collected archive that might contain upload password | ||
files_with_upload_passwd = [ | ||
"sos_logs/sos.log", | ||
"sos_reports/manifest.json", | ||
"sos_commands/process/ps_*", | ||
"sos_commands/selinux/ps_*", | ||
"sos_commands/systemd/systemctl_status_--all", | ||
] | ||
|
||
def __init__(self, parser, parsed_args, cmdline_args): | ||
self.parser = parser | ||
self.args = parsed_args | ||
|
@@ -367,6 +376,22 @@ def setup_archive(self, name=''): | |
|
||
self.archive.set_debug(self.opts.verbosity > 2) | ||
|
||
def _obfuscate_upload_passwords(self): | ||
# obfuscate strings like: | ||
# --upload-pass=PASSWORD | ||
# --upload-pass PASSWORD | ||
# --upload-url https://user:[email protected] | ||
# in both sos_logs/sos.log and in sos_reports/manifest.json | ||
# and several sos_commands/* places from plugins's collected data | ||
_arc_path = self.archive.get_archive_path() | ||
for path in self.files_with_upload_passwd: | ||
for f in Path(_arc_path).glob(path): | ||
# get just the relative path that archive works with | ||
f = os.path.relpath(f, _arc_path) | ||
for re in [r"(--upload-pass[\s=]+)\S+", | ||
r"(--upload-url[\s=]+\S+://.*:)([^@]*)"]: | ||
self.archive.do_file_sub(f, re, r"\1********") | ||
|
||
def add_ui_log_to_stdout(self): | ||
ui_console = logging.StreamHandler(sys.stdout) | ||
ui_console.setFormatter(logging.Formatter('%(message)s')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters