Skip to content

Commit bca64db

Browse files
karesyaauie
andauthored
Feat: ssl_supported_protocols (TLSv1.3) + ssl_cipher_suites (#198)
* requires Logstash 8.1 or later (due jruby-openssl pinning) Co-authored-by: Ry Biesemeyer <[email protected]>
1 parent 038acbe commit bca64db

File tree

9 files changed

+318
-18
lines changed

9 files changed

+318
-18
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
import:
2-
- logstash-plugins/.ci:travis/[email protected]
2+
- logstash-plugins/.ci:travis/[email protected]
3+
- logstash-plugins/.ci:travis/[email protected]
4+
5+
env:
6+
jobs:
7+
- ELASTIC_STACK_VERSION=8.x
8+
- SNAPSHOT=true ELASTIC_STACK_VERSION=8.x

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 6.3.0
2+
- Feat: ssl_supported_protocols (TLSv1.3) + ssl_cipher_suites [#198](https://github.com/logstash-plugins/logstash-input-tcp/pull/198)
3+
14
## 6.2.7
25
- Build: skip shadowing jar dependencies [#187](https://github.com/logstash-plugins/logstash-input-tcp/pull/187)
36
* plugin no longer shadows dependencies into its *logstash-input-tcp.jar*

docs/index.asciidoc

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ This plugin supports the following configuration options plus the <<plugins-{typ
132132
| <<plugins-{type}s-{plugin}-proxy_protocol>> |<<boolean,boolean>>|No
133133
| <<plugins-{type}s-{plugin}-ssl_cert>> |a valid filesystem path|No
134134
| <<plugins-{type}s-{plugin}-ssl_certificate_authorities>> |<<array,array>>|No
135+
| <<plugins-{type}s-{plugin}-ssl_cipher_suites>> |<<string,string>>|No
135136
| <<plugins-{type}s-{plugin}-ssl_enable>> |<<boolean,boolean>>|No
136137
| <<plugins-{type}s-{plugin}-ssl_extra_chain_certs>> |<<array,array>>|No
137138
| <<plugins-{type}s-{plugin}-ssl_key>> |a valid filesystem path|No
138139
| <<plugins-{type}s-{plugin}-ssl_key_passphrase>> |<<password,password>>|No
140+
| <<plugins-{type}s-{plugin}-ssl_supported_protocols>> |<<string,string>>|No
139141
| <<plugins-{type}s-{plugin}-ssl_verify>> |<<boolean,boolean>>|No
140142
| <<plugins-{type}s-{plugin}-tcp_keep_alive>> |<<boolean,boolean>>|No
141143
|=======================================================================
@@ -158,13 +160,13 @@ at the TCP layer and IPs will not be resolved to hostnames.
158160
[id="plugins-{type}s-{plugin}-ecs_compatibility"]
159161
===== `ecs_compatibility`
160162

161-
* Value type is <<string,string>>
162-
* Supported values are:
163-
** `disabled`: unstructured connection metadata added at root level
164-
** `v1`,`v8`: structured connection metadata added under `[@metadata][input][tcp]`
165-
* Default value depends on which version of Logstash is running:
166-
** When Logstash provides a `pipeline.ecs_compatibility` setting, its value is used as the default
167-
** Otherwise, the default value is `disabled`.
163+
* Value type is <<string,string>>
164+
* Supported values are:
165+
** `disabled`: unstructured connection metadata added at root level
166+
** `v1`,`v8`: structured connection metadata added under `[@metadata][input][tcp]`
167+
* Default value depends on which version of Logstash is running:
168+
** When Logstash provides a `pipeline.ecs_compatibility` setting, its value is used as the default
169+
** Otherwise, the default value is `disabled`.
168170

169171
Controls this plugin's compatibility with the https://www.elastic.co/guide/en/ecs/current/index.html[Elastic Common Schema (ECS)].
170172
The value of this setting affects the <<plugins-{type}s-{plugin}-ecs_metadata,placement of a TCP connection's metadata>> on events.
@@ -224,6 +226,18 @@ to the connecting clients.
224226
Validate client certificate or certificate chain against these authorities.
225227
You can define multiple files or paths. All the certificates will be read and added to the trust store.
226228

229+
[id="plugins-{type}s-{plugin}-ssl_cipher_suites"]
230+
===== `ssl_cipher_suites`
231+
232+
* Value type is <<string,string>>
233+
* Default value includes _all_ cipher suites enabled by the JDK and depends on JDK configuration
234+
235+
Supported cipher suites vary depending on Java version used, and entries look like `TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384`.
236+
For more information, see Oracle’s https://docs.oracle.com/en/java/javase/11/security/oracle-providers.html#GUID-7093246A-31A3-4304-AC5F-5FB6400405E2[JDK SunJSSE provider documentation] and
237+
the table of supported https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#jsse-cipher-suite-names[Java cipher suite names].
238+
239+
NOTE: To check the supported cipher suites locally run the following script: `$LS_HOME/bin/ruby -e 'p javax.net.ssl.SSLServerSocketFactory.getDefault.getSupportedCipherSuites'`.
240+
227241
[id="plugins-{type}s-{plugin}-ssl_enable"]
228242
===== `ssl_enable`
229243

@@ -258,6 +272,20 @@ The path to the private key corresponding to the specified certificate (PEM form
258272

259273
SSL key passphrase for the private key.
260274

275+
[id="plugins-{type}s-{plugin}-ssl_supported_protocols"]
276+
===== `ssl_supported_protocols`
277+
278+
* Value type is <<string,string>>
279+
* Allowed values are: `'TLSv1.1'`, `'TLSv1.2'`, `'TLSv1.3'`
280+
* Default depends on the JDK being used. With up-to-date Logstash, the default is `['TLSv1.2', 'TLSv1.3']`.
281+
`'TLSv1.1'` is not considered secure and is only provided for legacy applications.
282+
283+
List of allowed SSL/TLS versions to use when establishing a secure connection.
284+
285+
NOTE: If you configure the plugin to use `'TLSv1.1'` on any recent JVM, such as the one packaged with Logstash,
286+
the protocol is disabled by default and needs to be enabled manually by changing `jdk.tls.disabledAlgorithms` in
287+
the *$JDK_HOME/conf/security/java.security* configuration file. That is, `TLSv1.1` needs to be removed from the list.
288+
261289
[id="plugins-{type}s-{plugin}-ssl_verify"]
262290
===== `ssl_verify`
263291

lib/logstash/inputs/tcp.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
112112
# All the certificates will be read and added to the trust store.
113113
config :ssl_certificate_authorities, :validate => :array, :default => []
114114

115+
# NOTE: the default setting [] uses Java SSL engine defaults.
116+
config :ssl_supported_protocols, :validate => ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], :default => [], :list => true
117+
118+
# The list of ciphers suite to use, listed by priorities.
119+
# NOTE: the default setting [] uses Java SSL defaults.
120+
config :ssl_cipher_suites, :validate => SslContextBuilder.getSupportedCipherSuites.to_a, :default => [], :list => true
121+
115122
# Instruct the socket to use TCP keep alives. Uses OS defaults for keep alive settings.
116123
config :tcp_keep_alive, :validate => :boolean, :default => false
117124

@@ -286,7 +293,7 @@ def ssl_context
286293
return @ssl_context if @ssl_context
287294

288295
begin
289-
@ssl_context = OpenSSL::SSL::SSLContext.new
296+
@ssl_context = new_ssl_context
290297
@ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
291298
@ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@ssl_key),@ssl_key_passphrase.value)
292299
if @ssl_extra_chain_certs.any?
@@ -297,6 +304,21 @@ def ssl_context
297304
@ssl_context.cert_store = load_cert_store
298305
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
299306
end
307+
308+
@ssl_context.min_version = :TLS1_1 # not strictly required - JVM should have disabled TLSv1
309+
if ssl_supported_protocols.any?
310+
disabled_protocols = ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'] - ssl_supported_protocols
311+
unless OpenSSL::SSL.const_defined? :OP_NO_TLSv1_3 # work-around JRuby-OpenSSL bug - missing constant
312+
@ssl_context.max_version = :TLS1_2 if disabled_protocols.delete('TLSv1.3')
313+
end
314+
# mapping 'TLSv1.2' -> OpenSSL::SSL::OP_NO_TLSv1_2
315+
disabled_protocols.map! { |v| OpenSSL::SSL.const_get "OP_NO_#{v.sub('.', '_')}" }
316+
@ssl_context.options = disabled_protocols.reduce(@ssl_context.options, :|)
317+
end
318+
319+
if ssl_cipher_suites.any?
320+
@ssl_context.ciphers = ssl_cipher_suites # Java cipher names work with JOSSL >= 0.12.2
321+
end
300322
rescue => e
301323
@logger.error("Could not inititalize SSL context", :message => e.message, :exception => e.class, :backtrace => e.backtrace)
302324
raise e
@@ -305,6 +327,11 @@ def ssl_context
305327
@ssl_context
306328
end
307329

330+
# @note to be able to hook up into #ssl_context from tests
331+
def new_ssl_context
332+
OpenSSL::SSL::SSLContext.new
333+
end
334+
308335
def load_cert_store
309336
cert_store = OpenSSL::X509::Store.new
310337
cert_store.set_default_paths
@@ -379,6 +406,8 @@ def java_ssl_context
379406
.set_ssl_key_password(@ssl_key_passphrase.value)
380407
.set_ssl_extra_chain_certs(@ssl_extra_chain_certs.to_java(:string))
381408
.set_ssl_certificate_authorities(@ssl_certificate_authorities.to_java(:string))
409+
.set_ssl_supported_protocols(ssl_supported_protocols.to_java(:string))
410+
.set_ssl_cipher_suites(ssl_cipher_suites.to_java(:string))
382411
.build_context
383412
rescue java.lang.IllegalArgumentException => e
384413
@logger.error("SSL configuration invalid", error_details(e))

logstash-input-tcp.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Gem::Specification.new do |s|
2323
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
2424
s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~>1.2'
2525

26-
s.add_runtime_dependency 'logstash-core', '>= 6.7.0'
26+
s.add_runtime_dependency 'logstash-core', '>= 8.1.0'
2727

2828
# we depend on bouncycastle's bcpkix-jdk15on being on the class-path
29-
s.add_runtime_dependency 'jruby-openssl', '>= 0.10.2'
29+
s.add_runtime_dependency 'jruby-openssl', '>= 0.12.2' # 0.12 supports TLSv1.3
3030

3131
# line vs streaming codecs required for fix_streaming_codecs
3232
# TODO: fix_streaming_codecs should be refactored to not

0 commit comments

Comments
 (0)