: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(trino): explain permission denied errors instead of the raw driver error (#120915)
Tom Owersdb0715af321f
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.pyindex 87b451164dff..96c3e24d312e 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@@ -34,6 +34,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.trino.trinTRINO_ACCESS_CONTROL_UNAVAILABLE_ERROR,TRINO_ACCESS_DENIED_ERROR,TRINO_AUTHENTICATION_ERROR,+ TRINO_CLUSTER_ACCESS_DENIED_ERROR,TRINO_CONNECT_TIMEOUT_ERROR,TRINO_CREDENTIALS_REQUIRE_TLS_VERIFICATION_ERROR,TRINO_DISCOVERY_TIMEOUT_ERROR,@@ -325,6 +326,16 @@ def test_trino_error_to_message_preserves_tls_verification_action() -> None:'Cannot select from table hive.analytics.events", query_id=20260902_123401_00000_abcde)',TRINO_ACCESS_DENIED_ERROR,),+ (+ 'TrinoUserError(type=USER_ERROR, name=PERMISSION_DENIED, message="User [email protected] with role '+ 'reader does not have the privilege to use cluster example-cluster", query_id=20260101_000000_00000_abcde)',+ TRINO_CLUSTER_ACCESS_DENIED_ERROR,+ ),+ (+ 'TrinoUserError(type=USER_ERROR, name=PERMISSION_DENIED, message="Role reader cannot do this", '+ "query_id=20260101_000000_00000_abcde)",+ TRINO_ACCESS_DENIED_ERROR,+ ),],)def test_trino_error_to_message_explains_access_failures(raw_error: str, expected: str) -> None: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.pyindex 36ef892ac3e6..8451f110f6ad 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@@ -69,6 +69,10 @@ TRINO_ACCESS_DENIED_ERROR = ("Trino did not allow this user to read the requested data. ""Ask your Trino administrator for read access, then try again.")+TRINO_CLUSTER_ACCESS_DENIED_ERROR = (+ "Your Trino user's role isn't allowed to use this cluster. "+ "Ask your Trino administrator to grant that role access to the cluster, then try again."+)TRINO_ACCESS_CONTROL_UNAVAILABLE_ERROR = ("Trino's access control service did not answer, so Trino could not authorize the request. ""Try again, or ask your Trino administrator to check that service."@@ -138,6 +142,7 @@ TRINO_KNOWN_ERROR_MESSAGES = (TRINO_AUTHENTICATION_ERROR,TRINO_CATALOG_NOT_FOUND_ERROR,TRINO_ACCESS_DENIED_ERROR,+ TRINO_CLUSTER_ACCESS_DENIED_ERROR,TRINO_ACCESS_CONTROL_UNAVAILABLE_ERROR,TRINO_TLS_CERTIFICATE_ERROR,TRINO_CONNECTION_ERROR,@@ -153,6 +158,7 @@ TRINO_PERMANENT_SYNC_ERROR_MESSAGES = frozenset(TRINO_AUTHENTICATION_ERROR,TRINO_CATALOG_NOT_FOUND_ERROR,TRINO_ACCESS_DENIED_ERROR,+ TRINO_CLUSTER_ACCESS_DENIED_ERROR,})POSTHOG_MANAGED_TRINO_HOST_PATTERN = re.compile(r"[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.dw\.(?:dev|eu|us)\.postwh\.com")@@ -282,11 +288,19 @@ def trino_error_to_message(error: Exception) -> str:# text carries a query ID whose time part can hold "401" and would derail this classification.if "authentication" in lowered or "unauthorized" in lowered or "error 401" in lowered:return TRINO_AUTHENTICATION_ERROR+ # Starburst Galaxy checks a role's privilege to use the cluster before any catalog access check.+ if "privilege to use cluster" in lowered:+ return TRINO_CLUSTER_ACCESS_DENIED_ERROR# Trino gives permission checks to an access control plugin. That plugin can fail on its own, for# example when it cannot reach its policy service, which nobody can fix from PostHog.if "opa backend" in lowered or "access control" in lowered:return TRINO_ACCESS_CONTROL_UNAVAILABLE_ERROR- if "access denied" in lowered or "permission denied" in lowered or "not authorized" in lowered:+ if (+ "access denied" in lowered+ or "permission denied" in lowered+ or "not authorized" in lowered+ or "name=permission_denied" in lowered+ ):return TRINO_ACCESS_DENIED_ERRORif "catalog" in lowered and ("not found" in lowered or "does not exist" in lowered):return TRINO_CATALOG_NOT_FOUND_ERROR