logstash-filter-geoip 7.2.13-java → 7.3.0-java

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: caca9f4a1ba058cc744e60279252429de5e33f041ecac3a2872b1973714961e2
4
- data.tar.gz: 248298b87dc000636fe7775910cd1cf28eb18842200426b831c46a8c835d7db2
3
+ metadata.gz: f7db08a266d05be61267f7921ede9b9e9c7177804574c96fcc94a25615b6449d
4
+ data.tar.gz: bdd2133e4acbea8e12dfd6dc57ce45a9b5e628cf7672a0c299768041855ec001
5
5
  SHA512:
6
- metadata.gz: f2a9c1475b3832ef62a61998427fd0f8cac9aa18c28cba340cb0f9086ca298882dc99e1fcf9c0c6f08dc9dcf5eeb6543f4145d6536c74b85235a46c1bc4a1ff4
7
- data.tar.gz: 10612c6801e46e32763c913ac55b9598959341b44f201a89cf1738ec2db84efdc3df3cf8edf1569d46dd5a5e06963023c1dc49f6e6127bb41aa2d25e655e8632
6
+ metadata.gz: d659cea20b030c2dfbfe30d7b1ce283b308250a710e90287595c836a0cb6ef678b25d473cca6da7b7d82d87e31dc5557ad37802e85e06c437a4f5b104d5c5b48
7
+ data.tar.gz: 5157efccb1f54d898d53ad6db5ae9ba1659473858de168d353789ca6f1fd7b78ffe8777e76130e9adda0d33cd23ebb2215c5d4812ec127b254ec925dfc6937ba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 7.3.0
2
+ - Added support for MaxMind GeoIP2 Enterprise and Anonymous-IP databases ([#223](https://github.com/logstash-plugins/logstash-filter-geoip/pull/223))
3
+ - Updated MaxMind dependencies.
4
+ - Added tests for the Java classes.
5
+
1
6
  ## 7.2.13
2
7
  - [DOC] Add documentation for database auto-update configuration [#210](https://github.com/logstash-plugins/logstash-filter-geoip/pull/210)
3
8
 
data/docs/index.asciidoc CHANGED
@@ -190,37 +190,44 @@ When ECS compatibility is enabled, the fields are structured to fit into an ECS
190
190
  |===========================
191
191
  | Database Field Name | ECS Field | Example
192
192
 
193
- | `ip` | `[ip]` | `12.34.56.78`
194
-
195
- | `city_name` | `[geo][city_name]` | `Seattle`
196
- | `country_name` | `[geo][country_name]` | `United States`
197
- | `continent_code` | `[geo][continent_code]` | `NA`
198
- | `continent_name` | `[geo][continent_name]` | `North America`
199
- | `country_code2` | `[geo][country_iso_code]` | `US`
200
- | `country_code3` | _N/A_ | `US`
201
-
202
- _maintained for legacy
203
- support, but populated
204
- with 2-character country
205
- code_
206
-
207
- | `postal_code` | `[geo][postal_code]` | `98106`
208
- | `region_name` | `[geo][region_name]` | `Washington`
209
- | `region_code` | `[geo][region_code]` | `WA`
210
- | `region_iso_code`* | `[geo][region_iso_code]` | `US-WA`
211
- | `timezone` | `[geo][timezone]` | `America/Los_Angeles`
212
- | `location`* | `[geo][location]` | `{"lat": 47.6062, "lon": -122.3321}"`
213
- | `latitude` | `[geo][location][lat]` | `47.6062`
214
- | `longitude` | `[geo][location][lon]` | `-122.3321`
215
-
216
- | `domain` | `[domain]` | `example.com`
217
-
218
- | `asn` | `[as][number]` | `98765`
219
- | `as_org` | `[as][organization][name]` | `Elastic, NV`
220
-
221
- | `isp` | `[mmdb][isp]` | `InterLink Supra LLC`
222
- | `dma_code` | `[mmdb][dma_code]` | `819`
223
- | `organization` | `[mmdb][organization]` | `Elastic, NV`
193
+ | `ip` | `[ip]` | `12.34.56.78`
194
+ | `anonymous` | `[ip_traits][anonymous]` | `false`
195
+ | `anonymous_vpn` | `[ip_traits][anonymous_vpn]` | `false`
196
+ | `hosting_provider` | `[ip_traits][hosting_provider]` | `true`
197
+ | `network` | `[ip_traits][network]` | `12.34.56.78/20`
198
+ | `public_proxy` | `[ip_traits][public_proxy]` | `true`
199
+ | `residential_proxy` | `[ip_traits][residential_proxy]` | `false`
200
+ | `tor_exit_node` | `[ip_traits][tor_exit_node]` | `true`
201
+
202
+ | `city_name` | `[geo][city_name]` | `Seattle`
203
+ | `country_name` | `[geo][country_name]` | `United States`
204
+ | `continent_code` | `[geo][continent_code]` | `NA`
205
+ | `continent_name` | `[geo][continent_name]` | `North America`
206
+ | `country_code2` | `[geo][country_iso_code]` | `US`
207
+ | `country_code3` | _N/A_ | `US`
208
+
209
+ _maintained for legacy
210
+ support, but populated
211
+ with 2-character country
212
+ code_
213
+
214
+ | `postal_code` | `[geo][postal_code]` | `98106`
215
+ | `region_name` | `[geo][region_name]` | `Washington`
216
+ | `region_code` | `[geo][region_code]` | `WA`
217
+ | `region_iso_code`* | `[geo][region_iso_code]` | `US-WA`
218
+ | `timezone` | `[geo][timezone]` | `America/Los_Angeles`
219
+ | `location`* | `[geo][location]` | `{"lat": 47.6062, "lon": -122.3321}"`
220
+ | `latitude` | `[geo][location][lat]` | `47.6062`
221
+ | `longitude` | `[geo][location][lon]` | `-122.3321`
222
+
223
+ | `domain` | `[domain]` | `example.com`
224
+
225
+ | `asn` | `[as][number]` | `98765`
226
+ | `as_org` | `[as][organization][name]` | `Elastic, NV`
227
+
228
+ | `isp` | `[mmdb][isp]` | `InterLink Supra LLC`
229
+ | `dma_code` | `[mmdb][dma_code]` | `819`
230
+ | `organization` | `[mmdb][organization]` | `Elastic, NV`
224
231
  |===========================
225
232
 
226
233
  NOTE: `*` indicates a composite field, which is only populated if GeoIP lookup result contains all components.
@@ -301,7 +308,7 @@ number of cache misses and waste memory.
301
308
  The path to MaxMind's database file that Logstash should use.
302
309
  The default database is `GeoLite2-City`.
303
310
  This plugin supports several free databases (`GeoLite2-City`, `GeoLite2-Country`, `GeoLite2-ASN`)
304
- and a selection of commercially-licensed databases (`GeoIP2-City`, `GeoIP2-ISP`, `GeoIP2-Country`).
311
+ and a selection of commercially-licensed databases (`GeoIP2-City`, `GeoIP2-ISP`, `GeoIP2-Country`, `GeoIP2-Domain`, `GeoIP2-Enterprise`, `GeoIP2-Anonymous-IP`).
305
312
 
306
313
  Database auto-update applies to the default distribution.
307
314
  When `database` points to user's database path, auto-update is disabled.
@@ -171,7 +171,17 @@ class LogStash::Filters::GeoIP < LogStash::Filters::Base
171
171
  end
172
172
 
173
173
  def close
174
- @database_manager.unsubscribe_database_path(@default_database_type, self) if @database_manager
174
+ begin
175
+ @database_manager.unsubscribe_database_path(@default_database_type, self) if @database_manager
176
+ rescue => e
177
+ @logger.error("Error unsubscribing geoip database path", :path => @database, :exception => e)
178
+ end
179
+
180
+ begin
181
+ @geoipfilter.close if @geoipfilter
182
+ rescue => e
183
+ @logger.error("Error closing GeoIPFilter", :exception => e)
184
+ end
175
185
  end
176
186
 
177
187
  def select_database_path
@@ -1,6 +1,6 @@
1
1
  # AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.
2
2
 
3
3
  require 'jar_dependencies'
4
- require_jar('com.maxmind.geoip2', 'geoip2', '2.9.0')
5
- require_jar('com.maxmind.db', 'maxmind-db', '1.2.2')
6
- require_jar('org.logstash.filters', 'logstash-filter-geoip', '6.0.0')
4
+ require_jar('com.maxmind.geoip2', 'geoip2', '2.17.0')
5
+ require_jar('com.maxmind.db', 'maxmind-db', '2.1.0')
6
+ require_jar('org.logstash.filters', 'logstash-filter-geoip', '7.3.0')
@@ -1,7 +1,9 @@
1
+ VERSION = File.read(File.expand_path(File.join(File.dirname(__FILE__), "VERSION"))).strip unless defined?(VERSION)
2
+
1
3
  Gem::Specification.new do |s|
2
4
 
3
5
  s.name = 'logstash-filter-geoip'
4
- s.version = '7.2.13'
6
+ s.version = VERSION
5
7
  s.licenses = ['Apache License (2.0)']
6
8
  s.summary = "Adds geographical information about an IP address"
7
9
  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"
@@ -112,7 +112,7 @@ describe LogStash::Filters::GeoIP do
112
112
  CONFIG
113
113
 
114
114
  context "should return the correct sourcefield in the logging message" do
115
- sample("ip" => "8.8.8.8") do
115
+ sample({"ip" => "8.8.8.8"}) do
116
116
  expect { subject }.to raise_error(java.lang.IllegalArgumentException, "The database provided is invalid or corrupted.")
117
117
  end
118
118
  end
@@ -1,67 +1,97 @@
1
1
  # encoding: utf-8
2
+ require 'pathname'
2
3
  require "logstash/devutils/rspec/spec_helper"
3
4
  require "insist"
4
5
  require "logstash/filters/geoip"
5
6
  require_relative 'test_helper'
6
7
 
7
8
  describe LogStash::Filters::GeoIP do
9
+ context "when no database_path is given" do
8
10
 
9
- before(:each) do
10
- ::File.delete(METADATA_PATH) if ::File.exist?(METADATA_PATH)
11
- end
11
+ let(:last_db_path_recorder) do
12
+ Module.new do
13
+ attr_reader :last_db_path
14
+ def setup_filter(db_path)
15
+ @last_db_path = db_path
16
+ super
17
+ end
18
+ end
19
+ end
12
20
 
13
- describe "config without database path in LS >= 7.14", :aggregate_failures do
14
- before(:each) do
15
- dir_path = Stud::Temporary.directory
16
- File.open(dir_path + '/uuid', 'w') { |f| f.write(SecureRandom.uuid) }
17
- allow(LogStash::SETTINGS).to receive(:get).and_call_original
18
- allow(LogStash::SETTINGS).to receive(:get).with("xpack.geoip.downloader.enabled").and_return(true)
19
- allow(LogStash::SETTINGS).to receive(:get).with("xpack.geoip.download.endpoint").and_return(nil)
20
- allow(LogStash::SETTINGS).to receive(:get).with("path.data").and_return(dir_path)
21
+ let(:plugin_config) { Hash["source" => "[source][ip]", "target" => "[target]"] }
22
+ let(:plugin) { described_class.new(plugin_config).extend(last_db_path_recorder) }
23
+ let(:event) { LogStash::Event.new("source" => { "ip" => "173.9.34.107" }) }
24
+
25
+ shared_examples "event enrichment" do
26
+ it 'enriches events' do
27
+ plugin.register
28
+ plugin.filter(event)
29
+
30
+ expect(event.get("target")).to include('ip')
31
+ end
21
32
  end
22
33
 
23
- let(:plugin) { LogStash::Filters::GeoIP.new("source" => "[target][ip]") }
34
+ database_management_available = (MAJOR >= 8 || (MAJOR == 7 && MINOR >= 14)) && !LogStash::OSS
35
+ if database_management_available
36
+ context "when geoip database management is available" do
37
+
38
+ let(:mock_manager) do
39
+ double('LogStash::Filters::Geoip::DatabaseManager').tap do |m|
40
+ allow(m).to receive(:subscribe_database_path) do |db_type, explicit_path, plugin_instance|
41
+ explicit_path || mock_managed[db_type]
42
+ end
43
+ allow(m).to receive(:unsubscribe_database_path).with(any_args)
44
+ end
45
+ end
46
+
47
+ # The extension to this plugin that lives in Logstash core will _always_ provide a valid
48
+ # database path, and how it does so is not the concern of this plugin. We emulate this
49
+ # behaviour here by copying the vendored CC-licensed db's into a temporary path
50
+ let(:mock_managed) do
51
+ managed_path = Pathname.new(temp_data_path).join("managed", Time.now.to_i.to_s).tap(&:mkpath)
52
+
53
+ managed_city_db_path = Pathname.new(DEFAULT_CITY_DB_PATH).basename.expand_path(managed_path).to_path
54
+ FileUtils.cp(DEFAULT_CITY_DB_PATH, managed_city_db_path)
24
55
 
25
- context "restart the plugin" do
26
- let(:event) { LogStash::Event.new("target" => { "ip" => "173.9.34.107" }) }
27
- let(:event2) { LogStash::Event.new("target" => { "ip" => "55.159.212.43" }) }
56
+ managed_asn_db_path = Pathname.new(DEFAULT_ASN_DB_PATH).basename.expand_path(managed_path).to_path
57
+ FileUtils.cp(DEFAULT_ASN_DB_PATH, managed_asn_db_path)
28
58
 
29
- it "should use the same database" do
30
- unless plugin.load_database_manager?
31
- logstash_path = ENV['LOGSTASH_PATH'] || '/usr/share/logstash' # docker logstash home
32
- stub_const('LogStash::Environment::LOGSTASH_HOME', logstash_path)
59
+ {
60
+ 'City' => managed_city_db_path,
61
+ 'ASN' => managed_asn_db_path,
62
+ }
33
63
  end
34
64
 
35
- plugin.register
36
- plugin.filter(event)
37
- plugin.close
38
- first_dirname = get_metadata_city_database_name
39
- plugin.register
40
- plugin.filter(event2)
41
- plugin.close
42
- second_dirname = get_metadata_city_database_name
65
+ before(:each) do
66
+ allow_any_instance_of(described_class).to receive(:load_database_manager?).and_return(true)
67
+ stub_const("LogStash::Filters::Geoip::DatabaseManager", double("DatabaseManager.Class", :instance => mock_manager))
68
+ end
43
69
 
44
- expect(first_dirname).not_to be_nil
45
- expect(first_dirname).to eq(second_dirname)
46
- expect(File).to exist(get_file_path(first_dirname))
70
+ let(:temp_data_path) { Stud::Temporary.directory }
71
+ after(:each) do
72
+ FileUtils.rm_rf(temp_data_path) if File.exist?(temp_data_path)
73
+ end
74
+
75
+ it "uses a managed database" do
76
+ plugin.register
77
+ plugin.filter(event)
78
+ expect(plugin.last_db_path).to_not be_nil
79
+ expect(plugin.last_db_path).to start_with(temp_data_path)
80
+ end
81
+
82
+ include_examples "event enrichment"
47
83
  end
48
- end
49
- end if MAJOR >= 8 || (MAJOR == 7 && MINOR >= 14)
50
-
51
- describe "config without database path in LS < 7.14" do
52
- context "should run in offline mode" do
53
- config <<-CONFIG
54
- filter {
55
- geoip {
56
- source => "ip"
57
- }
58
- }
59
- CONFIG
60
-
61
- sample("ip" => "173.9.34.107") do
62
- insist { subject.get("geoip") }.include?("ip")
63
- expect(::File.exist?(METADATA_PATH)).to be_falsey
84
+ else
85
+ context "when geoip database management is not available" do
86
+
87
+ include_examples "event enrichment"
88
+
89
+ it "uses a plugin-vendored database" do
90
+ plugin.register
91
+ expect(plugin.last_db_path).to_not be_nil
92
+ expect(plugin.last_db_path).to include("/vendor/")
93
+ end
64
94
  end
65
95
  end
66
- end if MAJOR < 7 || (MAJOR == 7 && MINOR < 14)
96
+ end
67
97
  end
@@ -19,13 +19,13 @@ describe LogStash::Filters::GeoIP do
19
19
  end
20
20
  end
21
21
 
22
- describe ">= 7.14" do
22
+ shared_examples "with database manager" do
23
23
  it "load_database_manager? should be true" do
24
24
  expect(plugin.load_database_manager?).to be_truthy
25
25
  end
26
- end if MAJOR >= 8 || (MAJOR == 7 && MINOR >= 14)
26
+ end
27
27
 
28
- describe "<= 7.13" do
28
+ shared_examples "without database manager" do
29
29
  it "load_database_manager? should be false" do
30
30
  expect(plugin.load_database_manager?).to be_falsey
31
31
  end
@@ -37,6 +37,24 @@ describe LogStash::Filters::GeoIP do
37
37
  expect(plugin.select_database_path).to eql(DEFAULT_CITY_DB_PATH)
38
38
  end
39
39
  end
40
- end if MAJOR < 7 || (MAJOR == 7 && MINOR <= 13)
40
+ end
41
+
42
+ if MAJOR >= 8 || (MAJOR == 7 && MINOR >= 14)
43
+ context "Logstash >= 7.14" do
44
+ if LogStash::OSS
45
+ context "OSS-only" do
46
+ include_examples "without database manager"
47
+ end
48
+ else
49
+ context "default distro" do
50
+ include_examples "with database manager"
51
+ end
52
+ end
53
+ end
54
+ else
55
+ describe "Logstash < 7.14" do
56
+ include_examples "without database manager"
57
+ end
58
+ end
41
59
  end
42
60
  end
@@ -2,28 +2,46 @@ require "logstash-core/logstash-core"
2
2
  require "digest"
3
3
  require "csv"
4
4
 
5
- def get_vendor_path(filename)
6
- ::File.join(::File.expand_path("../../vendor/", ::File.dirname(__FILE__)), filename)
7
- end
8
-
9
- def get_data_dir
10
- ::File.join(LogStash::SETTINGS.get_value("path.data"), "plugins", "filters", "geoip")
11
- end
12
-
13
- def get_file_path(filename)
14
- ::File.join(get_data_dir, filename)
15
- end
5
+ # Since we use Logstash's x-pack WITHOUT the LogStash::Runner,
6
+ # we must find it relative to logstash-core and add it to the load path.
7
+ require 'pathname'
8
+ logstash_core_path = Gem.loaded_specs['logstash-core']&.full_gem_path or fail("logstash-core lib not found")
9
+ logstash_xpack_load_path = Pathname.new(logstash_core_path).join("../x-pack/lib").cleanpath.to_s
10
+ if ENV['OSS'] == "true" || !File.exists?(logstash_xpack_load_path)
11
+ $stderr.puts("X-PACK is not available")
12
+ LogStash::OSS = true
13
+ else
14
+ if !$LOAD_PATH.include?(logstash_xpack_load_path)
15
+ $stderr.puts("ADDING LOGSTASH X-PACK to load path: #{logstash_xpack_load_path}")
16
+ $LOAD_PATH.unshift(logstash_xpack_load_path)
17
+ end
18
+ LogStash::OSS = false
16
19
 
17
- def get_metadata_city_database_name
18
- if ::File.exist?(METADATA_PATH)
19
- city = ::CSV.read(METADATA_PATH, headers: false).select { |row| row[0].eql?("City") }.last
20
- city[3]
20
+ # when running in a Logstash process that has a geoip extension available, it will
21
+ # be loaded before this plugin is instantiated. In tests, we need to find and load the
22
+ # appropriate extension ourselves.
23
+ extension = nil
24
+ extension ||= begin; require 'geoip_database_management/extension'; LogStash::const_get("GeoipDatabaseManagement::Extension"); rescue Exception; nil; end
25
+ extension ||= begin; require 'filters/geoip/extension'; LogStash::const_get("Filters::Geoip::Extension"); rescue Exception; nil; end
26
+ if extension
27
+ $stderr.puts("loading logstash extension for geoip: #{extension}")
28
+ extension.new.tap do |instance|
29
+ # the extensions require logstash/runner even though they don't need to,
30
+ # resulting in _all_ extensions being loaded into the registry, including
31
+ # those whose dependencies are not met by this plugin's dependency graph.
32
+ def instance.require(path)
33
+ super unless path == "logstash/runner"
34
+ end
35
+ end.additionals_settings(LogStash::SETTINGS)
21
36
  else
22
- nil
37
+ $stderr.puts("no logstash extension for geoip is available")
23
38
  end
24
39
  end
25
40
 
26
- METADATA_PATH = get_file_path("metadata.csv")
41
+ def get_vendor_path(filename)
42
+ ::File.join(::File.expand_path("../../vendor/", ::File.dirname(__FILE__)), filename)
43
+ end
44
+
27
45
  DEFAULT_CITY_DB_PATH = get_vendor_path("GeoLite2-City.mmdb")
28
46
  DEFAULT_ASN_DB_PATH = get_vendor_path("GeoLite2-ASN.mmdb")
29
47
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-geoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.13
4
+ version: 7.3.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2024-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -127,9 +127,9 @@ files:
127
127
  - spec/filters/test_helper.rb
128
128
  - vendor/GeoLite2-ASN.mmdb
129
129
  - vendor/GeoLite2-City.mmdb
130
- - vendor/jar-dependencies/com/maxmind/db/maxmind-db/1.2.2/maxmind-db-1.2.2.jar
131
- - vendor/jar-dependencies/com/maxmind/geoip2/geoip2/2.9.0/geoip2-2.9.0.jar
132
- - vendor/jar-dependencies/org/logstash/filters/logstash-filter-geoip/6.0.0/logstash-filter-geoip-6.0.0.jar
130
+ - vendor/jar-dependencies/com/maxmind/db/maxmind-db/2.1.0/maxmind-db-2.1.0.jar
131
+ - vendor/jar-dependencies/com/maxmind/geoip2/geoip2/2.17.0/geoip2-2.17.0.jar
132
+ - vendor/jar-dependencies/org/logstash/filters/logstash-filter-geoip/7.3.0/logstash-filter-geoip-7.3.0.jar
133
133
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
134
134
  licenses:
135
135
  - Apache License (2.0)
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.1.6
155
+ rubygems_version: 3.2.33
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Adds geographical information about an IP address