Repository navigation
fix(spanner): revert sharing caller-provided GoogleAuth from #9957 - #9995
Closed
sakthivelmanii wants to merge 1 commit into
Closed
sakthivelmanii wants to merge 1 commit into
sakthivelmanii wants to merge 1 commit into
Conversation
Partially reverts #9957 (`3ce79be100`, `fix(spanner): respect universeDomain and custom endpoints in metrics`). Restores `this.auth = new GoogleAuth(this.options)` so a caller-provided `options.auth` instance is not shared with `Spanner.auth` or built-in metrics.
sakthivelmanii
marked this pull request as ready for review
November 30, 2026 20:12
sakthivelmanii
added a commit
that referenced
this pull request
Dec 1, 2026
…Client ## Problem Statement - Built-in metrics reused `Spanner.auth`, inheriting Spanner-specific `options.scopes` (such as `spanner.data` and `spanner.admin`) instead of requesting only the Cloud Monitoring write scope required to publish metrics. When a caller restricted `options.scopes` to Spanner-only scopes, metrics export lacked `https://www.googleapis.com/auth/monitoring.write`. - When a caller passed an unscoped `JWT` via `options.authClient` on `google-auth-library >= 11.3.2` (resolved by `^11.3.1`), `GoogleAuth.getClient()` calls `setGapicJWTValues()` on `cachedCredential`, latching `defaultServicePath` across `SpannerClient` and `MetricServiceClient` and causing `UNAUTHENTICATED` errors. ## Solution - Always construct a dedicated `GoogleAuth` lazily inside `_createMetricsAuth()` scoped strictly to `['https://www.googleapis.com/auth/monitoring.write']` when initializing a new metrics reader. - Clone a `JWT` passed via `options.authClient` with `jwt.createScoped(jwt.scopes)` so it gets an isolated instance for `google-auth-library >= 11.3.2` while preserving its original scope semantics (unscoped `JWT`s stay unscoped and keep local self-signed JWT signing with zero `oauth2.googleapis.com/token` calls on all versions). - Omit `universeDomain` from `_createMetricsAuth()` unless explicitly configured on `options` so TPC credential universe-domain mismatch validation remains active. - Note: Related changes were split into #9995 (partial revert of #9957 `options.auth` sharing) and #10000 (`universeDomain` validation and default-endpoint handling).
olavloite
requested changes
Dec 1, 2026
| options.auth instanceof GoogleAuth | ||
| ? options.auth | ||
| : new GoogleAuth(this.options); | ||
| this.auth = new GoogleAuth(this.options); |
Contributor
There was a problem hiding this comment.
Thanks for splitting this out, but after reviewing this alongside #9981 and #10000, I don't think we should merge #9995:
- Reverting
this.authback tonew GoogleAuth(this.options)restores the pre-9.1.1 split-brain situation:SpannerOptions(viaGrpcClientOptions) still exposesoptions.authand the underlyingv1GAPIC clients (SpannerClient,InstanceAdminClient,DatabaseAdminClient) still use it, whileSpanner.auth(getProjectId()) and built-in metrics silently ignoreoptions.authand fall back to ambient ADC. Also, if the goal of fix(spanner): revert sharing caller-provided GoogleAuth from #9957 #9995 was to make a behavior change from 9.1.1 clear in the release notes, the current PR title/description does not clearly communicate what changed for callers or what to use instead. - More importantly, fix(spanner): revert sharing caller-provided GoogleAuth from #9957 #9995 is not needed at all. Instead, we should close fix(spanner): revert sharing caller-provided GoogleAuth from #9957 #9995 and handle this in fix(spanner): scope metrics auth to monitoring.write and isolate authClient #9981 along the lines of my review comment: keep
options.authworking onSpanner.auth(ideally with a structural check rather thaninstanceof GoogleAuth), and have_createMetricsAuth()derive a fresh,monitoring.write-scopedGoogleAuthfromoptions.auth's credential source (jsonContent,keyFilename, clonedJWTauthClient, andclientOptions) without sharing or mutating the caller'sGoogleAuthinstance, backed by an unmocked test intest/metrics/spanner-metrics-exporter.ts. - Combining fix(spanner): fix universeDomain validation and default endpoint metrics #10000 with that update to fix(spanner): scope metrics auth to monitoring.write and isolate authClient #9981 will ensure there is no regression for anyone using 9.1.1, prevents built-in metrics from falling back to ambient ADC, and ensures
options.authis used by the Spanner client in a way that is consistent withgoogle-auth-library(wherecredentialsandkeyFilenameare now deprecated in favor ofoptions.auth).
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Statement
3ce79be100,fix(spanner): respect universeDomain and custom endpoints in metrics).Solution
this.auth = new GoogleAuth(this.options)so a caller-providedoptions.authinstance is not shared withSpanner.author built-in metrics.