Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Disable snowflake WIF without token in cloud (#85631)

metamben147dffcf2bb2
diff --git a/modules/drivers/snowflake/resources/metabase/snowflake/metabase-plugin.yaml b/modules/drivers/snowflake/resources/metabase/snowflake/metabase-plugin.yaml
index 19db119d934..eb7168167e5 100644
--- a/modules/drivers/snowflake/resources/metabase/snowflake/metabase-plugin.yaml
+++ b/modules/drivers/snowflake/resources/metabase/snowflake/metabase-plugin.yaml
@@ -38,9 +38,9 @@ driver:
required: true
options:
- {name: "OpenID Connect (JWT)", value: "OIDC"}
- - {name: "AWS", value: "AWS"}
- - {name: "Azure", value: "AZURE"}
- - {name: "Google Cloud", value: "GCP"}
+ - {name: "AWS", value: "AWS", hidden-when-hosted: true}
+ - {name: "Azure", value: "AZURE", hidden-when-hosted: true}
+ - {name: "Google Cloud", value: "GCP", hidden-when-hosted: true}
visible-if:
auth-mode: wif
- name: wif-token
diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj
index 15b929f446c..10edd066d9b 100644
--- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj
+++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj
@@ -254,15 +254,29 @@
(some-> (json/decode+kw json-str) :exp long (* 1000)))
(catch Throwable _ nil)))
+(def ^:private hosted-allowed-wif-providers
+ ;; OIDC is the only WIF mode on Metabase Cloud where the identity is admin-supplied (a token or a
+ ;; token file). Every other provider — AWS/AZURE/GCP today, and anything the Snowflake JDBC
+ ;; driver adds later — pulls an attestation from the host's cloud metadata and would silently
+ ;; authenticate as the Metabase host. A blank provider also falls through to auto-detect, which
+ ;; walks the same ambient paths. Whitelisting here fails closed on both.
+ #{"OIDC"})
+
(defn- resolve-wif-credentials
- "Translate WIF details into Snowflake JDBC properties. For OIDC we always pass the token as a
- plain `:token` string; the Snowflake JDBC driver only honors `token_file_path` under the special
- `jdbc:snowflake:auto` URL, which we don't use. `:wif-token-file-path` wins over an inline
- `:wif-token` — the file is slurped here into the pool spec. When the token carries an `exp`
- claim we set `:password-expiry-timestamp` so the pool self-invalidates on expiry and rebuilds
- against a rotated file or a fresh in-process mint."
+ "Return `details` with Snowflake JDBC WIF properties replacing the Metabase-side auth keys."
[{:keys [wif-provider wif-token wif-token-file-path] :as details}]
(let [provider (some-> wif-provider u/upper-case-en)
+ _ (when (and (driver-api/is-hosted?)
+ (not (contains? hosted-allowed-wif-providers provider)))
+ (throw (ex-info (if (str/blank? provider)
+ (tru (str "A workload-identity provider is required on Metabase Cloud. "
+ "Use OIDC with an explicit token."))
+ (tru (str "Workload identity federation with the {0} provider is not available "
+ "on Metabase Cloud. Use OIDC with an explicit token.")
+ provider))
+ {:wif-provider provider})))
+ ;; Pass OIDC tokens inline; the Snowflake JDBC driver only reads `token_file_path` under
+ ;; the special `jdbc:snowflake:auto` URL, which we don't use.
token (when (= "OIDC" provider)
(cond
(not (str/blank? wif-token-file-path))
@@ -271,6 +285,8 @@
(not (str/blank? wif-token))
wif-token))
+ ;; `:password-expiry-timestamp` lets the connection pool self-invalidate on expiry and
+ ;; rebuild against a rotated file or a fresh in-process mint.
expiry-ms (some-> token jwt-expiry-ms)
wif-spec (cond-> {:authenticator "WORKLOAD_IDENTITY"
:workloadIdentityProvider provider}
diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
index a37496c71cb..d93f0a7155f 100644
--- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
+++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
@@ -32,6 +32,7 @@
[metabase.lib.test-metadata :as meta]
[metabase.lib.test-util :as lib.tu]
[metabase.lib.test-util.notebook-helpers :as notebook-helpers]
+ [metabase.premium-features.core :as premium-features]
[metabase.query-processor.compile :as qp.compile]
^{:clj-kondo/ignore [:deprecated-namespace]} [metabase.query-processor.store :as qp.store]
[metabase.query-processor.test :as qp]
@@ -336,17 +337,70 @@
:wif-token (fake-jwt {:sub "s"})))]
(is (not (contains? spec :password-expiry-timestamp))))))
-(deftest ^:parallel connection-details->spec-wif-cloud-providers-test
- (testing "WIF AWS/AZURE/GCP set no client-side credential fields"
- (doseq [provider ["AWS" "AZURE" "GCP"]]
- (testing provider
- (let [spec (sql-jdbc.conn/connection-details->spec
- :snowflake
- (assoc wif-base-details :wif-provider provider))]
- (is (= "WORKLOAD_IDENTITY" (:authenticator spec)))
- (is (= provider (:workloadIdentityProvider spec)))
- (is (not (contains? spec :token)))
- (is (not (contains? spec :token_file_path))))))))
+(deftest connection-details->spec-wif-cloud-providers-test
+ (testing "WIF AWS/AZURE/GCP set no client-side credential fields (self-hosted only -- Metabase Cloud rejects these)"
+ (mt/with-dynamic-fn-redefs [premium-features/is-hosted? (constantly false)]
+ (doseq [provider ["AWS" "AZURE" "GCP"]]
+ (testing provider
+ (let [spec (sql-jdbc.conn/connection-details->spec
+ :snowflake
+ (assoc wif-base-details :wif-provider provider))]
+ (is (= "WORKLOAD_IDENTITY" (:authenticator spec)))
+ (is (= provider (:workloadIdentityProvider spec)))
+ (is (not (contains? spec :token)))
+ (is (not (contains? spec :token_file_path)))))))))
+
+(deftest connection-details->spec-wif-hosted-rejects-ambient-providers-test
+ (testing "On Metabase Cloud, ambnient WIF providers (e.g., AWS, AZURE, GCP) are not allowed."
+ (mt/with-dynamic-fn-redefs [premium-features/is-hosted? (constantly true)]
+ (doseq [provider ["AWS" "AZURE" "GCP"]]
+ (testing provider
+ (is (thrown-with-msg?
+ clojure.lang.ExceptionInfo
+ #"not available on Metabase Cloud"
+ (sql-jdbc.conn/connection-details->spec
+ :snowflake
+ (assoc wif-base-details :wif-provider provider))))))))
+ (testing "WIF OIDC with an explicit token is still allowed on Metabase Cloud."
+ (mt/with-dynamic-fn-redefs [premium-features/is-hosted? (constantly true)]
+ (let [spec (sql-jdbc.conn/connection-details->spec
+ :snowflake
+ (assoc wif-base-details :wif-provider "OIDC" :wif-token "eyJhbGciOi.jwt.sig"))]
+ (is (= "WORKLOAD_IDENTITY" (:authenticator spec)))
+ (is (= "OIDC" (:workloadIdentityProvider spec)))
+ (is (= "eyJhbGciOi.jwt.sig" (:token spec))))))
+ (testing (str "A missing wif-provider on Metabase Cloud is rejected too to prevent the Snowflake JDBC driver "
+ "from using ambient providers.")
+ (mt/with-dynamic-fn-redefs [premium-features/is-hosted? (constantly true)]
+ (doseq [[label details] [["nil" (dissoc wif-base-details :wif-provider)]
+ ["blank" (assoc wif-base-details :wif-provider "")]]]
+ (testing label
+ (is (thrown-with-msg?
+ clojure.lang.ExceptionInfo
+ #"required on Metabase Cloud"
+ (sql-jdbc.conn/connection-details->spec :snowflake details)))))))
+ (testing "Off Metabase Cloud, ambient WIF providers continue to work."
+ (mt/with-dynamic-fn-redefs [premium-features/is-hosted? (constantly false)]
+ (doseq [provider ["AWS" "AZURE" "GCP"]]
+ (testing provider
+ (let [spec (sql-jdbc.conn/connection-details->spec
+ :snowflake
+ (assoc wif-base-details :wif-provider provider))]
+ (is (= "WORKLOAD_IDENTITY" (:authenticator spec)))
+ (is (= provider (:workloadIdentityProvider spec)))))))))
+
+(deftest wif-provider-options-hidden-when-hosted-test
+ (let [wif-provider-values
+ (fn [] (->> (:details-fields (:snowflake (driver.u/available-drivers-info)))
+ (m/find-first #(= "wif-provider" (:name %)))
+ :options
+ (mapv :value)))]
+ (testing "On Metabase Cloud, the ambient options are stripped from the wif-provider select."
+ (mt/with-premium-features #{:hosting}
+ (is (= ["OIDC"] (wif-provider-values)))))
+ (testing "Off Metabase Cloud, every provider is offered."
+ (mt/with-premium-features #{}
+ (is (= ["OIDC" "AWS" "AZURE" "GCP"] (wif-provider-values)))))))
(deftest ^:parallel connection-details->spec-wif-strips-legacy-creds-test
(testing "under WIF, stray password and private-key fields do not leak into the JDBC spec"
diff --git a/src/metabase/driver/util.clj b/src/metabase/driver/util.clj
index d1c24dd17f1..f27fff6350c 100644
--- a/src/metabase/driver/util.clj
+++ b/src/metabase/driver/util.clj
@@ -713,6 +713,19 @@
[conn-prop]))
+(defn- strip-hidden-when-hosted
+ "Return `prop` with any option tagged `:hidden-when-hosted` removed. Recurses into group fields."
+ [prop]
+ (cond
+ (= :group (:type prop))
+ (update prop :fields #(mapv strip-hidden-when-hosted %))
+
+ (seq (:options prop))
+ (update prop :options #(filterv (complement :hidden-when-hosted) %))
+
+ :else
+ prop))
+
(defn connection-props-server->client
"Transforms `conn-props` for the given `driver` from their server side definition into a client side definition.
@@ -724,7 +737,8 @@
if one was provided."
{:added "0.42.0"}
[driver conn-props]
- (let [final-props (into [] (mapcat process-connection-prop) conn-props)
+ (let [hosted-filter (if (premium-features/is-hosted?) strip-hidden-when-hosted identity)
+ final-props (into [] (comp (mapcat process-connection-prop) (map hosted-filter)) conn-props)
;; Build complete props-by-name map including nested fields from groups
props-by-name (collect-all-props-by-name final-props)]
;; now, traverse the visible-if-edges and update all visible-if entries with their full set of "transitive"
diff --git a/test/metabase/driver/util_test.clj b/test/metabase/driver/util_test.clj
index 13298f3286e..e84c3bc1a93 100644
--- a/test/metabase/driver/util_test.clj
+++ b/test/metabase/driver/util_test.clj
@@ -183,6 +183,29 @@
nil
[{:name "test", :type :info}])))))))
+(deftest connection-props-server->client-hidden-when-hosted-test
+ (let [prop {:name "auth-mode"
+ :type "select"
+ :options [{:name "Local" :value "local"}
+ {:name "Ambient" :value "ambient" :hidden-when-hosted true}]}
+ strip #(-> (driver.u/connection-props-server->client nil [prop]) first :options (->> (mapv :value)))]
+ (testing "On Metabase Cloud, options tagged :hidden-when-hosted are stripped from the client payload."
+ (mt/with-premium-features #{:hosting}
+ (is (= ["local"] (strip)))))
+ (testing "Off Metabase Cloud, every option passes through unchanged."
+ (mt/with-premium-features #{}
+ (is (= ["local" "ambient"] (strip))))))
+ (testing "Group fields recurse: a tagged option inside a nested :group field is stripped on hosted."
+ (let [prop {:type :group
+ :fields [{:name "nested"
+ :type "select"
+ :options [{:name "ok" :value "ok"}
+ {:name "nope" :value "nope" :hidden-when-hosted true}]}]}]
+ (mt/with-premium-features #{:hosting}
+ (is (= ["ok"]
+ (-> (driver.u/connection-props-server->client nil [prop])
+ first :fields first :options (->> (mapv :value)))))))))
+
(deftest ^:parallel connection-props-server->client-schema-filters-test
(testing "connection-props-server->client works as expected for the schema-filters type"
(is (= [{:name "first-prop"}