Skip to content

tls: moving the server name into SocketAddressProvider#16574

Merged
mattklein123 merged 20 commits intoenvoyproxy:mainfrom
soulxu:populate_server_name_1
Jun 30, 2021
Merged

tls: moving the server name into SocketAddressProvider#16574
mattklein123 merged 20 commits intoenvoyproxy:mainfrom
soulxu:populate_server_name_1

Conversation

@soulxu
Copy link
Member

@soulxu soulxu commented May 19, 2021

Commit Message: tls: moving the server name into SocketAddressProvider

Additional Description:
Making the SocketAddressProvider is single source of server name.

Risk Level: low
Testing: n/a
Part of #17168
Fixes #14922

Signed-off-by: He Jie Xu hejie.xu@intel.com

Before the connection reach to TCPPorxy filter or HCM, the server
name won't be populated into stream info. It leads to the access
log get empty server name. This patch populate the server name in
the path of closing socket.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu soulxu changed the title Populate the server name into stream info when the connection closed tls:populate the server name into stream info when the connection closed May 19, 2021
@soulxu soulxu changed the title tls:populate the server name into stream info when the connection closed tls: populate the server name into stream info when the connection closed May 19, 2021
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Thanks for working on a fix here! High level question on the approach

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu soulxu changed the title tls: populate the server name into stream info when the connection closed tls: populate the server name into stream info in ActiveTCPListener May 21, 2021
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Member Author

soulxu commented May 24, 2021

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16574 (comment) was created by @soulxu.

see: more, trace.

Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Thanks this seems like a better direction to me, a few comments.

@ggreenway do you also want to review this?

Copy link
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

This is looking good; I like this approach better.

void ActiveTcpListener::newConnection(Network::ConnectionSocketPtr&& socket,
std::unique_ptr<StreamInfo::StreamInfo> stream_info) {
// populate the SNI into stream info, the network filters needn't do that again.
if (!socket->requestedServerName().empty()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be done unconditionally? I would expect that calling setRequestedServerName() with an empty string would have no effect.

Copy link
Member Author

Choose a reason for hiding this comment

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

It has a constructor even for empty string https://github.com/envoyproxy/envoy/blob/main/source/common/stream_info/stream_info_impl.h#L237. Or we can move the check inside the setRequestedServerName(), but that will block the case when want to set the server name back to empty. Although I'm not sure we have any case to set the server name back to empty, but it still feels bad for an interface.

Copy link
Member

Choose a reason for hiding this comment

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

I think it is functionally the same without this check; setting it to empty is the same as not setting it. Please remove the conditional to simplify the code. Same in unlink().

Copy link
Member Author

Choose a reason for hiding this comment

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

got it, let me remove it.

soulxu added 2 commits May 26, 2021 16:05
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Member Author

soulxu commented May 31, 2021

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16574 (comment) was created by @soulxu.

see: more, trace.

Copy link
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

Please add another test case for listener filter timeout that verifies the server name is set.

/wait

void ActiveTcpListener::newConnection(Network::ConnectionSocketPtr&& socket,
std::unique_ptr<StreamInfo::StreamInfo> stream_info) {
// populate the SNI into stream info, the network filters needn't do that again.
if (!socket->requestedServerName().empty()) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it is functionally the same without this check; setting it to empty is the same as not setting it. Please remove the conditional to simplify the code. Same in unlink().

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Member Author

soulxu commented Jun 3, 2021

thanks for the review, I will update soon!

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Member Author

soulxu commented Jun 3, 2021

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16574 (comment) was created by @soulxu.

see: more, trace.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@ggreenway
Copy link
Member

Yes I think this is likely a bug in the same class of issues I fixed a while back with addresses. Optimally, we would do something similar here so we don't mess this up.

I didn't realize until now how similar it is. There's an accessor for the requestedServerName on the Connection, which I didn't realize. Maybe we can just delete that entirely, and say that the way to get it is always from the streamInfo, and make sure it's always populated on the streamInfo. Then it becomes a simpler problem than the addresses. It's only used in about ~10 places off of the Connection. Thoughts @mattklein123 ?

@mattklein123
Copy link
Member

I didn't realize until now how similar it is. There's an accessor for the requestedServerName on the Connection, which I didn't realize. Maybe we can just delete that entirely, and say that the way to get it is always from the streamInfo, and make sure it's always populated on the streamInfo. Then it becomes a simpler problem than the addresses. It's only used in about ~10 places off of the Connection. Thoughts @mattklein123 ?

I think this would be fine, but keep in mind that there are unfortunately multiple stacked stream infos (connection, stream, etc.) so we need to make sure to not actually break copying the data over.

Another option would be just adding this to SocketAddressProvider (and maybe renaming it) which is how I fixed all the address bugs. Basically I made it impossible to not have this data be carried everywhere.

@soulxu
Copy link
Member Author

soulxu commented Jun 8, 2021

I didn't realize until now how similar it is. There's an accessor for the requestedServerName on the Connection, which I didn't realize. Maybe we can just delete that entirely, and say that the way to get it is always from the streamInfo, and make sure it's always populated on the streamInfo. Then it becomes a simpler problem than the addresses. It's only used in about ~10 places off of the Connection. Thoughts @mattklein123 ?

I think this would be fine, but keep in mind that there are unfortunately multiple stacked stream infos (connection, stream, etc.) so we need to make sure to not actually break copying the data over.

Another option would be just adding this to SocketAddressProvider (and maybe renaming it) which is how I fixed all the address bugs. Basically I made it impossible to not have this data be carried everywhere.

Hope I understand correctly. I search the socket address issue #14133, so the goal here is not to carry the info anywhere, avoid the bug we always forget to populate the info somewhere, just share the same info from the connection. So we can put the server_name into the socket address provider(need to rename it). Is it correct? @mattklein123

If it is correct, I found other than the 'server name', we also can put the 'downstream ssl info'

filter_manager_.streamInfo().setDownstreamSslConnection(
and 'connection id'
filter_manager_.streamInfo().setConnectionID(

into the socket address provider. Those are used for l4 stream info and http stream info and also populated from the connection.

Also, @ggreenway mentioned, we should clean up the way to get the stream info, it should be always from the stream info. for example:

callbacks_->connection()->requestedServerName(),

let me know whether this is the direction you guys looking for, I'm happy to work on it :)

@mattklein123
Copy link
Member

Yeah in general ^ makes sense to me. In general if we can consolidate information that should never change into a single structure to avoid bugs in copying it around that would be optimal.

soulxu added 3 commits June 23, 2021 12:23
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu
Copy link
Member Author

soulxu commented Jun 28, 2021

@mattklein123 @ggreenway I'm going to separate the whole thing into different PR since I found the PR will become huge and hard to review, this PR is just moving the server_name inside SocketAddressProvider. Then I will have other PRs for moving 'ssl info' and 'connection id'. Then a PR for ensure the server name only get from the address provider, the last PR will rename the SocketAddressProvider to proper name. But let me know if you have other perference.

@soulxu soulxu changed the title tls: populate the server name into stream info in ActiveTCPListener tls: moving the server name into SocketAddressProvider Jun 28, 2021
soulxu added 3 commits June 28, 2021 13:02
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
@soulxu soulxu requested a review from PiotrSikora as a code owner June 28, 2021 13:47
@soulxu
Copy link
Member Author

soulxu commented Jun 28, 2021

fyi, I create an issue to track the whole thing #17168

@mattklein123
Copy link
Member

Check CI?

/wait

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks this looks like a great improvement. One small comment.

/wait

*/
virtual const Address::InstanceConstSharedPtr& directRemoteAddress() const PURE;

/**
Copy link
Member

Choose a reason for hiding this comment

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

Just to leave an intermediate comment trail, can you add a TODO above here on what you plan to rename it to? Otherwise this will get confusing if someone looks at it now.

Copy link
Member Author

Choose a reason for hiding this comment

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

yea, good point. let me add a TODO

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
soulxu added 2 commits June 29, 2021 23:19
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 merged commit 8e3441c into envoyproxy:main Jun 30, 2021
baojr added a commit to baojr/envoy that referenced this pull request Jul 1, 2021
* main: (51 commits)
  listener: add filter chain match support for direct source address (envoyproxy#17118)
  Increase common/common coverage (envoyproxy#17193)
  crash_dump: Added local_end_stream_ to crash dump for H2. (envoyproxy#17199)
  codeql: improve Ubuntu dependency installation (envoyproxy#16556)
  ci: Move tooling tests to tooling job (envoyproxy#17071)
  Fix issue with Windows container image (envoyproxy#17113)
  fix filter linking urls (envoyproxy#17185)
  bug fix: fix bug that check_format.py will check files which are ignored (envoyproxy#17195)
  tls: moving the server name into SocketAddressProvider (envoyproxy#16574)
  network: Use std::make_unique and std::make_shared in source/common/network instead of bare new() (envoyproxy#17177)
  Revert "alpha matching: support generic action factory context (envoyproxy#17025)" (envoyproxy#17191)
  ci: Dont clone filter example where not required (envoyproxy#17182)
  alpha matching: support generic action factory context (envoyproxy#17025)
  xds: Clarify comment for RouteMatch.case_sensitive field. (envoyproxy#17176)
  ci: Only publish the required docker image (envoyproxy#17080)
  coverage: fixing flake (envoyproxy#17190)
  api: add cluster_specifier_plugin to RouteAction (envoyproxy#16944)
  wasm: update V8 to v9.2.230.13. (envoyproxy#17183)
  wasm: update Proxy-Wasm C++ Host and SDK to latest (2021-06-24). (envoyproxy#17174)
  owners: add Piotr as senior extension maintainer (envoyproxy#17175)
  ...

Signed-off-by: Garrett Bourg <bourg@squareup.com>
chrisxrepo pushed a commit to chrisxrepo/envoy that referenced this pull request Jul 8, 2021
)

Before the connection reach to TCPPorxy filter or HCM, the server
name won't be populated into stream info. It leads to the access
log get empty server name. This patch populate the server name in
the path of closing socket.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
Signed-off-by: chris.xin <xinchuantao@qq.com>
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
)

Before the connection reach to TCPPorxy filter or HCM, the server
name won't be populated into stream info. It leads to the access
log get empty server name. This patch populate the server name in
the path of closing socket.

Signed-off-by: He Jie Xu <hejie.xu@intel.com>
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.

Listener access logs missing %REQUESTED_SERVER_NAME% when no filter chain matches

6 participants