Skip to content

fix: ignore .netrc in backend requests - #454

Merged
uniqueg merged 3 commits into
devfrom
fix/no-netrc
Nov 7, 2026
Merged

uniqueg merged 3 commits into
devfrom
fix/no-netrc

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Requests to configured TES backends no longer get credentials from a .netrc file of the environment (~/.netrc, or NETRC). Before, requests added the Basic credentials of a matching entry to requests without credentials (auth: none, anonymous service-info reads), put them in place of proTES' access token, and looked them up again after each redirect.

  • BackendSession (a requests.Session) has a no-op session auth, so that requests never looks up .netrc for the first request, and overrides rebuild_auth so that redirects only drop credentials on host changes (as requests does) and never add any.

  • backend_request() sends each request to a configured backend through such a session (one per request, as requests.request does); proxies and CA certificates of the environment still apply (trust_env stays on).

  • Discovered backends use FOCA's guarded client, which ignores .netrc already.

  • Docs: access control (credentials of TES instances), upgrade notes, module docstring.

  • Identity provider of proTES (found in review): the token request and the discovery request pass a no-op auth too, so client_secret_post no longer gets netrc Basic credentials besides the form fields (two client authentication methods, which RFC 6749 forbids). Redirects of the discovery request still use requests' lookup (documented).

Closes #449

Verification

  • pytest with coverage (MongoDB mock, helm on PATH): 1720 passed, 11 skipped, 100% coverage (before the last test-only commit; tests/ga4gh/tes/test_backends.py after it: 195 passed).
  • pytest against MongoDB 7.0 (mongod --nounixsocket, own port): 1726 passed, 1 skipped (first commit).
  • ruff 0.17.3 (check, format), mypy, ast-grep (scan, test), semgrep: clean. mkdocs build --strict: clean.
  • test_netrc_ignored fails on dev (netrc Basic credentials on both hops, also in place of the token) and passes here.
  • CI: all checks passed (Lint, Test (mongomock), Test (MongoDB 7.0), Chart, Docs, Smoke test, Scan image, CodeQL, codecov).

Review

Full review: adversarial-reviewer and quality-reviewer (round 1), both again in round 2 (quality had medium findings, and the identity provider fix changes logic). Fixed: the identity provider requests, the docs on which redirects drop credentials (also ports and https to http), one parametrized case per redirect, stale docstrings, Path type, keyword arguments; round 2 (low): the http-to-https redirect case, a check that NO_CREDENTIALS keeps .netrc out, docs wording.

Declined review findings

  • Extract a shared helper for the local test servers (quality, medium): the four existing handlers serve different things with their own setup; refactoring them is outside fix: don't apply ambient .netrc credentials to backend requests #449.
  • End-to-end redirect to another host (adversarial and quality, low): the tests allow connections to 127.0.0.1 only and block name resolution, so a second host name isn't available; test_session_redirect_credentials covers cross-host, cross-port and https-to-http redirects on rebuild_auth, where requests looks up .netrc again.
  • Send the identity provider's discovery request through BackendSession too (adversarial, low): its redirects still get .netrc credentials of the redirect target (documented); the tests fake the identity provider at requests.get/post, and fix: don't apply ambient .netrc credentials to backend requests #449 covers TES backends.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Prevent environment .netrc credentials from leaking into TES backend and identity-provider requests while retaining intended authentication and environment networking behavior.

Bug Fixes:

  • Prevent requests to configured TES backends and proTES identity-provider endpoints from receiving credentials from the environment's .netrc file, including after redirects.
  • Preserve explicitly supplied backend credentials while dropping them on redirects where requests would normally strip them.

Enhancements:

  • Continue applying environment proxy and CA certificate settings to backend requests while isolating credential handling in a dedicated backend request session.

Documentation:

  • Document .netrc credential handling for TES backends, identity-provider requests, redirects, and the upgrade path for deployments relying on .netrc authentication.

Tests:

  • Add coverage for ignoring .netrc credentials, redirect credential behavior, explicit no-credential requests, and inherited proxy and CA settings.

uniqueg and others added 3 commits November 7, 2026 07:18
requests takes Basic credentials from a .netrc file of the environment
for requests without credentials, puts them in place of proTES' access
token, and looks them up again after redirects. Requests to configured
backends now go through BackendSession, which never reads .netrc: a
no-op session auth keeps it from the first request, and rebuild_auth
only drops credentials on redirects to other hosts. Proxies and CA
certificates of the environment still apply.

Document it in the access control page and the upgrade notes.

Closes #449

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The token request of client_secret_post got Basic credentials of a
matching .netrc entry besides the client's form fields (two client
authentication methods, which RFC 6749 forbids), and the discovery
request got them too. Both now pass NO_CREDENTIALS.

Document which redirects drop credentials (other hosts or ports, https
to http), parametrize the redirect test per case, and fix stale test
docstrings and type hints.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the http-to-https redirect on default ports, a check that requests
with NO_CREDENTIALS get nothing from .netrc, and reword which redirects
keep credentials.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.6.0 milestone Nov 7, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Route configured-backend requests through a session that suppresses .netrc credentials while preserving the intended redirect and environment behavior.

  • pro_tes/ga4gh/tes/backends.py L25-27, L1003, L1113-1179

Pass the no-op authentication handler to identity-provider discovery and token requests so those requests do not acquire .netrc credentials.

  • pro_tes/ga4gh/tes/backends.py L301-302, L353-354

Documentation

Explain which credentials TES requests receive and how redirects and environment settings affect them.

  • docs/access-control.md L249-259

Document the .netrc behavior change and the configuration users should use if a backend relied on those credentials.

  • docs/upgrading.md L94-102

Tests

Update backend-version tests to replace the new backend request wrapper rather than requests.request.

  • tests/ga4gh/tes/test_backend_versions.py L328-503 (5 small edits)

Verify the identity-provider requests suppress .netrc credentials and adapt backend request fakes to the new wrapper.

  • tests/ga4gh/tes/test_backends.py L740-745, L1166-1316 (+11 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35714909 | 📁 Comparing a336705 against latest (b423d7c)

  🔍 Preview build  

3 files changed
± access-control/index.html
± reference/index.html
± upgrading/index.html

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b423d7c) to head (a336705).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #454   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines         2817      2832   +15     
=========================================
+ Hits          2817      2832   +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 7, 2026 06:48

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Linked issues

#449 fix: don't apply ambient .netrc credentials to backend requests · 3 of 3 met

# Requirement Status Notes
1 No request to a TES backend gets credentials from .netrc, including requests without credentials, requests with the token or Basic credentials, and requests after redirects. ✅ Met BackendSession sets a no-op session auth and overrides redirect auth rebuilding; the tests cover anonymous, Bearer, and Basic credentials, including a real redirect.
2 Proxy and CA settings of the environment still apply. ✅ Met BackendSession retains the default environment trust behavior, and test_session_environment checks proxy and CA settings.
3 Tests cover the first request and a redirect; the credentials-of-TES-instances docs explain the behavior. ✅ Met test_netrc_ignored checks the initial and redirected requests, and the access-control page documents .netrc handling and redirect credential behavior.

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit a1ac9c7 into dev Nov 7, 2026
60 of 64 checks passed
@uniqueg
uniqueg deleted the fix/no-netrc branch November 7, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: don't apply ambient .netrc credentials to backend requests

1 participant