: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
feat(data-warehouse): open custom source to all teams (#60596)
Marcus Hofdaf2a69d7ccf
diff --git a/posthog/temporal/data_imports/sources/custom/source.py b/posthog/temporal/data_imports/sources/custom/source.pyindex 606f762c4f47..7e7775693353 100644--- a/posthog/temporal/data_imports/sources/custom/source.py+++ b/posthog/temporal/data_imports/sources/custom/source.py@@ -2,8 +2,6 @@ import jsonfrom typing import Any, Literal, Optional, castfrom urllib.parse import urlparse-from django.conf import settings-from pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validatorfrom requests import Responsefrom urllib3.util.retry import Retry@@ -62,17 +60,6 @@ MAX_MANIFEST_RESOURCES = 50MAX_CUSTOM_SOURCES_PER_TEAM = 5-def is_custom_source_available_for_team(team_id: int | None) -> bool:- # While the custom source is in development it is restricted to a single- # pilot team on PostHog Cloud US. The wizard listing is gated client-side by- # the `dwh_custom_source` feature flag; this is the server-side enforcement- # that rejects creation from anywhere else (other cloud regions, self-hosted).- # Temporary: remove this gate once SSRF protection for arbitrary user-supplied- # URLs is enabled, after which the source can open up to all teams.- allowed_team_id = 2- return settings.CLOUD_DEPLOYMENT == "US" and team_id == allowed_team_id--class ManifestValidationError(ValueError):"""Raised when the user-provided manifest doesn't conform to RESTAPIConfig."""diff --git a/posthog/temporal/data_imports/sources/custom/test_custom_source.py b/posthog/temporal/data_imports/sources/custom/test_custom_source.pyindex 70be0830c5ff..90ec70705655 100644--- a/posthog/temporal/data_imports/sources/custom/test_custom_source.py+++ b/posthog/temporal/data_imports/sources/custom/test_custom_source.py@@ -17,7 +17,6 @@ from posthog.temporal.data_imports.sources.custom.source import (CustomSource,ManifestValidationError,_read_capped_text,- is_custom_source_available_for_team,manifest_request_hosts,validate_manifest,validate_manifest_urls,@@ -692,22 +691,6 @@ class TestManifestRequestHosts(SimpleTestCase):assert manifest_request_hosts(raw) == frozenset()-class TestIsCustomSourceAvailableForTeam(SimpleTestCase):- @override_settings(CLOUD_DEPLOYMENT="US")- def test_allows_pilot_team_on_us_cloud(self):- assert is_custom_source_available_for_team(2) is True-- @parameterized.expand([("EU",), ("DEV",), ("E2E",), ("",), (None,)])- def test_rejects_non_us_deployment(self, deployment):- with override_settings(CLOUD_DEPLOYMENT=deployment):- assert is_custom_source_available_for_team(2) is False-- @parameterized.expand([(1,), (3,), (999,), (None,)])- @override_settings(CLOUD_DEPLOYMENT="US")- def test_rejects_other_teams_even_on_us(self, team_id):- assert is_custom_source_available_for_team(team_id) is False--class TestCustomSourceSourceForPipeline(SimpleTestCase):def test_invalid_manifest_raises_non_retryable(self):# A permanent config error must fail fast, not burn the Temporal retry budget.diff --git a/products/data_warehouse/backend/api/external_data_source.py b/products/data_warehouse/backend/api/external_data_source.pyindex 71a91b040440..d0db0d228b35 100644--- a/products/data_warehouse/backend/api/external_data_source.py+++ b/products/data_warehouse/backend/api/external_data_source.py@@ -49,11 +49,7 @@ from posthog.temporal.data_imports.sources.common.config import Configfrom posthog.temporal.data_imports.sources.common.schema import SourceSchemafrom posthog.temporal.data_imports.sources.common.sql import filter_dwh_columns_by_enabled_columns, sql_schema_metadatafrom posthog.temporal.data_imports.sources.common.sql.base import SQLSource-from posthog.temporal.data_imports.sources.custom.source import (- MAX_CUSTOM_SOURCES_PER_TEAM,- is_custom_source_available_for_team,- manifest_request_hosts,-)+from posthog.temporal.data_imports.sources.custom.source import MAX_CUSTOM_SOURCES_PER_TEAM, manifest_request_hostsfrom posthog.temporal.data_imports.sources.postgres.cdc.slot_manager import cdc_pg_connectionfrom posthog.temporal.data_imports.sources.postgres.postgres import get_primary_key_columns, source_requires_sslfrom posthog.temporal.data_imports.sources.postgres.source import PostgresSource@@ -1147,11 +1143,6 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixiif isinstance(value, str):payload[key] = value.strip()source_type_model = ExternalDataSourceType(source_type)- if source_type_model == ExternalDataSourceType.CUSTOM and not is_custom_source_available_for_team(self.team_id):- return Response(- status=status.HTTP_400_BAD_REQUEST,- data={"message": "Custom REST source is not available for this team."},- )if (source_type_model == ExternalDataSourceType.CUSTOMand count_active_custom_sources(self.team_id) >= MAX_CUSTOM_SOURCES_PER_TEAMdiff --git a/products/data_warehouse/backend/api/test/test_external_data_source.py b/products/data_warehouse/backend/api/test/test_external_data_source.pyindex ff2000de5854..08f4efa5a19d 100644--- a/products/data_warehouse/backend/api/test/test_external_data_source.py+++ b/products/data_warehouse/backend/api/test/test_external_data_source.py@@ -5665,36 +5665,6 @@ class TestExternalDataSource(APIBaseTest):assert response.status_code == 200assert payload is not None- def test_create_custom_source_rejected_when_team_ineligible(self):- response = self.client.post(- f"/api/environments/{self.team.pk}/external_data_sources/",- data={- "source_type": "Custom",- "prefix": "custom_",- "payload": {"manifest_json": "{}"},- },- )- assert response.status_code == status.HTTP_400_BAD_REQUEST- assert response.json()["message"] == "Custom REST source is not available for this team."-- def test_create_custom_source_allowed_when_team_eligible(self):- with patch(- "products.data_warehouse.backend.api.external_data_source.is_custom_source_available_for_team",- return_value=True,- ):- response = self.client.post(- f"/api/environments/{self.team.pk}/external_data_sources/",- data={- "source_type": "Custom",- "prefix": "custom_",- "payload": {"manifest_json": "{}"},- },- )- # Past the team gate, the request fails later on the (empty) manifest rather- # than on availability — i.e. the eligibility check no longer blocks it.- assert response.status_code == status.HTTP_400_BAD_REQUEST- assert response.json()["message"] != "Custom REST source is not available for this team."-@parameterized.expand([# name, seed sources soft-deleted?, seed for a different team?, expect the limit error@@ -5720,21 +5690,17 @@ class TestExternalDataSource(APIBaseTest):deleted=deleted,)- with patch(- "products.data_warehouse.backend.api.external_data_source.is_custom_source_available_for_team",- return_value=True,- ):- response = self.client.post(- f"/api/environments/{self.team.pk}/external_data_sources/",- data={- "source_type": "Custom",- "prefix": "custom_new_",- "payload": {"manifest_json": "{}"},- },- )+ response = self.client.post(+ f"/api/environments/{self.team.pk}/external_data_sources/",+ data={+ "source_type": "Custom",+ "prefix": "custom_new_",+ "payload": {"manifest_json": "{}"},+ },+ )# Every case 400s; only the at-limit case is blocked *by the per-team limit* — the- # excluded cases pass the gate and fail later on the (empty) manifest instead.+ # excluded cases stay under the limit and fail later on the (empty) manifest instead.limit_message = f"You can create at most {MAX_CUSTOM_SOURCES_PER_TEAM} custom sources per project."assert response.status_code == status.HTTP_400_BAD_REQUESTif expect_blocked: