Repository navigation
fix(metrics): don't send ~/.netrc credentials on OTLP export - #35928
Conversation
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.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix sets an 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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 shipsInventory (4 items) — 4 justifiedIntent: an operator's metrics export carries only the credential they set for that collector, never an unrelated
[FIRST-PRINCIPLES-REVIEWED] 4fed4f9 Description read[DESCRIPTION-READ] 3fbbdd7902730f9bf44f214a679b5ef5cc74f0bb7203845301df417382819730 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
bolichen97
left a comment
There was a problem hiding this comment.
Approving. I read the product change in metrics/otlp_session.py and skimmed the doc and tests.
- The fix is in the right place.
requestsreads$NETRC/~/.netrconly when neither the request nor the session has anauth, so giving everyauth-less session_url_auth_onlystops a.netrclogin reaching the collector, or replacing a configuredAuthorizationheader. - Nothing else changes. A session's own
auth(the credential-provider session's, or an edition's) is kept as is.trust_envstays on for proxy and CA settings, andmax_redirectsstays 0. request.prepare_auth(None)applies the endpoint URL's ownuser:password@, which is whatrequestsdoes with noauth, 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
.netrcentry now needs a destination header.
Problem / Motivation
Goal: A metrics OTLP export sends only the credential the operator configured for that destination, never a
~/.netrclogin.The metrics exporter's HTTP session had no
authand kepttrust_envon. For such a sessionrequestsreads$NETRC(else~/.netrc) for the collector's host and sends that entry as a Basic login. It replaces a configuredAuthorizationheader, or adds one where the destination set none.Why it matters
A
.netrcentry 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 legacytelemetry.otlp_endpoint, eachtelemetry.otlp_endpointsentry, and a destination an edition builds in code.Not a goal
trust_envstays on).What changed (motivation → approach → change)
Metrics exports stop sending a
~/.netrclogin. A destination with a configuredAuthorizationheader sends exactly that header, and one without sends none.requestsreads.netrconly when neither the request nor the session has anauth. Soexport_sessioninsrc/kiro_crew/metrics/otlp_session.pygives every session with none of its own anauththat applies only the endpoint URL's ownuser:password@, which is whatrequestsdoes with noauthand no.netrcmatch. An endpoint carrying its credentials in the URL keeps sending them.authon its sessiontelemetry.otlp_endpointauthwhen it has one, else the URL-only onetelemetry.otlp_endpointsentrysessionauth(same object) when set, else the URL-only one on the copy; the edition's session is not changedProxy and CA settings from the environment still apply, and
max_redirectsstays 0.docs/system-specs/modules/metrics.mddescribes the rule.Backwards compatibility
Breaking: a collector that authenticated metrics only through a
~/.netrcentry 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.netrcfor OTLP export (git grep -niE netrcoversrc/kiro_crew/metrics,src/kiro_crew/tracing,test/metrics,test/tracing,docs/guides/telemetry-otlp-export.md,docs/system-specs/modules/metrics.mdandsrc/kiro_crew/docsfinds 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 for127.0.0.1to a temp file named byNETRC. It then exports through the real SDK exporter to a loopback collector, for each of the three destination kinds, once with a configuredAuthorization: Bearer …header and once without. The collector must see exactly the configured header, or none. It needs theotlpextra.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 sessionexport_sessionreturns for the list entry, the legacy plain and loaded sessions, and a supplied session, each with and without its ownauth. A session without one sends noAuthorization. One with its own sends that login, keeps the same object, and leaves the edition's session unchanged.trust_envstays on.test_credentials_in_the_endpoint_url_are_still_sent_instead_of_netrcposts through the same four sessions without their ownauthto a URL carryinguser:password@, with the tempNETRCstill 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-
authsession cases and the four URL-credential cases fail onorigin/main, each receivingBasic …from the tempNETRC. The URL-credential cases also fail with a plain no-opauth, which drops the URL's login. The two own-authcases pass onorigin/maintoo, as expected.Determinism (D12): the new tests pass 20/20 at
-n0, all oftest/metricspasses 10/10 at-n 4, and both changed files pass in a shuffled order (seed 20261112).test/metrics,test/tracingandtest/test_lts_telemetry_endpoint.py: 1976 passed with theotlpextra installed; 1944 passed and 32 skipped without it, whereotlp_session.pymeasures 100%.Manual verification
N/A — the loopback tests drive the real
requestssession (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.Sessionthat sends a configured credential withtrust_envon and noauthlets~/.netrcreplace that credentialChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)