From f06f5a81d82287fcb4486d733bf90a7e33317f79 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Mon, 18 Nov 2024 13:56:54 -0300 Subject: [PATCH 1/4] Add parameter to not create additional users on cloudstack-setup-databases --- setup/bindir/cloud-setup-databases.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 7920bb5eff6e..76c650173d62 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -72,6 +72,7 @@ class DBDeployer(object): magicString = 'This_is_a_magic_string_i_think_no_one_will_duplicate' tmpMysqlFile = os.path.join(os.path.expanduser('~/'), 'cloudstackmysql.tmp.sql') mysqlBinPath = None + skipUsersAutoCreation = False def preRun(self): def backUpDbDotProperties(): @@ -219,6 +220,19 @@ for full help ""), ) + queriesToSkip = ( + "CREATE USER cloud@`localhost` identified by 'cloud';", + "CREATE USER cloud@`%` identified by 'cloud';", + "GRANT ALL ON cloud.* to cloud@`localhost`;", + "GRANT ALL ON cloud.* to cloud@`%`;", + "GRANT process ON *.* TO cloud@`localhost`;", + "GRANT process ON *.* TO cloud@`%`;", + "GRANT ALL ON cloud_usage.* to cloud@`localhost`;", + "GRANT ALL ON cloud_usage.* to cloud@`%`;", + "GRANT process ON *.* TO cloud@`localhost`;", + "GRANT process ON *.* TO cloud@`%`;", + ) + scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"] if self.options.schemaonly: scriptsToRun = ["create-schema", "create-schema-premium"] @@ -227,6 +241,8 @@ for full help p = os.path.join(self.dbFilesPath,"%s.sql"%f) if not os.path.exists(p): continue text = open(p).read() + if self.options.skipUsersAutoCreation: + for t in queriesToSkip: text = text.replace(t,"") for t, r in replacements: text = text.replace(t,r) self.info("Applying %s"%p) self.runMysql(text, p, self.rootuser != None) @@ -470,6 +486,8 @@ for example: self.encryptionJarPath = self.options.encryptionJarPath if self.options.mysqlbinpath: self.mysqlBinPath = self.options.mysqlbinpath + if self.options.skipUsersAutoCreation: + self.skipUsersAutoCreation = self.options.skipUsersAutoCreation if self.options.encryptorVersion: self.encryptorVersion = "--encryptorversion %s" % self.options.encryptorVersion @@ -610,6 +628,9 @@ for example: self.parser.add_option("-g", "--encryptor-version", action="store", dest="encryptorVersion", default="V2", help="The encryptor version to be used to encrypt the values in db.properties") self.parser.add_option("-b", "--mysql-bin-path", action="store", dest="mysqlbinpath", help="The mysql installed bin path") + self.parser.add_option("-u", "--skip-users-auto-creation", action="store_true", dest="skipUsersAutoCreation", + help="Indicates whether to skip the auto-creation of users in the database. Use this flag when your database users " \ + "are already configured and you only want to populate the db.properties file.") (self.options, self.args) = self.parser.parse_args() parseCasualCredit() parseOtherOptions() From ce658e5058584c8d5d75b09e951369bd3a28d219 Mon Sep 17 00:00:00 2001 From: Lucas Martins <56271185+lucas-a-martins@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:52:40 -0300 Subject: [PATCH 2/4] apply dahn's suggestion Co-authored-by: dahn --- setup/bindir/cloud-setup-databases.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 76c650173d62..48285695bea3 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -225,8 +225,6 @@ for full help "CREATE USER cloud@`%` identified by 'cloud';", "GRANT ALL ON cloud.* to cloud@`localhost`;", "GRANT ALL ON cloud.* to cloud@`%`;", - "GRANT process ON *.* TO cloud@`localhost`;", - "GRANT process ON *.* TO cloud@`%`;", "GRANT ALL ON cloud_usage.* to cloud@`localhost`;", "GRANT ALL ON cloud_usage.* to cloud@`%`;", "GRANT process ON *.* TO cloud@`localhost`;", From 42c6e7ad8e16a6feadc864ad71134958ae12a702 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Thu, 13 Feb 2025 12:35:13 -0300 Subject: [PATCH 3/4] Fix --skip-users-auto-creation flag --- setup/bindir/cloud-setup-databases.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 48285695bea3..1392ad95e1e4 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -229,6 +229,10 @@ for full help "GRANT ALL ON cloud_usage.* to cloud@`%`;", "GRANT process ON *.* TO cloud@`localhost`;", "GRANT process ON *.* TO cloud@`%`;", + "IF foo > 0 THEN", + "DROP USER 'cloud'@'localhost' ;", + "END IF;", + "DROP USER 'cloud'@'%' ;" ) scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"] From 09ec0a9a5d9f6bb7d5d92cae138de995b1b9d129 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Thu, 6 Mar 2025 14:58:19 -0300 Subject: [PATCH 4/4] Change to not remove IF and END IF --- setup/bindir/cloud-setup-databases.in | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in index 1392ad95e1e4..320054939e5d 100755 --- a/setup/bindir/cloud-setup-databases.in +++ b/setup/bindir/cloud-setup-databases.in @@ -221,18 +221,16 @@ for full help ) queriesToSkip = ( - "CREATE USER cloud@`localhost` identified by 'cloud';", - "CREATE USER cloud@`%` identified by 'cloud';", - "GRANT ALL ON cloud.* to cloud@`localhost`;", - "GRANT ALL ON cloud.* to cloud@`%`;", - "GRANT ALL ON cloud_usage.* to cloud@`localhost`;", - "GRANT ALL ON cloud_usage.* to cloud@`%`;", - "GRANT process ON *.* TO cloud@`localhost`;", - "GRANT process ON *.* TO cloud@`%`;", - "IF foo > 0 THEN", - "DROP USER 'cloud'@'localhost' ;", - "END IF;", - "DROP USER 'cloud'@'%' ;" + ("CREATE USER cloud@`localhost` identified by 'cloud';", ""), + ("CREATE USER cloud@`%` identified by 'cloud';", ""), + ("GRANT ALL ON cloud.* to cloud@`localhost`;", ""), + ("GRANT ALL ON cloud.* to cloud@`%`;", ""), + ("GRANT ALL ON cloud_usage.* to cloud@`localhost`;", ""), + ("GRANT ALL ON cloud_usage.* to cloud@`%`;", ""), + ("GRANT process ON *.* TO cloud@`localhost`;", ""), + ("GRANT process ON *.* TO cloud@`%`;", ""), + ("DROP USER 'cloud'@'localhost' ;", "DO NULL;"), + ("DROP USER 'cloud'@'%' ;", "DO NULL;") ) scriptsToRun = ["create-database","create-schema", "create-database-premium","create-schema-premium"] @@ -244,7 +242,7 @@ for full help if not os.path.exists(p): continue text = open(p).read() if self.options.skipUsersAutoCreation: - for t in queriesToSkip: text = text.replace(t,"") + for t, r in queriesToSkip: text = text.replace(t,r) for t, r in replacements: text = text.replace(t,r) self.info("Applying %s"%p) self.runMysql(text, p, self.rootuser != None)