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
Ensure Snowflake driver blocks GET and PUT commands. (#73578)
technomancy8da5157bef31
diff --git a/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.clj b/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.cljindex 58b4e3882ad..14d4a04d423 100644--- a/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.clj+++ b/enterprise/backend/test/metabase_enterprise/impersonation/driver_test.clj@@ -709,7 +709,7 @@;; (`LIMITED.ROLE` in CI Snowflake has no data access)(is (thrown-with-msg?clojure.lang.ExceptionInfo- #"Cannot perform SELECT. This session does not have a current database. Call 'USE DATABASE', or use a qualified name."+ #"(?s)SQL compilation error.*operation cannot be performed"(mt/run-mbql-query venues{:aggregation [[:count]]})))diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.cljindex 1cf0882ee8d..27fec76e226 100644--- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj+++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj@@ -1,6 +1,6 @@(ns metabase.driver.snowflake"Snowflake Driver."- (:refer-clojure :exclude [select-keys not-empty mapv])+ (:refer-clojure :exclude [select-keys empty? not-empty mapv])(:require[buddy.core.codecs :as codecs][clojure.java.jdbc :as jdbc]@@ -36,7 +36,7 @@[metabase.util.json :as json][metabase.util.log :as log][metabase.util.malli :as mu]- [metabase.util.performance :refer [mapv not-empty select-keys]]+ [metabase.util.performance :refer [mapv empty? not-empty select-keys]][ring.util.codec :as codec])(:import(java.io File)@@ -223,6 +223,13 @@(and (not use-password) password-details)(conj password-details)))))+(defn- set-put-get [additional-options]+ (cond (empty? additional-options) "enablePutGet=false"+ (re-find #"(?i)enablePutGet=" additional-options) (str/replace additional-options+ #"enablePutGet=[^&]+"+ "enablePutGet=false")+ :else (str additional-options "&enablePutGet=false")))+(defmethod sql-jdbc.conn/connection-details->spec :snowflake[_ {:keys [account additional-options host use-hostname password use-password], :as details}](when (get "week_start" (sql-jdbc.common/additional-options->map additional-options :url))@@ -274,7 +281,8 @@(m/update-existing :schema upcase-not-nil)resolve-private-key(dissoc :host :port :timezone)))- (sql-jdbc.common/handle-additional-options details)+ (sql-jdbc.common/handle-additional-options (update details+ :additional-options set-put-get));; Role is not respected when used as connection property if connection string is present with private key;; file. Hence it is moved to connection url. https://github.com/metabase/metabase/issues/43600(maybe-add-role-to-spec-url details))))diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.cljindex 399b92f6ff0..9184f531a41 100644--- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj+++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj@@ -166,15 +166,19 @@(assoc :host alternative-host)(assoc :use-hostname use-hostname))](sql-jdbc.conn/connection-details->spec :snowflake details))))- true nil "//ls10467.us-east-2.aws.snowflakecomputing.com/"- true "" "//ls10467.us-east-2.aws.snowflakecomputing.com/"- true " " "//ls10467.us-east-2.aws.snowflakecomputing.com/"- true "snowflake.example.com/" "//snowflake.example.com/"- true "snowflake.example.com" "//snowflake.example.com/"- false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/"- false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/"- false "snowflake.example.com/" "//ls10467.us-east-2.aws.snowflakecomputing.com/"- false "snowflake.example.com" "//ls10467.us-east-2.aws.snowflakecomputing.com/"))+ true nil "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"+ true "" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"+ true " " "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"+ true "snowflake.example.com/" "//snowflake.example.com/?enablePutGet=false"+ true "snowflake.example.com" "//snowflake.example.com/?enablePutGet=false"+ false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"+ false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"+ false "snowflake.example.com/" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"+ false "snowflake.example.com" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"))+ (testing "Unsafe options are removed"+ (let [details (assoc details :additional-options "enablePutGet=true")+ spec (sql-jdbc.conn/connection-details->spec :snowflake details)]+ (is (re-find #"enablePutGet=false" (:subname spec)))))(testing "Application parameter is set to identify Metabase connections"(is (= "Metabase_Metabase"(:application (sql-jdbc.conn/connection-details->spec :snowflake details)))))))