Skip to content

Commit 6db6964

Browse files
committed
add ca_cert to control peer verification
1 parent 2366aa3 commit 6db6964

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Renamed `cert` and `key` to `client_cert` and `client_key` respectively.
44
* Change to short timeouts on network calls so logging doesn't go dead for extended periods.
55
* Added `idle_timeout` to force upstream reconnection after a period of time with no traffic for a particular tag. Useful for low-traffic senders. Not recommended for high-traffic.
6+
* Added `ca_cert` to validate the remote certificate. Defaults to 'system' which uses the system certificate store.
67

78

89
#### 1.0.0

docs/configuration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ Example: `6514`
1919

2020
If a given tag has gone this many seconds between log messages, disconnect and reconnect before sending logs. Useful in low-traffic logging situations with remote hosts that disconnect after a period of time. Disabled by default. Example: `600`
2121

22+
### ca_cert
23+
24+
Whether and how to verify the server's TLS certificate. Examples:
25+
* ca_cert system - Default; use the system CA certificate store (which must then be configured correctly)
26+
* ca_cert false - Disable verification; not recommended
27+
* ca_cert /path/to/file - A path+filename to a single CA file
28+
* ca_cert /path/to/dir/ - A directory of CA files (in format that OpenSSL can parse); must end with /
29+
2230
### token
2331

2432
Some services require a token to identify the account. Example: `ABABABABABABA@99999`. Not required for Papertrail.

lib/fluent/plugin/out_syslog_tls.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class SyslogTlsOutput < Fluent::Output
3030
config_param :host, :string
3131
config_param :port, :integer
3232
config_param :idle_timeout, :integer, default: nil
33+
config_param :ca_cert, :string, default: 'system'
3334
config_param :token, :string, default: nil
3435
config_param :client_cert, :string, default: nil
3536
config_param :client_key, :string, default: nil
@@ -100,7 +101,7 @@ def logger(tag)
100101
end
101102

102103
def new_logger(tag)
103-
transport = ::SyslogTls::SSLTransport.new(host, port, idle_timeout: idle_timeout, client_cert: client_cert, client_key: client_key, max_retries: 3)
104+
transport = ::SyslogTls::SSLTransport.new(host, port, idle_timeout: idle_timeout, ca_cert: ca_cert, client_cert: client_cert, client_key: client_key, max_retries: 3)
104105
logger = ::SyslogTls::Logger.new(transport, token)
105106
logger.facility(facility)
106107
logger.hostname(hostname)

lib/syslog_tls/ssl_transport.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ class SSLTransport
2525

2626
attr_accessor :socket
2727

28-
attr_reader :host, :port, :idle_timeout, :client_cert, :client_key, :ssl_version
28+
attr_reader :host, :port, :idle_timeout, :ca_cert, :client_cert, :client_key, :ssl_version
2929

3030
attr_writer :retries
3131

32-
def initialize(host, port, idle_timeout: nil, client_cert: nil, client_key: nil, ssl_version: :TLSv1_2, max_retries: 1)
32+
def initialize(host, port, idle_timeout: nil, ca_cert: 'system', client_cert: nil, client_key: nil, ssl_version: :TLSv1_2, max_retries: 1)
3333
@host = host
3434
@port = port
3535
@idle_timeout = idle_timeout
36+
@ca_cert = ca_cert
3637
@client_cert = client_cert
3738
@client_key = client_key
3839
@ssl_version = ssl_version
@@ -96,6 +97,19 @@ def get_ssl_connection
9697
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
9798
ctx.ssl_version = ssl_version
9899

100+
case ca_cert
101+
when true, 'true', 'system'
102+
# use system certs, same as openssl cli
103+
ctx.cert_store = OpenSSL::X509::Store.new
104+
ctx.cert_store.set_default_paths
105+
when false, 'false'
106+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
107+
when %r{/$} # ends in /
108+
ctx.ca_path = ca_cert
109+
when String
110+
ctx.ca_file = ca_cert
111+
end
112+
99113
ctx.cert = OpenSSL::X509::Certificate.new(File.read(client_cert)) if client_cert
100114
ctx.key = OpenSSL::PKey::read(File.read(client_key)) if client_key
101115
socket = OpenSSL::SSL::SSLSocket.new(tcp, ctx)

0 commit comments

Comments
 (0)