Skip to content

fix(storage): resolve universe domain from options and env - #10001

Merged
kalragauri merged 12 commits into
googleapis:mainfrom
thiyaguk09:fix/storage-universe-domain-resolution
Dec 3, 2026
Merged

kalragauri merged 12 commits into
googleapis:mainfrom
thiyaguk09:fix/storage-universe-domain-resolution

Conversation

@thiyaguk09

@thiyaguk09 thiyaguk09 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

@google-cloud/storage resolves the client universe domain from options.universeDomain, then GOOGLE_CLOUD_UNIVERSE_DOMAIN, and defaults to 'googleapis.com', keeping apiEndpoint independent of the universe domain, omitting top-level universeDomain from GoogleAuth so credential-derived client.universeDomain values are preserved (including apiKey and .pem/.p12 clients), and validating conflicting clientOptions universe settings during construction when no authClient is provided.

Unchanged Behavior

Default 'googleapis.com' configuration without GOOGLE_CLOUD_UNIVERSE_DOMAIN, pre-PR storage.customEndpoint and generateSignedPostPolicyV4() behavior, emulator (STORAGE_EMULATOR_HOST) and GCE Compute flows without conflicting clientOptions universe keys, and unauthenticated custom-endpoint upload paths remain unchanged. Passing conflicting clientOptions.universeDomain or clientOptions.universe_domain without an explicit authClient now throws at new Storage() construction time (including on Compute).

Tests Updated

Updated unit tests in test/index.ts, test/storage-transport.ts, test/resumable-upload.ts, test/file.ts, and test/util.ts.

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Dec 1, 2026
@thiyaguk09 thiyaguk09 changed the title fix(storage): resolve universe domain from options, env, and authClient fix(storage): resolve universe domain from options and env Dec 2, 2026
@thiyaguk09
thiyaguk09 marked this pull request as ready for review December 2, 2026 14:53
@thiyaguk09
thiyaguk09 requested review from a team as code owners December 2, 2026 14:53
Comment thread handwritten/storage/src/util.ts Outdated
clientOptions,
};
if (normalizedConfigured) {
authOptions.universeDomain = normalizedConfigured;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Setting authOptions.universeDomain here makes GoogleAuth copy the configured universe into this.clientOptions.universeDomain, which then overwrites client.universeDomain in fromJSON, fromStreamAsync, and fromAPIKey. For non-JSON clients (apiKey, .pem/.p12) where jsonContent is null, assertUniverseDomain ends up comparing the configured universe against itself.

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.

Fixed. buildGoogleAuthOptions() now strips authOptions.universeDomain, with tests added for apiKey and .pem mismatches.

Comment thread handwritten/storage/src/storage.ts Outdated
this.customEndpoint = true;
if (options.apiEndpoint) {
apiEndpoint = sanitizeEndpoint(options.apiEndpoint);
if (isCustomEndpoint(apiEndpoint, universe)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

isCustomEndpoint() treats apiEndpoint: 'storage.googleapis.com' and 'https://storage.googleapis.com/' as non-custom, flipping storage.customEndpoint to false and changing the url returned by generateSignedPostPolicyV4(). That behavior change is unrelated to universe domain resolution. Consider using isCustomEndpoint() only for hasCustomApiEndpoint here, or moving the customEndpoint change to a separate PR.

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.

Fixed. restored this.customEndpoint behavior, scoped isCustomEndpoint() to hasCustomApiEndpoint, and reverted the test/file.ts changes.

);
});

it('should compare custom endpoints after sanitizing', () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This test does not cover the protocol, pathname, search, and hash conditions or the catch branch of isCustomEndpoint(), so each could be removed without a failure.

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.

Added coverage for protocol, username, password, pathname, search, hash and the catch branch.

);
});

it('should allow explicit DEFAULT_UNIVERSE via universeDomain to override GOOGLE_CLOUD_UNIVERSE_DOMAIN', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No test combines a non-default GOOGLE_CLOUD_UNIVERSE_DOMAIN with an explicit apiEndpoint: 'https://storage.googleapis.com'. Consider adding a test verifying that default-universe credentials are rejected unless universeDomain: 'googleapis.com' is also passed.

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.

Added tests verifying default-universe credentials are rejected unless universeDomain: 'googleapis.com' is explicitly passed.

@kalragauri

Copy link
Copy Markdown

## Unchanged Behavior says default 'googleapis.com' configuration without GOOGLE_CLOUD_UNIVERSE_DOMAIN and Compute flows stay unchanged. This PR still changes storage.customEndpoint and generateSignedPostPolicyV4() for inputs like 'storage.googleapis.com', and throws in new Storage() for conflicting clientOptions universe keys (including on Compute). Could you tighten that section once the comments above are resolved?

@thiyaguk09

Copy link
Copy Markdown
Contributor Author

## Unchanged Behavior says default 'googleapis.com' configuration without GOOGLE_CLOUD_UNIVERSE_DOMAIN and Compute flows stay unchanged. This PR still changes storage.customEndpoint and generateSignedPostPolicyV4() for inputs like 'storage.googleapis.com', and throws in new Storage() for conflicting clientOptions universe keys (including on Compute). Could you tighten that section once the comments above are resolved?

Updated. Restored pre-PR customEndpoint / generateSignedPostPolicyV4() behavior and clarified the intentional throwing behavior for conflicting clientOptions universe keys.

@thiyaguk09
thiyaguk09 requested a review from kalragauri December 3, 2026 08:39
@kalragauri
kalragauri requested a review from bshaffer December 3, 2026 10:09
@kalragauri
kalragauri merged commit 7393449 into googleapis:main Dec 3, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants