Skip to content

network: add DownstreamTransportSocketConfigFactory and registry#2437

Merged
alyssawilk merged 23 commits intoenvoyproxy:masterfrom
lizan:downstream_tsf_registry
Feb 1, 2018
Merged

network: add DownstreamTransportSocketConfigFactory and registry#2437
alyssawilk merged 23 commits intoenvoyproxy:masterfrom
lizan:downstream_tsf_registry

Conversation

@lizan
Copy link
Copy Markdown
Member

@lizan lizan commented Jan 23, 2018

Signed-off-by: Lizan Zhou zlizan@google.com

Description:
Add DownstreamTransportSocketConfigFactory and its implementations.

Risk Level: Medium

Testing:
unit test, integration tests

Docs Changes:

Release Notes:

Fixes #1840.

Signed-off-by: Lizan Zhou <zlizan@google.com>
@lizan
Copy link
Copy Markdown
Member Author

lizan commented Jan 23, 2018

Will add changes to listeners after #2346, PTAL on the interface @mattklein123 @alyssawilk cc/ @PiotrSikora

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Looks good - only a few minor nits. Hurrah for (bidirectional) pluggable crypto!

};

/**
* Implemented by each transport socket and registered via class RegisterFactory for upstream
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have a requirement that each transport socket needs both ends or should this be "implemented by each transport socket which does upstream connections"?

GFE has some things it speaks upstream and not downstream. With Envoy I have a hard time figuring out how we'd do testing without doing both so it's quite likely this comment should stand, maybe with an additional comment somewhere that it's required we always do both.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No such requirement. Though I expect most implementations will have both upstream and downstream, nothing blocks an implementation with upstream only or downstream only, the interfaces and configuration support that. I will update the comments.

Tests could be done with external process, in some cases it could be done with existing other implementations, e.g. a transport socket is using other TLS implementation than BoringSSL.

* Create a particular downstream transport socket factory implementation.
* TODO(lizan): Revisit the interface when TLS sniffing and filter chain match are implemented.
* @param listener_name const std::string& the name of the listener.
* @param server_names const std::vector<std::string>& the names of the server.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mind adding a bit more detail here?
I assumed it was for SNI, then didn't know how SNI worked if you have a vector of server names. I was going to dig through code but I think our API comments should have enough data us non-crypto folk can puzzle it out. If it's blatantly obvious to crypto folk that may be enough =P

* TODO(lizan): Revisit the interface when TLS sniffing and filter chain match are implemented.
* @param listener_name const std::string& the name of the listener.
* @param server_names const std::vector<std::string>& the names of the server.
* @param skip_ssl_context_update bool indicates whether the ssl context update should be skipped.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto

@alyssawilk alyssawilk self-assigned this Jan 24, 2018
lizan added 5 commits January 26, 2018 15:11
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
@lizan lizan changed the title [WIP] network: add DownstreamTransportSocketConfigFactory and registry network: add DownstreamTransportSocketConfigFactory and registry Jan 29, 2018
@lizan
Copy link
Copy Markdown
Member Author

lizan commented Jan 29, 2018

@alyssawilk @zuercher This is ready to be reviewed, PTAL.

Copy link
Copy Markdown
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.

LGTM, some random small comments. Thanks!

Ssl::Context* ssl_ctx) PURE;
virtual Network::ConnectionPtr
createServerConnection(Network::ConnectionSocketPtr&& socket,
Network::TransportSocketPtr&& transport_socket) PURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix doc comments

};

/**
* Implemented by each transport socket which does downstream connection. Registered via class
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: "used for downstream connections."

};

/**
* Implemented by each transport socket which does upstream connection. Registered via class
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: "used for upstream connections."

bool implementsSecureTransport() const override;

private:
ServerContextPtr ssl_ctx_;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: const

}

void ConnectionHandlerImpl::ActiveListener::newConnection(Network::ConnectionSocketPtr&& socket) {
auto ts = config_.transportSocketFactory().createTransportSocket();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: local var not needed

}

ASSERT(!transport_socket_factories_.empty());
ASSERT(transport_socket_factories_[0]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: != nullptr

Server::Configuration::DownstreamTransportSocketConfigFactory>(transport_socket.name());
ProtobufTypes::MessagePtr message =
Config::Utility::translateToFactoryConfig(transport_socket, config_factory);
transport_socket_factories_.emplace_back(config_factory.createTransportSocketFactory(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that right now we effectively only support a single filter chain, I would recommend not using a vector here and just storing a single filter chain. The check at the end verifies that all filter chains are the same if they are implemented. All of this is going to have to get refactored when we do real matching. I would also add some TODO comments about the coming refactoring.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We do support multiple filter chain, only with same filters, to support SNI. There are tests here:
https://github.com/envoyproxy/envoy/blob/master/test/server/listener_manager_impl_test.cc#L842

Since TransportSocketFactory replaces ServerContext here, it has to be vector.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you always return the 0th element of the vector, what is the point of the vector?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Inside the SslServerContext, it switches the the context to others based on ClientHello here, unless skip_context_update is true. So now the default is being used until SslServerContext process client hello, and then switch the context after. Since SslContextManager doesn't own the SslServerContexts, the transport socket factories owns them here.

This behavior should be updated once SNI based filter chain match is implemented correctly, right @PiotrSikora?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ohh. OK I see. Now that factory holds context, you need to store them all. Hmm, yeah this is pretty hacky/ugly but I get why you did it until filter chain matching is implemented. Can you add a bunch of comments? This is really unclear from reading. Thank you.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, done.

Address::SocketType type);

/**
* Create a transport socket for testing purpse.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: "purpse" same below. Also should be "testing purposes"

@mattklein123
Copy link
Copy Markdown
Member

@lizan does this complete #1840? If so can you add "Fixes" to the description?

lizan added 4 commits January 30, 2018 13:31
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
server_initialized_.waitReady();

if (ssl_ctx_) {
throw EnvoyException("debug");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oops, done.

lizan added 3 commits January 30, 2018 14:00
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>

// Each transport socket factory owns one SslServerContext, we need to store them all in a
// vector since Ssl::ContextManager doesn't owns SslServerContext. While
// transportSocketFacotry() always return the first element of transport_socket_factories_,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: "transportSocketFactory()" and "returns the first element"

// Each transport socket factory owns one SslServerContext, we need to store them all in a
// vector since Ssl::ContextManager doesn't owns SslServerContext. While
// transportSocketFacotry() always return the first element of transport_socket_factories_,
// other transport socket facotires are needed when the default Ssl::ServerContext updates
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: factories


/**
* @return Ssl::ServerContext* the default SSL context.
* @return TransportSocketFacotry& the transport socket factory.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: TransportSocketFactory

};

/**
* Implemented by each transport socket which used for upstream connections. Registered via class
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: rm which (repeated below for DownstreamTransportSocketConfigFactory)

@lizan
Copy link
Copy Markdown
Member Author

lizan commented Jan 31, 2018

Hmm, I ran coverage locally and it says coverage is 98.0%, and I double checked every file I changed that didn't lose coverage. Not sure why CircleCI complain it is 97.9%... The artifacts wasn't uploaded.

@mattklein123
Copy link
Copy Markdown
Member

@lizan sorry. You can either find some coverage to add, or wait until we do some coverage fixes.

Copy link
Copy Markdown
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

one last question, but otherwise LGTM

}

ASSERT(!transport_socket_factories_.empty());
ASSERT(transport_socket_factories_[0] != nullptr);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: should this be asserting that the just-added pointer is not null?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah that works too.

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

One more nit on my end as well

has_stk++;

auto transport_socket = filter_chain.transport_socket();
if (!filter_chain.has_transport_socket()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Snagging transport_socket before checking has_transport_socket is weird and could definitely use some commenting. Would it instead make more sense to have string name from transport_socket and if name were empty to override it based on has_tls_config?

Copy link
Copy Markdown
Member Author

@lizan lizan Jan 31, 2018

Choose a reason for hiding this comment

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

Added a comment (also to upstream_impl). Checking the name does same thing. proto here is validated, so the name won't be empty if filter chain has transport socket.

Copy link
Copy Markdown
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.

small nit, LGTM other than remaining @zuercher and @alyssawilk comments.

Config::Utility::translateToFactoryConfig(transport_socket, config_factory);

// Each transport socket factory owns one SslServerContext, we need to store them all in a
// vector since Ssl::ContextManager doesn't owns SslServerContext. While
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: "doesn't owns". While you are here please reflow comment.

Copy link
Copy Markdown
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.

@lizan small nit since you have to do a master merge anyway. Thanks!

ProtobufTypes::MessagePtr message =
Config::Utility::translateToFactoryConfig(transport_socket, config_factory);

// Each transport socket factory owns one SslServerContext, we need to store them all in a
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Can you please reflow this comment out to 100 cols? I think the sentences got broken up when the formatter kicked in.

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

@mattklein123 @zuercher any final comments?

@alyssawilk alyssawilk merged commit 605fa42 into envoyproxy:master Feb 1, 2018
jpsim added a commit that referenced this pull request Nov 28, 2022
We were on a very old release. This is also going to be needed to update
to the latest bazel 6.x release which we need to do to update Envoy.

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
We were on a very old release. This is also going to be needed to update
to the latest bazel 6.x release which we need to do to update Envoy.

Signed-off-by: JP Simard <jp@jpsim.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.

4 participants