chore: preserve default TLS authority for bypass-routed channels#4396
chore: preserve default TLS authority for bypass-routed channels#4396
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
7debc6d to
0f2878c
Compare
0f2878c to
59501ac
Compare
|
/gemini summary |
Summary of ChangesThis 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
Changelog
Activity
|
|
/gemini review |
There was a problem hiding this comment.
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.
| 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); | ||
| }); |
There was a problem hiding this comment.
This new logic can be made more readable and concise with a couple of small improvements:
- 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. - The lambda body can be simplified by reassigning
channelBuilderdirectly, which removes the need for theeffectiveBuildervariable.
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);
});There was a problem hiding this comment.
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.
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.