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

Feat: review and deprecate ssl protocol/cipher settings #151

Merged
merged 12 commits into from
Apr 19, 2022

Conversation

kares
Copy link
Contributor

@kares kares commented Mar 21, 2022

following up on #146:

  • deprecating cipher_suites in favor of ssl_cipher_suites (with better validation of the supported cipher set)
  • adding ssl_supported_protocols as a replacement for tls_min_version / tls_max_version

@kares kares marked this pull request as ready for review March 30, 2022 11:04
@kares kares changed the title Feat: review and deprecate ssl protocol/cipher related settings Feat: review and deprecate ssl protocol/cipher settings Mar 30, 2022
@kares kares mentioned this pull request Mar 30, 2022
40 tasks
@andsel andsel self-requested a review March 31, 2022 13:39
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

Tested locally, with deprecated config settings and the plugin starts cleanly with only the warnings, it doesn't create any breakage.

I've requested changes to know your opinion on those, if you feel it's worthwhile to simplify.

Comment on lines 251 to 257
if @ssl && (original_params.key?('cipher_suites') && original_params.key?('ssl_cipher_suites'))
raise LogStash::ConfigurationError, "Both `ssl_cipher_suites` and (deprecated) `cipher_suites` were set. Use only `ssl_cipher_suites`."
elsif original_params.key?('cipher_suites')
@ssl_cipher_suites_final = @cipher_suites
else
@ssl_cipher_suites_final = @ssl_cipher_suites
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if @ssl is false then @ssl_cipher_suites_final end in:

  • empty list if the user configured cipher_suites.
  • SslSimpleBuilder.getDefaultCiphers if the user in any other case.
    I think that if ssl => false it shouldn't set anything related to the ciphers

I know that the method build_ssl_params has a guard:

return nil unless @ssl

Maybe isolating the fragment with an if @sslshould help.

Suggested change
if @ssl && (original_params.key?('cipher_suites') && original_params.key?('ssl_cipher_suites'))
raise LogStash::ConfigurationError, "Both `ssl_cipher_suites` and (deprecated) `cipher_suites` were set. Use only `ssl_cipher_suites`."
elsif original_params.key?('cipher_suites')
@ssl_cipher_suites_final = @cipher_suites
else
@ssl_cipher_suites_final = @ssl_cipher_suites
end
if @ssl
if original_params.key?('cipher_suites') && original_params.key?('ssl_cipher_suites')
raise LogStash::ConfigurationError, "Both `ssl_cipher_suites` and (deprecated) `cipher_suites` were set. Use only `ssl_cipher_suites`."
@ssl_cipher_suites_final = original_params.key?('cipher_suites') ?
@cipher_suites :
@ssl_cipher_suites
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ssl_cipher_suites_final won't be used since build_ssl_params isn't called.
the reason why I have it this way is due existing convention above:

    # ...
    elsif original_params.key?("verify_mode")
      @ssl_verify_mode_final = @verify_mode
    else
      @ssl_verify_mode_final = @ssl_verify_mode

Comment on lines 259 to 269
if @ssl && (original_params.key?('tls_min_version') && original_params.key?('ssl_supported_protocols'))
raise LogStash::ConfigurationError, "Both `ssl_supported_protocols` and (deprecated) `tls_min_ciphers` were set. Use only `ssl_supported_protocols`."
elsif @ssl && (original_params.key?('tls_max_version') && original_params.key?('ssl_supported_protocols'))
raise LogStash::ConfigurationError, "Both `ssl_supported_protocols` and (deprecated) `tls_max_ciphers` were set. Use only `ssl_supported_protocols`."
else
if @ssl && (original_params.key?('tls_min_version') || original_params.key?('tls_max_version'))
@ssl_supported_protocols_final = TLS.get_supported(tls_min_version..tls_max_version).map(&:name)
else
@ssl_supported_protocols_final = @ssl_supported_protocols
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Same observation as the one above, protect with an if @ssl could make it more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the attr is not set @ssl_supported_protocols_final = @ssl_supported_protocols is just nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here's a compromise refactoring: db159bb ... wdyt?

Copy link
Contributor

@andsel andsel Apr 19, 2022

Choose a reason for hiding this comment

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

The compromise is almost good, I would made it more "assertive", I mean that if an if statement return in the positive branch then simplify the negative branch.

so

if !@ssl
  @logger.warn("SSL Certificate will not be used") if @ssl_certificate
  @logger.warn("SSL Key will not be used") if @ssl_key
  @logger.warn("SSL Java Key Store will not be used") if @keystore
  return # code bellow assumes `ssl => true`
elsif !(ssl_key_configured? || ssl_jks_configured?)
  raise LogStash::ConfigurationError, "Certificate or JKS must be configured"
end

becomes:

if !@ssl
  @logger.warn("SSL Certificate will not be used") if @ssl_certificate
  @logger.warn("SSL Key will not be used") if @ssl_key
  @logger.warn("SSL Java Key Store will not be used") if @keystore
  return
end  

# code below assumes `ssl => true`
if !(ssl_key_configured? || ssl_jks_configured?)
  raise LogStash::ConfigurationError, "Certificate or JKS must be configured"
end

@kares kares requested a review from andsel April 19, 2022 09:05
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

Left just maybe a nitpick at #151 (comment) but I think it makes the code more readable.

Everything else seems ok to me.

Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants