From a98b76cd555fd0c9273d7d47223bf189ca5cfdf8 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Fri, 21 Apr 2023 11:14:54 +0000 Subject: [PATCH] Grant `ALL PRIVILEGES` to mysqlrouter user (#211) Needed for mysqlrouter refactoring: https://github.com/canonical/mysql-router-k8s-operator/pull/51 --- lib/charms/mysql/v0/mysql.py | 4 ++-- src/relations/mysql_provider.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/charms/mysql/v0/mysql.py b/lib/charms/mysql/v0/mysql.py index f3593fb64..b7752e418 100644 --- a/lib/charms/mysql/v0/mysql.py +++ b/lib/charms/mysql/v0/mysql.py @@ -91,7 +91,7 @@ def wait_until_mysql_connection(self) -> None: # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 21 +LIBPATCH = 22 UNIT_TEARDOWN_LOCKNAME = "unit-teardown" @@ -1167,7 +1167,7 @@ def grant_privileges_to_user( raise MySQLGrantPrivilegesToUserError("Failed to get cluster primary address") grant_privileges_commands = ( - f"shell.connect('{self.cluster_admin_user}:{self.cluster_admin_password}@{cluster_primary}')", + f"shell.connect('{self.server_config_user}:{self.server_config_password}@{cluster_primary}')", f"session.run_sql(\"GRANT {', '.join(privileges)} ON *.* TO '{username}'@'{hostname}'{' WITH GRANT OPTION' if with_grant_option else ''}\")", ) diff --git a/src/relations/mysql_provider.py b/src/relations/mysql_provider.py index 00201c066..4e0213b77 100644 --- a/src/relations/mysql_provider.py +++ b/src/relations/mysql_provider.py @@ -167,7 +167,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None: if "mysqlrouter" in extra_user_roles: self.charm._mysql.upgrade_user_for_mysqlrouter(db_user, "%") self.charm._mysql.grant_privileges_to_user( - db_user, "%", ["CREATE USER"], with_grant_option=True + db_user, "%", ["ALL PRIVILEGES"], with_grant_option=True ) logger.info(f"Created user for app {remote_app}")