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
Content controlled file access (#83156)
Nathan Voxlandf6e203b8d3e9
diff --git a/modules/drivers/databricks/src/metabase/driver/databricks.clj b/modules/drivers/databricks/src/metabase/driver/databricks.cljindex 8b79804e623..d110231532b 100644--- a/modules/drivers/databricks/src/metabase/driver/databricks.clj+++ b/modules/drivers/databricks/src/metabase/driver/databricks.clj@@ -79,7 +79,8 @@[_driver details](sql-jdbc/reject-dangerous-additional-options! details)(when-let [opts (not-empty (:additional-options details))]- (when (re-find #"(?i)VolumeOperationAllowedLocalPaths" opts)+ ;; `StagingAllowedLocalPaths` is the older spelling of the same setting, and the client still honors it+ (when (re-find #"(?i)VolumeOperationAllowedLocalPaths|StagingAllowedLocalPaths" opts)(throw (Exception. "Potentially dangerous keys in connection details")))))(defn- catalog-present?diff --git a/modules/drivers/databricks/test/metabase/driver/databricks_test.clj b/modules/drivers/databricks/test/metabase/driver/databricks_test.cljindex 37f48f4a62b..59ab5b1b2f1 100644--- a/modules/drivers/databricks/test/metabase/driver/databricks_test.clj+++ b/modules/drivers/databricks/test/metabase/driver/databricks_test.clj@@ -532,6 +532,15 @@(is (thrown-with-msg? Exception #"Potentially dangerous keys"(driver/validate-db-details! :databricks details)))))))+(deftest ^:parallel staging-allowed-local-paths-is-rejected-test+ (testing "the legacy spelling of `VolumeOperationAllowedLocalPaths` enables the same local file reads and writes"+ (doseq [opts ["StagingAllowedLocalPaths=/"+ "stagingallowedlocalpaths=/tmp"+ "UseNativeQuery=1;StagingAllowedLocalPaths=/etc"]]+ (testing opts+ (is (thrown-with-msg? Exception #"Potentially dangerous keys"+ (driver/validate-db-details! :databricks {:additional-options opts})))))))+(deftest can-connect-using-m2m-test(mt/test-driver:databricksdiff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.cljindex f7e830509d7..e9679867f2b 100644--- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj+++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj@@ -484,6 +484,10 @@;; 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)+ ;; `PUT` and `GET` move files between the Metabase host and a stage. Details are merged into the spec above, and+ ;; the client reads property names case-insensitively, so a detail key such as `Enableputget` would otherwise+ ;; sit beside ours and, depending on hash order, win.+ (as-> spec (m/remove-keys #(= "enableputget" (u/lower-case-en (str/trim (name %)))) spec))(assoc :enablePutGet "false"))))(mu/defn- database-type->base-typediff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.cljindex 713824988c5..2f9bc524ecc 100644--- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj+++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj@@ -61,6 +61,7 @@(java.io StringWriter)(java.security KeyFactory)(java.security.spec PKCS8EncodedKeySpec)+ (net.snowflake.client.internal.jdbc SnowflakeConnectString)(org.bouncycastle.openssl PKCS8Generator)(org.bouncycastle.openssl.jcajce JcaPEMWriter JcaPKCS8Generator JceOpenSSLPKCS8EncryptorBuilder)))@@ -172,6 +173,17 @@(is (= "\"alma\"" (#'driver.snowflake/quote-name "alma")))(is (= "\"Al\"\"aba\"\"Ma\"" (#'driver.snowflake/quote-name "Al\"aba\"Ma"))))+(defn- put-get-as-the-client-reads-it+ "The `enablePutGet` value the Snowflake client resolves `spec` to, asking its own parser. `clojure.java.jdbc` hands+ it the URL built from `:subname` and every other spec key as a connection property."+ [spec]+ (let [url (str "jdbc:" (:subprotocol spec) ":" (:subname spec))+ props (java.util.Properties.)]+ (doseq [[k v] (dissoc spec :classname :subprotocol :subname)+ :when (some? v)]+ (.setProperty props (name k) (str v)))+ (get (.getParameters (SnowflakeConnectString/parse url props)) "ENABLEPUTGET")))+(deftest ^:parallel connection-details->spec-test(let [details {:role nil:warehouse "COMPUTE_WH"@@ -216,6 +228,11 @@(let [spec (sql-jdbc.conn/connection-details->spec :snowflake (assoc details :additional-options opts))](is (= "false" (:enablePutGet spec)))(is (not (re-find #"(?i)enablePutGet" (str (:subname spec))))))))+ (testing "...including through a detail key in another casing, which the client would read in place of ours"+ (doseq [k ["Enableputget" "eNableputget" "ENablePutGet" "enableputget" "ENABLEPUTGET" " enablePutGet "]]+ (testing (pr-str k)+ (is (= "false" (put-get-as-the-client-reads-it+ (sql-jdbc.conn/connection-details->spec :snowflake (assoc details (keyword k) "true"))))))))(testing "additional options wins over top-level schema";; https://github.com/metabase/metabase/issues/65493(let [details (assoc details :schema "BAD" :additional-options "schema=GOOD")diff --git a/modules/drivers/vertica/src/metabase/driver/vertica.clj b/modules/drivers/vertica/src/metabase/driver/vertica.cljindex 1fa73333ecb..597e2f4b7c6 100644--- a/modules/drivers/vertica/src/metabase/driver/vertica.clj+++ b/modules/drivers/vertica/src/metabase/driver/vertica.clj@@ -1,6 +1,8 @@(ns metabase.driver.vertica+ (:refer-clojure :exclude [not-empty])(:require[clojure.java.jdbc :as jdbc]+ [clojure.string :as str][honey.sql :as sql][java-time.api :as t][metabase.driver :as driver]@@ -20,8 +22,10 @@[metabase.util :as u][metabase.util.date-2 :as u.date][metabase.util.honey-sql-2 :as h2x]- [metabase.util.log :as log])+ [metabase.util.log :as log]+ [metabase.util.performance :refer [not-empty]])(:import+ (java.net URLDecoder)(java.sql ResultSet ResultSetMetaData Types)))(set! *warn-on-reflection* true)@@ -79,6 +83,18 @@(keyword "Long Varchar") :type/Text(keyword "Long Varbinary") :type/*} database-type))+(defn- copy-local-parameter?+ "Whether a connection parameter name, as a user may have written it, is the client's `disablecopylocal`. The client+ reads names case-insensitively; decoded and trimmed too, so no spelling of it survives to compete with ours."+ [parameter-name]+ (let [s (str/trim (str parameter-name))]+ (str/includes? (u/lower-case-en (try (URLDecoder/decode s "UTF-8") (catch Exception _ s))) "copylocal")))++(defn- remove-copy-local-option [additional-options]+ (when-not (str/blank? additional-options)+ (not-empty (str/join "&" (remove #(copy-local-parameter? (first (str/split % #"=" 2)))+ (str/split additional-options #"&"))))))+(defmethod sql-jdbc.conn/connection-details->spec :vertica[_ {:keys [host port db dbname]:or {host "localhost", port 5433, db ""}@@ -86,8 +102,14 @@(-> (merge {:classname "com.vertica.jdbc.Driver":subprotocol "vertica":subname (str "//" host ":" port "/" (or dbname db))}- (dissoc details :host :port :dbname :db :ssl))- (sql-jdbc.common/handle-additional-options details)))+ ;; detail keys reach the client as connection properties+ (into {}+ (remove (comp copy-local-parameter? name key))+ (dissoc details :host :port :dbname :db :ssl)))+ (sql-jdbc.common/handle-additional-options (update details :additional-options remove-copy-local-option))+ ;; `COPY ... FROM LOCAL` reads files on the Metabase host and loads them into the warehouse, where a native query+ ;; can read them back. Metabase never uses it, so it is disabled for every connection whatever the details say.+ (assoc :disablecopylocal "true")))(defmethod sql.qp/current-datetime-honeysql-form :vertica[_driver]diff --git a/modules/drivers/vertica/test/metabase/driver/vertica_test.clj b/modules/drivers/vertica/test/metabase/driver/vertica_test.cljindex 4b05782f6e5..a835ef2c44e 100644--- a/modules/drivers/vertica/test/metabase/driver/vertica_test.clj+++ b/modules/drivers/vertica/test/metabase/driver/vertica_test.clj@@ -18,14 +18,37 @@(deftest ^:parallel additional-connection-string-options-test(testing "Make sure you can add additional connection string options (#6651)"- (is (= {:classname "com.vertica.jdbc.Driver"- :subprotocol "vertica"- :subname "//localhost:5433/birds-near-me?ConnectionLoadBalance=1"}+ (is (= {:classname "com.vertica.jdbc.Driver"+ :subprotocol "vertica"+ :subname "//localhost:5433/birds-near-me?ConnectionLoadBalance=1"+ :disablecopylocal "true"}(sql-jdbc.conn/connection-details->spec :vertica {:host "localhost":port 5433:db "birds-near-me":additional-options "ConnectionLoadBalance=1"})))))+(deftest ^:parallel copy-local-is-disabled-test+ (testing "`COPY ... FROM LOCAL` reads files on the Metabase host into the warehouse, so it is always disabled"+ ;; the connection details pass detail keys through as connection properties and `:additional-options` into the+ ;; URL, and the client reads property names case-insensitively, so a user's value in any casing, either way in, is+ ;; dropped rather than left to compete with ours+ (doseq [details [{}+ {:additional-options "DisableCopyLocal=false"}+ {:additional-options "ConnectionLoadBalance=1&disablecopylocal=0"}+ {:additional-options " DISABLECOPYLOCAL =false&ConnectionLoadBalance=1"}+ {:DisableCopyLocal false}+ {:disablecopylocal "false"}+ {:DISABLECOPYLOCAL "0"}]]+ (testing (pr-str details)+ (let [spec (sql-jdbc.conn/connection-details->spec :vertica (merge {:host "localhost" :port 5433 :db "birds"}+ details))]+ (is (= "true" (:disablecopylocal spec)))+ (is (= [:disablecopylocal] (filterv #(re-find #"(?i)copylocal" (name %)) (keys spec))))+ (is (not (re-find #"(?i)copylocal" (:subname spec))))+ (testing "other options are kept"+ (when (re-find #"ConnectionLoadBalance" (str (:additional-options details)))+ (is (re-find #"ConnectionLoadBalance=1" (:subname spec))))))))))+(defn- compile-query [query](-> (qp.compile/compile query)(update :query #(str/split-lines (driver/prettify-native-form :vertica %)))))diff --git a/modules/drivers/vertica/test/metabase/test/data/vertica.clj b/modules/drivers/vertica/test/metabase/test/data/vertica.cljindex f6d33f3563d..49df58e7db9 100644--- a/modules/drivers/vertica/test/metabase/test/data/vertica.clj+++ b/modules/drivers/vertica/test/metabase/test/data/vertica.clj@@ -20,6 +20,7 @@[metabase.test.data.sql-jdbc :as sql-jdbc.tx][metabase.test.data.sql-jdbc.execute :as execute][metabase.test.data.sql-jdbc.load-data :as load-data]+ [metabase.test.data.sql-jdbc.spec :as spec][metabase.util :as u][metabase.util.files :as u.files][metabase.util.malli :as mu]@@ -89,6 +90,12 @@[& args](apply sql.tx/drop-table-if-exists-cascade-sql args))+(defmethod spec/dbdef->spec :vertica+ [driver context dbdef]+ ;; the driver always disables `COPY ... FROM LOCAL`; the test loader needs it+ (assoc (sql-jdbc.conn/connection-details->spec driver (tx/dbdef->connection-details driver context dbdef))+ :disablecopylocal "false"))+(defn- dbspec [](sql-jdbc.conn/connection-details->spec :vertica @db-connection-details))