Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plumb mtls endpoint to TransportChannelProvider #3673

Merged
merged 12 commits into from
Mar 19, 2025

Conversation

rmehta19
Copy link
Contributor

@rmehta19 rmehta19 commented Mar 4, 2025

This PR plumbs the MTLS endpoint (separately from the resolved endpoint) from the EndpointContext to the InstantiatingGrpcChannelProvider.

Why not just set the MTLS endpoint in EndpointContext if S2A can be used?

  • Although we can decide whether or not to try to use S2A in EndpointContext, we could fail to use S2A in InstantiatingGrpcChannelProvider (if autoconfig doesn't return an address), in which case we fall back to using a TLS connection
  • DirectPath supersedes S2A in InstantiatingGrpcChannelProvider, and the decision to use DirectPath is made in InstantiatingGrpcChannelProvider, not EndpointContext. We may decide to use S2A in EndpointContext, but when we go to create the channel in InstantiatingGrpcChannelProvider, we may find that we should be using DirectPath, in which case we need to use the non-MTLS endpoint

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Mar 4, 2025
@rmehta19
Copy link
Contributor Author

rmehta19 commented Mar 4, 2025

@lqiu96 , please review, thanks!

@rmehta19 rmehta19 changed the title feat: plumb mtls endpoint to TransportChannelProvider fix: plumb mtls endpoint to TransportChannelProvider Mar 4, 2025
@rmehta19
Copy link
Contributor Author

rmehta19 commented Mar 7, 2025

Friendly ping @lqiu96 . Thanks!

Comment on lines +291 to +295
@Override
public TransportChannelProvider withMtlsEndpoint(String mtlsEndpoint) {
validateEndpoint(mtlsEndpoint);
return toBuilder().setMtlsEndpoint(mtlsEndpoint).build();
}
Copy link
Contributor

@lqiu96 lqiu96 Mar 11, 2025

Choose a reason for hiding this comment

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

Would you be able to add @InternalApi to all the new public methods? We have a few ways to configure endpoints (i.e. ClientSettings and TransportChannelProvider for endpoint and led us to have to account for it in EndpointContext). If we add these ways for users to configure the mtls value, I think we'll need to account for it in EndpointContext as well.

Given that we can't make this package-private scope, we should let users know that they really shouldn't be tinkering with these values since they're really used to help S2A (one flow for now).

I think a small note in the comment (for this method and all the other public ones) as well warning users This public method is used by Gax to help configure S2A fallback and not intended for users or something of that variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 7e36d1a. Would you prefer making the change in EndpointContext in this PR, or a follow up?

Copy link
Contributor

Choose a reason for hiding this comment

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

My thoughts are that we just leave EndpointContext as-is since we have publicly noted that these public methods have been marked with @InternalApi and shouldn't be set/customized by the user at all. If users do set these values via these new methods, they shouldn't expect support (as this is used to help to support S2A).

The existing way of setting the mtlsEndpoint in StubSettings is supported

@rmehta19
Copy link
Contributor Author

Thanks for the review @lqiu96 !

@lqiu96
Copy link
Contributor

lqiu96 commented Mar 12, 2025

@rmehta19 FYI I think there are lint issues and you need to run mvn fmt:format

@rmehta19
Copy link
Contributor Author

rmehta19 commented Mar 12, 2025

Thanks @lqiu96 ! synced to HEAD and formatted.

@lqiu96
Copy link
Contributor

lqiu96 commented Mar 12, 2025

/gcbrun

@rmehta19
Copy link
Contributor Author

@lqiu96 , resolved merge conflict, could you run gcbrun again? Thanks!

@lqiu96
Copy link
Contributor

lqiu96 commented Mar 12, 2025

/gcbrun

Copy link
Contributor

@lqiu96 lqiu96 left a comment

Choose a reason for hiding this comment

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

LGTM. This follows the approach that we had discussed in the previous S2A PR.

@rmehta19
Copy link
Contributor Author

Thanks @lqiu96 ! I see all the checks have passed, would you be able to merge once you get a chance?

@lqiu96 lqiu96 requested a review from blakeli0 March 12, 2025 21:29
@lqiu96
Copy link
Contributor

lqiu96 commented Mar 12, 2025

Adding @blakeli0 to take a quick glance as well in case there is anything missed.

@rmehta19
Copy link
Contributor Author

friendly ping, @blakeli0. Thanks!

@@ -97,6 +97,20 @@ public interface TransportChannelProvider {
*/
TransportChannelProvider withEndpoint(String endpoint);

/** True for gRPC transport provider which has no mtlsEndpoint set. */
default boolean needsMtlsEndpoint() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we tried to avoid introducing these new public interfaces by encapsulating the logic to determine if we should use S2A in EndpointContext. Now that we need to have access to mtlsEndpoint in TransportChannelProvider anyway, maybe we can move shouldUseS2A to InstantiatingGrpcChannelProvider.java? And remove withUseS2A from this interface? This could be separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed that by plumbing the MTLS endpoint separately, we no longer need the shouldUseS2A logic in EndpointContext. I'll take care of this in a followup PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@blakeli0 I started working on this and I realized that we should keep shouldUseS2A in EndpointContext. The reason being is that we want to skip S2A if using GDCH, or if the client sets a custom endpoint. This info is only available in EndpointContext.

Given this, we probably want to keep things as is. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if the client sets a custom endpoint

I see, yeah I think this info only exists in EndpointContext. cc: @lqiu96 in case there are more ideas.

@rmehta19
Copy link
Contributor Author

Thanks for reviewing @blakeli0 !

@blakeli0 blakeli0 merged commit a961459 into googleapis:main Mar 19, 2025
46 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants