Skip to content

transport socket: api and implementation for startTls transport socket#13112

Merged
mattklein123 merged 37 commits intoenvoyproxy:masterfrom
cpakulski:starttls/api
Dec 13, 2020
Merged

transport socket: api and implementation for startTls transport socket#13112
mattklein123 merged 37 commits intoenvoyproxy:masterfrom
cpakulski:starttls/api

Conversation

@cpakulski
Copy link
Copy Markdown
Contributor

@cpakulski cpakulski commented Sep 15, 2020

Commit Message:
PR defines configuration API and implementation for StartTls transport socket. StartTls is programmable transport socket which starts in clear-text but may programatically be switched to TLS.

Original discussion about use cases is here: #9577

Design document is here: https://docs.google.com/document/d/1ajrQpOEuup04V95xDDY8hSigW4B-J3iuhwn8QQEl-q4/edit?usp=sharing

Risk Level: Low.
Testing: Yes. Added integration tests.

Docs Changes: Some doc sections are automatically produced, but they contain minimum info.

Release Notes: No.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #13112 was opened by cpakulski.

see: more, trace.

Comment thread source/extensions/transport_sockets/starttls/BUILD Outdated
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
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.

Thanks, at a high level this LGTM. This is small enough that I'm not sure it's worth merging as is. Do you want to provide the implementation (even if without tests) and we can review the whole thing together?

/wait

Comment thread api/envoy/extensions/transport_sockets/starttls/v3/starttls.proto Outdated
Comment thread api/envoy/extensions/transport_sockets/starttls/v3/starttls.proto Outdated
Comment thread api/envoy/extensions/transport_sockets/starttls/v3/starttls.proto Outdated
Comment thread api/envoy/extensions/transport_sockets/starttls/v3/starttls.proto
Comment thread api/envoy/extensions/transport_sockets/starttls/v3/starttls.proto Outdated
@cpakulski
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing. It makes total sense to add socket implementation to this PR.

@stale
Copy link
Copy Markdown

stale Bot commented Oct 4, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale Bot added the stale stalebot believes this issue/PR has not been touched recently label Oct 4, 2020
@jsbucy jsbucy mentioned this pull request Oct 6, 2020
@cpakulski
Copy link
Copy Markdown
Contributor Author

WIP.

@stale stale Bot removed the stale stalebot believes this issue/PR has not been touched recently label Oct 7, 2020
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Consolidated fixture classes.
Renamed data members to indicate if they are used by cleartext or tls.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Changed passthrough_ to oper_socket_.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski
Copy link
Copy Markdown
Contributor Author

Originally this PR contained only api definition. Since then I added starttls socket implementation plus integration test.

The integration test simulates the intended usage of the starttls transport socket. A client opens a clear-text connection and as protocol exchange progresses, a filter understanding the protocol may instruct the transport socket to start using tls. Switching from clear-text to tls must happen without closing the socket: tls handshake starts over the same socket where clear-text exchange happened.

Testing/coverage should still be expanded, but I believe that there is enough content right now to see if this is going in the right direction.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, in general this is in good structure, starting from high level comments.

Comment thread include/envoy/network/connection.h Outdated
/**
* @return std::string type of the underlying transport socket.
*/
virtual std::string transportProtocol() const 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.

The only meaningful use of this one is to check whether transport socket can startSecureTransport, but I don't think you really need as you can call startSecureTransport and check its return value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are probably right. I was originally thinking that a filter could check underlying transport socket when it receives a configuration and could verify that it sits on top of starttls transport socket. But it has to wait until connection is formed and only then can check if the stack contains starttls transport socket. Therefore, as you suggest, it can just try to call startSecureTransport and complain when it returns false.

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.

Yeah if you want to reject at configuration level this should be part of transport socket factory but not connection.

Comment thread source/common/network/connection_impl.cc
Comment thread include/envoy/network/connection.h Outdated
/**
* @return std::string type of the underlying transport socket.
*/
virtual std::string transportProtocol() const 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.

Yeah if you want to reject at configuration level this should be part of transport socket factory but not connection.

Comment thread source/extensions/transport_sockets/starttls/config.cc Outdated
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski cpakulski changed the title api: config API for StartTls transport socket transport socket: api and implementation for startTls transport socket Dec 8, 2020
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski cpakulski requested a review from lizan December 9, 2020 22:15
Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

LGTM, @mattklein123 can you take a look?

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.

Thanks generally LGTM. Flushing out a few comments. Thank you!

/wait

Comment thread include/envoy/network/connection.h Outdated
Comment thread include/envoy/network/connection.h Outdated
Comment thread source/common/network/raw_buffer_socket.h Outdated
Comment thread source/extensions/transport_sockets/alts/tsi_socket.h Outdated
Comment thread source/extensions/transport_sockets/starttls/starttls_socket.h Outdated
// Socket used in all transport socket operations.
// initially it is set to use raw buffer socket but
// can be converted to use ssl.
Network::TransportSocketPtr oper_socket_;
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: I don't know what oper_socket means. Can you name this something a bit better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed to active_socket_

I imagined oper_ to mean operating

if (!using_ssl_) {
ssl_socket_->setTransportSocketCallbacks(*callbacks_);
ssl_socket_->onConnected();
oper_socket_ = std::move(ssl_socket_);
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.

Can transport sockets internally buffer? Is this guaranteed to be correct? Can we drop buffered data if there is flow control?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that in this case we are safe. RawBuffer::doWrite/doRead do not buffer.
In general case, where any type of transport socket could be plugged in, it would be nice to have ::flush() method to call before switching.

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 add a TODO/comment about this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added TODO.

Comment thread source/extensions/transport_sockets/tls/ssl_socket.cc Outdated
Comment thread source/extensions/transport_sockets/tls/ssl_socket.h Outdated
const std::string Tap = "envoy.transport_sockets.tap";
const std::string Tls = "envoy.transport_sockets.tls";
const std::string UpstreamProxyProtocol = "envoy.transport_sockets.upstream_proxy_protocol";
const std::string StartTls = "envoy.transport_sockets.starttls";
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.

We are trying to get rid of these files so just inline the strings where they are needed. Same below.

Copy link
Copy Markdown
Contributor Author

@cpakulski cpakulski Dec 11, 2020

Choose a reason for hiding this comment

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

What would you say if I leave it as is and create a PR which removes well_known_names.h and inlines strings instead of variables across all files?

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.

OK that's fine.

… sockets

except starttls.

Renamed data members to better reflect their meaning.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
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.

Thanks!

@mattklein123 mattklein123 merged commit 98e8bf3 into envoyproxy:master Dec 13, 2020
Comment thread test/integration/BUILD
":starttls_integration_proto_cc_proto",
"//source/extensions/filters/network/tcp_proxy:config",
"//source/extensions/transport_sockets/raw_buffer:config",
"//source/extensions/transport_sockets/starttls:config",
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.

We introduced a new direct dependency between core tests and //source/extensions.
Could we move this test to //test/extensions/transport_sockets ?

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.

Oops sorry I missed this. Yes @cpakulski please move.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No problem - will move it.

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.

Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the test: #14425

IoResult doRead(Buffer::Instance& buffer) override;
IoResult doWrite(Buffer::Instance& buffer, bool end_stream) override;
Ssl::ConnectionInfoConstSharedPtr ssl() const override { return nullptr; }
bool startSecureTransport() override { return false; }
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @antoniovicente. I will investigate it.

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.

6 participants