Skip to content

Commit

Permalink
[foreman] [foreman_proxy] Add ALL_PROXY and NO_PROXY to collected env…
Browse files Browse the repository at this point in the history
…_vars

Resolves: #3788

Signed-off-by: Pablo Fernández Rodríguez <[email protected]>
  • Loading branch information
pafernanr committed Sep 27, 2024
1 parent 0ab183d commit e4c485f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 16 deletions.
15 changes: 15 additions & 0 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,21 @@ def do_file_sub(self, srcpath, regexp, subst):
replacements = 0
return replacements

def do_paths_http_sub(self, pathspecs):
""" Obfuscate credentials in *_PROXY variables in all files in the
given list. Proxy setting without protocol is ignored, since that
is not recommended setting and obfuscating that one can hit false
positives.
:param pathspecs: A filepath to obfuscate credentials in
:type pathspecs: ``str`` or a ``list`` of strings
"""
if isinstance(pathspecs, str):
pathspecs = [pathspecs]
for path in pathspecs:
self.do_path_regex_sub(
path, r"(http(s)?://)\S+:\S+(@.*)", r"\1******:******\3")

def do_path_regex_sub(self, pathexp, regexp, subst):
"""Apply a regexp substituation to a set of files archived by
sos. The set of files to be substituted is generated by matching
Expand Down
9 changes: 5 additions & 4 deletions sos/report/plugins/anaconda.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ class Anaconda(Plugin, RedHatPlugin):

def setup(self):

paths = [
self.copypaths = [
"/root/anaconda-ks.cfg"
]

if self.path_isdir('/var/log/anaconda'):
# new anaconda
paths.append('/var/log/anaconda')
self.copypaths.append('/var/log/anaconda')
else:
paths = paths + [
self.copypaths = self.copypaths + [
"/var/log/anaconda.*",
"/root/install.log",
"/root/install.log.syslog"
]

self.add_copy_spec(paths)
self.add_copy_spec(self.copypaths)

def postproc(self):
self.do_file_sub(
Expand All @@ -51,5 +51,6 @@ def postproc(self):
r"(user.*--password=*\s*)\s*(\S*)",
r"\1********"
)
self.do_paths_http_sub(self.copypaths)

# vim: set et ts=4 sw=4 :
12 changes: 2 additions & 10 deletions sos/report/plugins/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,11 @@ def setup(self):
def postproc(self):
super().postproc()

common_regex = r"(http(s)?://)\S+:\S+(@.*)"
common_replace = r"\1******:******\3"

files_to_sub = [
self.do_paths_http_sub([
"/etc/apt/sources.list",
"/etc/apt/sources.list.d/",
"/etc/apt/apt.conf",
"/etc/apt/apt.conf.d/",
]

for file in files_to_sub:
self.do_path_regex_sub(
file, common_regex, common_replace
)
])

# vim: set et ts=4 sw=4 :
7 changes: 6 additions & 1 deletion sos/report/plugins/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ def collect_proxies(self):
timeout=10)

# collect http[|s]_proxy env.variables
self.add_env_var(["http_proxy", "https_proxy"])
self.add_env_var([
'HTTP_PROXY',
'HTTPS_PROXY',
'NO_PROXY',
'ALL_PROXY',
])

def build_query_cmd(self, query, csv=False, binary="psql"):
"""
Expand Down
7 changes: 6 additions & 1 deletion sos/report/plugins/foreman_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def setup(self):
])

# collect http[|s]_proxy env.variables
self.add_env_var(["http_proxy", "https_proxy"])
self.add_env_var([
'HTTP_PROXY',
'HTTPS_PROXY',
'NO_PROXY',
'ALL_PROXY',
])

def postproc(self):
self.do_path_regex_sub(
Expand Down
6 changes: 6 additions & 0 deletions sos/report/plugins/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ def setup(self):
"ld.so --list-tunables"
])

def postproc(self):
self.do_paths_http_sub([
"/etc/sysconfig",
"/etc/default",
"/etc/environment",
])

# vim: set et ts=4 sw=4 :
7 changes: 7 additions & 0 deletions sos/report/plugins/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ def setup(self):
])
self.add_forbidden_path('/dev/null')

def postproc(self):
self.do_paths_http_sub([
"/etc/systemd/system",
"/lib/systemd/system",
"/run/systemd/system",
])

# vim: set et ts=4 sw=4 :

0 comments on commit e4c485f

Please sign in to comment.