fix google-auth: use auth.transport.requests as default#16076
fix google-auth: use auth.transport.requests as default#16076uweber wants to merge 1 commit intogoogleapis:mainfrom
Conversation
mTLS support was recently added and added a hard requirement for requests. google.auth.compute_engine would fail to load, if requests is missing, so its safe to switch to google.auth.transport.requests here. Therefore switch default from google.auth.transport._http_client.Request() to google.auth.transport.requests.Request() which is required for mTLS to work. Fixes the following code: import google.auth credentials, project_id = google.auth.default() print(project_id) Signed-off-by: Ulrich Weber <ulrich.weber@gmail.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request updates the core Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request successfully updates the default HTTP client for GCE credentials from google.auth.transport._http_client.Request to google.auth.transport.requests.Request. This change is crucial for enabling mTLS support, which has a hard requirement for the requests library. The code correctly removes the outdated import, integrates the new Request import within the try...except ImportError block, and updates the relevant comments to reflect the new rationale. My primary feedback is a suggestion to refine the warning message in the ImportError block for better debugging clarity.
| from google.auth.compute_engine import _metadata | ||
| from google.auth.transport.requests import Request | ||
| except ImportError: | ||
| _LOGGER.warning("Import of Compute Engine auth library failed.") |
There was a problem hiding this comment.
The ImportError block now handles potential failures from importing google.auth.transport.requests.Request in addition to compute_engine and _metadata. If the underlying requests library is missing, the current warning message "Import of Compute Engine auth library failed." might be misleading. Consider making the warning message more general to accurately reflect that multiple authentication-related libraries could have failed to import, which would aid in debugging.
_LOGGER.warning("Failed to import necessary authentication libraries for GCE.")|
We have a different PR that attempts to solve the same problem by disabling mtls enablement on |
With the mTLS support the _http_client code is no longer functional. Since default is to use mTLS when a certificate is found, no fallback to HTTP is possible anymore. And to use mTLS python request session is needed. |
mTLS support was recently added and added a hard requirement for requests. google.auth.compute_engine would fail to load, if requests is missing, so its safe to switch to google.auth.transport.requests here.
Therefore switch default from google.auth.transport._http_client.Request() to google.auth.transport.requests.Request() which is required for mTLS to work.
Fixes the following code:
import google.auth
credentials, project_id = google.auth.default()
print(project_id)
Fixes #16035