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

Added support for CRL check #62

Merged
merged 3 commits into from
Sep 14, 2023
Merged

Conversation

tsaarni
Copy link
Contributor

@tsaarni tsaarni commented Sep 15, 2022

This change adds support for CRL (Certificate Revocation List) check, to validate that the certificate of the syslog server has not been revoked. The CRL is loaded from file, meaning it must be pre-loaded on the system where logstash is executing.


Part of elastic/logstash#15236

@tsaarni
Copy link
Contributor Author

tsaarni commented Sep 15, 2022

Tests do not work anymore with current logstash version because of #51.

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.

I have some doubts on how the code behaves if the file is malformed. Maybe those error could be catched and shape a better ConfigurationError exception.
How could I test this?
Could you cover the feature with some unit test?

lib/logstash/outputs/syslog.rb Outdated Show resolved Hide resolved
lib/logstash/outputs/syslog.rb Show resolved Hide resolved
@tsaarni
Copy link
Contributor Author

tsaarni commented Sep 13, 2023

Sorry for delay!

The plugin is lacking all TLS related tests, so I made an attempt to add some, including tests for reading malformed PEM files. I took inspiration from https://github.com/logstash-plugins/logstash-output-tcp for the setup of TLS server.

I needed some test certificates, which I committed in the repo. I hope that is OK. I used my own tool certyaml to create those.

I have some doubts on how the code behaves if the file is malformed. Maybe those error could be catched and shape a better ConfigurationError exception. How could I test this? Could you cover the feature with some unit test?

It seems to fail in a same way as it has been failing if user would pass invalid certificate or private key. For some reason, there is no error when loading malformed CA certificate, which may be a problem jruby-openssl.

@andsel andsel self-requested a review September 14, 2023 07:00
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.

A great thank you @tsaarni for huge amount of work on this!

I think we are pretty close, left a couple of suggestions.

Comment on lines 136 to 150
# TODO: there is no failure when reading malformed CA certificate
#
# context "invalid CA certificate" do
# let(:options ) { super().merge(
# "ssl_cert" => File.join(FIXTURES_PATH, "client.pem"),
# "ssl_key" => File.join(FIXTURES_PATH, "client-key.pem"),
# "ssl_cacert" => File.join(FIXTURES_PATH, "invalid.pem"),
# "ssl_crl" => File.join(FIXTURES_PATH, "ca-crl.pem")
# ) }

# it "register raises error" do
# expect { subject.register }.to raise_error(OpenSSL::PKey::RSAError, /malformed PEM data/)
# 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.

Suggested change
# TODO: there is no failure when reading malformed CA certificate
#
# context "invalid CA certificate" do
# let(:options ) { super().merge(
# "ssl_cert" => File.join(FIXTURES_PATH, "client.pem"),
# "ssl_key" => File.join(FIXTURES_PATH, "client-key.pem"),
# "ssl_cacert" => File.join(FIXTURES_PATH, "invalid.pem"),
# "ssl_crl" => File.join(FIXTURES_PATH, "ca-crl.pem")
# ) }
# it "register raises error" do
# expect { subject.register }.to raise_error(OpenSSL::PKey::RSAError, /malformed PEM data/)
# end
# end

Remove commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment on lines 74 to 92
context "ssl_verify == false, server with untrusted certificates" do
let(:options ) { super().merge("ssl_verify" => false) }
let(:server_cert_file) { File.join(FIXTURES_PATH, "untrusted-server.pem") }
let(:server_pkey_file) { File.join(FIXTURES_PATH, "untrusted-server-key.pem") }

it_behaves_like "syslog output"
end

context "ssl_verify == true, server with untrusted certificates" do
let(:options ) { super().merge("ssl_verify" => true) }
let(:server_cert_file) { File.join(FIXTURES_PATH, "untrusted-server.pem") }
let(:server_pkey_file) { File.join(FIXTURES_PATH, "untrusted-server-key.pem") }

it "syslog output refuses to connect" do
Thread.start { secure_server.accept rescue nil }
expect(subject.logger).to receive(:error).with(/SSL Error/i, hash_including(exception: OpenSSL::SSL::SSLError)).once.and_throw :TEST_DONE
expect { subject.receive event }.to throw_symbol(:TEST_DONE)
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.

Suggested change
context "ssl_verify == false, server with untrusted certificates" do
let(:options ) { super().merge("ssl_verify" => false) }
let(:server_cert_file) { File.join(FIXTURES_PATH, "untrusted-server.pem") }
let(:server_pkey_file) { File.join(FIXTURES_PATH, "untrusted-server-key.pem") }
it_behaves_like "syslog output"
end
context "ssl_verify == true, server with untrusted certificates" do
let(:options ) { super().merge("ssl_verify" => true) }
let(:server_cert_file) { File.join(FIXTURES_PATH, "untrusted-server.pem") }
let(:server_pkey_file) { File.join(FIXTURES_PATH, "untrusted-server-key.pem") }
it "syslog output refuses to connect" do
Thread.start { secure_server.accept rescue nil }
expect(subject.logger).to receive(:error).with(/SSL Error/i, hash_including(exception: OpenSSL::SSL::SSLError)).once.and_throw :TEST_DONE
expect { subject.receive event }.to throw_symbol(:TEST_DONE)
end
end
context "server with untrusted certificates" do
let(:server_cert_file) { File.join(FIXTURES_PATH, "untrusted-server.pem") }
let(:server_pkey_file) { File.join(FIXTURES_PATH, "untrusted-server-key.pem") }
context "ss_verify disabled" do
let(:options ) { super().merge("ssl_verify" => false) }
it_behaves_like "syslog output"
end
context "ss_verify enabled" do
let(:options ) { super().merge("ssl_verify" => true) }
it "should refuse to connect" do
Thread.start { secure_server.accept rescue nil }
expect(subject.logger).to receive(:error).with(/SSL Error/i, hash_including(exception: OpenSSL::SSL::SSLError)).once.and_throw :TEST_DONE
expect { subject.receive event }.to throw_symbol(:TEST_DONE)
end
end
end

A nested context could make it even 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.

True, changed accordingly!

@tsaarni
Copy link
Contributor Author

tsaarni commented Sep 14, 2023

A great thank you @tsaarni for huge amount of work on this!

I think we are pretty close, left a couple of suggestions.

No problem, adding TLS tests is a good learning experience for a ruby newbie like me :)

@andsel andsel self-requested a review September 14, 2023 08:31
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

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, please add a line to the Changelog file describing this feature.

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

@andsel andsel merged commit e8008b1 into logstash-plugins:main Sep 14, 2023
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.

Contributing to logstash-output-syslog and status of the plugin?
2 participants