: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): bypass egress proxy for internal ClickHouse direct queries (#74270)
Tom Owers5a2115e18ab1
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.pyindex a675df3817e5..d30d57be6897 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py@@ -314,6 +314,7 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Valverify=config.verify,query_timeout=query_timeout,settings=settings,+ bypass_env_proxy=is_team_allowlisted_for_internal_hosts(team_id),)try:yield clientdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.pyindex e43e5ca0a96c..cc8823249b33 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py@@ -1386,3 +1386,39 @@ class TestInternalHostTeamAllowlist:with patch.object(mixins, "get_instance_region", return_value=region):assert mixins.is_team_allowlisted_for_internal_hosts(team_id) is expected+++class TestDirectQueryClientBypassEnvProxy:+ """`direct_query_client` backs the HogQL direct-SQL adapter, and unlike every other+ `_get_client` call site on `ClickHouseSource` it once omitted `bypass_env_proxy` entirely —+ an allowlisted internal team's direct query silently routed through the egress proxy and+ failed to reach the PostHog-internal host it was pointed at.+ """++ @pytest.mark.parametrize(+ "region,team_id,expected_bypass",+ [+ ("US", 2, True),+ ("US", 12345, False),+ ],+ )+ def test_forwards_bypass_env_proxy_from_team_allowlist(self, region, team_id, expected_bypass):+ from products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse import source as source_module+ from products.warehouse_sources.backend.temporal.data_imports.sources.common import mixins++ source = ClickHouseSource()+ config = MagicMock()+ config.database = "default"+ config.user = "default"+ config.password = None+ config.secure = True+ config.verify = True++ with patch.object(mixins, "get_instance_region", return_value=region):+ with patch.object(source, "with_ssh_tunnel") as mock_with_ssh_tunnel:+ mock_with_ssh_tunnel.return_value.__enter__.return_value = ("host", 8443)+ with patch.object(source_module, "_get_client") as mock_get_client:+ with source.direct_query_client(config, team_id, query_timeout=60):+ pass++ assert mock_get_client.call_args.kwargs["bypass_env_proxy"] is expected_bypass