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

enhancement(sources): Add TLS support to socket, syslog, and vector sources #1892

Merged
merged 7 commits into from
Feb 26, 2020

Conversation

bruceg
Copy link
Member

@bruceg bruceg commented Feb 21, 2020

This is the first down payment on #1553, adding support for TLS to the three sources that accept simple TCP connections: socket, syslog, and vector.

Note that the vector sink does not yet support TLS connections, presumably because the source didn't support them at the time. Adding that support should be trivial, but I will put it in a follow up PR.

Similarly, this does not add support for TLS to the sources that make outgoing connections. That too will be done in a separate PR.

Note also there is a hiccup in the added send_lines_tls function to do with shutdown of the socket. If somebody has an idea how to resolve that, I'd like to clean it up, but it works as it is now.

@bruceg bruceg added source: syslog Anything `syslog` source related source: socket Anything `socket` source related type: enhancement A value-adding code change that enhances its existing functionality. source: vector Anything `vector` source related domain: security Anything related to security domain: networking Anything related to Vector's networking domain: sources Anything related to the Vector's sources labels Feb 21, 2020
@bruceg bruceg requested review from LucioFranco and a user February 21, 2020 22:25
@bruceg bruceg changed the title enhancement(sources): Add TLS support to TCP connection accepting sources enhancement(sources): Add TLS support to socket, syslog, and vector sources Feb 21, 2020
@binarylogic binarylogic removed request for lukesteensen and a user February 22, 2020 15:32
Bruce Guenter added 3 commits February 22, 2020 20:35
Signed-off-by: Bruce Guenter <bruce@timber.io>
Signed-off-by: Bruce Guenter <bruce@timber.io>
Signed-off-by: Bruce Guenter <bruce@timber.io>
Copy link
Contributor

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

This looks great, I left a few comments and suggestions.

@@ -15,6 +15,7 @@ use tokio::{
reactor::Handle,
timer,
};
use tokio_tls::TlsAcceptor;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to just start using tokio_openssl instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

That may make sense. However, given that nothing else in Vector uses tokio_openssl yet, but other modules use tokio_tls as well (ex the parallel `src/sinks/utils/tcp.rs'), I think it would make more sense as a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well that isn't true, I did add this :P https://github.com/timberio/vector/blob/ce326530da9235233355a86dcc5c27b626f40a10/src/sinks/util/rusoto.rs#L7

We really need to just pick one I think if we are already here we should just do it now instead of punting imo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh, ok, you said tokio_openssl, so I grepped the sources for tokio_openssl direct uses, of which there are still none.

I can rework the sources here, but are you also advising me to rework the sinks as well to use tokio_openssl in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

No just the stuff you touch in this PR. And sorry I totally could have been more clear. hyper-openssl and tokio-openssl are basically just wrappers around each other that implement the correct traits for the openssl crate. So I think it makes sense to write any new code using that then going back later and updating the others.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so I looked into this, and it requires a rework of the TLS config handling that will end up being easier if I just do both acceptors and connectors at once, due to the different types involved (native_tls wrappers vs direct use of openssl).

Copy link
Contributor

Choose a reason for hiding this comment

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

That works for me 👍

)
.forward(out)
.map(|_| debug!("TLS connection closed."));
tokio::spawn(handler);
Copy link
Contributor

Choose a reason for hiding this comment

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

this has no span attached to it, we need to ensure it gets the correct span.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

if let Some(tls) = tls.clone() {
match tls.acceptor() {
Err(error) => error!(message = "Failed to create a TLS connection acceptor", %error),
Ok(acceptor)=> {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we break out this nested iflet matches a bit so that its a bit easier to follow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I pushed up a030d99, is that what you were suggesting?

match tls.acceptor() {
Err(error) => error!(message = "Failed to create a TLS connection acceptor", %error),
Ok(acceptor)=> {
let handler = TlsAcceptor::from(acceptor)
Copy link
Contributor

Choose a reason for hiding this comment

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

there is some duplicated code here, I would suggest we do the same thing we did with sinks and enum out a MaybeTlsStream and then have one FramedRead::new() setup. I think that would make this a bit more clear.

.forward(out)
.and_then(|(_source, sink)| {
let mut stream = sink.into_inner().into_inner();
// We should catch TLS shutdown errors here,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not directly following why we need to handle the shutdown here? the forward future should in theory flush all the way?

Copy link
Member Author

Choose a reason for hiding this comment

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

The parallel send_lines function has a shutdown, so I tried to get it to work in the TLS version and was unable. I am uncomfortable removing one without the other.

Copy link
Contributor

@LucioFranco LucioFranco Feb 24, 2020

Choose a reason for hiding this comment

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

Yeah, so I think dropping the tcpstream should be fine enough since forward should ensure its all flushed. So I think its safe to ignore it.

Edit: maybe not we should explore, in theory I think just dropping should work fine for tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

The tests that use this new send_lines_tls have passed every time I tried, so if there is a race or other issue with this it isn't obvious. However, I left the comment there because of the discrepancy.

}

pub(crate) fn acceptor(&self) -> crate::Result<TlsAcceptor> {
match self.identity() {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: this would be better if it were just an if let imo

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is the match vs if debate again... (ref #1720)

Copy link
Contributor

Choose a reason for hiding this comment

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

Though I think the reason I prefer if let here is because the option enumerates to exactly two options here therefore we don't need the extra syntax for matching None. I don't mind either way.

Bruce Guenter added 3 commits February 24, 2020 13:10
Signed-off-by: Bruce Guenter <bruce@timber.io>
Signed-off-by: Bruce Guenter <bruce@timber.io>
Signed-off-by: Bruce Guenter <bruce@timber.io>
Copy link
Contributor

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

docs look good 👍

Copy link
Contributor

@binarylogic binarylogic left a comment

Choose a reason for hiding this comment

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

Nice work. :shipit:

Signed-off-by: Bruce Guenter <bruce@timber.io>
@bruceg bruceg merged commit 33d529f into master Feb 26, 2020
@binarylogic binarylogic deleted the tls-sources-acceptors branch April 24, 2020 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: networking Anything related to Vector's networking domain: security Anything related to security domain: sources Anything related to the Vector's sources source: socket Anything `socket` source related source: syslog Anything `syslog` source related source: vector Anything `vector` source related type: enhancement A value-adding code change that enhances its existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants