Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(snowflake): treat encrypted key-pair passphrase failure as non-retryable (#70385)

Tom Owersb1d8665873a5
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
index 6ba559ed0c60..8c6154cfb465 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/source.py
@@ -42,6 +42,15 @@ _MALFORMED_PEM_MESSAGE = (
"then {action}"
)
+# `load_pem_private_key` rejects an encrypted key-pair private key with a wrong passphrase
+# (ValueError "Incorrect password, could not decrypt key") or no passphrase at all
+# (TypeError "Password was not given but private key is encrypted"). Same `{action}` placeholder
+# convention as `_MALFORMED_PEM_MESSAGE`.
+_WRONG_KEY_PASSPHRASE_MESSAGE = (
+ "Your Snowflake key-pair private key is encrypted, but the passphrase is missing or incorrect. "
+ "Enter the passphrase that decrypts your private key (or paste an unencrypted key), then {action}"
+)
+
SnowflakeErrors = {
"No active warehouse selected in the current session": "No active warehouse is available for this connection. Check that the configured warehouse exists, is running, and that the connecting role has USAGE on it, then try again.",
"or attempt to login with another role": "Role specified doesn't exist or is not authorized",
@@ -257,6 +266,13 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):
# See `_MALFORMED_PEM_MESSAGE`: the key-pair private key can't be parsed, so retrying can
# never succeed until the user pastes a valid PEM key.
"Unable to load PEM file": _MALFORMED_PEM_MESSAGE.format(action="resync."),
+ # See `_WRONG_KEY_PASSPHRASE_MESSAGE`: the encrypted key-pair private key can't be decrypted
+ # because the passphrase is wrong (ValueError) or was never provided (TypeError), so retrying
+ # can never succeed until the user fixes it.
+ "Incorrect password, could not decrypt key": _WRONG_KEY_PASSPHRASE_MESSAGE.format(action="resync."),
+ "Password was not given but private key is encrypted": _WRONG_KEY_PASSPHRASE_MESSAGE.format(
+ action="resync."
+ ),
# Snowflake error 002003 (SQLSTATE 42S02 for tables / 02000 for schemas): a table or
# schema the source syncs was dropped or renamed in Snowflake, or the role's grant on it
# was revoked, after the schema was discovered. The driver raises "<object> does not exist
@@ -311,11 +327,19 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):
capture_exception(e)
return False, "Could not connect to Snowflake. Please check all connection details are valid."
- except ValueError as e:
+ except (ValueError, TypeError) as e:
+ error_str = str(e)
# A malformed key-pair private key fails to parse in `load_pem_private_key` before we ever
# reach Snowflake — a user config error, not an unexpected failure worth capturing.
- if "Unable to load PEM file" in str(e):
+ if "Unable to load PEM file" in error_str:
return False, _MALFORMED_PEM_MESSAGE.format(action="try again.")
+ # An encrypted private key whose passphrase is wrong (ValueError) or was never provided
+ # (TypeError) — also a user config error.
+ if (
+ "Incorrect password, could not decrypt key" in error_str
+ or "Password was not given but private key is encrypted" in error_str
+ ):
+ return False, _WRONG_KEY_PASSPHRASE_MESSAGE.format(action="try again.")
capture_exception(e)
return False, "Could not connect to Snowflake. Please check all connection details are valid."
except Exception as e:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
index 76ba2c79d32f..f9554446baf3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
@@ -837,6 +837,20 @@ class TestSnowflakeSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Unparseable private-key error should be non-retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Wrong passphrase for an encrypted key (cryptography ValueError).
+ "Incorrect password, could not decrypt key",
+ # No passphrase given for an encrypted key (cryptography TypeError).
+ "Password was not given but private key is encrypted",
+ ],
+ )
+ def test_encrypted_key_passphrase_is_non_retryable(self, source, error_msg):
+ non_retryable = source.get_non_retryable_errors()
+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
+ assert is_non_retryable, f"Encrypted-key passphrase error should be non-retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[
@@ -872,6 +886,28 @@ class TestSnowflakeValidateCredentials:
assert message is not None and "PEM private key" in message
mock_capture.assert_not_called()
+ @pytest.mark.parametrize(
+ "error",
+ [
+ # Wrong passphrase for an encrypted key.
+ ValueError("Incorrect password, could not decrypt key"),
+ # No passphrase given for an encrypted key — a TypeError, not a ValueError.
+ TypeError("Password was not given but private key is encrypted"),
+ ],
+ )
+ def test_encrypted_key_passphrase_returns_friendly_message_without_capture(self, source, error):
+ with (
+ patch.object(source, "get_schemas", side_effect=error),
+ patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.snowflake.source.capture_exception"
+ ) as mock_capture,
+ ):
+ ok, message = source.validate_credentials(_make_config("keypair"), team_id=1)
+
+ assert ok is False
+ assert message is not None and "passphrase" in message
+ mock_capture.assert_not_called()
+
def test_mfa_enrollment_required_returns_friendly_message_without_capture(self, source):
# The account enforces MFA enrollment, so validate_credentials must surface an actionable
# message instead of capturing it as an unexpected failure.