aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2015-01-22 15:37:15 +0000
committerBryn M. Reeves <bmr@redhat.com>2015-01-22 15:37:15 +0000
commit7c12e6c994b3320ef57a13e06f5c445b6bca7935 (patch)
tree247bee9781260d37a36770c6e25c4602695db884
parent05466cd6d9d70321fc7a0097334ef36af8dfeb43 (diff)
downloadsos-7c12e6c994b3320ef57a13e06f5c445b6bca7935.tar.gz
[mysql] improve handling of dbuser, dbpass and MYSQL_PWD
Make sure that the mysql plugin behaves correctly when given different combinations of values for dbuser, dbpass and MYSQL_PWD. * If dbdump is set then either dbpass or MYSQL_PWD must be set * Warn if dbdump is set and dbuser or dbpass is True/False/null (indicates either 'sosreport -a' or '-k mysql.dbpass') Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/plugins/mysql.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/sos/plugins/mysql.py b/sos/plugins/mysql.py
index dd899a36..8dba204d 100644
--- a/sos/plugins/mysql.py
+++ b/sos/plugins/mysql.py
@@ -24,35 +24,51 @@ class Mysql(Plugin):
profiles = ('services',)
mysql_cnf = "/etc/my.cnf"
+ pw_warn_text = " (password visible in process listings)"
+
option_list = [
("dbuser", "username for database dumps", "", "mysql"),
- ("dbpass", "password for database dumps", "", False),
+ ("dbpass", "password for database dumps" + pw_warn_text, "", False),
("dbdump", "collect a database dump", "", False)
]
def setup(self):
super(Mysql, self).setup()
+
self.add_copy_spec([
self.mysql_cnf,
"/var/log/mysql/mysqld.log",
"/var/log/mariadb/mariadb.log",
])
+
if self.get_option("all_logs"):
self.add_copy_spec([
"/var/log/mysql*",
"/var/log/mariadb*"
])
+
if self.get_option("dbdump"):
+ msg = "database user name and password must be supplied"
+ dbdump_err = "mysql.dbdump: %s" % msg
+
dbuser = self.get_option("dbuser")
dbpass = self.get_option("dbpass")
- if isinstance(dbuser, bool) or isinstance(dbpass, bool):
- # sosreport -a
- return
+
if 'MYSQL_PWD' in os.environ:
dbpass = os.environ['MYSQL_PWD']
+
+ if dbuser is True or dbpass is True:
+ # sosreport -a or -k mysql.{dbuser,dbpass}
+ self.soslog.warning(dbdump_err)
+ return
+
if not dbpass or dbpass is False:
# no MySQL password
+ self.soslog.warning(dbdump_err)
return
+
+ # no need to save/restore as this variable is private to
+ # the mysql plugin.
os.environ['MYSQL_PWD'] = dbpass
opts = "--user=%s --all-databases" % dbuser