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(warehouse): bypass proxy for managed Trino (#92265)

Benjamin Knofe-Vider31f11b35f32b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/trino/tests/test_trino.py b/products/warehouse_sources/backend/temporal/data_imports/sources/trino/tests/test_trino.py
index 5d14f1aed2c0..734a44af89e9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/trino/tests/test_trino.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/trino/tests/test_trino.py
@@ -55,6 +55,46 @@ def test_connect_trino_uses_tracked_session_and_closes_resources() -> None:
session.close.assert_called_once_with()
+ ("host", "port", "use_ssl", "verify_ssl", "expected_trust_env"),
+ [
+ ("trino.dw.us.postwh.com", 443, True, True, False),
+ ("TRINO.DW.DEV.POSTWH.COM.", 443, True, True, False),
+ ("trino.example.com", 443, True, True, True),
+ ("other.dw.us.postwh.com", 443, True, True, True),
+ ("trino.dw.us.postwh.com", 8443, True, True, True),
+ ("trino.dw.us.postwh.com", 443, False, True, True),
+ ("trino.dw.us.postwh.com", 443, True, False, True),
+ ],
+)
+def test_connect_trino_bypasses_proxy_only_for_managed_tls_endpoints(
+ host: str, port: int, use_ssl: bool, verify_ssl: bool, expected_trust_env: bool
+) -> None:
+ connection = MagicMock()
+ session = MagicMock(trust_env=True)
+ auth_type = TrinoAuthTypeConfig(user="posthog", selection="none")
+
+ with (
+ patch("trino.dbapi.connect", return_value=connection),
+ patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.trino.trino.make_tracked_session",
+ return_value=session,
+ ),
+ connect_trino(
+ _config(
+ host=host,
+ port=port,
+ use_ssl=use_ssl,
+ verify_ssl=verify_ssl,
+ auth_type=auth_type,
+ )
+ ),
+ ):
+ pass
+
+ assert session.trust_env is expected_trust_env
+
+
def test_connect_trino_rejects_credentials_over_http() -> None:
with pytest.raises(ValueError, match="require HTTPS"):
with connect_trino(_config(use_ssl=False)):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.py b/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.py
index a18f01a7e8bb..4ff5a2873cec 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/trino/trino.py
@@ -18,6 +18,16 @@ TRINO_SYSTEM_SCHEMAS = ("information_schema",)
TRINO_CREDENTIALS_REQUIRE_TLS_VERIFICATION_ERROR = (
"Turn on TLS certificate verification to use password or JWT authentication."
)
+POSTHOG_MANAGED_TRINO_HOSTS = frozenset(
+ {
+ "trino.dw.dev.postwh.com",
+ "trino.dw.us.postwh.com",
+ }
+)
+
+
+def _is_posthog_managed_trino_host(host: str) -> bool:
+ return host.lower().rstrip(".") in POSTHOG_MANAGED_TRINO_HOSTS
@frozen
@@ -84,6 +94,8 @@ def connect_trino(config: TrinoSourceConfig) -> Iterator[Connection]:
value for value in (config.auth_type.password, config.auth_type.token) if isinstance(value, str) and value
)
session = make_tracked_session(redact_values=redacted, allow_redirects=False)
+ if _is_posthog_managed_trino_host(config.host) and config.port == 443 and config.use_ssl and config.verify_ssl:
+ session.trust_env = False
session.verify = config.verify_ssl
log_connection_open(db_host=config.host, via="trino_https" if config.use_ssl else "trino_http")
connection: Connection | None = None