Skip to content

Commit adaeae3

Browse files
out_http: TLS1.3 support (#4859)
**Which issue(s) this PR fixes**: Fixes #4332 **What this PR does / why we need it**: Changes the way we configure Net::HTTP client. **Docs Changes**: fluent/fluentd-docs-gitbook#579 **Release Note**: The same as the title. --------- Signed-off-by: Athishpranav2003 <athishanna@gmail.com>
1 parent c43586e commit adaeae3

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

lib/fluent/plugin/out_http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def setup_http_option
270270
OpenSSL::SSL::VERIFY_PEER
271271
end
272272
opt[:ciphers] = @tls_ciphers
273-
opt[:ssl_version] = @tls_version
273+
opt = Fluent::TLS.set_version_to_options(opt, @tls_version, nil, nil)
274274
end
275275

276276
opt

lib/fluent/tls.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ def set_version_to_context(ctx, version, min_version, max_version)
7676
ctx
7777
end
7878
module_function :set_version_to_context
79+
80+
def set_version_to_options(opt, version, min_version, max_version)
81+
if MIN_MAX_AVAILABLE
82+
case
83+
when min_version.nil? && max_version.nil?
84+
min_version = METHODS_MAP[version] || version
85+
max_version = METHODS_MAP[version] || version
86+
when min_version.nil? && max_version
87+
raise Fluent::ConfigError, "When you set max_version, must set min_version together"
88+
when min_version && max_version.nil?
89+
raise Fluent::ConfigError, "When you set min_version, must set max_version together"
90+
else
91+
min_version = METHODS_MAP[min_version] || min_version
92+
max_version = METHODS_MAP[max_version] || max_version
93+
end
94+
opt[:min_version] = min_version
95+
opt[:max_version] = max_version
96+
else
97+
opt[:ssl_version] = METHODS_MAP[version] || version
98+
end
99+
100+
opt
101+
end
102+
module_function :set_version_to_options
79103
end
80104
end
81105

test/plugin/test_out_http.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ def server_config
501501
# WEBrick supports self-generated self-signed certificate
502502
config[:SSLEnable] = true
503503
config[:SSLCertName] = [["CN", WEBrick::Utils::getservername]]
504+
config[:SSLMaxVersion] = OpenSSL::SSL::TLS1_3_VERSION
504505
config
505506
end
506507

@@ -512,6 +513,7 @@ def test_write_with_https
512513
d = create_driver(%[
513514
endpoint https://127.0.0.1:#{server_port}/test
514515
tls_verify_mode none
516+
tls_version TLSv1_3
515517
ssl_timeout 2s
516518
])
517519
d.run(default_tag: 'test.http') do

test/test_tls.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class UniqueIdTest < Test::Unit::TestCase
1010
'New TLS v1.2' => :'TLS1_2',
1111
'Old TLS v1.2' => :'TLSv1_2'
1212
}
13+
TEST_TLS1_3_CASES = {
14+
'New TLS v1.3' => :'TLS1_3',
15+
'Old TLS v1.3' => :'TLSv1_3'
16+
} if defined?(OpenSSL::SSL::TLS1_3_VERSION)
1317
TEST_TLS_CASES = TEST_TLS1_1_CASES.merge(TEST_TLS1_2_CASES)
1418

1519
sub_test_case 'constants' do
@@ -62,4 +66,26 @@ class UniqueIdTest < Test::Unit::TestCase
6266
}
6367
end
6468
end
69+
70+
sub_test_case 'set_version_to_options' do
71+
setup do
72+
@opt = {}
73+
end
74+
75+
test 'set min_version/max_version when supported' do
76+
omit "min_version=/max_version= is not supported" unless Fluent::TLS::MIN_MAX_AVAILABLE
77+
78+
ver = Fluent::TLS::DEFAULT_VERSION
79+
assert_raise(Fluent::ConfigError) {
80+
Fluent::TLS.set_version_to_options(@opt, ver, ver, nil)
81+
}
82+
assert_raise(Fluent::ConfigError) {
83+
Fluent::TLS.set_version_to_options(@opt, ver, nil, ver)
84+
}
85+
86+
ver = :'TLSv1_3' if defined?(OpenSSL::SSL::TLS1_3_VERSION)
87+
assert_equal Fluent::TLS.const_get(:METHODS_MAP)[ver], Fluent::TLS.set_version_to_options(@opt, ver, nil, nil)[:min_version]
88+
assert_equal Fluent::TLS.const_get(:METHODS_MAP)[ver], Fluent::TLS.set_version_to_options(@opt, ver, nil, nil)[:max_version]
89+
end
90+
end
6591
end

0 commit comments

Comments
 (0)