
In this short blog post, we are going to review how to avoid using credentials in the Percona Monitoring and Management (PMM) client command line when adding new exporters. We will use an example with the MySQL exporter, but it is extensible to others (PostgreSQL, MongoDB, etc.).
In the online documentation we can see the basic steps for adding a new MySQL exporter:
- Configure the PMM client
pmm-admin config ...
- Add the MySQL exporter
pmm-admin add mysql --username=pmm --password=pass
The issue with this approach is that the user and password are there in plain sight for anyone to see, be it through the shell history or via commands like ps aux
.
The PMM client uses kingpin to parse the arguments given, so we can use its feature for reading them from a file to do it in a more secure way. We just need to create the files with the arguments we want to hide from the commands, like:
shell> cat <<EOF >/home/agustin/pmm-admin-config.conf --server-insecure-tls --server-url=https://admin:admin@X.X.X.X:443 EOF shell> cat <<EOF >/home/agustin/pmm-admin-mysql.conf --username=pmm --password=pmmpassword EOF
Note that the above commands were used for simplicity in showing how they can be created. If you are worried about leaving traces in the shell command history use vim (or your editor of choice) to actually create the files and their contents.
We can use these files in the following way, instead:
shell> pmm-admin config @/home/agustin/pmm-admin-config.conf shell> pmm-admin add mysql @/home/agustin/pmm-admin-mysql.conf
We can still use other arguments in the command directly. For example, for the MySQL command:
shell> pmm-admin add mysql --port=6033 @/home/agustin/pmm-admin.conf
PMM clients will not store database credentials within themselves, but will instead request this data from the PMM server. After the exporters are added and running, remove the pmm-admin conf files.
Using Shell Variables
Another way of achieving this is to use “hidden” variables, like:
shell> read -s pmm_mysql_pass [type_the_password_here] shell> pmm-admin add mysql --username=pmm --password=${pmm_mysql_pass}
You can then even wipe the variable out if you want:
shell> pmm_mysql_pass=""
Complete the 2021 Percona Open Source Data Management Software Survey