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(bigquery): stop retrying when a service account lacks connection-use permission (#85942)

Tom Owers5adb87c99988
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
index 8084968c3440..e03a3d8bed5a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/source.py
@@ -107,6 +107,17 @@ class BigQuerySource(SQLSource[BigQuerySourceConfig]):
# Deterministic IAM config problem; retrying can't grant the permission. Matched on the
# stable permission name, not the volatile project id.
"bigquery.jobs.create": "BigQuery denied your service account permission to run query jobs — it's missing the bigquery.jobs.create permission on the project it queries. Read access alone isn't enough, because PostHog runs query jobs to sync your data. Please grant your service account permission to run jobs (for example the BigQuery Job User role) on that project, then reconnect the source.",
+ # Raised as a 403 Forbidden when a table or view being synced reads through a BigQuery
+ # connection (used for federated queries or BigLake external tables) that the service
+ # account isn't authorized to use, e.g. "Access Denied: Connection projects/<p>/
+ # locations/<l>/connections/<c>: User does not have bigquery.connections.use permission
+ # for connection projects/<p>/locations/<l>/connections/<c>.". This is a separate IAM
+ # grant from table/dataset access — it lives on the connection resource itself, not the
+ # dataset — so the generic "Access Denied:" key below would match first and misdirect the
+ # customer to grant table read access (Data Viewer), which can't authorize connection use.
+ # Deterministic IAM config problem; retrying can't grant the permission. Matched on the
+ # stable permission name, not the volatile project/location/connection id.
+ "bigquery.connections.use": "BigQuery denied access to a BigQuery connection that a table or view being synced depends on (used for federated queries or external/BigLake tables). Please grant your service account the bigquery.connections.use permission (for example the BigQuery Connection User role) on that connection, then reconnect the source.",
# BigQuery prefixes every IAM/permission failure with "Access Denied:" — e.g.
# "Access Denied: Table <id>: Permission bigquery.tables.getData denied on table <id>
# (or it may not exist).". The matched string above only covers the REST client's
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
index 9260a8fd9eb0..b720061946ae 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bigquery/tests/test_source.py
@@ -1291,13 +1291,27 @@ def test_non_retryable_errors_match_permission_denied(observed_error):
"bigquery.tables.create",
"create",
),
+ # Querying a table/view that reads through a BigQuery connection (federated query or
+ # BigLake) the service account isn't authorized to use — denied with
+ # bigquery.connections.use on the connection resource, not the table/dataset.
+ (
+ str(
+ Forbidden(
+ "Access Denied: Connection projects/proj/locations/us/connections/conn: User does not "
+ "have bigquery.connections.use permission for connection "
+ "projects/proj/locations/us/connections/conn."
+ )
+ ),
+ "bigquery.connections.use",
+ "connection",
+ ),
],
)
-def test_temp_table_write_denial_surfaces_write_permission_guidance(observed_error, expected_key, expected_word):
- # A temp-table write/create denial also contains "Access Denied:", so both that generic key and the
- # write-specific key match. external_data_job surfaces the first matching key's message, so the
- # write-specific key must sit above "Access Denied:" — otherwise the customer is told to grant read
- # access to fix a write/create failure.
+def test_specific_permission_denial_outranks_generic_access_denied(observed_error, expected_key, expected_word):
+ # Each of these denials also contains "Access Denied:", so both the generic key and the
+ # more specific key match. external_data_job surfaces the first matching key's message, so the
+ # specific key must sit above "Access Denied:" — otherwise the customer is told to grant table
+ # read access to fix a failure that read access can't resolve.
non_retryable_errors = BigQuerySource().get_non_retryable_errors()
first_key, friendly = next((key, msg) for key, msg in non_retryable_errors.items() if key in observed_error)
assert first_key == expected_key