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

Improve consistency of messaging around ssl_verify_mode #359

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions lib/logstash/inputs/beats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ def register
end

if @ssl && require_certificate_authorities? && !client_authentification?
raise LogStash::ConfigurationError, "Using `verify_mode` set to PEER or FORCE_PEER, requires the configuration of `certificate_authorities`"
raise LogStash::ConfigurationError, "Using `ssl_verify_mode` set to `peer` or `force_peer`, requires the configuration of `certificate_authorities`"
end

if client_authentication_metadata? && !require_certificate_authorities?
raise LogStash::ConfigurationError, "Enabling `peer_metadata` requires using `verify_mode` set to PEER or FORCE_PEER"
raise LogStash::ConfigurationError, "Enabling `peer_metadata` requires using `ssl_verify_mode` set to `peer` or `force_peer`"
end

# Logstash 6.x breaking change (introduced with 4.0.0 of this gem)
Expand Down Expand Up @@ -177,9 +177,9 @@ def create_server
ssl_builder.setHandshakeTimeoutMilliseconds(@ssl_handshake_timeout)

if client_authentification?
if @ssl_verify_mode.upcase == "FORCE_PEER"
if @ssl_verify_mode == "force_peer"
ssl_builder.setVerifyMode(org.logstash.netty.SslSimpleBuilder::SslClientVerifyMode::FORCE_PEER)
elsif @ssl_verify_mode.upcase == "PEER"
elsif @ssl_verify_mode == "peer"
ssl_builder.setVerifyMode(org.logstash.netty.SslSimpleBuilder::SslClientVerifyMode::VERIFY_PEER)
end
ssl_builder.setCertificateAuthorities(@ssl_certificate_authorities)
Expand Down Expand Up @@ -217,7 +217,7 @@ def client_authentication_metadata?
end

def client_authentication_required?
@ssl_verify_mode == "force_peer"
@ssl_verify_mode == "force_peer"
end

def require_certificate_authorities?
Expand Down
19 changes: 14 additions & 5 deletions spec/inputs/beats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@
end
end

context "verify_mode" do
context "verify_mode configured to PEER" do
context "ssl_verify_mode" do
context 'ssl_verify_mode requires downcased values' do
let(:config) { {"ssl_certificate_authorities" => [certificate.ssl_cert], "port" => 0, "ssl" => true, "ssl_verify_mode" => "PEER", "ssl_certificate" => certificate.ssl_cert, "ssl_key" => certificate.ssl_key, "type" => "example", "tags" => "Beats"} }

it "raise a ConfigurationError when ssl_verify_mode is not downcased" do
expect {LogStash::Inputs::Beats.new(config)}.to raise_error(LogStash::ConfigurationError)
end

end

context "ssl_verify_mode configured to peer" do
let(:config) { { "port" => 0, "ssl" => true, "ssl_verify_mode" => "peer", "ssl_certificate" => certificate.ssl_cert, "ssl_key" => certificate.ssl_key, "type" => "example", "tags" => "Beats"} }

it "raise a ConfigurationError when certificate_authorities is not set" do
plugin = LogStash::Inputs::Beats.new(config)
expect {plugin.register}.to raise_error(LogStash::ConfigurationError, "Using `verify_mode` set to PEER or FORCE_PEER, requires the configuration of `certificate_authorities`")
expect {plugin.register}.to raise_error(LogStash::ConfigurationError, "Using `ssl_verify_mode` set to `peer` or `force_peer`, requires the configuration of `certificate_authorities`")
end

it "doesn't raise a configuration error when certificate_authorities is set" do
Expand All @@ -78,12 +87,12 @@
end
end

context "verify_mode configured to FORCE_PEER" do
context "ssl_verify_mode configured to force_peer" do
let(:config) { { "port" => 0, "ssl" => true, "ssl_verify_mode" => "force_peer", "ssl_certificate" => certificate.ssl_cert, "ssl_key" => certificate.ssl_key, "type" => "example", "tags" => "Beats"} }

it "raise a ConfigurationError when certificate_authorities is not set" do
plugin = LogStash::Inputs::Beats.new(config)
expect {plugin.register}.to raise_error(LogStash::ConfigurationError, "Using `verify_mode` set to PEER or FORCE_PEER, requires the configuration of `certificate_authorities`")
expect {plugin.register}.to raise_error(LogStash::ConfigurationError, "Using `ssl_verify_mode` set to `peer` or `force_peer`, requires the configuration of `certificate_authorities`")
end

it "doesn't raise a configuration error when certificate_authorities is set" do
Expand Down