logstash-filter-elasticsearch 3.7.1 → 3.8.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTORS +1 -0
- data/docs/index.asciidoc +20 -11
- data/lib/logstash/filters/elasticsearch.rb +36 -17
- data/lib/logstash/filters/elasticsearch/client.rb +24 -10
- data/logstash-filter-elasticsearch.gemspec +1 -1
- data/spec/filters/elasticsearch_spec.rb +31 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77145aca4fea09d207fbe7efb17c271760fb7fd7eaf3c1411c08298959a54767
|
4
|
+
data.tar.gz: 599f7a6cfdc37a5f7f867b44411f82438a53a17fb8ed9bbbfe8c34f4aa9496d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c764d630938fd180399b4d0f113bb3af17b5db41594838d6e4b109b280457443c97920999c74f62c0518bc69780bc8c8569383477e576dc80e6433ccbab3c02
|
7
|
+
data.tar.gz: 998fbdba7ede11d6ab4ab74c5620076f730490cb37831041fa947540917d7da519f9ff0b75989445f5a1a25937dc5e04fc7a33afa56ebec6cc8234d48b7e9444
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 3.8.0
|
2
|
+
- Added api_key support [#132](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/132)
|
3
|
+
|
4
|
+
## 3.7.2
|
5
|
+
- [DOC] Removed outdated compatibility notice [#131](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/131)
|
6
|
+
|
1
7
|
## 3.7.1
|
2
8
|
- Fix: solves an issue where non-ascii unicode values in a template were not handled correctly [#128](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/128)
|
3
9
|
|
data/CONTRIBUTORS
CHANGED
@@ -9,6 +9,7 @@ Contributors:
|
|
9
9
|
* Richard Pijnenburg (electrical)
|
10
10
|
* Suyog Rao (suyograo)
|
11
11
|
* Adrian Solom (addrians)
|
12
|
+
* Colin Surprenant (colinsurprenant)
|
12
13
|
|
13
14
|
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
14
15
|
Logstash, and you aren't on the list above and want to be, please let us know
|
data/docs/index.asciidoc
CHANGED
@@ -20,18 +20,8 @@ include::{include_path}/plugin_header.asciidoc[]
|
|
20
20
|
|
21
21
|
==== Description
|
22
22
|
|
23
|
-
.Compatibility Note
|
24
|
-
[NOTE]
|
25
|
-
================================================================================
|
26
|
-
Starting with Elasticsearch 5.3, there's an {ref}/modules-http.html[HTTP setting]
|
27
|
-
called `http.content_type.required`. If this option is set to `true`, and you
|
28
|
-
are using Logstash 2.4 through 5.2, you need to update the Elasticsearch filter
|
29
|
-
plugin to version 3.1.1 or higher.
|
30
|
-
|
31
|
-
================================================================================
|
32
|
-
|
33
23
|
Search Elasticsearch for a previous log event and copy some fields from it
|
34
|
-
into the current event.
|
24
|
+
into the current event. Below are two complete examples of how this filter might
|
35
25
|
be used.
|
36
26
|
|
37
27
|
The first example uses the legacy 'query' parameter where the user is limited to an Elasticsearch query_string.
|
@@ -111,6 +101,14 @@ Notice also that when you use `query_template`, the Logstash attributes `result_
|
|
111
101
|
and `sort` will be ignored. They should be specified directly in the JSON
|
112
102
|
template, as shown in the example above.
|
113
103
|
|
104
|
+
[id="plugins-{type}s-{plugin}-auth"]
|
105
|
+
==== Authentication
|
106
|
+
|
107
|
+
Authentication to a secure Elasticsearch cluster is possible using _one_ of the following options:
|
108
|
+
|
109
|
+
* <<plugins-{type}s-{plugin}-user>> AND <<plugins-{type}s-{plugin}-password>>
|
110
|
+
* <<plugins-{type}s-{plugin}-cloud_auth>>
|
111
|
+
* <<plugins-{type}s-{plugin}-api_key>>
|
114
112
|
|
115
113
|
[id="plugins-{type}s-{plugin}-options"]
|
116
114
|
==== Elasticsearch Filter Configuration Options
|
@@ -121,6 +119,7 @@ This plugin supports the following configuration options plus the < |
|
121
119
|
|=======================================================================
|
122
120
|
|Setting |Input type|Required
|
123
121
|
| <<plugins-{type}s-{plugin}-aggregation_fields>> |<<hash,hash>>|No
|
122
|
+
| <<plugins-{type}s-{plugin}-api_key>> |<<password,password>>|No
|
124
123
|
| <<plugins-{type}s-{plugin}-ca_file>> |a valid filesystem path|No
|
125
124
|
| <<plugins-{type}s-{plugin}-cloud_auth>> |<<password,password>>|No
|
126
125
|
| <<plugins-{type}s-{plugin}-cloud_id>> |<<string,string>>|No
|
@@ -162,6 +161,16 @@ Example:
|
|
162
161
|
}
|
163
162
|
}
|
164
163
|
|
164
|
+
[id="plugins-{type}s-{plugin}-api_key"]
|
165
|
+
===== `api_key`
|
166
|
+
|
167
|
+
* Value type is <<password,password>>
|
168
|
+
* There is no default value for this setting.
|
169
|
+
|
170
|
+
Authenticate using Elasticsearch API key. Note that this option also requires enabling the `ssl` option.
|
171
|
+
|
172
|
+
Format is `id:api_key` where `id` and `api_key` are as returned by the Elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html[Create API key API].
|
173
|
+
|
165
174
|
[id="plugins-{type}s-{plugin}-ca_file"]
|
166
175
|
===== `ca_file`
|
167
176
|
|
@@ -15,11 +15,6 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
15
15
|
# List of elasticsearch hosts to use for querying.
|
16
16
|
config :hosts, :validate => :array, :default => [ DEFAULT_HOST ]
|
17
17
|
|
18
|
-
# Cloud ID, from the Elastic Cloud web console. If set `hosts` should not be used.
|
19
|
-
#
|
20
|
-
# For more info, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_id[Logstash-to-Cloud documentation]
|
21
|
-
config :cloud_id, :validate => :string
|
22
|
-
|
23
18
|
# Comma-delimited list of index names to search; use `_all` or empty string to perform the operation on all indices.
|
24
19
|
# Field substitution (e.g. `index-name-%{date_field}`) is available
|
25
20
|
config :index, :validate => :string, :default => ""
|
@@ -50,11 +45,20 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
50
45
|
# Basic Auth - password
|
51
46
|
config :password, :validate => :password
|
52
47
|
|
48
|
+
# Cloud ID, from the Elastic Cloud web console. If set `hosts` should not be used.
|
49
|
+
#
|
50
|
+
# For more info, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_id[Logstash-to-Cloud documentation]
|
51
|
+
config :cloud_id, :validate => :string
|
52
|
+
|
53
53
|
# Cloud authentication string ("<username>:<password>" format) is an alternative for the `user`/`password` configuration.
|
54
54
|
#
|
55
55
|
# For more info, check out the https://www.elastic.co/guide/en/logstash/current/connecting-to-cloud.html#_cloud_auth[Logstash-to-Cloud documentation]
|
56
56
|
config :cloud_auth, :validate => :password
|
57
57
|
|
58
|
+
# Authenticate using Elasticsearch API key.
|
59
|
+
# 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])
|
60
|
+
config :api_key, :validate => :password
|
61
|
+
|
58
62
|
# SSL
|
59
63
|
config :ssl, :validate => :boolean, :default => false
|
60
64
|
|
@@ -84,8 +88,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
84
88
|
@query_dsl = file.read
|
85
89
|
end
|
86
90
|
|
87
|
-
|
91
|
+
validate_authentication
|
88
92
|
fill_user_password_from_cloud_auth
|
93
|
+
fill_hosts_from_cloud_id
|
89
94
|
|
90
95
|
@hosts = Array(@hosts).map { |host| host.to_s } # for ES client URI#to_s
|
91
96
|
|
@@ -156,19 +161,21 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
156
161
|
end # def filter
|
157
162
|
|
158
163
|
private
|
164
|
+
|
159
165
|
def client_options
|
160
166
|
{
|
167
|
+
:user => @user,
|
168
|
+
:password => @password,
|
169
|
+
:api_key => @api_key,
|
161
170
|
:ssl => @ssl,
|
162
|
-
:hosts => @hosts,
|
163
171
|
:ca_file => @ca_file,
|
164
|
-
:logger => @logger
|
165
172
|
}
|
166
173
|
end
|
167
174
|
|
168
175
|
def new_client
|
169
176
|
# NOTE: could pass cloud-id/cloud-auth to client but than we would need to be stricter on ES version requirement
|
170
177
|
# and also LS parsing might differ from ES client's parsing so for consistency we do not pass cloud options ...
|
171
|
-
LogStash::Filters::ElasticsearchClient.new(@
|
178
|
+
LogStash::Filters::ElasticsearchClient.new(@logger, @hosts, client_options)
|
172
179
|
end
|
173
180
|
|
174
181
|
def get_client
|
@@ -213,25 +220,37 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
|
|
213
220
|
hosts.is_a?(Array) && hosts.size == 1 && hosts.first.equal?(DEFAULT_HOST)
|
214
221
|
end
|
215
222
|
|
216
|
-
def
|
217
|
-
|
223
|
+
def validate_authentication
|
224
|
+
authn_options = 0
|
225
|
+
authn_options += 1 if @cloud_auth
|
226
|
+
authn_options += 1 if (@api_key && @api_key.value)
|
227
|
+
authn_options += 1 if (@user || (@password && @password.value))
|
218
228
|
|
219
|
-
if
|
220
|
-
raise LogStash::ConfigurationError, '
|
229
|
+
if authn_options > 1
|
230
|
+
raise LogStash::ConfigurationError, 'Multiple authentication options are specified, please only use one of user/password, cloud_auth or api_key'
|
231
|
+
end
|
232
|
+
|
233
|
+
if @api_key && @api_key.value && @ssl != true
|
234
|
+
raise(LogStash::ConfigurationError, "Using api_key authentication requires SSL/TLS secured communication using the `ssl => true` option")
|
221
235
|
end
|
222
|
-
@hosts = parse_host_uri_from_cloud_id(@cloud_id)
|
223
236
|
end
|
224
237
|
|
225
238
|
def fill_user_password_from_cloud_auth
|
226
239
|
return unless @cloud_auth
|
227
240
|
|
228
|
-
if @user || @password
|
229
|
-
raise LogStash::ConfigurationError, 'Both cloud_auth and user/password specified, please only use one.'
|
230
|
-
end
|
231
241
|
@user, @password = parse_user_password_from_cloud_auth(@cloud_auth)
|
232
242
|
params['user'], params['password'] = @user, @password
|
233
243
|
end
|
234
244
|
|
245
|
+
def fill_hosts_from_cloud_id
|
246
|
+
return unless @cloud_id
|
247
|
+
|
248
|
+
if @hosts && !hosts_default?(@hosts)
|
249
|
+
raise LogStash::ConfigurationError, 'Both cloud_id and hosts specified, please only use one of those.'
|
250
|
+
end
|
251
|
+
@hosts = parse_host_uri_from_cloud_id(@cloud_id)
|
252
|
+
end
|
253
|
+
|
235
254
|
def parse_host_uri_from_cloud_id(cloud_id)
|
236
255
|
begin # might not be available on older LS
|
237
256
|
require 'logstash/util/cloud_setting_id'
|
@@ -10,23 +10,22 @@ module LogStash
|
|
10
10
|
|
11
11
|
attr_reader :client
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
ssl
|
15
|
-
|
16
|
-
|
13
|
+
def initialize(logger, hosts, options = {})
|
14
|
+
ssl = options.fetch(:ssl, false)
|
15
|
+
user = options.fetch(:user, nil)
|
16
|
+
password = options.fetch(:password, nil)
|
17
|
+
api_key = options.fetch(:api_key, nil)
|
17
18
|
|
18
|
-
transport_options = {}
|
19
|
-
|
20
|
-
|
21
|
-
transport_options[:headers] = { Authorization: "Basic #{token}" }
|
22
|
-
end
|
19
|
+
transport_options = {:headers => {}}
|
20
|
+
transport_options[:headers].merge!(setup_basic_auth(user, password))
|
21
|
+
transport_options[:headers].merge!(setup_api_key(api_key))
|
23
22
|
|
24
23
|
hosts.map! {|h| { host: h, scheme: 'https' } } if ssl
|
25
24
|
# set ca_file even if ssl isn't on, since the host can be an https url
|
26
25
|
ssl_options = { ssl: true, ca_file: options[:ca_file] } if options[:ca_file]
|
27
26
|
ssl_options ||= {}
|
28
27
|
|
29
|
-
|
28
|
+
logger.info("New ElasticSearch filter client", :hosts => hosts)
|
30
29
|
@client = ::Elasticsearch::Client.new(hosts: hosts, transport_options: transport_options, transport_class: ::Elasticsearch::Transport::Transport::HTTP::Manticore, :ssl => ssl_options)
|
31
30
|
end
|
32
31
|
|
@@ -34,6 +33,21 @@ module LogStash
|
|
34
33
|
@client.search(params)
|
35
34
|
end
|
36
35
|
|
36
|
+
private
|
37
|
+
|
38
|
+
def setup_basic_auth(user, password)
|
39
|
+
return {} unless user && password && password.value
|
40
|
+
|
41
|
+
token = ::Base64.strict_encode64("#{user}:#{password.value}")
|
42
|
+
{ Authorization: "Basic #{token}" }
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup_api_key(api_key)
|
46
|
+
return {} unless (api_key && api_key.value)
|
47
|
+
|
48
|
+
token = ::Base64.strict_encode64(api_key.value)
|
49
|
+
{ Authorization: "ApiKey #{token}" }
|
50
|
+
end
|
37
51
|
end
|
38
52
|
end
|
39
53
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-elasticsearch'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.8.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Copies fields from previous log events in Elasticsearch to current events "
|
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"
|
@@ -367,7 +367,37 @@ describe LogStash::Filters::Elasticsearch do
|
|
367
367
|
let(:config) { super.merge({ 'cloud_auth' => 'elastic:my-passwd-00', 'user' => 'another' }) }
|
368
368
|
|
369
369
|
it "should fail" do
|
370
|
-
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /
|
370
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end if LOGSTASH_VERSION > '6.0'
|
374
|
+
|
375
|
+
describe "api_key" do
|
376
|
+
context "without ssl" do
|
377
|
+
let(:config) { super.merge({ 'api_key' => LogStash::Util::Password.new('foo:bar') }) }
|
378
|
+
|
379
|
+
it "should fail" do
|
380
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /api_key authentication requires SSL\/TLS/
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context "with ssl" do
|
385
|
+
let(:config) { super.merge({ 'api_key' => LogStash::Util::Password.new('foo:bar'), "ssl" => true }) }
|
386
|
+
|
387
|
+
it "should set authorization" do
|
388
|
+
plugin.register
|
389
|
+
client = plugin.send(:get_client).client
|
390
|
+
auth_header = client.transport.options[:transport_options][:headers][:Authorization]
|
391
|
+
|
392
|
+
expect( auth_header ).to eql "ApiKey #{Base64.strict_encode64('foo:bar')}"
|
393
|
+
end
|
394
|
+
|
395
|
+
context 'user also set' do
|
396
|
+
let(:config) { super.merge({ 'api_key' => 'foo:bar', 'user' => 'another' }) }
|
397
|
+
|
398
|
+
it "should fail" do
|
399
|
+
expect { plugin.register }.to raise_error LogStash::ConfigurationError, /Multiple authentication options are specified/
|
400
|
+
end
|
371
401
|
end
|
372
402
|
end
|
373
403
|
end if LOGSTASH_VERSION > '6.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|