Skip to content

chore: preserve default TLS authority for bypass-routed channels#4396

Merged
rahul2393 merged 1 commit intomainfrom
support-bypass-with-tls
Mar 26, 2026
Merged

chore: preserve default TLS authority for bypass-routed channels#4396
rahul2393 merged 1 commit intomainfrom
support-bypass-with-tls

Conversation

@rahul2393
Copy link
Contributor

Bypass with mTLS was creating new per-endpoint channels using the routed
endpoint as authority, which broke TLS/SNI when all routed endpoints were
expected to present the same host identity as the original endpoint.

Update GrpcChannelEndpointCache so channels created via withEndpoint(...)
reuse the default channel authority by applying overrideAuthority(defaultAuthority)
to each routed channel builder.

@rahul2393 rahul2393 requested review from a team as code owners March 26, 2026 06:48
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/java-spanner API. labels Mar 26, 2026
@gemini-code-assist

This comment was marked as outdated.

@rahul2393 rahul2393 force-pushed the support-bypass-with-tls branch from 7debc6d to 0f2878c Compare March 26, 2026 06:49
@rahul2393 rahul2393 force-pushed the support-bypass-with-tls branch from 0f2878c to 59501ac Compare March 26, 2026 06:49
@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: m Pull request size is medium. labels Mar 26, 2026
gemini-code-assist[bot]

This comment was marked as outdated.

@rahul2393 rahul2393 requested a review from olavloite March 26, 2026 06:52
@rahul2393
Copy link
Contributor Author

/gemini summary

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This pull request addresses a critical mTLS issue in the GrpcChannelEndpointCache where dynamically created channels for bypass-routed endpoints were incorrectly using the routed endpoint's authority instead of the default. The changes ensure that all such channels consistently apply the original default TLS authority, thereby restoring proper TLS/SNI functionality and preventing connection failures in mTLS environments.

Highlights

  • mTLS/SNI Fix: Resolved an issue where bypass-routed channels incorrectly used the routed endpoint as the TLS authority, leading to TLS/SNI failures.
  • Default TLS Authority Preservation: Modified GrpcChannelEndpointCache to ensure that channels created for routed endpoints explicitly reuse the default channel authority, maintaining consistent host identity.
Changelog
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GrpcChannelEndpointCache.java
    • Introduced a new private field defaultAuthority to store the initial channel's authority.
    • Modified the channel creation logic to explicitly override the authority of new channels with the stored defaultAuthority.
    • Added a helper method createProviderWithAuthorityOverride to encapsulate the logic for applying the authority override.
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GrpcChannelEndpointCacheTest.java
    • Added a new test case routedChannelsReuseDefaultAuthority to verify that routed channels correctly inherit the default authority.
Activity
  • gemini-code-assist[bot] provided an initial summary of changes.
  • rahul2393 requested a summary using /gemini summary.

@rahul2393
Copy link
Contributor Author

/gemini review

Copy link
Contributor

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

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 a mechanism to ensure that routed gRPC channels reuse the default authority. A new defaultAuthority field is added to GrpcChannelEndpointCache, and a createProviderWithAuthorityOverride method is implemented to override the channel builder's authority for non-default endpoints. A new test case routedChannelsReuseDefaultAuthority verifies this behavior. The reviewer suggests improving the readability and conciseness of the lambda logic within the createProviderWithAuthorityOverride method by importing ApiFunction and simplifying the channelBuilder reassignment.

Comment on lines +106 to +115
final com.google.api.core.ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>
baseConfigurator = builder.getChannelConfigurator();
builder.setChannelConfigurator(
channelBuilder -> {
ManagedChannelBuilder effectiveBuilder = channelBuilder;
if (baseConfigurator != null) {
effectiveBuilder = baseConfigurator.apply(effectiveBuilder);
}
return effectiveBuilder.overrideAuthority(defaultAuthority);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This new logic can be made more readable and concise with a couple of small improvements:

  1. Instead of using the fully qualified name for ApiFunction, it's better to add an import at the top of the file (import com.google.api.core.ApiFunction;) and use the simple name.
  2. The lambda body can be simplified by reassigning channelBuilder directly, which removes the need for the effectiveBuilder variable.

Here's a suggestion that applies both improvements:

    final com.google.api.core.ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>
        baseConfigurator = builder.getChannelConfigurator();
    builder.setChannelConfigurator(
        channelBuilder -> {
          if (baseConfigurator != null) {
            channelBuilder = baseConfigurator.apply(channelBuilder);
          }
          return channelBuilder.overrideAuthority(defaultAuthority);
        });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid style suggestion, but not a functional issue. The current code is correct, and using effectiveBuilder is an acceptable readability choice. This should be downgraded to a nit, not medium severity.

@rahul2393 rahul2393 merged commit ceb6bc9 into main Mar 26, 2026
42 of 43 checks passed
@rahul2393 rahul2393 deleted the support-bypass-with-tls branch March 26, 2026 09:48
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 googleapis/java-spanner API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants