logstash-input-elasticsearch 4.16.0 → 4.17.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c5466b50a56ec047ac20dc019d9e24862756b518613b63edf44583900a090e2
4
- data.tar.gz: 6b3915bd640318ebd6fa4b87f676d7e43d4fba7fe54893efdb6eb39f70481da8
3
+ metadata.gz: 9cdbda91c48e11353b49426f1d9c01e461698e507506563848045560d05421d0
4
+ data.tar.gz: 367351221d9028775410a4ef272de5bf6bad66ab82d91aedacb91ef462c5ff56
5
5
  SHA512:
6
- metadata.gz: 930202045f30125060cce1f3d45b22c0336976a6cdcbf5931f4b98410785bd425cf665224edfe4994953ad2d53cdaa994b31be9db86fd05f538a722ff788ba97
7
- data.tar.gz: 8cf1f45481575f653867831ab38fb7efd286c12432b2afc2c6940c32d4eb91f913dd7b89c284ed4e11e9205536cc75b318f399b92136777f84ac6dec75d2de2d
6
+ metadata.gz: 88071a99d4ee00c356c2729cdb0d873e7b0ecb067f02e3ccc76c83ec86166d4b4c1daa036d6943a5913339b524e69ecf3f741d17cd871cdba8cf19f59a371016
7
+ data.tar.gz: 1b20527dd5f3f3ca00bed248b6cdb57dc81d816f56d3f3d08c393fec4fdcf37f57f8ba61dec957efe03cf6f8695426ef544780e32d7b6818671ae0f0d6930b90
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## 4.17.1
2
+ - Fix: scroll slice high memory consumption [#189](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/189)
3
+
4
+ ## 4.17.0
5
+ - Added SSL settings for: [#185](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/185)
6
+ - `ssl_enabled`: Enable/disable the SSL settings. If not provided, the value is inferred from the hosts scheme
7
+ - `ssl_certificate`: OpenSSL-style X.509 certificate file to authenticate the client
8
+ - `ssl_key`: OpenSSL-style RSA private key that corresponds to the `ssl_certificate`
9
+ - `ssl_truststore_path`: The JKS truststore to validate the server's certificate
10
+ - `ssl_truststore_type`: The format of the truststore file
11
+ - `ssl_truststore_password`: The truststore password
12
+ - `ssl_keystore_path`: The keystore used to present a certificate to the server
13
+ - `ssl_keystore_type`: The format of the keystore file
14
+ - `ssl_keystore_password`: The keystore password
15
+ - `ssl_cipher_suites`: The list of cipher suites to use
16
+ - `ssl_supported_protocols`: Supported protocols with versions
17
+ - Reviewed and deprecated SSL settings to comply with Logstash's naming convention
18
+ - Deprecated `ssl` in favor of `ssl_enabled`
19
+ - Deprecated `ca_file` in favor of `ssl_certificate_authorities`
20
+ - Deprecated `ssl_certificate_verification` in favor of `ssl_verification_mode`
21
+
1
22
  ## 4.16.0
2
23
  - Added `ssl_certificate_verification` option to control SSL certificate verification [#180](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/180)
3
24
 
data/docs/index.asciidoc CHANGED
@@ -96,13 +96,12 @@ TIP: Set the `target` option to avoid potential schema conflicts.
96
96
  [id="plugins-{type}s-{plugin}-options"]
97
97
  ==== Elasticsearch Input configuration options
98
98
 
99
- This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
99
+ This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> and the <<plugins-{type}s-{plugin}-deprecated-options>> described later.
100
100
 
101
101
  [cols="<,<,<",options="header",]
102
102
  |=======================================================================
103
103
  |Setting |Input type|Required
104
104
  | <<plugins-{type}s-{plugin}-api_key>> |<<password,password>>|No
105
- | <<plugins-{type}s-{plugin}-ca_file>> |a valid filesystem path|No
106
105
  | <<plugins-{type}s-{plugin}-ca_trusted_fingerprint>> |<<string,string>>|No
107
106
  | <<plugins-{type}s-{plugin}-cloud_auth>> |<<password,password>>|No
108
107
  | <<plugins-{type}s-{plugin}-cloud_id>> |<<string,string>>|No
@@ -121,8 +120,19 @@ This plugin supports the following configuration options plus the <<plugins-{typ
121
120
  | <<plugins-{type}s-{plugin}-scroll>> |<<string,string>>|No
122
121
  | <<plugins-{type}s-{plugin}-size>> |<<number,number>>|No
123
122
  | <<plugins-{type}s-{plugin}-slices>> |<<number,number>>|No
124
- | <<plugins-{type}s-{plugin}-ssl>> |<<boolean,boolean>>|No
125
- | <<plugins-{type}s-{plugin}-ssl_certificate_verification>> |<<boolean,boolean>>|No
123
+ | <<plugins-{type}s-{plugin}-ssl_certificate>> |<<path,path>>|No
124
+ | <<plugins-{type}s-{plugin}-ssl_certificate_authorities>> |list of <<path,path>>|No
125
+ | <<plugins-{type}s-{plugin}-ssl_cipher_suites>> |list of <<string,string>>|No
126
+ | <<plugins-{type}s-{plugin}-ssl_enabled>> |<<boolean,boolean>>|No
127
+ | <<plugins-{type}s-{plugin}-ssl_key>> |<<path,path>>|No
128
+ | <<plugins-{type}s-{plugin}-ssl_keystore_password>> |<<password,password>>|No
129
+ | <<plugins-{type}s-{plugin}-ssl_keystore_path>> |<<path,path>>|No
130
+ | <<plugins-{type}s-{plugin}-ssl_keystore_type>> |<<string,string>>|No
131
+ | <<plugins-{type}s-{plugin}-ssl_supported_protocols>> |<<string,string>>|No
132
+ | <<plugins-{type}s-{plugin}-ssl_truststore_password>> |<<password,password>>|No
133
+ | <<plugins-{type}s-{plugin}-ssl_truststore_path>> |<<path,path>>|No
134
+ | <<plugins-{type}s-{plugin}-ssl_truststore_type>> |<<string,string>>|No
135
+ | <<plugins-{type}s-{plugin}-ssl_verification_mode>> |<<string,string>>, one of `["full", "none"]`|No
126
136
  | <<plugins-{type}s-{plugin}-socket_timeout_seconds>> | <<number,number>>|No
127
137
  | <<plugins-{type}s-{plugin}-target>> | {logstash-ref}/field-references-deepdive.html[field reference] | No
128
138
  | <<plugins-{type}s-{plugin}-retries>> | <<number,number>>|No
@@ -140,21 +150,13 @@ input plugins.
140
150
  * Value type is <<password,password>>
141
151
  * There is no default value for this setting.
142
152
 
143
- Authenticate using Elasticsearch API key. Note that this option also requires enabling the `ssl` option.
153
+ Authenticate using Elasticsearch API key. Note that this option also requires enabling the <<plugins-{type}s-{plugin}-ssl_enabled>> option.
144
154
 
145
155
  Format is `id:api_key` where `id` and `api_key` are as returned by the
146
156
  Elasticsearch
147
157
  {ref}/security-api-create-api-key.html[Create
148
158
  API key API].
149
159
 
150
- [id="plugins-{type}s-{plugin}-ca_file"]
151
- ===== `ca_file`
152
-
153
- * Value type is <<path,path>>
154
- * There is no default value for this setting.
155
-
156
- SSL Certificate Authority file in PEM encoded format, must also include any chain certificates as necessary.
157
-
158
160
  [id="plugins-{type}s-{plugin}-ca_trusted_fingerprint"]
159
161
  ===== `ca_trusted_fingerprint`
160
162
 
@@ -351,6 +353,7 @@ documents and/or the <<plugins-{type}s-{plugin}-size>> has been specified as a l
351
353
  The number of times to re-run the query after the first failure. If the query fails after all retries, it logs an error message.
352
354
  The default is 0 (no retry). This value should be equal to or greater than zero.
353
355
 
356
+ NOTE: Partial failures - such as errors in a subset of all slices - can result in the entire query being retried, which can lead to duplication of data. Avoiding this would require Logstash to store the entire result set of a query in memory which is often not possible.
354
357
 
355
358
  [id="plugins-{type}s-{plugin}-schedule"]
356
359
  ===== `schedule`
@@ -406,28 +409,138 @@ NOTE: The Elasticsearch manual indicates that there can be _negative_ performanc
406
409
  If the `slices` parameter is left unset, the plugin will _not_ inject slice
407
410
  instructions into the query.
408
411
 
409
- [id="plugins-{type}s-{plugin}-ssl"]
410
- ===== `ssl`
412
+ [id="plugins-{type}s-{plugin}-ssl_certificate"]
413
+ ===== `ssl_certificate`
414
+ * Value type is <<path,path>>
415
+ * There is no default value for this setting.
416
+
417
+ SSL certificate to use to authenticate the client. This certificate should be an OpenSSL-style X.509 certificate file.
418
+
419
+ NOTE: This setting can be used only if <<plugins-{type}s-{plugin}-ssl_key>> is set.
420
+
421
+ [id="plugins-{type}s-{plugin}-ssl_certificate_authorities"]
422
+ ===== `ssl_certificate_authorities`
423
+
424
+ * Value type is a list of <<path,path>>
425
+ * There is no default value for this setting
426
+
427
+ The `.cer` or `.pem` files to validate the server's certificate.
428
+
429
+ NOTE: You cannot use this setting and <<plugins-{type}s-{plugin}-ssl_truststore_path>> at the same time.
430
+
431
+ [id="plugins-{type}s-{plugin}-ssl_cipher_suites"]
432
+ ===== `ssl_cipher_suites`
433
+ * Value type is a list of <<string,string>>
434
+ * There is no default value for this setting
435
+
436
+ The list of cipher suites to use, listed by priorities.
437
+ Supported cipher suites vary depending on the Java and protocol versions.
438
+
439
+ [id="plugins-{type}s-{plugin}-ssl_enabled"]
440
+ ===== `ssl_enabled`
411
441
 
412
442
  * Value type is <<boolean,boolean>>
413
- * Default value is `false`
443
+ * There is no default value for this setting.
414
444
 
415
- If enabled, SSL will be used when communicating with the Elasticsearch
416
- server (i.e. HTTPS will be used instead of plain HTTP).
445
+ Enable SSL/TLS secured communication to Elasticsearch cluster.
446
+ Leaving this unspecified will use whatever scheme is specified in the URLs listed in <<plugins-{type}s-{plugin}-hosts>> or extracted from the <<plugins-{type}s-{plugin}-cloud_id>>.
447
+ If no explicit protocol is specified plain HTTP will be used.
417
448
 
418
- [id="plugins-{type}s-{plugin}-ssl_certificate_verification"]
419
- ===== `ssl_certificate_verification`
449
+ [id="plugins-{type}s-{plugin}-ssl_key"]
450
+ ===== `ssl_key`
451
+ * Value type is <<path,path>>
452
+ * There is no default value for this setting.
420
453
 
421
- * Value type is <<boolean,boolean>>
422
- * Default value is `true`
454
+ OpenSSL-style RSA private key that corresponds to the <<plugins-{type}s-{plugin}-ssl_certificate>>.
423
455
 
424
- Option to validate the server's certificate. Disabling this severely compromises security.
425
- When certificate validation is disabled, this plugin implicitly trusts the machine
426
- resolved at the given address without validating its proof-of-identity.
427
- In this scenario, the plugin can transmit credentials to or process data from an untrustworthy
428
- man-in-the-middle or other compromised infrastructure.
429
- More information on the importance of certificate verification:
430
- **https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf**.
456
+ NOTE: This setting can be used only if <<plugins-{type}s-{plugin}-ssl_certificate>> is set.
457
+
458
+ [id="plugins-{type}s-{plugin}-ssl_keystore_password"]
459
+ ===== `ssl_keystore_password`
460
+
461
+ * Value type is <<password,password>>
462
+ * There is no default value for this setting.
463
+
464
+ Set the keystore password
465
+
466
+ [id="plugins-{type}s-{plugin}-ssl_keystore_path"]
467
+ ===== `ssl_keystore_path`
468
+
469
+ * Value type is <<path,path>>
470
+ * There is no default value for this setting.
471
+
472
+ The keystore used to present a certificate to the server.
473
+ It can be either `.jks` or `.p12`
474
+
475
+ NOTE: You cannot use this setting and <<plugins-{type}s-{plugin}-ssl_certificate>> at the same time.
476
+
477
+ [id="plugins-{type}s-{plugin}-ssl_keystore_type"]
478
+ ===== `ssl_keystore_type`
479
+
480
+ * Value can be any of: `jks`, `pkcs12`
481
+ * If not provided, the value will be inferred from the keystore filename.
482
+
483
+ The format of the keystore file. It must be either `jks` or `pkcs12`.
484
+
485
+ [id="plugins-{type}s-{plugin}-ssl_supported_protocols"]
486
+ ===== `ssl_supported_protocols`
487
+
488
+ * Value type is <<string,string>>
489
+ * Allowed values are: `'TLSv1.1'`, `'TLSv1.2'`, `'TLSv1.3'`
490
+ * Default depends on the JDK being used. With up-to-date Logstash, the default is `['TLSv1.2', 'TLSv1.3']`.
491
+ `'TLSv1.1'` is not considered secure and is only provided for legacy applications.
492
+
493
+ List of allowed SSL/TLS versions to use when establishing a connection to the Elasticsearch cluster.
494
+
495
+ For Java 8 `'TLSv1.3'` is supported only since **8u262** (AdoptOpenJDK), but requires that you set the
496
+ `LS_JAVA_OPTS="-Djdk.tls.client.protocols=TLSv1.3"` system property in Logstash.
497
+
498
+ NOTE: If you configure the plugin to use `'TLSv1.1'` on any recent JVM, such as the one packaged with Logstash,
499
+ the protocol is disabled by default and needs to be enabled manually by changing `jdk.tls.disabledAlgorithms` in
500
+ the *$JDK_HOME/conf/security/java.security* configuration file. That is, `TLSv1.1` needs to be removed from the list.
501
+
502
+ [id="plugins-{type}s-{plugin}-ssl_truststore_password"]
503
+ ===== `ssl_truststore_password`
504
+
505
+ * Value type is <<password,password>>
506
+ * There is no default value for this setting.
507
+
508
+ Set the truststore password.
509
+
510
+ [id="plugins-{type}s-{plugin}-ssl_truststore_path"]
511
+ ===== `ssl_truststore_path`
512
+
513
+ * Value type is <<path,path>>
514
+ * There is no default value for this setting.
515
+
516
+ The truststore to validate the server's certificate.
517
+ It can be either .jks or .p12.
518
+
519
+ NOTE: You cannot use this setting and <<plugins-{type}s-{plugin}-ssl_certificate_authorities>> at the same time.
520
+
521
+ [id="plugins-{type}s-{plugin}-ssl_truststore_type"]
522
+ ===== `ssl_truststore_type`
523
+
524
+ * Value can be any of: `jks`, `pkcs12`
525
+ * If not provided, the value will be inferred from the truststore filename.
526
+
527
+ The format of the truststore file. It must be either `jks` or `pkcs12`.
528
+
529
+ [id="plugins-{type}s-{plugin}-ssl_verification_mode"]
530
+ ===== `ssl_verification_mode`
531
+
532
+ * Value can be any of: `full`, `none`
533
+ * Default value is `full`
534
+
535
+ Defines how to verify the certificates presented by another party in the TLS connection:
536
+
537
+ `full` validates that the server certificate has an issue date that’s within
538
+ the not_before and not_after dates; chains to a trusted Certificate Authority (CA), and
539
+ has a hostname or IP address that matches the names within the certificate.
540
+
541
+ `none` performs no certificate validation.
542
+
543
+ WARNING: Setting certificate verification to `none` disables many security benefits of SSL/TLS, which is very dangerous. For more information on disabling certificate verification please read https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf
431
544
 
432
545
  [id="plugins-{type}s-{plugin}-socket_timeout_seconds"]
433
546
  ===== `socket_timeout_seconds`
@@ -463,6 +576,55 @@ option when authenticating to the Elasticsearch server. If set to an
463
576
  empty string authentication will be disabled.
464
577
 
465
578
 
579
+ [id="plugins-{type}s-{plugin}-deprecated-options"]
580
+ ==== Elasticsearch Input deprecated configuration options
581
+
582
+ This plugin supports the following deprecated configurations.
583
+
584
+ WARNING: Deprecated options are subject to removal in future releases.
585
+
586
+ [cols="<,<,<",options="header",]
587
+ |=======================================================================
588
+ |Setting|Input type|Replaced by
589
+ | <<plugins-{type}s-{plugin}-ca_file>> |a valid filesystem path|<<plugins-{type}s-{plugin}-ssl_certificate_authorities>>
590
+ | <<plugins-{type}s-{plugin}-ssl>> |<<boolean,boolean>>|<<plugins-{type}s-{plugin}-ssl_enabled>>
591
+ | <<plugins-{type}s-{plugin}-ssl_certificate_verification>> |<<boolean,boolean>>|<<plugins-{type}s-{plugin}-ssl_verification_mode>>
592
+ |=======================================================================
593
+
594
+ [id="plugins-{type}s-{plugin}-ca_file"]
595
+ ===== `ca_file`
596
+ deprecated[4.17.0, Replaced by <<plugins-{type}s-{plugin}-ssl_certificate_authorities>>]
597
+
598
+ * Value type is <<path,path>>
599
+ * There is no default value for this setting.
600
+
601
+ SSL Certificate Authority file in PEM encoded format, must also include any chain certificates as necessary.
602
+
603
+ [id="plugins-{type}s-{plugin}-ssl"]
604
+ ===== `ssl`
605
+ deprecated[4.17.0, Replaced by <<plugins-{type}s-{plugin}-ssl_enabled>>]
606
+
607
+ * Value type is <<boolean,boolean>>
608
+ * Default value is `false`
609
+
610
+ If enabled, SSL will be used when communicating with the Elasticsearch
611
+ server (i.e. HTTPS will be used instead of plain HTTP).
612
+
613
+
614
+ [id="plugins-{type}s-{plugin}-ssl_certificate_verification"]
615
+ ===== `ssl_certificate_verification`
616
+ deprecated[4.17.0, Replaced by <<plugins-{type}s-{plugin}-ssl_verification_mode>>]
617
+
618
+ * Value type is <<boolean,boolean>>
619
+ * Default value is `true`
620
+
621
+ Option to validate the server's certificate. Disabling this severely compromises security.
622
+ When certificate validation is disabled, this plugin implicitly trusts the machine
623
+ resolved at the given address without validating its proof-of-identity.
624
+ In this scenario, the plugin can transmit credentials to or process data from an untrustworthy
625
+ man-in-the-middle or other compromised infrastructure.
626
+ More information on the importance of certificate verification:
627
+ **https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf**.
466
628
 
467
629
  [id="plugins-{type}s-{plugin}-common-options"]
468
630
  include::{include_path}/{type}.asciidoc[]
@@ -9,6 +9,7 @@ require 'logstash/plugin_mixins/ecs_compatibility_support'
9
9
  require 'logstash/plugin_mixins/ecs_compatibility_support/target_check'
10
10
  require 'logstash/plugin_mixins/ca_trusted_fingerprint_support'
11
11
  require "logstash/plugin_mixins/scheduler"
12
+ require "logstash/plugin_mixins/normalize_config_support"
12
13
  require "base64"
13
14
  require 'logstash/helpers/loggable_try'
14
15
 
@@ -82,6 +83,8 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
82
83
 
83
84
  include LogStash::PluginMixins::Scheduler
84
85
 
86
+ include LogStash::PluginMixins::NormalizeConfigSupport
87
+
85
88
  config_name "elasticsearch"
86
89
 
87
90
  # List of elasticsearch hosts to use for querying.
@@ -185,15 +188,60 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
185
188
  config :proxy, :validate => :uri_or_empty
186
189
 
187
190
  # SSL
188
- config :ssl, :validate => :boolean, :default => false
191
+ config :ssl, :validate => :boolean, :default => false, :deprecated => "Set 'ssl_enabled' instead."
192
+
193
+ # SSL Certificate Authority file in PEM encoded format, must also include any chain certificates as necessary
194
+ config :ca_file, :validate => :path, :deprecated => "Set 'ssl_certificate_authorities' instead."
195
+
196
+ # OpenSSL-style X.509 certificate certificate to authenticate the client
197
+ config :ssl_certificate, :validate => :path
189
198
 
190
- # SSL Certificate Authority file in PEM encoded format, must also include any chain certificates as necessary
191
- config :ca_file, :validate => :path
199
+ # SSL Certificate Authority files in PEM encoded format, must also include any chain certificates as necessary
200
+ config :ssl_certificate_authorities, :validate => :path, :list => true
192
201
 
193
202
  # Option to validate the server's certificate. Disabling this severely compromises security.
194
203
  # For more information on the importance of certificate verification please read
195
204
  # https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf
196
- config :ssl_certificate_verification, :validate => :boolean, :default => true
205
+ config :ssl_certificate_verification, :validate => :boolean, :default => true, :deprecated => "Set 'ssl_verification_mode' instead."
206
+
207
+ # The list of cipher suites to use, listed by priorities.
208
+ # Supported cipher suites vary depending on which version of Java is used.
209
+ config :ssl_cipher_suites, :validate => :string, :list => true
210
+
211
+ # SSL
212
+ config :ssl_enabled, :validate => :boolean
213
+
214
+ # OpenSSL-style RSA private key to authenticate the client
215
+ config :ssl_key, :validate => :path
216
+
217
+ # Set the keystore password
218
+ config :ssl_keystore_password, :validate => :password
219
+
220
+ # The keystore used to present a certificate to the server.
221
+ # It can be either .jks or .p12
222
+ config :ssl_keystore_path, :validate => :path
223
+
224
+ # The format of the keystore file. It must be either jks or pkcs12
225
+ config :ssl_keystore_type, :validate => %w[pkcs12 jks]
226
+
227
+ # Supported protocols with versions.
228
+ config :ssl_supported_protocols, :validate => %w[TLSv1.1 TLSv1.2 TLSv1.3], :default => [], :list => true
229
+
230
+ # Set the truststore password
231
+ config :ssl_truststore_password, :validate => :password
232
+
233
+ # The JKS truststore to validate the server's certificate.
234
+ # Use either `:ssl_truststore_path` or `:ssl_certificate_authorities`
235
+ config :ssl_truststore_path, :validate => :path
236
+
237
+ # The format of the truststore file. It must be either jks or pkcs12
238
+ config :ssl_truststore_type, :validate => %w[pkcs12 jks]
239
+
240
+ # Options to verify the server's certificate.
241
+ # "full": validates that the provided certificate has an issue date that’s within the not_before and not_after dates;
242
+ # chains to a trusted Certificate Authority (CA); has a hostname or IP address that matches the names within the certificate.
243
+ # "none": performs no certificate validation. Disabling this severely compromises security (https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf)
244
+ config :ssl_verification_mode, :validate => %w[full none], :default => 'full'
197
245
 
198
246
  # Schedule of when to periodically run statement, in Cron format
199
247
  # for example: "* * * * *" (execute query every minute, on the minute)
@@ -208,6 +256,8 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
208
256
  # config :ca_trusted_fingerprint, :validate => :sha_256_hex
209
257
  include LogStash::PluginMixins::CATrustedFingerprintSupport
210
258
 
259
+ attr_reader :pipeline_id
260
+
211
261
  def initialize(params={})
212
262
  super(params)
213
263
 
@@ -219,6 +269,11 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
219
269
  def register
220
270
  require "rufus/scheduler"
221
271
 
272
+ @pipeline_id = execution_context&.pipeline_id || 'main'
273
+
274
+ fill_hosts_from_cloud_id
275
+ setup_ssl_params!
276
+
222
277
  @options = {
223
278
  :index => @index,
224
279
  :scroll => @scroll,
@@ -234,8 +289,6 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
234
289
 
235
290
  validate_authentication
236
291
  fill_user_password_from_cloud_auth
237
- fill_hosts_from_cloud_id
238
-
239
292
 
240
293
  transport_options = {:headers => {}}
241
294
  transport_options[:headers].merge!(setup_basic_auth(user, password))
@@ -246,7 +299,7 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
246
299
  transport_options[:socket_timeout] = @socket_timeout_seconds unless @socket_timeout_seconds.nil?
247
300
 
248
301
  hosts = setup_hosts
249
- ssl_options = setup_ssl
302
+ ssl_options = setup_client_ssl
250
303
 
251
304
  @logger.warn "Supplied proxy setting (proxy => '') has no effect" if @proxy.eql?('')
252
305
 
@@ -277,20 +330,22 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
277
330
  def do_run(output_queue)
278
331
  # if configured to run a single slice, don't bother spinning up threads
279
332
  if @slices.nil? || @slices <= 1
280
- success, events = retryable_slice
281
- success && events.each { |event| output_queue << event }
282
- return
333
+ return retryable(JOB_NAME) do
334
+ do_run_slice(output_queue)
335
+ end
283
336
  end
284
337
 
285
338
  logger.warn("managed slices for query is very large (#{@slices}); consider reducing") if @slices > 8
286
339
 
287
- slice_results = parallel_slice # array of tuple(ok, events)
288
340
 
289
- # insert events to queue if all slices success
290
- if slice_results.all?(&:first)
291
- slice_results.flat_map { |success, events| events }
292
- .each { |event| output_queue << event }
293
- end
341
+ @slices.times.map do |slice_id|
342
+ Thread.new do
343
+ LogStash::Util::set_thread_name("[#{pipeline_id}]|input|elasticsearch|slice_#{slice_id}")
344
+ retryable(JOB_NAME) do
345
+ do_run_slice(output_queue, slice_id)
346
+ end
347
+ end
348
+ end.map(&:join)
294
349
 
295
350
  logger.trace("#{@slices} slices completed")
296
351
  end
@@ -298,42 +353,14 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
298
353
  def retryable(job_name, &block)
299
354
  begin
300
355
  stud_try = ::LogStash::Helpers::LoggableTry.new(logger, job_name)
301
- output = stud_try.try((@retries + 1).times) { yield }
302
- [true, output]
356
+ stud_try.try((@retries + 1).times) { yield }
303
357
  rescue => e
304
358
  error_details = {:message => e.message, :cause => e.cause}
305
359
  error_details[:backtrace] = e.backtrace if logger.debug?
306
360
  logger.error("Tried #{job_name} unsuccessfully", error_details)
307
- [false, nil]
308
361
  end
309
362
  end
310
363
 
311
-
312
- # @return [(ok, events)] : Array of tuple(Boolean, [Logstash::Event])
313
- def parallel_slice
314
- pipeline_id = execution_context&.pipeline_id || 'main'
315
- @slices.times.map do |slice_id|
316
- Thread.new do
317
- LogStash::Util::set_thread_name("[#{pipeline_id}]|input|elasticsearch|slice_#{slice_id}")
318
- retryable_slice(slice_id)
319
- end
320
- end.map do |t|
321
- t.join
322
- t.value
323
- end
324
- end
325
-
326
- # @param scroll_id [Integer]
327
- # @return (ok, events) [Boolean, Array(Logstash::Event)]
328
- def retryable_slice(slice_id=nil)
329
- retryable(JOB_NAME) do
330
- output = []
331
- do_run_slice(output, slice_id)
332
- output
333
- end
334
- end
335
-
336
-
337
364
  def do_run_slice(output_queue, slice_id=nil)
338
365
  slice_query = @base_query
339
366
  slice_query = slice_query.merge('slice' => { 'id' => slice_id, 'max' => @slices}) unless slice_id.nil?
@@ -416,6 +443,15 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
416
443
  hosts.nil? || ( hosts.is_a?(Array) && hosts.empty? )
417
444
  end
418
445
 
446
+ def effectively_ssl?
447
+ return true if @ssl_enabled
448
+
449
+ hosts = Array(@hosts)
450
+ return false if hosts.nil? || hosts.empty?
451
+
452
+ hosts.all? { |host| host && host.to_s.start_with?("https") }
453
+ end
454
+
419
455
  def validate_authentication
420
456
  authn_options = 0
421
457
  authn_options += 1 if @cloud_auth
@@ -426,26 +462,113 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
426
462
  raise LogStash::ConfigurationError, 'Multiple authentication options are specified, please only use one of user/password, cloud_auth or api_key'
427
463
  end
428
464
 
429
- if @api_key && @api_key.value && @ssl != true
430
- raise(LogStash::ConfigurationError, "Using api_key authentication requires SSL/TLS secured communication using the `ssl => true` option")
465
+ if @api_key && @api_key.value && @ssl_enabled != true
466
+ raise(LogStash::ConfigurationError, "Using api_key authentication requires SSL/TLS secured communication using the `ssl_enabled => true` option")
431
467
  end
432
468
  end
433
469
 
434
- def setup_ssl
470
+ def setup_client_ssl
435
471
  ssl_options = {}
472
+ ssl_options[:ssl] = true if @ssl_enabled
436
473
 
437
- ssl_options[:ssl] = true if @ssl
438
- ssl_options[:ca_file] = @ca_file if @ssl && @ca_file
439
- ssl_options[:trust_strategy] = trust_strategy_for_ca_trusted_fingerprint
440
- if @ssl && !@ssl_certificate_verification
441
- logger.warn "You have enabled encryption but DISABLED certificate verification, " +
442
- "to make sure your data is secure remove `ssl_certificate_verification => false`"
443
- ssl_options[:verify] = :disable
474
+ unless @ssl_enabled
475
+ # Keep it backward compatible with the deprecated `ssl` option
476
+ ssl_options[:trust_strategy] = trust_strategy_for_ca_trusted_fingerprint if original_params.include?('ssl')
477
+ return ssl_options
478
+ end
479
+
480
+ ssl_certificate_authorities, ssl_truststore_path, ssl_certificate, ssl_keystore_path = params.values_at('ssl_certificate_authorities', 'ssl_truststore_path', 'ssl_certificate', 'ssl_keystore_path')
481
+
482
+ if ssl_certificate_authorities && ssl_truststore_path
483
+ raise LogStash::ConfigurationError, 'Use either "ssl_certificate_authorities/ca_file" or "ssl_truststore_path" when configuring the CA certificate'
484
+ end
485
+
486
+ if ssl_certificate && ssl_keystore_path
487
+ raise LogStash::ConfigurationError, 'Use either "ssl_certificate" or "ssl_keystore_path/keystore" when configuring client certificates'
488
+ end
489
+
490
+ if ssl_certificate_authorities&.any?
491
+ raise LogStash::ConfigurationError, 'Multiple values on "ssl_certificate_authorities" are not supported by this plugin' if ssl_certificate_authorities.size > 1
492
+ ssl_options[:ca_file] = ssl_certificate_authorities.first
493
+ end
494
+
495
+ if ssl_truststore_path
496
+ ssl_options[:truststore] = ssl_truststore_path
497
+ ssl_options[:truststore_type] = params["ssl_truststore_type"] if params.include?("ssl_truststore_type")
498
+ ssl_options[:truststore_password] = params["ssl_truststore_password"].value if params.include?("ssl_truststore_password")
499
+ end
500
+
501
+ if ssl_keystore_path
502
+ ssl_options[:keystore] = ssl_keystore_path
503
+ ssl_options[:keystore_type] = params["ssl_keystore_type"] if params.include?("ssl_keystore_type")
504
+ ssl_options[:keystore_password] = params["ssl_keystore_password"].value if params.include?("ssl_keystore_password")
505
+ end
506
+
507
+ ssl_key = params["ssl_key"]
508
+ if ssl_certificate
509
+ raise LogStash::ConfigurationError, 'Using an "ssl_certificate" requires an "ssl_key"' unless ssl_key
510
+ ssl_options[:client_cert] = ssl_certificate
511
+ ssl_options[:client_key] = ssl_key
512
+ elsif !ssl_key.nil?
513
+ raise LogStash::ConfigurationError, 'An "ssl_certificate" is required when using an "ssl_key"'
514
+ end
515
+
516
+ ssl_verification_mode = params["ssl_verification_mode"]
517
+ unless ssl_verification_mode.nil?
518
+ case ssl_verification_mode
519
+ when 'none'
520
+ logger.warn "You have enabled encryption but DISABLED certificate verification, " +
521
+ "to make sure your data is secure set `ssl_verification_mode => full`"
522
+ ssl_options[:verify] = :disable
523
+ else
524
+ ssl_options[:verify] = :strict
525
+ end
444
526
  end
445
527
 
528
+ ssl_options[:cipher_suites] = params["ssl_cipher_suites"] if params.include?("ssl_cipher_suites")
529
+
530
+ protocols = params['ssl_supported_protocols']
531
+ ssl_options[:protocols] = protocols if protocols&.any?
532
+ ssl_options[:trust_strategy] = trust_strategy_for_ca_trusted_fingerprint
533
+
446
534
  ssl_options
447
535
  end
448
536
 
537
+ def setup_ssl_params!
538
+ @ssl_enabled = normalize_config(:ssl_enabled) do |normalize|
539
+ normalize.with_deprecated_alias(:ssl)
540
+ end
541
+
542
+ # Infer the value if neither the deprecate `ssl` and `ssl_enabled` were set
543
+ infer_ssl_enabled_from_hosts
544
+
545
+ @ssl_certificate_authorities = normalize_config(:ssl_certificate_authorities) do |normalize|
546
+ normalize.with_deprecated_mapping(:ca_file) do |ca_file|
547
+ [ca_file]
548
+ end
549
+ end
550
+
551
+ @ssl_verification_mode = normalize_config(:ssl_verification_mode) do |normalize|
552
+ normalize.with_deprecated_mapping(:ssl_certificate_verification) do |ssl_certificate_verification|
553
+ if ssl_certificate_verification == true
554
+ "full"
555
+ else
556
+ "none"
557
+ end
558
+ end
559
+ end
560
+
561
+ params['ssl_enabled'] = @ssl_enabled
562
+ params['ssl_certificate_authorities'] = @ssl_certificate_authorities unless @ssl_certificate_authorities.nil?
563
+ params['ssl_verification_mode'] = @ssl_verification_mode unless @ssl_verification_mode.nil?
564
+ end
565
+
566
+ def infer_ssl_enabled_from_hosts
567
+ return if original_params.include?('ssl') || original_params.include?('ssl_enabled')
568
+
569
+ @ssl_enabled = params['ssl_enabled'] = effectively_ssl?
570
+ end
571
+
449
572
  def setup_hosts
450
573
  @hosts = Array(@hosts).map { |host| host.to_s } # potential SafeURI#to_s
451
574
  @hosts.map do |h|
@@ -453,7 +576,7 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
453
576
  h
454
577
  else
455
578
  host, port = h.split(':')
456
- { host: host, port: port, scheme: (@ssl ? 'https' : 'http') }
579
+ { host: host, port: port, scheme: (@ssl_enabled ? 'https' : 'http') }
457
580
  end
458
581
  end
459
582
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-elasticsearch'
4
- s.version = '4.16.0'
4
+ s.version = '4.17.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Reads query results from an Elasticsearch cluster"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.add_runtime_dependency 'elasticsearch', '>= 7.17.1'
30
30
  s.add_runtime_dependency 'logstash-mixin-ca_trusted_fingerprint_support', '~> 1.0'
31
+ s.add_runtime_dependency 'logstash-mixin-normalize_config_support', '~>1.0'
31
32
 
32
33
  s.add_runtime_dependency 'tzinfo'
33
34
  s.add_runtime_dependency 'tzinfo-data'
@@ -204,7 +204,7 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
204
204
  context 'with `slices => 1`' do
205
205
  let(:slices) { 1 }
206
206
  it 'runs just one slice' do
207
- expect(plugin).to receive(:do_run_slice).with(duck_type(:<<), nil)
207
+ expect(plugin).to receive(:do_run_slice).with(duck_type(:<<))
208
208
  expect(Thread).to_not receive(:new)
209
209
 
210
210
  plugin.register
@@ -215,7 +215,7 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
215
215
  context 'without slices directive' do
216
216
  let(:config) { super().tap { |h| h.delete('slices') } }
217
217
  it 'runs just one slice' do
218
- expect(plugin).to receive(:do_run_slice).with(duck_type(:<<), nil)
218
+ expect(plugin).to receive(:do_run_slice).with(duck_type(:<<))
219
219
  expect(Thread).to_not receive(:new)
220
220
 
221
221
  plugin.register
@@ -414,18 +414,19 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
414
414
  expect(Elasticsearch::Client).to receive(:new).with(any_args).and_return(client)
415
415
  plugin.register
416
416
 
417
- expect(client).to receive(:clear_scroll).and_return(nil)
417
+ expect(client).to receive(:clear_scroll).twice.and_return(nil)
418
418
 
419
- # SLICE0 is a three-page scroll in which the second page throw exception
419
+ # SLICE0 is a three-page scroll
420
420
  slice0_query = LogStash::Json.dump(query.merge('slice' => { 'id' => 0, 'max' => 2}))
421
421
  expect(client).to receive(:search).with(hash_including(:body => slice0_query)).and_return(slice0_response0)
422
- expect(client).to receive(:scroll).with(hash_including(:body => { :scroll_id => slice0_scroll1 })).and_raise("boom")
422
+ expect(client).to receive(:scroll).with(hash_including(:body => { :scroll_id => slice0_scroll1 })).and_return(slice0_response1)
423
+ expect(client).to receive(:scroll).with(hash_including(:body => { :scroll_id => slice0_scroll2 })).and_return(slice0_response2)
423
424
  allow(client).to receive(:ping)
424
425
 
425
- # SLICE1 is a two-page scroll in which the last page has no next scroll id
426
+ # SLICE1 is a two-page scroll in which the last page throws exception
426
427
  slice1_query = LogStash::Json.dump(query.merge('slice' => { 'id' => 1, 'max' => 2}))
427
428
  expect(client).to receive(:search).with(hash_including(:body => slice1_query)).and_return(slice1_response0)
428
- expect(client).to receive(:scroll).with(hash_including(:body => { :scroll_id => slice1_scroll1 })).and_return(slice1_response1)
429
+ expect(client).to receive(:scroll).with(hash_including(:body => { :scroll_id => slice1_scroll1 })).and_raise("boom")
429
430
 
430
431
  synchronize_method!(plugin, :scroll_request)
431
432
  synchronize_method!(plugin, :search_request)
@@ -433,18 +434,22 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
433
434
 
434
435
  let(:client) { Elasticsearch::Client.new }
435
436
 
436
- it 'does not insert event to queue' do
437
- expect(plugin).to receive(:parallel_slice).and_wrap_original do |m, *args|
438
- slice0, slice1 = m.call
439
- expect(slice0[0]).to be_falsey
440
- expect(slice1[0]).to be_truthy
441
- expect(slice1[1].size).to eq(4) # four items from SLICE1
442
- [slice0, slice1]
437
+ it 'insert event to queue without waiting other slices' do
438
+ expect(plugin).to receive(:do_run_slice).twice.and_wrap_original do |m, *args|
439
+ q = args[0]
440
+ slice_id = args[1]
441
+ if slice_id == 0
442
+ m.call(*args)
443
+ expect(q.size).to eq(3)
444
+ else
445
+ sleep(1)
446
+ m.call(*args)
447
+ end
443
448
  end
444
449
 
445
450
  queue = Queue.new
446
451
  plugin.run(queue)
447
- expect(queue.size).to eq(0)
452
+ expect(queue.size).to eq(5)
448
453
  end
449
454
  end
450
455
  end
@@ -681,7 +686,7 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
681
686
  end
682
687
 
683
688
  context "with ssl" do
684
- let(:config) { super().merge({ 'api_key' => LogStash::Util::Password.new('foo:bar'), "ssl" => true }) }
689
+ let(:config) { super().merge({ 'api_key' => LogStash::Util::Password.new('foo:bar'), "ssl_enabled" => true }) }
685
690
 
686
691
  it "should set authorization" do
687
692
  plugin.register
@@ -700,9 +705,9 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
700
705
  end
701
706
 
702
707
  context 'ssl verification disabled' do
703
- let(:config) { super().merge({ 'ssl_certificate_verification' => false }) }
708
+ let(:config) { super().merge({ 'ssl_verification_mode' => 'none' }) }
704
709
  it 'should warn data security risk' do
705
- expect(plugin.logger).to receive(:warn).once.with("You have enabled encryption but DISABLED certificate verification, to make sure your data is secure remove `ssl_certificate_verification => false`")
710
+ expect(plugin.logger).to receive(:warn).once.with("You have enabled encryption but DISABLED certificate verification, to make sure your data is secure set `ssl_verification_mode => full`")
706
711
  plugin.register
707
712
  end
708
713
  end
@@ -0,0 +1,265 @@
1
+ require 'stud/temporary'
2
+ require "elasticsearch"
3
+
4
+ describe "SSL options" do
5
+ let(:es_client_double) { double("Elasticsearch::Client #{self.inspect}") }
6
+ let(:hosts) {["localhost"]}
7
+ let(:settings) { { "ssl_enabled" => true, "hosts" => hosts } }
8
+
9
+ subject do
10
+ require "logstash/inputs/elasticsearch"
11
+ LogStash::Inputs::Elasticsearch.new(settings)
12
+ end
13
+
14
+ before do
15
+ allow(es_client_double).to receive(:close)
16
+ allow(es_client_double).to receive(:ping).with(any_args).and_return(double("pong").as_null_object)
17
+ allow(Elasticsearch::Client).to receive(:new).and_return(es_client_double)
18
+ end
19
+
20
+ after do
21
+ subject.close
22
+ end
23
+
24
+ context "when ssl_enabled is" do
25
+ context "true and there is no https hosts" do
26
+ let(:hosts) { %w[http://es01 http://es01] }
27
+
28
+ it "should not infer the ssl_enabled value" do
29
+ subject.register
30
+ expect(subject.instance_variable_get(:@ssl_enabled)).to eql(true)
31
+ expect(subject.params).to match hash_including("ssl_enabled" => true)
32
+ end
33
+ end
34
+
35
+ context "false and cloud_id resolved host is https" do
36
+ let(:settings) {{
37
+ "ssl_enabled" => false,
38
+ "hosts" => [],
39
+ "cloud_id" => "sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=="
40
+ }}
41
+
42
+ it "should not infer the ssl_enabled value" do
43
+ subject.register
44
+ expect(subject.instance_variable_get(:@ssl_enabled)).to eql(false)
45
+ expect(subject.params).to match hash_including("ssl_enabled" => false)
46
+ end
47
+ end
48
+ end
49
+
50
+ context "when neither ssl nor ssl_enabled is set" do
51
+ let(:settings) { super().reject { |k| %w[ssl ssl_enabled].include?(k) } }
52
+
53
+ context "and there is no https hosts" do
54
+ let(:hosts) { %w[http://es01 http://es01] }
55
+
56
+ it "should infer the ssl_enabled value to false" do
57
+ subject.register
58
+ expect(subject.instance_variable_get(:@ssl_enabled)).to eql(false)
59
+ expect(subject.params).to match hash_including("ssl_enabled" => false)
60
+ end
61
+ end
62
+
63
+ context "and there is https hosts" do
64
+ let(:hosts) { %w[https://sec-es01 https://sec-es01] }
65
+
66
+ it "should infer the ssl_enabled value to true" do
67
+ subject.register
68
+ expect(subject.instance_variable_get(:@ssl_enabled)).to eql(true)
69
+ expect(subject.params).to match hash_including("ssl_enabled" => true)
70
+ end
71
+ end
72
+
73
+ context "and hosts have no scheme defined" do
74
+ let(:hosts) { %w[es01 es01] }
75
+
76
+ it "should infer the ssl_enabled value to false" do
77
+ subject.register
78
+ expect(subject.instance_variable_get(:@ssl_enabled)).to eql(false)
79
+ expect(subject.params).to match hash_including("ssl_enabled" => false)
80
+ end
81
+ end
82
+
83
+ context "and cloud_id resolved host is https" do
84
+ let(:settings) {{
85
+ "hosts" => [],
86
+ "cloud_id" => "sample:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA=="
87
+ }}
88
+
89
+ it "should infer the ssl_enabled value to false" do
90
+ subject.register
91
+ expect(subject.instance_variable_get(:@ssl_enabled)).to eql(true)
92
+ expect(subject.params).to match hash_including("ssl_enabled" => true)
93
+ end
94
+ end
95
+ end
96
+
97
+ context "when ssl_verification_mode" do
98
+ context "is set to none" do
99
+ let(:settings) { super().merge(
100
+ "ssl_verification_mode" => "none",
101
+ ) }
102
+
103
+ it "should print a warning" do
104
+ expect(subject.logger).to receive(:warn).with(/You have enabled encryption but DISABLED certificate verification/).at_least(:once)
105
+ allow(subject.logger).to receive(:warn).with(any_args)
106
+
107
+ subject.register
108
+ end
109
+
110
+ it "should pass the flag to the ES client" do
111
+ expect(::Elasticsearch::Client).to receive(:new) do |args|
112
+ expect(args[:ssl]).to match hash_including(:ssl => true, :verify => :disable)
113
+ end.and_return(es_client_double)
114
+
115
+ subject.register
116
+ end
117
+ end
118
+
119
+ context "is set to full" do
120
+ let(:settings) { super().merge(
121
+ "ssl_verification_mode" => 'full',
122
+ ) }
123
+
124
+ it "should pass the flag to the ES client" do
125
+ expect(::Elasticsearch::Client).to receive(:new) do |args|
126
+ expect(args[:ssl]).to match hash_including(:ssl => true, :verify => :strict)
127
+ end.and_return(es_client_double)
128
+
129
+ subject.register
130
+ end
131
+ end
132
+ end
133
+
134
+ context "with the conflicting configs" do
135
+ context "ssl_certificate_authorities and ssl_truststore_path set" do
136
+ let(:ssl_truststore_path) { Stud::Temporary.file.path }
137
+ let(:ssl_certificate_authorities_path) { Stud::Temporary.file.path }
138
+ let(:settings) { super().merge(
139
+ "ssl_truststore_path" => ssl_truststore_path,
140
+ "ssl_certificate_authorities" => ssl_certificate_authorities_path
141
+ ) }
142
+
143
+ after :each do
144
+ File.delete(ssl_truststore_path)
145
+ File.delete(ssl_certificate_authorities_path)
146
+ end
147
+
148
+ it "should raise a configuration error" do
149
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError, /Use either "ssl_certificate_authorities\/ca_file" or "ssl_truststore_path"/)
150
+ end
151
+ end
152
+
153
+ context "ssl_certificate and ssl_keystore_path set" do
154
+ let(:ssl_keystore_path) { Stud::Temporary.file.path }
155
+ let(:ssl_certificate_path) { Stud::Temporary.file.path }
156
+ let(:settings) { super().merge(
157
+ "ssl_certificate" => ssl_certificate_path,
158
+ "ssl_keystore_path" => ssl_keystore_path
159
+ ) }
160
+
161
+ after :each do
162
+ File.delete(ssl_keystore_path)
163
+ File.delete(ssl_certificate_path)
164
+ end
165
+
166
+ it "should raise a configuration error" do
167
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError, /Use either "ssl_certificate" or "ssl_keystore_path\/keystore"/)
168
+ end
169
+ end
170
+ end
171
+
172
+ context "when configured with Java store files" do
173
+ let(:ssl_truststore_path) { Stud::Temporary.file.path }
174
+ let(:ssl_keystore_path) { Stud::Temporary.file.path }
175
+
176
+ after :each do
177
+ File.delete(ssl_truststore_path)
178
+ File.delete(ssl_keystore_path)
179
+ end
180
+
181
+ let(:settings) { super().merge(
182
+ "ssl_truststore_path" => ssl_truststore_path,
183
+ "ssl_truststore_type" => "jks",
184
+ "ssl_truststore_password" => "foo",
185
+ "ssl_keystore_path" => ssl_keystore_path,
186
+ "ssl_keystore_type" => "jks",
187
+ "ssl_keystore_password" => "bar",
188
+ "ssl_verification_mode" => "full",
189
+ "ssl_cipher_suites" => ["TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"],
190
+ "ssl_supported_protocols" => ["TLSv1.3"]
191
+ ) }
192
+
193
+ it "should pass the parameters to the ES client" do
194
+ expect(::Elasticsearch::Client).to receive(:new) do |args|
195
+ expect(args[:ssl]).to match hash_including(
196
+ :ssl => true,
197
+ :keystore => ssl_keystore_path,
198
+ :keystore_type => "jks",
199
+ :keystore_password => "bar",
200
+ :truststore => ssl_truststore_path,
201
+ :truststore_type => "jks",
202
+ :truststore_password => "foo",
203
+ :verify => :strict,
204
+ :cipher_suites => ["TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"],
205
+ :protocols => ["TLSv1.3"],
206
+ )
207
+ end.and_return(es_client_double)
208
+
209
+ subject.register
210
+ end
211
+ end
212
+
213
+ context "when configured with certificate files" do
214
+ let(:ssl_certificate_authorities_path) { Stud::Temporary.file.path }
215
+ let(:ssl_certificate_path) { Stud::Temporary.file.path }
216
+ let(:ssl_key_path) { Stud::Temporary.file.path }
217
+ let(:settings) { super().merge(
218
+ "ssl_certificate_authorities" => [ssl_certificate_authorities_path],
219
+ "ssl_certificate" => ssl_certificate_path,
220
+ "ssl_key" => ssl_key_path,
221
+ "ssl_verification_mode" => "full",
222
+ "ssl_cipher_suites" => ["TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"],
223
+ "ssl_supported_protocols" => ["TLSv1.3"]
224
+ ) }
225
+
226
+ after :each do
227
+ File.delete(ssl_certificate_authorities_path)
228
+ File.delete(ssl_certificate_path)
229
+ File.delete(ssl_key_path)
230
+ end
231
+
232
+ it "should pass the parameters to the ES client" do
233
+ expect(::Elasticsearch::Client).to receive(:new) do |args|
234
+ expect(args[:ssl]).to match hash_including(
235
+ :ssl => true,
236
+ :ca_file => ssl_certificate_authorities_path,
237
+ :client_cert => ssl_certificate_path,
238
+ :client_key => ssl_key_path,
239
+ :verify => :strict,
240
+ :cipher_suites => ["TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"],
241
+ :protocols => ["TLSv1.3"],
242
+ )
243
+ end.and_return(es_client_double)
244
+
245
+ subject.register
246
+ end
247
+
248
+ context "and only the ssl_certificate is set" do
249
+ let(:settings) { super().reject { |k| "ssl_key".eql?(k) } }
250
+
251
+ it "should raise a configuration error" do
252
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError, /Using an "ssl_certificate" requires an "ssl_key"/)
253
+ end
254
+ end
255
+
256
+ context "and only the ssl_key is set" do
257
+ let(:settings) { super().reject { |k| "ssl_certificate".eql?(k) } }
258
+
259
+ it "should raise a configuration error" do
260
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError, /An "ssl_certificate" is required when using an "ssl_key"/)
261
+ end
262
+ end
263
+ end
264
+ end
265
+
@@ -95,13 +95,13 @@ describe LogStash::Inputs::Elasticsearch do
95
95
  end
96
96
 
97
97
  context 'with ca_file' do
98
- let(:config) { super().merge('ssl' => true, 'ca_file' => ca_file) }
98
+ let(:config) { super().merge('ssl_enabled' => true, 'ssl_certificate_authorities' => ca_file) }
99
99
  it_behaves_like 'secured_elasticsearch'
100
100
  end
101
101
 
102
102
  context 'with `ca_trusted_fingerprint`' do
103
103
  let(:ca_trusted_fingerprint) { File.read("spec/fixtures/test_certs/ca.der.sha256").chomp }
104
- let(:config) { super().merge('ssl' => true, 'ca_trusted_fingerprint' => ca_trusted_fingerprint) }
104
+ let(:config) { super().merge('ssl_enabled' => true, 'ca_trusted_fingerprint' => ca_trusted_fingerprint) }
105
105
 
106
106
  if Gem::Version.create(LOGSTASH_VERSION) >= Gem::Version.create("8.3.0")
107
107
  it_behaves_like 'secured_elasticsearch'
@@ -125,11 +125,11 @@ describe LogStash::Inputs::Elasticsearch do
125
125
 
126
126
  context 'setting host:port (and ssl)', secure_integration: true do
127
127
 
128
- let(:client_options) { { :ca_file => ca_file, :user => user, :password => password } }
128
+ let(:client_options) { { :ssl_certificate_authorities => ca_file, :user => user, :password => password } }
129
129
 
130
130
  let(:config) do
131
131
  config = super().merge "hosts" => [ESHelper.get_host_port]
132
- config.merge('user' => user, 'password' => password, 'ssl' => true, 'ca_file' => ca_file)
132
+ config.merge('user' => user, 'password' => password, 'ssl_enabled' => true, 'ssl_certificate_authorities' => ca_file)
133
133
  end
134
134
 
135
135
  it_behaves_like 'an elasticsearch index plugin'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.16.0
4
+ version: 4.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-12 00:00:00.000000000 Z
11
+ date: 2023-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '1.0'
117
+ - !ruby/object:Gem::Dependency
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.0'
123
+ name: logstash-mixin-normalize_config_support
124
+ prerelease: false
125
+ type: :runtime
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.0'
117
131
  - !ruby/object:Gem::Dependency
118
132
  requirement: !ruby/object:Gem::Requirement
119
133
  requirements:
@@ -267,6 +281,7 @@ files:
267
281
  - spec/fixtures/test_certs/es.crt
268
282
  - spec/fixtures/test_certs/es.key
269
283
  - spec/inputs/elasticsearch_spec.rb
284
+ - spec/inputs/elasticsearch_ssl_spec.rb
270
285
  - spec/inputs/integration/elasticsearch_spec.rb
271
286
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
272
287
  licenses:
@@ -301,4 +316,5 @@ test_files:
301
316
  - spec/fixtures/test_certs/es.crt
302
317
  - spec/fixtures/test_certs/es.key
303
318
  - spec/inputs/elasticsearch_spec.rb
319
+ - spec/inputs/elasticsearch_ssl_spec.rb
304
320
  - spec/inputs/integration/elasticsearch_spec.rb