Title: Auth(mtls): `_has_logged_mtls_warning` masks distinct mTLS configuration errors · Issue #17697 · googleapis/google-cloud-python · GitHub
Open Graph Title: Auth(mtls): `_has_logged_mtls_warning` masks distinct mTLS configuration errors · Issue #17697 · googleapis/google-cloud-python
X Title: Auth(mtls): `_has_logged_mtls_warning` masks distinct mTLS configuration errors · Issue #17697 · googleapis/google-cloud-python
Description: Determine this is the right repository I determined this is the correct repository in which to report this bug. Summary of the issue Describe the bug In google.auth.transport._mtls_helper.py, the global boolean flag _has_logged_mtls_warn...
Open Graph Description: Determine this is the right repository I determined this is the correct repository in which to report this bug. Summary of the issue Describe the bug In google.auth.transport._mtls_helper.py, the g...
X Description: Determine this is the right repository I determined this is the correct repository in which to report this bug. Summary of the issue Describe the bug In google.auth.transport._mtls_helper.py, the g...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/17697
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Auth(mtls): `_has_logged_mtls_warning` masks distinct mTLS configuration errors","articleBody":"### Determine this is the right repository\n\n- [x] I determined this is the correct repository in which to report this bug.\n\n### Summary of the issue\n\n## Describe the bug\nIn `google.auth.transport._mtls_helper.py`, the global boolean flag `_has_logged_mtls_warning` is used to prevent log spam when mTLS auto-enablement fails. However, because it is a single global flag, it suppresses multiple distinct error conditions. \n\nIf a long-running application encounters one configuration error (e.g., file not found), the flag is set to `True`. If the user attempts to fix the configuration but introduces a different error (e.g., the JSON structure is invalid), the new error is silently swallowed for the lifetime of the process.\n\n## To Reproduce\n1. Create a Google API client with `GOOGLE_API_CERTIFICATE_CONFIG` pointing to a non-existent file.\n2. The client will log: `WARNING: mTLS auto-enablement failed: Could not read/parse certificate file...`\n3. Create the file at that path, but omit the required `['cert_configs']['workload']` JSON section.\n4. Create another Google API client in the same Python process.\n5. **Expected behavior:** A new warning should be logged stating the file is missing the required workload section.\n6. **Actual behavior:** No warning is logged. The client silently disables mTLS.\n\n## Root Cause & Context\nThis behavior was introduced in PR #17470 where the implementation used `_LOGGER.warning` combined with a custom global boolean `_has_logged_mtls_warning`. \nBecause the custom flag does not track *which* warning was logged, it permanently disables all future configuration warnings in the process after the first failure. Additionally, it never clears the cache upon a successful read, meaning transient errors will permanently disable warnings for the remainder of the process's lifetime.\n\n\n\n## Proposed Solution\n\nWe should drop the custom global `_has_logged_mtls_warning` state entirely and revert the log level back to `_LOGGER.debug(...)`.\n\n\n\n**Reasoning:**\n\n1. **It restores the intended fallback behavior:** Auto-enablement is designed to be a \"best-effort\" enhancement. If it fails, falling back to standard TLS silently keeps the application running. \n\n2. **Users requiring strict mTLS are protected:** If a user strictly requires mTLS, they should explicitly set `GOOGLE_API_USE_CLIENT_CERTIFICATE=\"true\"`. Doing so bypasses this auto-enablement fallback and hard-fails with a `ClientCertError` if the config is broken.\n\n3. **Debuggability is preserved:** If auto-enablement fails and the standard TLS fallback is subsequently rejected by a server requiring mTLS (e.g., returning a 401/403), the user can turn on debug logging to see exactly why their mTLS configuration was rejected.\n\n4. **Removes custom state:** Reverting to `debug` entirely eliminates the log spam risk, allowing us to safely remove the buggy global cache from this foundational library.","author":{"url":"https://github.com/nbayati","@type":"Person","name":"nbayati"},"datePublished":"2026-07-12T02:54:02Z","url":"https://github.com/googleapis/google-cloud-python/issues/17697"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:89d2088b-3ca3-4883-5bf7-4caf36f75ef5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE9C:10A6E7:7B7001:A9E6F5:6AFDF0EA |
| html-safe-nonce | 17aeef3a933d96ce4afaa8e9c84d653ddf572777518f136a4a869de04951f9bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTlDOjEwQTZFNzo3QjcwMDE6QTlFNkY1OjZBRkRGMEVBIiwidmlzaXRvcl9pZCI6IjgwMzk4MDA2ODk2NDA5OTMwMDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 64077c5f7433223ffcb421bc07b14cb2970d6e3fecda175b74da57c62694a505 |
| hovercard-subject-tag | issue:4865153342 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/17697/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9d900358b9da9b77af5b9814f667b9cd0274e8443a66e0f0bfec147db10238ee/googleapis/google-cloud-python/issues/17697 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9d900358b9da9b77af5b9814f667b9cd0274e8443a66e0f0bfec147db10238ee/googleapis/google-cloud-python/issues/17697 |
| og:image:alt | Determine this is the right repository I determined this is the correct repository in which to report this bug. Summary of the issue Describe the bug In google.auth.transport._mtls_helper.py, the g... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nbayati |
| hostname | github.com |
| expected-hostname | github.com |
| None | dd812ec581ecac95855f5ec917ef9827506c39a9da1443f43ddb4179a46471eb |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32ac708bac264dafdc28e10ff49b4d137f0c34a7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width