-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(seer-infra-telemetry): Add Datadog site allowlist to identity provider #117541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shashjar
merged 16 commits into
master
from
shashjar/add-datadog-site-allowlist-validation
Jun 16, 2026
+48
−7
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
118f34f
Implement monitoring provider connection API endpoints
shashjar bbed6c0
:hammer_and_wrench: Sync API Urls to TypeScript
getsantry[bot] e01cffa
Fix typing
shashjar aed2996
Fixes / cleanup
shashjar f08d22a
More fixes
shashjar 41c4739
Add Datadog site allowlist to identity provider
shashjar 8243e7e
Merge branch 'master' into shashjar/add-monitoring-provider-connectio…
shashjar d852e40
Update endpoint implementation with new identity provider behavior
shashjar 2d63fb1
Make request validation consistent
shashjar 5b5dff1
Merge branch 'shashjar/add-monitoring-provider-connection-API-endpoin…
shashjar 73582f8
Fixes
shashjar 0b62de2
Cleanup
shashjar 21d95c6
Add validation to refresh identity flow
shashjar 53d7bed
Merge branch 'master' into shashjar/add-datadog-site-allowlist-valida…
shashjar cecb559
Fix merge
shashjar ff2ca14
Merge branch 'master' into shashjar/add-datadog-site-allowlist-valida…
shashjar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
src/sentry/api/endpoints/organization_monitoring_providers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| from django.http import HttpResponseRedirect | ||
| from rest_framework.request import Request | ||
| from rest_framework.response import Response | ||
|
|
||
| from sentry import features | ||
| from sentry.api.api_owners import ApiOwner | ||
| from sentry.api.api_publish_status import ApiPublishStatus | ||
| from sentry.api.base import control_silo_endpoint | ||
| from sentry.api.bases.organization import ( | ||
| ControlSiloOrganizationEndpoint, | ||
| OrganizationPermission, | ||
| ) | ||
| from sentry.identity.datadog.provider import DATADOG_VALID_SITES | ||
| from sentry.identity.pipeline import IdentityPipeline | ||
| from sentry.organizations.services.organization.model import RpcOrganization | ||
| from sentry.users.models.identity import Identity, IdentityProvider | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| MONITORING_PROVIDERS: dict[str, dict[str, str]] = { | ||
| "datadog": {"name": "Datadog"}, | ||
| "gcp": {"name": "Google Cloud Platform"}, | ||
| } | ||
|
|
||
| MONITORING_PROVIDER_FEATURE = "organizations:seer-infra-telemetry" | ||
|
|
||
|
|
||
| class MonitoringProviderPermission(OrganizationPermission): | ||
| scope_map = { | ||
| "GET": ["org:read", "org:write", "org:admin"], | ||
| "POST": ["org:write", "org:admin"], | ||
| "DELETE": ["org:write", "org:admin"], | ||
| } | ||
|
|
||
|
|
||
| @control_silo_endpoint | ||
| class OrganizationMonitoringProviderIndexEndpoint(ControlSiloOrganizationEndpoint): | ||
| owner = ApiOwner.CODING_WORKFLOWS | ||
| publish_status = { | ||
| "GET": ApiPublishStatus.PRIVATE, | ||
| } | ||
| permission_classes = (MonitoringProviderPermission,) | ||
|
|
||
| def get(self, request: Request, organization: RpcOrganization, **kwargs: object) -> Response: | ||
| if not features.has(MONITORING_PROVIDER_FEATURE, organization, actor=request.user): | ||
| return Response(status=404) | ||
|
|
||
| user_id = request.user.id | ||
| if user_id is None: | ||
| return Response(status=401) | ||
|
|
||
| connected_identities = { | ||
| identity.idp.type: identity | ||
| for identity in Identity.objects.filter( | ||
| idp__type__in=MONITORING_PROVIDERS.keys(), | ||
| user_id=user_id, | ||
| ).select_related("idp") | ||
| } | ||
|
|
||
| providers = [] | ||
| for key, meta in MONITORING_PROVIDERS.items(): | ||
| identity = connected_identities.get(key) | ||
| providers.append( | ||
| { | ||
| "provider": key, | ||
| "name": meta["name"], | ||
| "connected": identity is not None, | ||
| } | ||
| ) | ||
|
|
||
| return Response({"providers": providers}) | ||
|
|
||
|
|
||
| @control_silo_endpoint | ||
| class OrganizationMonitoringProviderDetailsEndpoint(ControlSiloOrganizationEndpoint): | ||
| owner = ApiOwner.CODING_WORKFLOWS | ||
| publish_status = { | ||
| "POST": ApiPublishStatus.PRIVATE, | ||
| "DELETE": ApiPublishStatus.PRIVATE, | ||
| } | ||
| permission_classes = (MonitoringProviderPermission,) | ||
|
|
||
| def post( | ||
| self, request: Request, organization: RpcOrganization, provider_key: str, **kwargs: object | ||
| ) -> Response: | ||
| if not features.has(MONITORING_PROVIDER_FEATURE, organization, actor=request.user): | ||
| return Response(status=404) | ||
|
|
||
| if request.user.id is None: | ||
| return Response(status=401) | ||
|
|
||
| if provider_key not in MONITORING_PROVIDERS: | ||
| return Response({"detail": "Unknown monitoring provider."}, status=400) | ||
|
|
||
| config: dict[str, str] = {} | ||
| if provider_key == "datadog": | ||
| site = request.data.get("site") | ||
| if not site: | ||
| return Response( | ||
| {"detail": "Datadog requires a 'site' parameter (e.g. 'datadoghq.com')."}, | ||
| status=400, | ||
| ) | ||
| elif site not in DATADOG_VALID_SITES: | ||
| return Response({"detail": f"Invalid Datadog site: {site}"}, status=400) | ||
| config["site"] = site | ||
|
|
||
| # Datadog: the IdentityProvider is auto-created during the pipeline | ||
| idp: IdentityProvider | None = None | ||
| if provider_key != "datadog": | ||
| idp, _ = IdentityProvider.objects.get_or_create(type=provider_key, external_id="") | ||
|
|
||
| pipeline = IdentityPipeline( | ||
| request=request._request, | ||
| provider_key=provider_key, | ||
| organization=organization, | ||
| provider_model=idp, | ||
| config=config, | ||
| ) | ||
| pipeline.initialize() | ||
|
|
||
| response = pipeline.current_step() | ||
|
|
||
| if isinstance(response, HttpResponseRedirect): | ||
| return Response({"redirectUrl": response.url}) | ||
|
|
||
| logger.error( | ||
| "monitoring_provider.connect.unexpected_response", | ||
| extra={"provider": provider_key, "response_type": type(response).__name__}, | ||
| ) | ||
| return Response({"detail": "Failed to start OAuth flow."}, status=500) | ||
|
|
||
| def delete( | ||
| self, request: Request, organization: RpcOrganization, provider_key: str, **kwargs: object | ||
| ) -> Response: | ||
| if not features.has(MONITORING_PROVIDER_FEATURE, organization, actor=request.user): | ||
| return Response(status=404) | ||
|
|
||
| user_id = request.user.id | ||
| if user_id is None: | ||
| return Response(status=401) | ||
|
|
||
| if provider_key not in MONITORING_PROVIDERS: | ||
| return Response({"detail": "Unknown monitoring provider."}, status=400) | ||
|
|
||
| identities = list( | ||
| Identity.objects.filter( | ||
| idp__type=provider_key, | ||
| user_id=user_id, | ||
| ) | ||
| ) | ||
|
|
||
| if not identities: | ||
| return Response({"detail": "Not connected to this provider."}, status=404) | ||
|
|
||
| for identity in identities: | ||
| identity.delete() | ||
|
|
||
| return Response(status=204) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.