: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(data-imports): classify InvalidAccessKeyId as a permission refusal on our own bucket (#112458)
Tom Owers7723fdef8d85
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.pyindex 6ca82a93c9f7..269ea67d30ec 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/ops.py@@ -28,14 +28,20 @@ T = TypeVar("T")# `CommitFailedError` wrapping the same sentence, because delta-rs maps every# `DeltaTableError::Transaction` onto that class regardless of what the transaction failed on.# - s3fs translates an explicit S3 `AccessDenied` response code into `PermissionError("Access-# Denied")`.-# Both mean the bucket policy or the worker's role refuses the call on that key, so running the same-# call again returns the same refusal. A bodyless 403 is deliberately not matched: AWS omits the-# error code from a HEAD response, so s3fs raises `PermissionError("Forbidden")` for a brief-# credential-resolution race as well as for a real refusal, and `_purge_s3_prefix` still retries it.+# Denied")`, and an `InvalidAccessKeyId` response (the worker's own access key no longer exists,+# e.g. a rotated or revoked credential) into `PermissionError("The AWS Access Key Id you provided+# does not exist in our records.")` — s3fs always uses the response's own `Message` field, so both+# collapse to the same `PermissionError` type but keep their own fixed text.+# `AccessDenied` means the bucket policy or the worker's role refuses the call on that key;+# `InvalidAccessKeyId` means AWS doesn't recognize the worker's access key at all. Neither is a race,+# so running the same call again returns the same refusal either way. A bodyless 403 is deliberately+# not matched: AWS omits the error code from a HEAD response, so s3fs raises+# `PermissionError("Forbidden")` for a brief credential-resolution race as well as for a real+# refusal, and `_purge_s3_prefix` still retries it.OBJECT_STORE_PERMISSION_DENIED_ERRORS = ("The operation lacked the necessary privileges to complete","Access Denied",+ "The AWS Access Key Id you provided does not exist in our records.",)# Reaches the customer as the sync run's error text, so it names neither the bucket nor the objectdiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.pyindex 8a9f4577ad94..a88653ac13a7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta/test/test_ops.py@@ -184,6 +184,12 @@ class TestExecuteWithConflictRetry:),# s3fs translates an explicit S3 AccessDenied response code into PermissionError.("s3fs_access_denied", PermissionError("Access Denied")),+ # s3fs collapses InvalidAccessKeyId (the worker's own access key no longer exists) into+ # the same PermissionError type, with AWS's own fixed message instead of "Access Denied".+ (+ "s3fs_invalid_access_key_id",+ PermissionError("The AWS Access Key Id you provided does not exist in our records."),+ ),])@pytest.mark.asynciodiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.pyindex f968622e9890..a4b8b5a0c9b9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py@@ -154,6 +154,15 @@ class TestBatchByteSize:class TestWriteBatchPermissionDenied:+ @parameterized.expand(+ [+ ("access_denied", "Access Denied"),+ # InvalidAccessKeyId: the worker's own access key no longer exists (rotated/revoked).+ # s3fs collapses this to the same PermissionError type as AccessDenied but with AWS's+ # own fixed message.+ ("invalid_access_key_id", "The AWS Access Key Id you provided does not exist in our records."),+ ]+ )@patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer._write_parquet_to_s3")@@ -161,15 +170,16 @@ class TestWriteBatchPermissionDenied:@patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer.get_s3_client")def test_write_batch_wraps_access_denied_instead_of_raising_raw_error(self,+ _name: str,+ error_message: str,_mock_get_s3_client,_mock_ensure_bucket,mock_write,) -> None:- # The data warehouse bucket is PostHog's own, so an AccessDenied writing to it used to- # escape write_batch as a raw PermissionError: it read to the customer as if their source- # credentials were bad, and error tracking grouped a fresh issue per retry instead of one- # stable title.- mock_write.side_effect = PermissionError("Access Denied")+ # The data warehouse bucket is PostHog-owned, so a permission refusal writing to it must not+ # read to the customer as if their source credentials were bad, and error tracking must group+ # every occurrence under one stable title rather than the raw per-key s3fs message.+ mock_write.side_effect = PermissionError(error_message)job = MagicMock()job.team_id = 1