Skip to content

fix(metrics): don't send ~/.netrc credentials on OTLP export - #35928

Merged
bolichen97 merged 1 commit into
mainfrom
crew/devmate/metrics-otlp-no-netrc
Nov 12, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
crew/devmate/metrics-otlp-no-netrc

Conversation

@kyleseaman

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A metrics OTLP export sends only the credential the operator configured for that destination, never a ~/.netrc login.

The metrics exporter's HTTP session had no auth and kept trust_env on. For such a session requests reads $NETRC (else ~/.netrc) for the collector's host and sends that entry as a Basic login. It replaces a configured Authorization header, or adds one where the destination set none.

Why it matters

A .netrc entry is usually there for another tool (git, curl, a package index) on the same host. Today a metrics destination can send that login to the collector without the operator choosing it, and a configured API key is replaced by it without any sign in the configuration. This hits every OTLP destination: the legacy telemetry.otlp_endpoint, each telemetry.otlp_endpoints entry, and a destination an edition builds in code.

Not a goal

What changed (motivation → approach → change)

Metrics exports stop sending a ~/.netrc login. A destination with a configured Authorization header sends exactly that header, and one without sends none.

requests reads .netrc only when neither the request nor the session has an auth. So export_session in src/kiro_crew/metrics/otlp_session.py gives every session with none of its own an auth that applies only the endpoint URL's own user:password@, which is what requests does with no auth and no .netrc match. An endpoint carrying its credentials in the URL keeps sending them.

Destination auth on its session
Legacy telemetry.otlp_endpoint the credential-provider session's own auth when it has one, else the URL-only one
telemetry.otlp_endpoints entry the URL-only one
Built in code with session the edition's own auth (same object) when set, else the URL-only one on the copy; the edition's session is not changed

Proxy and CA settings from the environment still apply, and max_redirects stays 0. docs/system-specs/modules/metrics.md describes the rule.

Backwards compatibility

