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

tls: select alpn override by upstream protocol #8501

Closed
wants to merge 3 commits into from

Conversation

yxue
Copy link
Contributor

@yxue yxue commented Oct 5, 2019

Signed-off-by: crazyxy [email protected]

Description: select alpn override by upstream protocol
Risk Level: Low
Testing: Unit test
Docs Changes: N/A
Release Notes: N/A
Fixes #Issue: Part of #8197

transport_socket_options_ = std::make_shared<Network::TransportSocketOptionsImpl>(
"", std::vector<std::string>{}, std::vector<std::string>{alpn.value()});

if (alpn.hasProtocol(protocol)) {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW I'm not thrilled that logic this specific is creeping into the router filter. Can we instead handle this in a similar fashion to:

/**
* Adds socket options to be applied to any connections used for upstream requests. Note that
* unique values for the options will likely lead to many connection pools being created. The
* added options are appended to any previously added.
*
* @param options The options to be added.
*/
virtual void addUpstreamSocketOptions(const Network::Socket::OptionsSharedPtr& options) PURE;
/**
* @return The socket options to be applied to the upstream request.
*/
virtual Network::Socket::OptionsSharedPtr getUpstreamSocketOptions() const PURE;

But instead for transport socket options? I think this should be a very similar situation?

cc @lizan can you take a look at ^ and guide in that direction depending on what you think? Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think the logic should be in extension (filter) code, then the transport socket options should be modified through filter callbacks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The filter has limited knowledge to set the transport socket option. The filter only knows the downstream protocol and it can only select the ALPN according to the downstream protocol but I think the ALPN should be selected according to the upstream protocol instead of downstream's. e.g., if the downstream connection uses HTTP/1.1 and upstream connection uses HTTP/2, the ALPN override will be wrong.

Copy link
Member

Choose a reason for hiding this comment

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

The filter will know the upstream cluster that the the request is going to be routed to. This should be sufficient to decide at that point which ALPN to use, no? I think this can all be moved into a custom filter other than allowing filters to modify the transport socket options.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for @yxue
Since router decide if the upstream http protocol is h1 or h2,
ALPN http filter should not set the final alpn, it should provide two pool: h1 and h2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC, we could do that without putting the upstream protocol in the cluster info because the http filter can also access the cluster and route info. Is the reason for the PR that we want to have single source of truth?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, there’s another PR to add Http3 and I expect that logic can be more complicated in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I would still prefer that we add generic facilities for filters to modify transport socket options and then just use that from the router for now.

Unlike socket options its not very generic so I think keep using filter state is fine, so:
#8546

Copy link
Member

Choose a reason for hiding this comment

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

with #8546 and #8544, an http filter can calculate alpn override based on either upstream or downstream protocol and set it to filter state, can we close this? @yxue

I'm inclining to have that filter in istio/proxy because it seems very istio specific. If we see other interest then we can move.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lizan thanks for PRs. I will close this one and another HTTP filter pr. I already created the PR in istio/proxy istio/proxy#2450

@yxue yxue closed this Oct 10, 2019
@yxue yxue deleted the alpnoverride branch December 3, 2019 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants