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(ingress): stop forwarding GitHub deliveries between regions (#102084)

Julian Bezc5c7ed0eced0
diff --git a/posthog/ingress/github/README.md b/posthog/ingress/github/README.md
index cf306d48688e..ce3023547841 100644
--- a/posthog/ingress/github/README.md
+++ b/posthog/ingress/github/README.md
@@ -28,11 +28,18 @@ Two apps share this incarnation, each subscribed to its own event types in GitHu
A consumer registers against an app name, so the two apps share no consumers.
+Each region runs its own `posthog` App, with its own webhook URL and its own secret.
+GitHub already delivers an installation's events to the region that holds it.
+The `stamphog` App is one App, and one region serves its endpoint.
+
## Quirks
The status codes are the defaults: 403 on a bad signature, 500 when unconfigured, 202 on success.
The installation lifecycle is a core consumer rather than a product one, because it keeps PostHog's own integration rows in step with GitHub.
-The `posthog` app's conversations consumer declares ownership by installation, so a delivery for an installation the other region holds is forwarded there before local dispatch. The consumers in this region still run — see [Regional forwarding](../README.md#regional-forwarding).
+A GitHub delivery is never forwarded to the other region, so no consumer here declares `ownership`.
+The other region verifies against its own App's secret, so it would answer a replayed delivery 403 and count it as an invalid signature.
+An installation this region does not hold is an installation this region never receives deliveries for.
+See [Regional forwarding](../README.md#regional-forwarding) for the lane the providers with one callback URL use.
## Consumers
diff --git a/posthog/ingress/test/test_registry.py b/posthog/ingress/test/test_registry.py
index 296ce6dcb4d7..24e186899511 100644
--- a/posthog/ingress/test/test_registry.py
+++ b/posthog/ingress/test/test_registry.py
@@ -3,6 +3,7 @@ from django.test import SimpleTestCase
from posthog.ingress.contracts import ProviderSpec, WebhookConsumer, WebhookDelivery
from posthog.ingress.dispatch.loading import get_consumer_registry, reset_consumer_registry
from posthog.ingress.dispatch.registry import ConsumerRegistry, RegistryError
+from posthog.ingress.github.provider import SPECS as GITHUB_SPECS
GITHUB = ProviderSpec(provider="github", app="posthog", event_types=frozenset({"pull_request", "push"}))
STAMPHOG = ProviderSpec(provider="github", app="stamphog", event_types=frozenset({"pull_request"}))
@@ -81,6 +82,20 @@ class TestConsumerRegistry(SimpleTestCase):
["installation_lifecycle"],
)
+ def test_no_github_consumer_opts_into_regional_forwarding(self) -> None:
+ # Each region runs its own GitHub App, with its own webhook URL and its own secret, so a
+ # replayed delivery can only fail the other region's signature check. The forward lane
+ # keys off `ownership` alone, so leaving it unset is what keeps GitHub out of it.
+ reset_consumer_registry()
+ self.addCleanup(reset_consumer_registry)
+
+ registry = get_consumer_registry()
+
+ for spec in GITHUB_SPECS:
+ for event_type in sorted(spec.event_types):
+ for consumer in registry.consumers_for(provider="github", app=spec.app, event_type=event_type):
+ self.assertIsNone(consumer.ownership, f"{consumer.name} would forward {event_type} deliveries")
+
def test_same_name_on_two_apps_is_kept_apart_when_providers_differ(self) -> None:
slack = ProviderSpec(provider="slack", app="supporthog", event_types=frozenset({"message"}))
registry = ConsumerRegistry(
diff --git a/products/conversations/backend/facade/api.py b/products/conversations/backend/facade/api.py
index 45b3bce833fd..5d86bd2a510d 100644
--- a/products/conversations/backend/facade/api.py
+++ b/products/conversations/backend/facade/api.py
@@ -23,7 +23,7 @@ from temporalio.exceptions import WorkflowAlreadyStartedError
from temporalio.service import RPCError
from posthog.dataclasses import frozen
-from posthog.ingress.contracts import DeliveryOwnership, WebhookDelivery
+from posthog.ingress.contracts import WebhookDelivery
from posthog.models.comment import Comment
from posthog.models.integration import Integration
from posthog.models.team import Team
@@ -114,18 +114,6 @@ def accept_github_event(delivery: WebhookDelivery) -> None:
github_events.accept_github_event(delivery)
-def github_delivery_ownership(delivery: WebhookDelivery) -> DeliveryOwnership:
- """Whether this region holds the team the delivery's GitHub installation is connected to.
-
- Ingress asks before it dispatches, and forwards the signed request to the other region when
- the answer is elsewhere.
- """
- # Deferred to keep the Celery task module off the facade import path.
- from products.conversations.backend.services import github_events # noqa: PLC0415
-
- return github_events.github_delivery_ownership(delivery)
-
-
def sync_google_account_email(integration_id: int, team_id: int) -> None:
from products.conversations.backend.services.gmail_sync import ( # noqa: PLC0415 -- avoids the Conversations and Customer Analytics facade cycle
GmailSyncError,
diff --git a/products/conversations/backend/services/github_events.py b/products/conversations/backend/services/github_events.py
index b87bb06c988f..17578db5a2ff 100644
--- a/products/conversations/backend/services/github_events.py
+++ b/products/conversations/backend/services/github_events.py
@@ -1,31 +1,25 @@
"""GitHub App deliveries for the Conversations GitHub Issues channel.
-Two entry points, both reached from the facade after ingress verified the signature and parsed
-the body: ``github_delivery_ownership`` answers which region holds the delivery's installation,
-and ``accept_github_event`` hands the delivery to the Celery pipeline. No HTTP in here — ingress
-owns the request, the receipt, and the forward to the region that owns the installation.
+One entry point, reached from the facade after ingress verified the signature and parsed the
+body: ``accept_github_event`` hands the delivery to the Celery pipeline. No HTTP in here,
+because ingress owns the request and the receipt.
"""
import json
import hashlib
from typing import Any, cast
-from django.db import OperationalError
-
import structlog
from posthog.github.installations import installation_id
-from posthog.ingress.contracts import DeliveryOwnership, WebhookDelivery
-from posthog.ingress.dispatch.database import bounded_statement_timeout, is_statement_timeout
+from posthog.ingress.contracts import WebhookDelivery
+from posthog.ingress.dispatch.database import bounded_statement_timeout
from posthog.models.integration import Integration
from products.conversations.backend.tasks.github import process_github_event
logger = structlog.get_logger(__name__)
-# The event types this product consumes, and so the only ones it can answer ownership for.
-_CONSUMED_EVENT_TYPES = frozenset({"issues", "issue_comment"})
-
# The lookup runs inside the request, before dispatch, so it draws on the delivery's wall clock.
_INSTALLATION_LOOKUP_TIMEOUT_MS = 800
@@ -50,8 +44,7 @@ def _team_for_github_installation(external_id: str) -> tuple[int | None, bool]:
whose conversations_settings.github_integration_id explicitly points back
to the Integration row, ensuring deterministic routing.
- A cancelled statement raises, because a lookup that never finished is not an answer. Each
- caller decides what to do with it.
+ A cancelled statement raises, because a lookup that never finished is not an answer.
"""
with bounded_statement_timeout(_INSTALLATION_LOOKUP_TIMEOUT_MS, models=[Integration]):
integrations = list(
@@ -72,34 +65,6 @@ def _team_for_github_installation(external_id: str) -> tuple[int | None, bool]:
return None, False
-def github_delivery_ownership(delivery: WebhookDelivery) -> DeliveryOwnership:
- """Which region holds the team this delivery's installation is connected to.
-
- An installation this region does not own is `ELSEWHERE` rather than undecided, so the
- delivery reaches the other region: it is the only one that can tell an installation it holds
- from one nobody holds, and GitHub never redelivers an event it got a receipt for.
- """
- if delivery.event_type not in _CONSUMED_EVENT_TYPES:
- return DeliveryOwnership.UNDECIDED
- external_id = installation_id(dict(delivery.payload))
- if external_id is None:
- return DeliveryOwnership.UNDECIDED
-
- try:
- team_id, github_enabled = _team_for_github_installation(external_id)
- except OperationalError as error:
- if not is_statement_timeout(error):
- raise
- # Elsewhere rather than an error: the two answers here are "this region owns it" and
- # "somebody else does", and a lookup that never finished has not shown ownership here.
- logger.warning("github_issues_webhook_installation_lookup_timed_out", installation_id=external_id)
- return DeliveryOwnership.ELSEWHERE
-
- if team_id and github_enabled:
- return DeliveryOwnership.LOCAL
- return DeliveryOwnership.ELSEWHERE
-
-
def accept_github_event(delivery: WebhookDelivery) -> None:
"""Route a verified GitHub delivery to the conversations Celery pipeline."""
payload = dict(delivery.payload)
@@ -112,8 +77,9 @@ def accept_github_event(delivery: WebhookDelivery) -> None:
# dedup mark and a redelivery reaches this consumer instead of the event being lost.
team_id, github_enabled = _team_for_github_installation(external_id)
if not (team_id and github_enabled):
- # Quiet on purpose: ingress reports a delivery no region here owns, off the ownership
- # answer this module gave it before dispatch.
+ # Quiet on purpose, because this is the normal case. Each region runs its own GitHub App,
+ # so this endpoint only ever receives its own installations, and an installation no team
+ # here has connected simply has the GitHub Issues channel off.
return
cast(Any, process_github_event).delay(
diff --git a/products/conversations/backend/tests/test_github_events.py b/products/conversations/backend/tests/test_github_events.py
index 14d7dc1308f9..01036e5842d5 100644
--- a/products/conversations/backend/tests/test_github_events.py
+++ b/products/conversations/backend/tests/test_github_events.py
@@ -10,7 +10,7 @@ from django.db import OperationalError
from parameterized import parameterized
-from posthog.ingress.contracts import DeliveryOwnership, WebhookDelivery
+from posthog.ingress.contracts import WebhookDelivery
from posthog.models.integration import Integration
from products.conversations.backend.facade import api as conversations_facade
@@ -86,45 +86,6 @@ class TestConversationsGitHubDeliveries(BaseTest):
self.team.conversations_settings[key] = value
self.team.save()
- @parameterized.expand(
- [
- ("an_installation_connected_here", "issues", 12345, {}, DeliveryOwnership.LOCAL),
- ("an_installation_no_team_here_has", "issues", 99999, {}, DeliveryOwnership.ELSEWHERE),
- ("github_turned_off_for_the_team", "issues", 12345, {"github_enabled": False}, DeliveryOwnership.ELSEWHERE),
- (
- "no_explicit_integration_binding",
- "issues",
- 12345,
- {"github_integration_id": None},
- DeliveryOwnership.ELSEWHERE,
- ),
- ("an_event_type_this_product_ignores", "pull_request", 99999, {}, DeliveryOwnership.UNDECIDED),
- ("a_delivery_outside_an_installation", "issues", None, {}, DeliveryOwnership.UNDECIDED),
- ]
- )
- def test_ownership_answers_where_the_installations_team_lives(
- self,
- _name: str,
- event_type: str,
- installation_id: int | None,
- settings_override: dict[str, Any],
- expected: DeliveryOwnership,
- ):
- self._disable(settings_override)
- delivery = _delivery(_issue_event(installation_id=installation_id), event_type=event_type)
-
- assert conversations_facade.github_delivery_ownership(delivery) == expected
-
- @patch(f"{GITHUB_EVENTS_MODULE}.Integration.objects.filter")
- def test_a_lookup_that_hits_its_timeout_forwards_rather_than_claiming_the_delivery(self, mock_filter):
- # Forwarding is the recoverable answer: the other region repeats the lookup and no-ops if
- # it does not own the installation, while claiming it here would drop the delivery.
- mock_filter.side_effect = OperationalError("canceling statement due to statement timeout")
-
- answer = conversations_facade.github_delivery_ownership(_delivery(_issue_event()))
-
- assert answer == DeliveryOwnership.ELSEWHERE
-
@patch(f"{GITHUB_EVENTS_MODULE}.process_github_event")
@patch(f"{GITHUB_EVENTS_MODULE}.Integration.objects.filter")
def test_a_lookup_that_hits_its_timeout_fails_the_dispatch_rather_than_receipting_it(self, mock_filter, mock_task):
@@ -163,6 +124,7 @@ class TestConversationsGitHubDeliveries(BaseTest):
@parameterized.expand(
[
("github_turned_off_for_the_team", 12345, {"github_enabled": False}),
+ ("no_explicit_integration_binding", 12345, {"github_integration_id": None}),
("a_delivery_outside_an_installation", None, {}),
]
)
diff --git a/products/conversations/backend/webhook_consumers.py b/products/conversations/backend/webhook_consumers.py
index dce28653c2c3..7df977766bbf 100644
--- a/products/conversations/backend/webhook_consumers.py
+++ b/products/conversations/backend/webhook_consumers.py
@@ -1,10 +1,10 @@
"""Conversations' consumer on the customer-facing GitHub App endpoint.
-The registry imports this module on the first delivery, so it stays cheap: both callables defer
-their own product import.
+The registry imports this module on the first delivery, so it stays cheap: the callable defers
+its own product import.
"""
-from posthog.ingress.contracts import DeliveryOwnership, WebhookConsumer, WebhookDelivery
+from posthog.ingress.contracts import WebhookConsumer, WebhookDelivery
def _run_conversations(delivery: WebhookDelivery) -> None:
@@ -13,12 +13,6 @@ def _run_conversations(delivery: WebhookDelivery) -> None:
accept_github_event(delivery)
-def _github_ownership(delivery: WebhookDelivery) -> DeliveryOwnership:
- from products.conversations.backend.facade.api import github_delivery_ownership # noqa: PLC0415
-
- return github_delivery_ownership(delivery)
-
-
WEBHOOK_CONSUMERS = (
WebhookConsumer(
name="conversations",
@@ -26,6 +20,5 @@ WEBHOOK_CONSUMERS = (
app="posthog",
event_types=frozenset({"issues", "issue_comment"}),
handler=_run_conversations,
- ownership=_github_ownership,
),
)