Breaking: a collector that authenticated metrics only through a ~/.netrc entry for its host now receives no credential; the operator sets it as a destination header instead. Writer sweep on origin/main @ 9038eab: no built-in config, test or doc relies on .netrc for OTLP export (git grep -niE netrc over src/kiro_crew/metrics, src/kiro_crew/tracing, test/metrics, test/tracing, docs/guides/telemetry-otlp-export.md, docs/system-specs/modules/metrics.md and src/kiro_crew/docs finds only the sandbox's credential-file lists).

Reader: src/kiro_crew/metrics/provider.py:_build_otlp_reader -- release -- test_a_netrc_login_for_the_collector_host_is_never_sent

Tests

test_a_netrc_login_for_the_collector_host_is_never_sent (test/metrics/test_otlp_no_redirect.py) writes a fake login for 127.0.0.1 to a temp file named by NETRC. It then exports through the real SDK exporter to a loopback collector, for each of the three destination kinds, once with a configured Authorization: Bearer … header and once without. The collector must see exactly the configured header, or none. It needs the otlp extra.

test_no_session_sends_a_netrc_login_and_an_own_auth_is_kept (test/metrics/test_otlp_session.py) runs without the extra, with the SDK module stubbed. It posts through the session export_session returns for the list entry, the legacy plain and loaded sessions, and a supplied session, each with and without its own auth. A session without one sends no Authorization. One with its own sends that login, keeps the same object, and leaves the edition's session unchanged. trust_env stays on.

test_credentials_in_the_endpoint_url_are_still_sent_instead_of_netrc posts through the same four sessions without their own auth to a URL carrying user:password@, with the temp NETRC still set. The receiver must see the URL's login.

Proof: PROVEN test/metrics/test_otlp_no_redirect.py::test_a_netrc_login_for_the_collector_host_is_never_sent[legacy-with-authorization], test/metrics/test_otlp_no_redirect.py::test_a_netrc_login_for_the_collector_host_is_never_sent[legacy-no-header], test/metrics/test_otlp_no_redirect.py::test_a_netrc_login_for_the_collector_host_is_never_sent[list-entry-with-authorization], test/metrics/test_otlp_no_redirect.py::test_a_netrc_login_for_the_collector_host_is_never_sent[list-entry-no-header], test/metrics/test_otlp_no_redirect.py::test_a_netrc_login_for_the_collector_host_is_never_sent[edition-session-with-authorization] (head 4fed4f9)

All six exporter cases, the four no-auth session cases and the four URL-credential cases fail on origin/main, each receiving Basic … from the temp NETRC. The URL-credential cases also fail with a plain no-op auth, which drops the URL's login. The two own-auth cases pass on origin/main too, as expected.

Determinism (D12): the new tests pass 20/20 at -n0, all of test/metrics passes 10/10 at -n 4, and both changed files pass in a shuffled order (seed 20261112). test/metrics, test/tracing and test/test_lts_telemetry_endpoint.py: 1976 passed with the otlp extra installed; 1944 passed and 32 skipped without it, where otlp_session.py measures 100%.

Manual verification

N/A — the loopback tests drive the real requests session (and, with the extra, the real SDK exporter) end to end on 127.0.0.1 with a real netrc file.

Related Issues

N/A — standalone fix requested by a maintainer, as for #34101; no issue filed.

Sibling sweep

Swept: git grep -nE "requests.Session(|import requests$" -- src/kiro_crew
Sibling: src/kiro_crew/metrics/otlp_session.py -- changed here
Sibling: src/kiro_crew/_vendor/llama_cpp/llama_grammar.py:456 -- not affected -- a vendored schema fetch that carries no configured credential of ours

Pattern harvest

Rule candidate: review-prompt
Pattern: a requests.Session that sends a configured credential with trust_env on and no auth lets ~/.netrc replace that credential

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

A metrics OTLP exporter's requests session had no auth and kept
trust_env on, so requests read $NETRC (else ~/.netrc) for the
collector's host and sent that Basic login, replacing a configured
Authorization header or adding one where none was set.

export_session now gives every session it returns a no-op auth when it
has none of its own. A caller-supplied session's auth and the
credential-provider session's auth are kept. Proxy and CA settings from
the environment still apply, and max_redirects stays 0.
@kyleseaman
kyleseaman requested review from a team and KiroCrewCaptain as code owners November 12, 2026 17:10
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4fed4f980997afe8848c2fae52b4e5ab3d83567a touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4fed4f980997afe8848c2fae52b4e5ab3d83567a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the fix sets an auth on every session, which is the one hook requests checks before reading .netrc, and the URL-only auth keeps credentials written into the endpoint URL working.

Notes

[DESIGN-REVIEWED] 4fed4f9

Description read

[DESCRIPTION-READ] 421afadd1ab93be07c251b1b85236b81ab71dba7b921171ca2fbbaf5653e3493

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4fed4f980997afe8848c2fae52b4e5ab3d83567a — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The tests fail on base, which shows the defect, and the fix is in the one place every metrics destination builds its session. The trace-export case is declared and handled by #35792.

What this change ships

Inventory (4 items) — 4 justified

Intent: an operator's metrics export carries only the credential they set for that collector, never an unrelated ~/.netrc login. FIX.

  1. Metrics exports to any OTLP destination stop sending a ~/.netrc Basic login, so a configured Authorization header is no longer replaced — justified
  2. An endpoint with user:password@ in its URL still sends that login (_url_auth_only) — justified
  3. A collector that authenticated only through .netrc now gets no credential; the operator must set a destination header instead — justified
  4. The metrics spec now states the rule that every session has an auth — justified

[FIRST-PRINCIPLES-REVIEWED] 4fed4f9

Description read

[DESCRIPTION-READ] 3fbbdd7902730f9bf44f214a679b5ef5cc74f0bb7203845301df417382819730

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4fed4f980997afe8848c2fae52b4e5ab3d83567a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4fed4f9

Verdict parsed from the review's SHA-scoped output markers for commit 4fed4f980997afe8848c2fae52b4e5ab3d83567a.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4fed4f980997afe8848c2fae52b4e5ab3d83567a false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4fed4f980997afe8848c2fae52b4e5ab3d83567a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4fed4f9

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4fed4f980997afe8848c2fae52b4e5ab3d83567a false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 12, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. I read the product change in metrics/otlp_session.py and skimmed the doc and tests.

  • The fix is in the right place. requests reads $NETRC / ~/.netrc only when neither the request nor the session has an auth, so giving every auth-less session _url_auth_only stops a .netrc login reaching the collector, or replacing a configured Authorization header.
  • Nothing else changes. A session's own auth (the credential-provider session's, or an edition's) is kept as is. trust_env stays on for proxy and CA settings, and max_redirects stays 0.
  • request.prepare_auth(None) applies the endpoint URL's own user:password@, which is what requests does with no auth, so URL-embedded credentials keep working.
  • The only behaviour change is the data-safety one the body calls out: a collector that relied on a .netrc entry now needs a destination header.

@bolichen97
bolichen97 merged commit a73e356 into main Nov 12, 2026
151 of 153 checks passed
@bolichen97
bolichen97 deleted the crew/devmate/metrics-otlp-no-netrc branch November 12, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants