: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(snowflake): treat MFA-enrollment-required login as non-retryable (#66419)
Tom Owers4e238f9f19ad
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.pyindex ef06d5fae275..44dd659c963c 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@@ -40,6 +40,7 @@ SnowflakeErrors = {"Incorrect username or password was specified": "Incorrect username or password was specified","This session does not have a current database": "Database specified not found","Verify the account name is correct": "Can't find an account with the specified account ID",+ "Multi-factor authentication is required for this account": "This Snowflake account requires multi-factor authentication enrollment. Connect with a service user that uses key-pair authentication or is exempt from MFA.",}@@ -205,6 +206,11 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):# connector's login is rejected (250001 / 08001). An unattended sync can't answer a# Duo push, so retrying never succeeds — surface an actionable message instead."Duo Security authentication is denied": "Snowflake rejected the login because multi-factor authentication (Duo Security) is enforced for this user. Automated syncs can't answer an MFA prompt — connect with a service user that uses key-pair authentication or is exempt from MFA.",+ # Snowflake error 250001 (08001): the account requires MFA enrollment, so the login is+ # rejected until the user enrolls via Snowsight. An unattended sync can't complete MFA, so+ # retrying never succeeds. The codes and host in the message are volatile, so we match the+ # stable phrase.+ "Multi-factor authentication is required for this account": "Snowflake rejected the login because this account requires multi-factor authentication enrollment. Automated syncs can't complete MFA — connect with a service user that uses key-pair authentication or is exempt from MFA, then resync.","invalid credentials": "Snowflake authentication failed. Please check your username, password, and account details.","authentication failed": "Snowflake authentication failed. Please check your username, password, and account details.",# Snowflake error 250001 (08001): the supplied username or password is wrong, so thediff --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.pyindex b1c85d5e98e1..78ab87928630 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@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patchfrom cryptography.hazmat.backends import default_backendfrom cryptography.hazmat.primitives import serializationfrom cryptography.hazmat.primitives.asymmetric import rsa+from snowflake.connector.errors import DatabaseErrorfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceInputsfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.predicates import (@@ -641,6 +642,20 @@ class TestSnowflakeSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Duo-denied error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ "Multi-factor authentication is required for this account",+ # The real shape from production: codes + host vary, but the MFA substring is stable.+ "250001 (08001): None: Failed to connect to DB: acme-xy123.snowflakecomputing.com:443. "+ "Multi-factor authentication is required for this account. Log in to Snowsight to enroll.",+ ],+ )+ def test_mfa_enrollment_required_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"MFA-enrollment error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[@@ -807,6 +822,27 @@ class TestSnowflakeValidateCredentials:assert message is not None and "PEM private key" in messagemock_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.+ mfa_error = DatabaseError(+ msg="250001 (08001): None: Failed to connect to DB: acme-xy123.snowflakecomputing.com:443. "+ "Multi-factor authentication is required for this account. Log in to Snowsight to enroll.",+ errno=250001,+ sqlstate="08001",+ )+ with (+ patch.object(source, "get_schemas", side_effect=mfa_error),+ patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.snowflake.source.capture_exception"+ ) as mock_capture,+ ):+ ok, message = source.validate_credentials(_make_config("password"), team_id=1)++ assert ok is False+ assert message is not None and "multi-factor authentication" in message+ mock_capture.assert_not_called()+def test_unexpected_value_error_is_still_captured(self, source):with (patch.object(source, "get_schemas", side_effect=ValueError("something unexpected")),