logstash-input-elasticsearch 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90dc46d1bcadf70173792a9c2319925ea5e78bd3e6322e7c323de178afb72fa4
4
- data.tar.gz: 21548a5935b0aa5b153b6e1bc00c7f9f3f6ade7f6546a0beb0ce7cc6cef5a984
3
+ metadata.gz: f16f7eb70ca4239c5d779c5fa8c77d0778ab48277c7f6ca4003d20894d0d7108
4
+ data.tar.gz: 59baf110729b3f8e353087dda028b6e6dc7c6973449307756729d451ddc4192e
5
5
  SHA512:
6
- metadata.gz: 59e8a03c25d8ee9a1a02014b75d1096b81250b85c7f6bd7e78114764534d9ad244d5d758e974c84bc20d9aa0c8fad669a3ef636b17037426c30f2705d74083d2
7
- data.tar.gz: 8b986365b25b8884e3aae581b37ce35f9190e50bf3ce4d17263887c31721efe16f16b97dcf2571dcb446991f7ea4406c6011a1d1dbd3afd7f3e07ec0c4b9b743
6
+ metadata.gz: 5450236e4c130d4a7737520de8571d9364327703c8b715ed3aa6de638f604e83c0062ebc2d1f36fecbb7d11d6e29931f8e713008ae89529f843d048c8f82227d
7
+ data.tar.gz: 1e5fdda8c6feafa77d40eda3940155995fba96b1c6d925b74e3392e246eb893a46dc38912335011cc9bd9235a4bf9ad68a0378b8799e48947ea98f68c1cb2207
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 5.3.2
2
+ - Support Elastic Cloud API keys in the `api_key` option, which now accepts an `id:api_key` pair, its base64-encoded form, or an `essu_` Cloud API key, and rejects an unrecognized format at startup [#274](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/274)
3
+
4
+ ## 5.3.1
5
+ - Fix serverless request failure caused by conflicting `compatible-with` and `Elastic-Api-Version` headers when using elasticsearch-ruby v9 [#269](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/269)
6
+
1
7
  ## 5.3.0
2
8
  - Drop a support for Logstash 7.x by requiring elasticsearch gem >= 8. Logstash 8+ continues to work as before [#252](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/252)
3
9
 
data/docs/index.asciidoc CHANGED
@@ -404,10 +404,12 @@ input plugins.
404
404
 
405
405
  Authenticate using Elasticsearch API key. Note that this option also requires enabling the <<plugins-{type}s-{plugin}-ssl_enabled>> option.
406
406
 
407
- Format is `id:api_key` where `id` and `api_key` are as returned by the
407
+ The format is `id:api_key`, where `id` and `api_key` are as returned by the
408
408
  Elasticsearch
409
409
  {ref}/security-api-create-api-key.html[Create
410
- API key API].
410
+ API key API]. The base64-encoded form of that pair is also accepted, as is an
411
+ https://www.elastic.co/docs/deploy-manage/api-keys/elastic-cloud-api-keys[Elastic Cloud API key]
412
+ (prefixed with `essu_`), which is used as-is.
411
413
 
412
414
  [id="plugins-{type}s-{plugin}-ca_trusted_fingerprint"]
413
415
  ===== `ca_trusted_fingerprint`
@@ -216,7 +216,8 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
216
216
  config :cloud_auth, :validate => :password
217
217
 
218
218
  # Authenticate using Elasticsearch API key.
219
- # format is id:api_key (as returned by https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html[Create API key])
219
+ # Format is either the `id:api_key` pair (as returned by https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html[Create API key]),
220
+ # its base64-encoded form, or an https://www.elastic.co/docs/deploy-manage/api-keys/elastic-cloud-api-keys[Elastic Cloud API key] (prefixed with `essu_`) can be used.
220
221
  config :api_key, :validate => :password
221
222
 
222
223
  # Set the address of a forward HTTP proxy.
@@ -331,31 +332,7 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
331
332
  validate_authentication
332
333
  fill_user_password_from_cloud_auth
333
334
 
334
- transport_options = {:headers => {}}
335
- transport_options[:headers].merge!(INTERNAL_ORIGIN_HEADER)
336
- transport_options[:headers].merge!(setup_basic_auth(user, password))
337
- transport_options[:headers].merge!(setup_api_key(api_key))
338
- transport_options[:headers].merge!({'user-agent' => prepare_user_agent()})
339
- transport_options[:headers].merge!(@custom_headers) unless @custom_headers.empty?
340
- transport_options[:request_timeout] = @request_timeout_seconds unless @request_timeout_seconds.nil?
341
- transport_options[:connect_timeout] = @connect_timeout_seconds unless @connect_timeout_seconds.nil?
342
- transport_options[:socket_timeout] = @socket_timeout_seconds unless @socket_timeout_seconds.nil?
343
-
344
- hosts = setup_hosts
345
- ssl_options = setup_client_ssl
346
-
347
- @logger.warn "Supplied proxy setting (proxy => '') has no effect" if @proxy.eql?('')
348
-
349
- transport_options[:proxy] = @proxy.to_s if @proxy && !@proxy.eql?('')
350
-
351
- @client_options = {
352
- :hosts => hosts,
353
- :transport_options => transport_options,
354
- :transport_class => ::Elastic::Transport::Transport::HTTP::Manticore,
355
- :ssl => ssl_options
356
- }
357
-
358
- @client = Elasticsearch::Client.new(@client_options)
335
+ @client = new_client
359
336
 
360
337
  test_connection!
361
338
 
@@ -566,10 +543,32 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
566
543
  def setup_api_key(api_key)
567
544
  return {} unless (api_key&.value)
568
545
 
569
- token = base64?(api_key.value) ? api_key.value : Base64.strict_encode64(api_key.value)
546
+ token = resolve_api_key(api_key.value)
570
547
  { 'Authorization' => "ApiKey #{token}" }
571
548
  end
572
549
 
550
+ # Resolves the `api_key` value into the credential used in the
551
+ # `Authorization: ApiKey` header. An already base64-encoded key and an Elastic
552
+ # Cloud API key are used as-is; a raw `id:api_key` pair is base64-encoded. An
553
+ # unrecognized value is rejected so a malformed key surfaces at startup rather
554
+ # than as a later authentication failure.
555
+ def resolve_api_key(key_value)
556
+ if base64?(key_value) || cloud_api_key?(key_value)
557
+ key_value
558
+ elsif key_value.match?(/\A[^:]+:[^:]+\z/)
559
+ Base64.strict_encode64(key_value)
560
+ else
561
+ raise LogStash::ConfigurationError, "Invalid api_key format. Expected a base64-encoded key, an 'id:api_key' pair, or a Cloud API key (essu_ prefix)."
562
+ end
563
+ end
564
+
565
+ # Elastic Cloud API keys (such as the unified Serverless keys) are opaque
566
+ # tokens prefixed with `essu_` that Elasticsearch accepts verbatim in the
567
+ # `Authorization: ApiKey` header, with no base64 encoding.
568
+ def cloud_api_key?(string)
569
+ string.match?(/\Aessu_.+/)
570
+ end
571
+
573
572
  def base64?(string)
574
573
  string == Base64.strict_encode64(Base64.strict_decode64(string))
575
574
  rescue ArgumentError
@@ -641,6 +640,31 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
641
640
  # @private used by unit specs
642
641
  attr_reader :client
643
642
 
643
+ def new_client(serverless: false)
644
+ headers = {}
645
+ headers.merge!(INTERNAL_ORIGIN_HEADER)
646
+ headers.merge!(setup_basic_auth(user, password))
647
+ headers.merge!(setup_api_key(api_key))
648
+ headers.merge!({'user-agent' => prepare_user_agent()})
649
+ headers.merge!(@custom_headers) unless @custom_headers.empty?
650
+ headers.merge!(DEFAULT_EAV_HEADER) if serverless
651
+
652
+ transport_options = { headers: headers }
653
+ transport_options[:request_timeout] = @request_timeout_seconds unless @request_timeout_seconds.nil?
654
+ transport_options[:connect_timeout] = @connect_timeout_seconds unless @connect_timeout_seconds.nil?
655
+ transport_options[:socket_timeout] = @socket_timeout_seconds unless @socket_timeout_seconds.nil?
656
+
657
+ @logger.warn "Supplied proxy setting (proxy => '') has no effect" if @proxy.eql?('')
658
+ transport_options[:proxy] = @proxy.to_s if @proxy && !@proxy.eql?('')
659
+
660
+ Elasticsearch::Client.new(
661
+ hosts: setup_hosts,
662
+ transport_options: transport_options,
663
+ transport_class: ::Elastic::Transport::Transport::HTTP::Manticore,
664
+ ssl: setup_client_ssl
665
+ )
666
+ end
667
+
644
668
  def test_connection!
645
669
  @client.ping
646
670
  rescue Elasticsearch::UnsupportedProductError
@@ -663,8 +687,7 @@ class LogStash::Inputs::Elasticsearch < LogStash::Inputs::Base
663
687
  # verify the header by sending GET /
664
688
  def setup_serverless
665
689
  if serverless?
666
- @client_options[:transport_options][:headers].merge!(DEFAULT_EAV_HEADER)
667
- @client = Elasticsearch::Client.new(@client_options)
690
+ @client = new_client(serverless: true)
668
691
  @client.info
669
692
  end
670
693
  rescue => e
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
14
+ s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "version", "docs/**/*"]
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -835,6 +835,28 @@ describe LogStash::Inputs::Elasticsearch, :ecs_compatibility_support do
835
835
  it_behaves_like "a plugin that sets the ApiKey authorization header"
836
836
  end
837
837
 
838
+ context "with an Elastic Cloud API key (essu_ prefix)" do
839
+ # The suffix is intentionally not canonical base64: a Cloud key is opaque
840
+ # and must be forwarded verbatim regardless of its payload encoding.
841
+ let(:api_key_value) { "essu_VFZGblZreFhTekJ4ZDB4M2NHUnZRMEU2YzNWd1pYSnpaV055WlhRPQ==AAAAAAAA" }
842
+
843
+ it "sets the Authorization header verbatim without re-encoding" do
844
+ plugin.register
845
+ client = plugin.send(:client)
846
+ auth_header = client.transport.options[:transport_options][:headers]['Authorization']
847
+
848
+ expect(auth_header).to eql("ApiKey #{api_key_value}")
849
+ end
850
+ end
851
+
852
+ context "with an unrecognized api_key format" do
853
+ let(:api_key_value) { "not-a-valid-key" }
854
+
855
+ it "fails registration with a configuration error" do
856
+ expect { plugin.register }.to raise_error(LogStash::ConfigurationError, /Invalid api_key format/)
857
+ end
858
+ end
859
+
838
860
  context 'user also set' do
839
861
  let(:config) { super().merge({ 'api_key' => 'foo:bar', 'user' => 'another' }) }
840
862
 
data/version ADDED
@@ -0,0 +1 @@
1
+ 5.3.2
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2026-07-03 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: logstash-core-plugin-api
@@ -283,6 +283,7 @@ files:
283
283
  - spec/inputs/integration/elasticsearch_esql_spec.rb
284
284
  - spec/inputs/integration/elasticsearch_spec.rb
285
285
  - spec/inputs/paginated_search_spec.rb
286
+ - version
286
287
  homepage: https://elastic.co/logstash
287
288
  licenses:
288
289
  - Apache License (2.0)
@@ -303,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
304
  - !ruby/object:Gem::Version
304
305
  version: '0'
305
306
  requirements: []
306
- rubygems_version: 3.7.2
307
+ rubygems_version: 3.6.3
307
308
  specification_version: 4
308
309
  summary: Reads query results from an Elasticsearch cluster
309
310
  test_files: