Title: Fix(auth): incorrect mTLS endpoint detection causes false positive cert rotations and breaks PSC endpoints · Issue #18147 · googleapis/google-cloud-python · GitHub
Open Graph Title: Fix(auth): incorrect mTLS endpoint detection causes false positive cert rotations and breaks PSC endpoints · Issue #18147 · googleapis/google-cloud-python
X Title: Fix(auth): incorrect mTLS endpoint detection causes false positive cert rotations and breaks PSC endpoints · Issue #18147 · googleapis/google-cloud-python
Description: Description In PR #17928, a check was added to AuthorizedSession.request (and pre-existed in AuthorizedHttp.urlopen) to only trigger mTLS client certificate rotation on mTLS endpoints upon receiving a 401 Unauthorized response: MTLS_URL_...
Open Graph Description: Description In PR #17928, a check was added to AuthorizedSession.request (and pre-existed in AuthorizedHttp.urlopen) to only trigger mTLS client certificate rotation on mTLS endpoints upon receivin...
X Description: Description In PR #17928, a check was added to AuthorizedSession.request (and pre-existed in AuthorizedHttp.urlopen) to only trigger mTLS client certificate rotation on mTLS endpoints upon receivin...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/18147
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fix(auth): incorrect mTLS endpoint detection causes false positive cert rotations and breaks PSC endpoints","articleBody":"### Description\nIn PR #17928, a check was added to `AuthorizedSession.request` (and pre-existed in `AuthorizedHttp.urlopen`) to only trigger mTLS client certificate rotation on mTLS endpoints upon receiving a `401 Unauthorized` response:\n\n```python\nMTLS_URL_PREFIXES = [\"mtls.googleapis.com\", \"mtls.sandbox.googleapis.com\"]\nuse_mtls = self.is_mtls and any(prefix in url for prefix in MTLS_URL_PREFIXES)\n```\n\n**However, this implementation has two critical defects:**\n\n1. False Positives via Substring Matching (prefix in url)\nUsing Python's in operator performs a substring search across the entire URL string (including path segments and query parameters). Any standard, non-mTLS URL that happens to contain mtls.googleapis.com anywhere in its path or query string (e.g. https://storage.googleapis.com/my-bucket/logs/mtls.googleapis.com.csv or https://logging.googleapis.com/v2/entries?filter=mtls.googleapis.com) evaluates to True. When an OAuth access token expires on these non-mTLS URLs, the transport falsely assumes the client certificate expired, triggering unnecessary certificate parsing, disk I/O, and SSL adapter reconfiguration.\n\n2. False Negatives on Private Service Connect (PSC) Endpoints\nEnterprise customers connecting via Private Service Connect (PSC) use endpoints under *.p.googleapis.com (e.g. https://storage.p.googleapis.com or https://pubsub.p.googleapis.com). These endpoints use mTLS, but because their hostname does not contain the substring mtls.googleapis.com, use_mtls evaluates to False. As a result, client certificate rotation upon certificate expiration is permanently broken for PSC users.\n\n**Expected Behavior**\n\n- Only genuine mTLS endpoints (e.g. *.mtls.googleapis.com, *.mtls.sandbox.googleapis.com, and *.p.googleapis.com) should trigger certificate rotation checks.\n- URL paths and query parameters should not influence mTLS endpoint detection.\n\n**Actual Behavior**\n\n- Non-mTLS URLs containing mtls.googleapis.com in paths/queries trigger certificate rotation on 401.\n- PSC mTLS endpoints (*.p.googleapis.com) fail to trigger certificate rotation on 401.\n\n**Proposed Solution**\n\n1. Introduce a centralized helper is_mtls_endpoint(url) in google.auth.transport._mtls_helper that isolates and parses the hostname using urllib.parse.urlsplit(url).hostname.\n2. Validate the hostname against:\n - Exact hosts: mtls.googleapis.com, mtls.sandbox.googleapis.com\n - Standard mTLS suffixes: .mtls.googleapis.com, .mtls.sandbox.googleapis.com\n - Private Service Connect (PSC) suffixes: .p.googleapis.com\n3. Update both requests.py (AuthorizedSession) and urllib3.py (AuthorizedHttp) to use this shared helper.","author":{"url":"https://github.com/attharva-24","@type":"Person","name":"attharva-24"},"datePublished":"2026-08-18T21:59:24Z","url":"https://github.com/googleapis/google-cloud-python/issues/18147"}
| 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:de703196-6980-f41d-aa19-e681c3985bf2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EE20:10CB0:42569C:56F4BD:6AFE62A1 |
| html-safe-nonce | 93e172ae14e571fd854e106b7e1edc85d2d7978853c40ecebafa6d342acfdc6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTIwOjEwQ0IwOjQyNTY5Qzo1NkY0QkQ6NkFGRTYyQTEiLCJ2aXNpdG9yX2lkIjoiMTU0OTY3NjE3OTg4NjA3MjQ4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c0f8953b6aa247aee439d962bb4c47394e534c0e64cb2d112a080e93636a66c5 |
| hovercard-subject-tag | issue:5186691574 |
| 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/18147/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5bf2a2f0aa4f95fb0779bafde067e84e2c09e4cbd1ab3c1def7e0484a2f9e175/googleapis/google-cloud-python/issues/18147 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5bf2a2f0aa4f95fb0779bafde067e84e2c09e4cbd1ab3c1def7e0484a2f9e175/googleapis/google-cloud-python/issues/18147 |
| og:image:alt | Description In PR #17928, a check was added to AuthorizedSession.request (and pre-existed in AuthorizedHttp.urlopen) to only trigger mTLS client certificate rotation on mTLS endpoints upon receivin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | attharva-24 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| 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 | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width