Repository navigation
fix: ignore .netrc in backend requests - #454
Conversation
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]>
Reviewer's GuideImplementationRoute configured-backend requests through a session that suppresses
Pass the no-op authentication handler to identity-provider discovery and token requests so those requests do not acquire
DocumentationExplain which credentials TES requests receive and how redirects and environment settings affect them.
Document the
TestsUpdate backend-version tests to replace the new backend request wrapper rather than
Verify the identity-provider requests suppress
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.
Summary
Requests to configured TES backends no longer get credentials from a
.netrcfile of the environment (~/.netrc, orNETRC). Before,requestsadded 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(arequests.Session) has a no-op sessionauth, so thatrequestsnever looks up.netrcfor the first request, and overridesrebuild_authso that redirects only drop credentials on host changes (asrequestsdoes) and never add any.backend_request()sends each request to a configured backend through such a session (one per request, asrequests.requestdoes); proxies and CA certificates of the environment still apply (trust_envstays on).Discovered backends use FOCA's guarded client, which ignores
.netrcalready.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
authtoo, soclient_secret_postno longer gets netrc Basic credentials besides the form fields (two client authentication methods, which RFC 6749 forbids). Redirects of the discovery request still userequests' lookup (documented).Closes #449
Verification
pytestwith coverage (MongoDB mock, helm on PATH): 1720 passed, 11 skipped, 100% coverage (before the last test-only commit;tests/ga4gh/tes/test_backends.pyafter it: 195 passed).pytestagainst MongoDB 7.0 (mongod --nounixsocket, own port): 1726 passed, 1 skipped (first commit).mkdocs build --strict: clean.test_netrc_ignoredfails on dev (netrc Basic credentials on both hops, also in place of the token) and passes here.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,
Pathtype, keyword arguments; round 2 (low): the http-to-https redirect case, a check thatNO_CREDENTIALSkeeps.netrcout, docs wording.Declined review findings
test_session_redirect_credentialscovers cross-host, cross-port and https-to-http redirects onrebuild_auth, whererequestslooks up.netrcagain.BackendSessiontoo (adversarial, low): its redirects still get.netrccredentials of the redirect target (documented); the tests fake the identity provider atrequests.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
.netrccredentials from leaking into TES backend and identity-provider requests while retaining intended authentication and environment networking behavior.Bug Fixes:
.netrcfile, including after redirects.requestswould normally strip them.Enhancements:
Documentation:
.netrccredential handling for TES backends, identity-provider requests, redirects, and the upgrade path for deployments relying on.netrcauthentication.Tests:
.netrccredentials, redirect credential behavior, explicit no-credential requests, and inherited proxy and CA settings.