Repository navigation
fix(storage): use ALTS for Compute Engine credentials on DirectPath endpoints - #16759
kalragauri wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
MakeComputeEngineCredentials()creates TLS-only channels on gRPC (GrpcComputeEngineAuthentication), and DirectPath backends require ALTS. An application that setsEndpointOptionto agoogle-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 singlegoogle-c2pchannel.With the new internal option
GrpcComputeEngineUseGoogleDefaultOption,CreateAuthenticationStrategy()builds the channel credentials for Compute Engine credentials fromgrpc::GoogleDefaultCredentials(), which negotiate ALTS with DirectPath backends. It does so only whenComputeEngineGoogleDefaultFallbackReason()returnsstd::nullopt: neitherGOOGLE_APPLICATION_CREDENTIALSnor the well-known gcloud Application Default Credentials file can be loaded by gRPC, so the identity remains the metadata server's, and neitherCARootsFilePathOptionnorGrpcGoogleDefaultTlsOnlyOptionis in use. When the option is set, the strategy logs atINFOifgrpc::GoogleDefaultCredentials()is selected, or logs aWARNINGnaming the blocking condition (or null return from gRPC) before falling back toGrpcComputeEngineAuthentication.DefaultOptionsGrpc()sets the option only for Compute Engine credentials on a non-Interconnect DirectPath endpoint (matchingGrpcGoogleDefaultTlsOnlyOptionwhen gRPC ignoresforce-xds) on a host with a Google Cloud BIOS; the default endpoint for these credentials stays CloudPath.MakeMinimalIamCredentialsOptions()drops the option andCreateStorageIamStub()builds its authentication strategy from those options, so the IAM Credentials channel does not change.ExplicitDirectPathEndpointWithNonAltsCredsTestnow uses access token credentials, because Compute Engine credentials query the GCP detector on these endpoints. Whether gRPC returns credentials depends on the host, soWithComputeEngineCredentialsUseGoogleDefaultandIamStubIgnoresComputeEngineUseGoogleDefaultOptiontell 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 throughComputeEngineGoogleDefaultFallbackReason()andCreateAuthenticationStrategy(), and the filesystem error cases on POSIX. Verified live on a Compute Engine VM with gRPC 1.81.1 and gRPC 1.65.5 thatMakeComputeEngineCredentials()withEndpointOption("google-c2p:///storage.googleapis.com")connects to DirectPath backends over ALTS when clean and logs the expected warning before falling back to TLS-only whenGOOGLE_APPLICATION_CREDENTIALS, a well-known gcloud ADC file, orCARootsFilePathOptionis set (plus an unsearchableHOMEon gRPC 1.81.1).