Repository navigation
Read the private key file when <ssl> is served by WEBrick #276
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |||||||||||
|
|
||||||||||||
| require 'net/http' | ||||||||||||
| require 'zlib' | ||||||||||||
| require 'tmpdir' | ||||||||||||
| require 'fileutils' | ||||||||||||
|
|
||||||||||||
| describe Fluent::Plugin::PrometheusInput do | ||||||||||||
| CONFIG = %[ | ||||||||||||
|
|
@@ -157,6 +159,56 @@ | |||||||||||
| end | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| context 'when extra_conf is used with certificate_path and private_key_path' do | ||||||||||||
| let(:tmpdir) { Dir.mktmpdir } | ||||||||||||
| let(:key) { OpenSSL::PKey::RSA.new(2048) } | ||||||||||||
| let(:cert) do | ||||||||||||
| cert = OpenSSL::X509::Certificate.new | ||||||||||||
| cert.version = 2 | ||||||||||||
| cert.serial = 1 | ||||||||||||
| cert.subject = cert.issuer = OpenSSL::X509::Name.parse('/CN=localhost') | ||||||||||||
| cert.public_key = key.public_key | ||||||||||||
| cert.not_before = Time.now - 60 | ||||||||||||
| cert.not_after = Time.now + 3600 | ||||||||||||
| cert.sign(key, OpenSSL::Digest::SHA256.new) | ||||||||||||
| cert | ||||||||||||
| end | ||||||||||||
| let(:cert_path) { File.join(tmpdir, 'cert.pem').tap { |path| File.write(path, cert.to_pem) } } | ||||||||||||
| let(:private_key_path) { File.join(tmpdir, 'key.pem').tap { |path| File.write(path, key.to_pem) } } | ||||||||||||
| let(:config) do | ||||||||||||
| %[ | ||||||||||||
| @type prometheus | ||||||||||||
| bind 127.0.0.1 | ||||||||||||
| <ssl> | ||||||||||||
| enable true | ||||||||||||
| certificate_path #{cert_path} | ||||||||||||
| private_key_path #{private_key_path} | ||||||||||||
| extra_conf { "SSLVerifyClient": 0 } | ||||||||||||
| </ssl> | ||||||||||||
| ] | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| after { FileUtils.rm_rf(tmpdir) } | ||||||||||||
|
|
||||||||||||
| it 'serves the given certificate' do | ||||||||||||
| driver.run(timeout: 1) do | ||||||||||||
| Net::HTTP.start('127.0.0.1', port, verify_mode: OpenSSL::SSL::VERIFY_NONE, use_ssl: true) do |http| | ||||||||||||
| res = http.request(Net::HTTP::Get.new('/metrics')) | ||||||||||||
| expect(res.code).to eq('200') | ||||||||||||
| expect(http.peer_cert.to_der).to eq(cert.to_der) | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| context 'when private_key_path holds the key itself instead of a path' do | ||||||||||||
| let(:private_key_path) { %["#{key.to_pem.gsub("\n", '\n')}"] } | ||||||||||||
|
|
||||||||||||
| it 'raises an error that does not include the key' do | ||||||||||||
| expect { driver.run(timeout: 1) }.to raise_error(Fluent::ConfigError, /\Afailed to read private_key_path \(Errno::\w+\)\z/) { |e| expect(e.cause).to be_nil } | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MUST: This is the spec change for my comment on Comparing with a new exception of the same class checks that the message has only the errno text and the parameter name. It works with any errno, such as
Suggested change
|
||||||||||||
| end | ||||||||||||
| end | ||||||||||||
| end | ||||||||||||
|
|
||||||||||||
| context 'cert_path and private_key_path combination' do | ||||||||||||
| let(:config) do | ||||||||||||
| %[ | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MUST: My previous suggestion was wrong here. A
Fluent::ConfigErrorraised instartmakes the worker exit with status 2. The supervisor treats that as unrecoverable and stops all workers.This stops a worker that keeps processing logs on master. For example:
On master, worker 1 keeps restarting, and worker 0 keeps processing events. With this commit, fluentd exits with status 2 after about two seconds, so worker 0 stops too. The same happens when
private_key_pathholds the PEM text itself.It also removes recovery when the key file appears after startup. With the previous commit, the worker restarted and served metrics once the file was there. With this commit, fluentd stays stopped.
Could you keep the original
SystemCallErrorsubclass, so the worker restarts as before? Please keepcause: nil. Only the message needs to change. Readable paths, including symlinks and FIFOs, should still go through the sameFile.readcall. With the change below, the message forErrno::ENOENTbecomesNo such file or directory - private_key_path.