From 1978ee5946fa3ecc78133a0baf57e49bf7fad590 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Thu, 5 Dec 2019 00:27:56 +0100 Subject: [PATCH] Do not leak passwords in logs --- restic_compose_backup/containers_db.py | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/restic_compose_backup/containers_db.py b/restic_compose_backup/containers_db.py index 9321396..813f641 100644 --- a/restic_compose_backup/containers_db.py +++ b/restic_compose_backup/containers_db.py @@ -37,17 +37,19 @@ class MariadbContainer(Container): f"--host={creds['host']}", f"--port={creds['port']}", f"--user={creds['username']}", - f"--password={creds['password']}", "--all-databases", ] def backup(self): config = Config() - return restic.backup_from_stdin( - config.repository, - f'/databases/{self.service_name}/all_databases.sql', - self.dump_command(), - ) + creds = self.get_credentials() + + with utils.environment('MYSQL_PWD', creds['password']): + return restic.backup_from_stdin( + config.repository, + f'/databases/{self.service_name}/all_databases.sql', + self.dump_command(), + ) class MysqlContainer(Container): @@ -80,17 +82,19 @@ class MysqlContainer(Container): f"--host={creds['host']}", f"--port={creds['port']}", f"--user={creds['username']}", - f"--password={creds['password']}", "--all-databases", ] def backup(self): config = Config() - return restic.backup_from_stdin( - config.repository, - f'/databases/{self.service_name}/all_databases.sql', - self.dump_command(), - ) + creds = self.get_credentials() + + with utils.environment('MYSQL_PWD', creds['password']): + return restic.backup_from_stdin( + config.repository, + f'/databases/{self.service_name}/all_databases.sql', + self.dump_command(), + ) class PostgresContainer(Container):