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 invalid key-pair JWT as non-retryable (#64603)

Tom Owers345f88049f6c
diff --git a/posthog/temporal/data_imports/sources/snowflake/source.py b/posthog/temporal/data_imports/sources/snowflake/source.py
index 196eb14ea789..a21c4503560c 100644
--- a/posthog/temporal/data_imports/sources/snowflake/source.py
+++ b/posthog/temporal/data_imports/sources/snowflake/source.py
@@ -206,6 +206,12 @@ class SnowflakeSource(SQLSource[SnowflakeSourceConfig]):
# rejects the connection because PostHog's egress IP isn't permitted. Retrying can never
# succeed until their admin allowlists our IPs, so stop retrying and surface what to do.
"is not allowed to access Snowflake": "Snowflake rejected the connection because a network policy (IP allowlist) on your account does not permit PostHog's IP address. Ask your Snowflake administrator to add PostHog's egress IP addresses to the network policy allowlist, then resync.",
+ # Snowflake error 250001 (08001): key-pair login was rejected because the JWT we signed with
+ # the configured private key doesn't match the public key registered on the Snowflake user
+ # (rotated/removed key, key assigned to a different user, or the wrong key pasted). Retrying
+ # can never succeed until the customer re-registers the matching public key. The host and
+ # request id in the message are volatile, so we match the stable phrase.
+ "JWT token is invalid": "Snowflake rejected key-pair authentication because the signed token is invalid — the private key you configured doesn't match the public key registered on the Snowflake user. Re-register the matching public key on the user in Snowflake (or paste the correct private key), then 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
diff --git a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
index 1ee16a2e7a12..7f3e44b65025 100644
--- a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
+++ b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py
@@ -699,6 +699,20 @@ class TestSnowflakeSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Network-policy block should be non-retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ "JWT token is invalid",
+ # The real shape from production: codes, host, and request id vary, but the substring is stable.
+ "250001 (08001): None: Failed to connect to DB: novjltn-acme.snowflakecomputing.com:443. "
+ "JWT token is invalid. [daf5b833-38d8-4aa9-9971-9d6bd736d978]",
+ ],
+ )
+ def test_invalid_jwt_token_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"Invalid-JWT error should be non-retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[