Skip to content

fix(spanner): revert sharing caller-provided GoogleAuth from #9957 - #9995

Closed
sakthivelmanii wants to merge 1 commit into
mainfrom
revert-spanner-shared-google-auth
Closed

sakthivelmanii wants to merge 1 commit into
mainfrom
revert-spanner-shared-google-auth

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Problem Statement

Solution

  • Restore this.auth = new GoogleAuth(this.options) so a caller-provided options.auth instance is not shared with Spanner.auth or built-in metrics.

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.
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Nov 30, 2026
@sakthivelmanii
sakthivelmanii marked this pull request as ready for review November 30, 2026 20:12
@sakthivelmanii
sakthivelmanii requested review from a team as code owners 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 olavloite self-assigned this Dec 1, 2026
options.auth instanceof GoogleAuth
? options.auth
: new GoogleAuth(this.options);
this.auth = new GoogleAuth(this.options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting this out, but after reviewing this alongside #9981 and #10000, I don't think we should merge #9995:

  1. Reverting this.auth back to new GoogleAuth(this.options) restores the pre-9.1.1 split-brain situation: SpannerOptions (via GrpcClientOptions) still exposes options.auth and the underlying v1 GAPIC clients (SpannerClient, InstanceAdminClient, DatabaseAdminClient) still use it, while Spanner.auth (getProjectId()) and built-in metrics silently ignore options.auth and 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.
  2. 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.auth working on Spanner.auth (ideally with a structural check rather than instanceof GoogleAuth), and have _createMetricsAuth() derive a fresh, monitoring.write-scoped GoogleAuth from options.auth's credential source (jsonContent, keyFilename, cloned JWT authClient, and clientOptions) without sharing or mutating the caller's GoogleAuth instance, backed by an unmocked test in test/metrics/spanner-metrics-exporter.ts.
  3. 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.auth is used by the Spanner client in a way that is consistent with google-auth-library (where credentials and keyFilename are now deprecated in favor of options.auth).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense — closing #9995 and updated #9981 to keep options.auth on Spanner.auth (with a structural check) and derive a fresh monitoring.write-scoped GoogleAuth from its credential source in _createMetricsAuth() with unmocked RSA tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants