Skip to content

Commit e3a6950

Browse files
committed
add verify_cert_name option
1 parent a182ff9 commit e3a6950

File tree

7 files changed

+34
-11
lines changed

7 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
* Support SNI and enable cert name verification.
1+
#### 2.0.0
2+
23
* Require Ruby 2.4
4+
* Support SNI and enable cert name verification by default. **This changes the default behavior** and may cause issues if the remote server's cert does not match the configured hostname.
5+
* Add `verify_cert_name` to enable (default) or disable cert name verification.
6+
Note: `ca_cert` verifies the certificate signing chain. `verify_cert_name` verifies the CN/SAN name on the cert.
37

48

59
#### 1.2.1

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
fluent-plugin-syslog-tls (1.2.1)
4+
fluent-plugin-syslog-tls (2.0.0)
55
fluentd (>= 0.14.0, < 2)
66

77
GEM

docs/configuration.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ If a given tag has gone this many seconds between log messages, disconnect and r
2121

2222
### ca_cert
2323

24-
Whether and how to verify the server's TLS certificate. Examples:
24+
Whether and how to verify the server's TLS certificate signing chain. Examples:
2525
* ca_cert system - Default; use the system CA certificate store (which must then be configured correctly)
2626
* ca_cert false - Disable verification; not recommended
2727
* ca_cert /path/to/file - A path+filename to a single CA file
2828
* ca_cert /path/to/dir/ - A directory of CA files (in format that OpenSSL can parse); must end with /
2929

30+
### verify_cert_name
31+
32+
Whether to verify that the server's cert matches `host`. Enabled by default (except when `ca_cert false`). Recommended; helps prevent MitM attacks. Example: `true`
33+
3034
### token
3135

3236
Some services require a token to identify the account. Example: `ABABABABABABA@99999`. Not required for Papertrail.
@@ -114,6 +118,7 @@ Optionally record key where to get msgid from the record. If not provided nil va
114118
token [token]@[iana-id]
115119
client_cert /path/to/cert/file.crt
116120
client_key /path/to/key/file.key
121+
verify_cert_name true
117122
118123
hostname static-hostname
119124
facility SYSLOG

lib/fluent/plugin/out_syslog_tls.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2016 Acquia, Inc.
2-
# Copyright 2016 t.e.morgan.
2+
# Copyright 2016-2019 t.e.morgan.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ class SyslogTlsOutput < Output
2929
config_param :port, :integer
3030
config_param :idle_timeout, :integer, default: nil
3131
config_param :ca_cert, :string, default: 'system'
32+
config_param :verify_cert_name, :bool, default: true
3233
config_param :token, :string, default: nil
3334
config_param :client_cert, :string, default: nil
3435
config_param :client_key, :string, default: nil
@@ -98,7 +99,14 @@ def logger(tag)
9899
end
99100

100101
def new_logger(tag)
101-
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)
102+
transport = ::SyslogTls::SSLTransport.new(host, port,
103+
idle_timeout: idle_timeout,
104+
ca_cert: ca_cert,
105+
client_cert: client_cert,
106+
client_key: client_key,
107+
verify_cert_name: verify_cert_name,
108+
max_retries: 3,
109+
)
102110
logger = ::SyslogTls::Logger.new(transport, token)
103111
logger.facility(facility)
104112
logger.hostname(hostname)

lib/syslog_tls/ssl_transport.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2016 Acquia, Inc.
2-
# Copyright 2016 t.e.morgan.
2+
# Copyright 2016-2019 t.e.morgan.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -25,17 +25,18 @@ class SSLTransport
2525

2626
attr_accessor :socket
2727

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

3030
attr_writer :retries
3131

32-
def initialize(host, port, idle_timeout: nil, ca_cert: 'system', 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, verify_cert_name: true, ssl_version: :TLSv1_2, max_retries: 1)
3333
@host = host
3434
@port = port
3535
@idle_timeout = idle_timeout
3636
@ca_cert = ca_cert
3737
@client_cert = client_cert
3838
@client_key = client_key
39+
@verify_cert_name = verify_cert_name
3940
@ssl_version = ssl_version
4041
@retries = max_retries
4142
connect
@@ -97,12 +98,15 @@ def get_ssl_connection
9798
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
9899
ctx.ssl_version = ssl_version
99100

101+
ctx.verify_hostname = verify_cert_name != false
102+
100103
case ca_cert
101104
when true, 'true', 'system'
102105
# use system certs, same as openssl cli
103106
ctx.cert_store = OpenSSL::X509::Store.new
104107
ctx.cert_store.set_default_paths
105108
when false, 'false'
109+
ctx.verify_hostname = false
106110
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
107111
when %r{/$} # ends in /
108112
ctx.ca_path = ca_cert

lib/syslog_tls/version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2016 Acquia, Inc.
2-
# Copyright 2016-2018 t.e.morgan.
2+
# Copyright 2016-2019 t.e.morgan.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -14,5 +14,5 @@
1414
# limitations under the License.
1515

1616
module SyslogTls
17-
VERSION = '1.2.1'
17+
VERSION = '2.0.0'
1818
end

test/fluent/test_out_syslog_tls.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2016 Acquia, Inc.
2-
# Copyright 2016 t.e.morgan.
2+
# Copyright 2016-2019 t.e.morgan.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -55,6 +55,7 @@ def test_configure
5555
port 6514
5656
client_cert
5757
client_key
58+
verify_cert_name true
5859
token 1234567890
5960
}
6061
instance = driver(config).instance
@@ -63,6 +64,7 @@ def test_configure
6364
assert_equal '6514', instance.port
6465
assert_equal '', instance.client_cert
6566
assert_equal '', instance.client_key
67+
assert_equal true, instance.verify_cert_name
6668
assert_equal '1234567890', instance.token
6769
end
6870

0 commit comments

Comments
 (0)