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

Make verify_hostname settable for ssl contexts #828

Merged
merged 2 commits into from
May 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -945,6 +945,8 @@ This configures the store to look up CA certificates from the system default cer

In order to authenticate the client to the cluster, you need to pass in a certificate and key created for the client and trusted by the brokers.

**NOTE**: You can disable hostname validation by passing `verify_hostname: false`.

```ruby
kafka = Kafka.new(
["kafka1:9092"],
4 changes: 4 additions & 0 deletions lib/kafka/client.rb
Original file line number Diff line number Diff line change
@@ -65,6 +65,10 @@ class Client
# @param sasl_oauth_token_provider [Object, nil] OAuthBearer Token Provider instance that
# implements method token. See {Sasl::OAuth#initialize}
#
# @param verify_hostname [Boolean, true] whether to verify that the host serving
# the SSL certificate and the signing chain of the certificate have the correct domains
# based on the CA certificate
#
# @return [Client]
def initialize(seed_brokers:, client_id: "ruby-kafka", logger: nil, connect_timeout: nil, socket_timeout: nil,
ssl_ca_cert_file_path: nil, ssl_ca_cert: nil, ssl_client_cert: nil, ssl_client_cert_key: nil,
7 changes: 4 additions & 3 deletions lib/kafka/ssl_context.rb
Original file line number Diff line number Diff line change
@@ -54,11 +54,12 @@ def self.build(ca_cert_file_path: nil, ca_cert: nil, client_cert: nil, client_ce
store.set_default_paths
end
ssl_context.cert_store = store
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
# Verify certificate hostname if supported (ruby >= 2.4.0)
ssl_context.verify_hostname = verify_hostname if ssl_context.respond_to?(:verify_hostname=)
end

ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
# Verify certificate hostname if supported (ruby >= 2.4.0)
ssl_context.verify_hostname = verify_hostname if ssl_context.respond_to?(:verify_hostname=)

ssl_context
end
end