Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(storage): use ALTS for Compute Engine credentials on DirectPath endpoints - #16759

Draft
kalragauri wants to merge 2 commits into
googleapis:mainfrom
kalragauri:feat/storage-compute-engine-directpath
Draft

kalragauri wants to merge 2 commits into
googleapis:mainfrom
kalragauri:feat/storage-compute-engine-directpath

Conversation

@kalragauri

@kalragauri kalragauri commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

MakeComputeEngineCredentials() creates TLS-only channels on gRPC (GrpcComputeEngineAuthentication), and DirectPath backends require ALTS. An application that sets EndpointOption to a google-c2p:/// target with these credentials therefore loses DirectPath: the handshakes to the DirectPath backends fail and gRPC falls back to the front-end cluster over the single google-c2p channel.

With the new internal option GrpcComputeEngineUseGoogleDefaultOption, CreateAuthenticationStrategy() builds the channel credentials for Compute Engine credentials from grpc::GoogleDefaultCredentials(), which negotiate ALTS with DirectPath backends. It does so only when ComputeEngineGoogleDefaultFallbackReason() returns std::nullopt: neither GOOGLE_APPLICATION_CREDENTIALS nor the well-known gcloud Application Default Credentials file can be loaded by gRPC, so the identity remains the metadata server's, and neither CARootsFilePathOption nor GrpcGoogleDefaultTlsOnlyOption is in use. When the option is set, the strategy logs at INFO if grpc::GoogleDefaultCredentials() is selected, or logs a WARNING naming the blocking condition (or null return from gRPC) before falling back to GrpcComputeEngineAuthentication. DefaultOptionsGrpc() sets the option only for Compute Engine credentials on a non-Interconnect DirectPath endpoint (matching GrpcGoogleDefaultTlsOnlyOption when gRPC ignores force-xds) on a host with a Google Cloud BIOS; the default endpoint for these credentials stays CloudPath. MakeMinimalIamCredentialsOptions() drops the option and CreateStorageIamStub() builds its authentication strategy from those options, so the IAM Credentials channel does not change.

ExplicitDirectPathEndpointWithNonAltsCredsTest now uses access token credentials, because Compute Engine credentials query the GCP detector on these endpoints. Whether gRPC returns credentials depends on the host, so WithComputeEngineCredentialsUseGoogleDefault and IamStubIgnoresComputeEngineUseGoogleDefaultOption tell the two strategies apart only on Compute Engine, and the null-return warning branch is reached only on hosts where gRPC returns no credentials; the option guards and standard credential-file checks are tested on every platform through ComputeEngineGoogleDefaultFallbackReason() and CreateAuthenticationStrategy(), and the filesystem error cases on POSIX. Verified live on a Compute Engine VM with gRPC 1.81.1 and gRPC 1.65.5 that MakeComputeEngineCredentials() with EndpointOption("google-c2p:///storage.googleapis.com") connects to DirectPath backends over ALTS when clean and logs the expected warning before falling back to TLS-only when GOOGLE_APPLICATION_CREDENTIALS, a well-known gcloud ADC file, or CARootsFilePathOption is set (plus an unsearchable HOME on gRPC 1.81.1).

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Dec 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the GrpcComputeEngineUseGoogleDefaultOption option, which allows Compute Engine credentials to negotiate ALTS using grpc::GoogleDefaultCredentials() on DirectPath endpoints when safety conditions are met (such as no custom CA roots, no local ADC file override, and running on a Google Cloud BIOS). It also ensures that the IAM credentials stub ignores this option, as it only applies to the main Cloud Storage endpoint. Regarding the review feedback, there is a style guide violation in storage_stub_factory.cc where auto is used for a return type that should be explicitly declared.

Comment on lines +143 to +144
auto auth = google::cloud::internal::CreateAuthenticationStrategy(
std::move(cq), options);
return google::cloud::internal::MakeMinimalIamCredentialsStub(
std::move(auth),
google::cloud::internal::MakeMinimalIamCredentialsOptions(options));
std::move(cq), iam_options);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

According to the repository style guide, using auto is disallowed when it obscures function return types or domain objects. Please explicitly specify the return type std::shared_ptr<google::cloud::internal::GrpcAuthenticationStrategy> instead of using auto.

  std::shared_ptr<google::cloud::internal::GrpcAuthenticationStrategy> auth =
      google::cloud::internal::CreateAuthenticationStrategy(
          std::move(cq), iam_options);
References
  1. Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.88991% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.95%. Comparing base (daf351d) to head (b2676b1).

Files with missing lines Patch % Lines
...le/cloud/internal/unified_grpc_credentials_test.cc 89.37% 27 Missing ⚠️
google/cloud/internal/unified_grpc_credentials.cc 91.83% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16759    +/-   ##
========================================
  Coverage   92.95%   92.95%            
========================================
  Files        2284     2284            
  Lines      234065   234484   +419     
========================================
+ Hits       217566   217970   +404     
- Misses      16499    16514    +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant