: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-warehouse): raise a clear error when no AWS role is configured to assume (#113399)
Tom Owers229c5d8dd887
diff --git a/products/batch_exports/backend/temporal/destinations/s3_batch_export.py b/products/batch_exports/backend/temporal/destinations/s3_batch_export.pyindex 910a642ef73e..fe81e7dddb5d 100644--- a/products/batch_exports/backend/temporal/destinations/s3_batch_export.py+++ b/products/batch_exports/backend/temporal/destinations/s3_batch_export.py@@ -109,6 +109,8 @@ NON_RETRYABLE_ERROR_TYPES = ("S3IntegrationNotFoundError",# The linked Integration is the wrong kind or has invalid/missing credentials"IntegrationError",+ # This environment has no external role configured to assume a customer's role with+ "ExternalRoleArnNotConfiguredError",)LOGGER = get_write_only_logger(__name__)@@ -282,6 +284,18 @@ class InvalidCredentialsError(Exception):super().__init__(message)+class ExternalRoleArnNotConfiguredError(Exception):+ """Raised when this environment has no role of ours to assume a customer's role with.++ Role-based AWS access always goes through our own external role first. Without it every+ attempt fails identically, regardless of how the customer's own role ARN is set up, so+ retrying never helps.+ """++ def __init__(self) -> None:+ super().__init__("Role-based AWS access is not available: BATCH_EXPORT_S3_EXTERNAL_ROLE_ARN is not set.")++def s3_default_fields() -> list[BatchExportField]:"""Default fields for an S3 batch export.@@ -430,6 +444,9 @@ async def get_credentials_using_user_aws_role(roles and/or policies may not be immediately available.delay: Initial delay in between connection attempts."""+ if not settings.BATCH_EXPORT_S3_EXTERNAL_ROLE_ARN:+ raise ExternalRoleArnNotConfiguredError()+for attempt in range(1, max_attempts + 1):try:async with SESSION.client("sts") as sts:diff --git a/products/batch_exports/backend/tests/temporal/destinations/s3/test_refreshable_credentials.py b/products/batch_exports/backend/tests/temporal/destinations/s3/test_refreshable_credentials.pyindex 3c19c289fdfe..38a6b4581fc6 100644--- a/products/batch_exports/backend/tests/temporal/destinations/s3/test_refreshable_credentials.py+++ b/products/batch_exports/backend/tests/temporal/destinations/s3/test_refreshable_credentials.py@@ -4,13 +4,17 @@ import collections.abcimport pytest+from django.test import override_settings+import aioboto3from aiobotocore.credentials import AioRefreshableCredentialsfrom botocore.credentials import ReadOnlyCredentialsfrom products.batch_exports.backend.service import AWSCredentialsfrom products.batch_exports.backend.temporal.destinations.s3_batch_export import (+ ExternalRoleArnNotConfiguredError,RefreshCoroutine,+ get_credentials_using_user_aws_role,get_refreshable_session,)@@ -75,3 +79,17 @@ async def test_get_refreshable_session_does_not_refresh_valid_credentials():assert frozen.access_key == "initial-key"assert frozen.secret_key == "initial-secret"assert frozen.token == "initial-token"+++async def test_get_credentials_using_user_aws_role_without_external_role_configured():+ # An unconfigured external role previously reached AWS first, surfacing as a cryptic+ # botocore ParamValidationError about the role ARN's length instead of this environment's+ # actual, fixable problem.+ with override_settings(BATCH_EXPORT_S3_EXTERNAL_ROLE_ARN=""):+ with pytest.raises(ExternalRoleArnNotConfiguredError):+ await get_credentials_using_user_aws_role(+ "arn:aws:iam::123456789012:role/customer-role",+ "posthog-external-id",+ session_name="test",+ policy_statements=[],+ )diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.pyindex 30816bc3f6d1..1dccbd37aecf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py@@ -173,6 +173,9 @@ NON_RETRYABLE_ERROR_PATTERNS: tuple[str, ...] = (# self-hosted object storage (MinIO) has hit its minimum free drive threshold and is# refusing writes — every retry hits the same full disk until an operator frees space"XMinioStorageFull",+ # a role-based AWS destination has no external role configured in this environment — every+ # retry fails identically until that's fixed, independent of the customer's own role ARN+ "BATCH_EXPORT_S3_EXTERNAL_ROLE_ARN is not set",# a destination's own settings refuse the connection (bad credentials, unknown database,# unroutable host); the next scheduled run tries again after the customer fixes themDESTINATION_CONFIGURATION_ERROR_MARKER,diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.pyindex e3bb98da78f0..50a99e70cbb8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py@@ -3961,6 +3961,10 @@ class TestIsRetryableError:("Primary key required for incremental syncs", False),("ExternalDataSchema matching query does not exist.", False),("ExternalDataJob matching query does not exist.", False),+ (+ "Role-based AWS access is not available: BATCH_EXPORT_S3_EXTERNAL_ROLE_ARN is not set.",+ False,+ ),("connection reset by peer", True),],)