: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(warehouse-sources): give Redshift SSH tunnel failures an actionable error (#87426)
Tom Owers6734cf0c06ee
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.pyindex 071948ef9956..3c1b7edf4309 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/source.py@@ -40,6 +40,17 @@ if TYPE_CHECKING:_REDSHIFT_IMPLEMENTATION = RedshiftImplementation()+# sshtunnel raises BaseSSHTunnelForwarderError("Could not establish session to SSH gateway") when it+# can't open a session to the bastion — the SSH host/port is wrong or unreachable, the bastion is+# down, or its firewall blocks PostHog's IPs. The raw message tells the user nothing actionable, so+# replace it with concrete guidance (the sibling SQL sources already do the same).+_SSH_GATEWAY_SESSION_ERROR = "Could not establish session to SSH gateway"+_SSH_GATEWAY_UNREACHABLE_MESSAGE = (+ "Could not connect to your SSH tunnel. Check that the SSH host, port, and credentials are "+ "correct, the bastion host is running and reachable, and that PostHog's IP addresses are "+ "allowed through its firewall."+)+RedshiftErrors = {"password authentication failed for user": "Invalid user or password","could not translate host name": "Could not connect to the host",@@ -217,9 +228,12 @@ class RedshiftSource(SQLSource[RedshiftSourceConfig], SSHTunnelMixin, ValidateDacapture_exception(e)return False, f"Could not connect to {self.source_name}. Please check all connection details are valid."except BaseSSHTunnelForwarderError as e:+ raw = e.value or ""+ if _SSH_GATEWAY_SESSION_ERROR in raw:+ return False, _SSH_GATEWAY_UNREACHABLE_MESSAGEreturn (False,- e.value+ rawor f"Could not connect to {self.source_name} via the SSH tunnel. Please check all connection details are valid.",)except Exception as e:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.py b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.pyindex 99590e0f7004..27e7e9ebeef5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/redshift/tests/test_redshift.py@@ -7,6 +7,7 @@ import psycopgimport pyarrow as pafrom psycopg import sqlfrom psycopg.pq import TransactionStatus+from sshtunnel import BaseSSHTunnelForwarderErrorfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.core.arrow_utils import (TemporaryFileSizeExceedsLimitException,@@ -1278,6 +1279,26 @@ class TestRedshiftValidateCredentials:assert error is not None and "does not support SSL" in errorcapture.assert_not_called()+ def test_ssh_gateway_session_error_maps_to_actionable_message(self, mocker):+ # sshtunnel's raw "Could not establish session to SSH gateway" is meaningless to the user;+ # it must be replaced with concrete guidance rather than surfaced verbatim.+ config = _make_config()+ source = RedshiftSource()+ mocker.patch.object(source, "ssh_tunnel_is_valid", return_value=(True, None))+ mocker.patch.object(source, "is_database_host_valid", return_value=(True, None))+ mocker.patch.object(+ source,+ "get_schemas",+ side_effect=BaseSSHTunnelForwarderError("Could not establish session to SSH gateway"),+ )++ ok, error = source.validate_credentials(config, team_id=1)++ assert ok is False+ assert error is not None+ assert "Could not establish session to SSH gateway" not in error+ assert "SSH tunnel" in error and "firewall" in error+class TestRedshiftSourceForPipeline:def test_forwards_chunk_size_override_from_external_data_schema(self, mocker):