Skip to content

Commit

Permalink
[mysql] Add obfuscation for password in conf files
Browse files Browse the repository at this point in the history
Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali authored and TurboTurtle committed Oct 23, 2024
1 parent 4d63e4f commit 1d2e27e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions sos/report/plugins/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Mysql(Plugin):
plugin_name = "mysql"
profiles = ('services',)
mysql_cnf = "/etc/my.cnf"
my_cnf_dir = "/etc/my.cnf.d"

pw_warn_text = " (password visible in process listings)"

Expand Down Expand Up @@ -84,6 +85,20 @@ def setup(self):

self.add_cmd_output("du -s /var/lib/mysql/*")

def postproc(self):
protect_keys = ['password']
regex = fr"(^\s*({'|'.join(protect_keys)})\s*=\s*)(.*)"
sub = r"\1*********"

self.do_path_regex_sub(
f"{self.my_cnf_dir}/*",
regex, sub
)
self.do_file_sub(
f"{self.mysql_cnf}",
regex, sub
)


class RedHatMysql(Mysql, RedHatPlugin):

Expand All @@ -100,7 +115,7 @@ def setup(self):
self.add_copy_spec([
"/etc/ld.so.conf.d/mysql-*.conf",
"/etc/ld.so.conf.d/mariadb-*.conf",
"/etc/my.cnf.d/*",
f"{self.my_cnf_dir}/*",
"/var/lib/config-data/puppet-generated/mysql/etc/my.cnf.d/*"
])

Expand All @@ -115,10 +130,13 @@ class DebianMysql(Mysql, DebianPlugin, UbuntuPlugin):
'percona-xtradb-cluster-server-.*',
)

my_cnf_dir = "/etc/mysql/"
mysql_cnf = f"{my_cnf_dir}/my.cnf"

def setup(self):
super().setup()
self.add_copy_spec([
"/etc/mysql/",
self.my_cnf_dir,
"/var/log/mysql/error.log",
"/var/lib/mysql/*.err",
"/var/lib/percona-xtradb-cluster/*.err",
Expand Down

0 comments on commit 1d2e27e

Please sign in to comment.