Skip to content

ci(tests): Add an outbound network guard in report mode on master - #131165

Draft
sentry-junior[bot] wants to merge 1 commit into
masterfrom
ci/network-guard-report
Draft

sentry-junior[bot] wants to merge 1 commit into
masterfrom
ci/network-guard-report

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

This re-lands the network guard from #127944 on current master, in a mode that can't break anything. #127945, #127946, #127947, getsentry/getsentry#22583 and getsentry/getsentry#22585 fixed what it found last time. Without a guard, real network calls in tests will creep back in.

Merge order: this PR first, then getsentry/getsentry#23239, which turns the guard on for getsentry.

What it does

sentry.testutils.pytest.network_guard is the same plugin as in #127944. It patches the Python socket connect and resolver entry points and records each attempt to reach a host outside the runner, per test, with the target and a short origin stack. xdist workers send their records to the controller. The allowlist (loopback, the unspecified address, the local hostname, the live server bridge IP, the reporting DSN hosts), the low-overhead design, and the native-client gap (libpq, librdkafka, grpc core) are unchanged. #127944 has the measurements.

Changes from #127944:

  • Off by default, also in CI. backend.yml sets report on master pushes and manual runs only. Pull requests run with the guard off and pay nothing.
  • Nothing fails. The JSON report is uploaded as network-guard-<run>-<shard>, and the upload step is continue-on-error.
  • New offenders show up in the job summary. Each shard appends a table of the tests that reached the network and aren't known offenders, with the attempt and its origin frame.
  • Known offenders file. tests/network_guard_known_offenders.txt (relative to the pytest rootdir) takes test files, classes, or test nodeids. Their attempts are still recorded but listed separately, and strict mode doesn't block them, so strict can be turned on with the remaining debt exempted per test. The summary also lists entries that ran clean, so the file shrinks as tests get fixed. It starts empty.

Offenders on master today

20 tests in 9 files reach 8 hostnames. None of them are known offenders yet.

  • slack.com: 9 test_on_agent_update_* tests in tests/sentry/seer/entrypoints/slack/test_slack.py. These make real HTTPS connections through slack_sdk.
  • api.github.com and controlserver: 6 tests in tests/sentry/tasks/test_post_process.py (4), tests/sentry/tasks/test_commit_context.py and tests/sentry/issues/auto_source_code_config/test_process_event.py. These are lookups only, from safe_create_connection and get_control_silo_ip_address.
  • example.com, new.com and other.com: 3 tests in tests/sentry/sentry_apps/api/endpoints/test_project_legacy_webhooks.py. is_safe_hostname looks these up while validating webhook URLs.
  • abc: 1 test in tests/sentry/integrations/perforce/test_integration.py, a lookup from is_safe_hostname.
  • testserver: 1 test in tests/sentry/middleware/test_notification_tracking.py, a lookup from proxy_cell_request.

Open decisions

  • Fix these 20 tests, or list them as known offenders first. The Slack tests come first, because they make real connections.
  • When to switch master to strict. Proposal: after a week or two of master runs with no new offenders. Also whether pull requests should run it then, since the guard has no measurable cost.
  • Whether new offenders on master should notify someone, or only appear in the job summary.

via @joshuarli.

--

View Session [Sentry]

Re-lands the network guard plugin from #127944 on current master. It records
tests that reach hosts outside the CI runner. CI runs it in report mode on
master pushes and manual runs only, uploads the JSON report, and writes new
offenders to the job summary. Nothing fails.

tests/network_guard_known_offenders.txt lists tests that still reach the
network, so the report separates them from new ones and a later strict mode
can exempt them per test.

Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 14, 2026
@linear-code

linear-code Bot commented Nov 14, 2026

Copy link
Copy Markdown

DI-2858

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant