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

Fix sslsubject regression #159

Closed
wants to merge 3 commits into from
Closed

Fix sslsubject regression #159

wants to merge 3 commits into from

Conversation

rwaweber
Copy link
Contributor

@rwaweber rwaweber commented Jun 17, 2020

- Removes some (what looks like to me) dead code for TLS setup Nope! The code was used in client mode, totally misread it.

  • Add a regression test to catch if the sslsubject field ever disappears in the future

Attempt to follow the same general flow for tls principal extraction as the beats input plugin:

https://github.com/logstash-plugins/logstash-input-beats/blob/5dd54594f65d32aad87d1dfd7b04d0c801216676/lib/logstash/inputs/beats/message_listener.rb#L125-L155

Extract the ssl subject from inbound messages by:

  • adjust the interface to pass in the Netty ChannelHandlerContext instead of an Address object. I think that this opens up the possibility for being able to eventually work in other metadata into TLS-ified objects

  • name the InputHandler's ssl_handler to more reliably retrieve it from the available netty Channel Pipelines.

  • in the decoder, check if ssl_verify and ssl_enable are true and pull out the subjectname from the context

Should help close #143

@rwaweber
Copy link
Contributor Author

Hey all! Any thoughts on the above?

@rwaweber
Copy link
Contributor Author

rwaweber commented Jul 9, 2020

Hey all -- friendly poke, would love to get your thoughts on this considering this component is currently broken and seems to have been that way since around the time of the Netty addition.

@rwaweber
Copy link
Contributor Author

Hey @jsvd -- sorry to ping you directly, but do you have an idea of when this could get looked at?
I'd love to be able to use the sslsubject features again in an upcoming release

Copy link
Contributor

@robbavey robbavey left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution @rwaweber, and thank you for your patience.

Unfortunately, as it stands, the PR breaks existing functionality - the plugin has two modes, server and client, which have quite different implementations. Reinstating the removed "dead" code and some minor refactoring should fix this, however.

lib/logstash/inputs/tcp.rb Outdated Show resolved Hide resolved
lib/logstash/inputs/tcp/decoder_impl.rb Outdated Show resolved Hide resolved
lib/logstash/inputs/tcp.rb Show resolved Hide resolved
@rwaweber
Copy link
Contributor Author

Hey Rob! Thanks for the suggestions -- my bad on accidentally snipping the client mode chunks, I completely missed those components.

I'll reinstate the aforementioned methods to not break functionality and incorporate the other suggestions too.

Attempt to follow the same general flow for tls principal extraction as
the beats input plugin:

https://github.com/logstash-plugins/logstash-input-beats/blob/5dd54594f65d32aad87d1dfd7b04d0c801216676/lib/logstash/inputs/beats/message_listener.rb#L125-L155

Extract's the ssl subject from inbound messages by:

- adjust the interface to pass in the Netty ChannelHandlerContext instead of the Address name the InputHandler's ssl_handler

- in the decoder, check if ssl_verify and ssl_enable are true and pull out the subjectname from the context

Follow up after review:

- Restore ssl-setup code needed for client-mode initialization

- Swap conditionals to check for sslsubject extraction
Reducing the number of times we refer to the socket object so that
most of the interaction lives in the `handle_socket` method.

Remove redundant conditional in ssl_subject assignment, it's already
assumed that we're in client mode at that point.

Necessary to also fix up refderences in the DecoderImpl class as well,
since the tcp plugin's decode_buffer method changed.
@rwaweber rwaweber requested a review from robbavey July 29, 2020 21:07
@tcp.decode_buffer(@ip_address, @address, @port, @codec,
@proxy_address, @proxy_port, tbuf, nil)
if @tcp.ssl_enable && @tcp.ssl_verify
session = ctx.channel().pipeline().get("ssl-handler").engine().getSession()
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a pretty long chain, and it is unclear why we stop here to bind a local variable session, which we use only once to continue the chain.

  • are all methods in the chain documented to never return nil?
  • should we extract this complexity to a helper method that has appropriate rescue clauses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are all methods in the chain documented to never return nil?

It seems that way, aside from the ChannelPipeline#get we invoke, though since we explicitly name our channelhandler here, we should be safe in that respect.

should we extract this complexity to a helper method that has appropriate rescue clauses?

I think thats a great idea, though I sort of think it might be worth tucking in somewhere like the logstash/base/inputs package, since we'd be repeating the same logic in this plugin, the beats input plugin, and potentially other plugins where netty is used and TLS metadata extraction is possible. We would need to be careful about formatting though, as different input plugins seem to serialize TLS metadata differently. (it gets cut to 3 fields in the beats plugin and one field here).

Also, as an update on my last message, looking more closely, I'm not sure that rescue clause I cite would really be adding much in terms of safety, but would be more for debug logging insight.

@rwaweber
Copy link
Contributor Author

Hey all! Is there anything else you'd like me to add here?

I think I covered most of @robbavey's earlier concerns, though I'm not quite sure if I've covered @yaauie's points. Happy to continue the discussion.

@rwaweber
Copy link
Contributor Author

Hey all, friendly ping — happy to make some additional changes to get this feature fixed.

@rwaweber
Copy link
Contributor Author

Hey @acchen97 -- any chance you'd be able to lend a hand here?

@kervel
Copy link

kervel commented Sep 8, 2021

Hello, we are facing the same issue. Any reason why this is not getting merged ?

yaauie added a commit to yaauie/logstash-input-tcp that referenced this pull request Mar 29, 2022
Alters the TCP#decode_buffer signature to accept the _ssl subject_ instead of
expecting a ruby socket, so that it can be interoperable between the ruby-based
client mode and the netty-powered server mode.

In server mode, the SSL subject is extracted _once_ when initializing the
connection IFF SSL is enabled and verification is turned on.

Co-authored-by: Will Weber <[email protected]>
Closes: logstash-plugins#159
yaauie added a commit to yaauie/logstash-input-tcp that referenced this pull request Mar 30, 2022
Alters the TCP#decode_buffer signature to accept the _ssl subject_ instead of
expecting a ruby socket, so that it can be interoperable between the ruby-based
client mode and the netty-powered server mode.

In server mode, the SSL subject is extracted _once_ when initializing the
connection IFF SSL is enabled and verification is turned on.

Co-authored-by: Will Weber <[email protected]>
Closes: logstash-plugins#159
yaauie added a commit to yaauie/logstash-input-tcp that referenced this pull request Apr 4, 2022
Alters the TCP#decode_buffer signature to accept the _ssl subject_ instead of
expecting a ruby socket, so that it can be interoperable between the ruby-based
client mode and the netty-powered server mode.

In server mode, the SSL subject is extracted _once_ when initializing the
connection IFF SSL is enabled and verification is turned on.

Co-authored-by: Will Weber <[email protected]>
Closes: logstash-plugins#159
@yaauie yaauie closed this in #199 Oct 12, 2022
yaauie added a commit that referenced this pull request Oct 12, 2022
* Fix SSL Subject regression in server mode

Alters the TCP#decode_buffer signature to accept the _ssl subject_ instead of
expecting a ruby socket, so that it can be interoperable between the ruby-based
client mode and the netty-powered server mode.

In server mode, the SSL subject is extracted _once_ when initializing the
connection IFF SSL is enabled and verification is turned on.

Co-authored-by: Will Weber <[email protected]>
Closes: #159

* include docker jdk17 env

Co-authored-by: Will Weber <[email protected]>
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.

SSLSUBJECT broken again
5 participants