The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Preserve MySQL role name case when expanding role grants (#77415)
Eric Normand368ed0381803
diff --git a/src/metabase/driver/mysql.clj b/src/metabase/driver/mysql.cljindex e1090c8070b..c04e33f869d 100644--- a/src/metabase/driver/mysql.clj+++ b/src/metabase/driver/mysql.clj@@ -1118,8 +1118,9 @@#"^GRANT (.+) TO ":>>(fn [[_ roles]]+ ;; role names are case-sensitive to MySQL, so they must be passed back to `SHOW GRANTS ... USING` verbatim{:type :roles- :roles (set (map u/lower-case-en (str/split roles #",")))})))+ :roles (set (str/split roles #","))})))(defn- privilege-grants-for-user"Returns a list of parsed privilege grants for a user, taking into account the roles that the user has.@@ -1135,7 +1136,7 @@privilege-grants :privileges} (group-by :type grants)](if (seq role-grants)(let [roles (:roles (first role-grants))- grants (map parse-grant (query (str "SHOW GRANTS FOR " user "USING " (str/join "," roles))))+ grants (map parse-grant (query (str "SHOW GRANTS FOR " user " USING " (str/join "," roles)))){privilege-grants :privileges} (group-by :type grants)]privilege-grants)privilege-grants)))diff --git a/test/metabase/driver/mysql_test.clj b/test/metabase/driver/mysql_test.cljindex 95e47ac1298..ec8cf920827 100644--- a/test/metabase/driver/mysql_test.clj+++ b/test/metabase/driver/mysql_test.clj@@ -837,6 +837,10 @@(is (= {:type :roles:roles #{"`example_role`@`%`" "`example_role_2`@`%`"}}(#'mysql/parse-grant "GRANT `example_role`@`%`,`example_role_2`@`%` TO 'metabase'@'localhost'")))+ (testing "role names keep their case (GHY-3835): MySQL 8 backticked role identifiers are case-sensitive, so lowercasing them makes the follow-up `SHOW GRANTS ... USING` fail with error 3530"+ (is (= {:type :roles+ :roles #{"`AWS_FOO_ROLE`@`%`"}}+ (#'mysql/parse-grant "GRANT `AWS_FOO_ROLE`@`%` TO `mb_case_test`@`%`"))))(is (nil? (#'mysql/parse-grant "GRANT PROXY ON 'metabase'@'localhost' TO 'metabase'@'localhost' WITH GRANT OPTION")))(testing "REVOKE grants (emitted under partial_revokes) are ignored rather than throwing"(is (nil? (#'mysql/parse-grant "REVOKE INSERT ON `test-data`.`foo` FROM 'metabase'@'localhost'")))