Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geoip processor update #11854

Merged
merged 35 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
310c016
Initial Commit. Added basic back-end implementation--sans IP validation
roberto-graylog Dec 16, 2021
d468052
Initial Commit. Added basic back-end implementation to handle multipl…
roberto-graylog Dec 17, 2021
f6e2da8
Updated GeoIpResolverConfig to use a DatabaseVendorType instead of in…
roberto-graylog Dec 21, 2021
c751444
Added database migration to remove field 'db_type' and add field 'dat…
roberto-graylog Dec 22, 2021
76b96cc
Updated ClusterConfigResource to validate GeoIpResolverConfig updates.
roberto-graylog Dec 22, 2021
a4eaeb0
Updated resolvers to use timer in try-catch as the original
roberto-graylog Jan 3, 2022
f5839e8
Started Guice factory conversion for GeoIpResolverFactory
roberto-graylog Jan 3, 2022
659f25b
Merge branch 'master' into geoip-processor-update
roberto-graylog Jan 3, 2022
c33b69d
Updated resolver constructor args with Assisted annotations
roberto-graylog Jan 3, 2022
c344776
Merge branch 'master' into geoip-processor-update
roberto-graylog Jan 3, 2022
0619080
Updated ClusterConfigResource to not validate ASN DB file path if not…
roberto-graylog Jan 3, 2022
877ef03
Started updates to validate database file (perform actual db query to…
roberto-graylog Jan 3, 2022
78bc2cc
Added last error tracking for resolvers and updated config resource t…
roberto-graylog Jan 3, 2022
3e203d3
Reverted front-end temp changes.
roberto-graylog Jan 3, 2022
18bf9ed
Code cleanup
roberto-graylog Jan 4, 2022
101336b
Started extraction of cluster config validation
roberto-graylog Jan 4, 2022
4efdb5d
Cleaned up cluster validation and db migration
roberto-graylog Jan 5, 2022
f3110ae
Updated message fields. Add config field to optionally enforce the G…
roberto-graylog Jan 6, 2022
46de5e6
updated db migration to explicitly set all defaults.
roberto-graylog Jan 6, 2022
c900c5b
Frontend functionality for the GeoIpResolverConfiguration
mikedklein Jan 6, 2022
4e2afe6
Updated resolver issue that caused false positive during validation
roberto-graylog Jan 6, 2022
e1b667b
Updated GeoIpResolverEngineTest. Moved Cluster Validation to a more …
roberto-graylog Jan 10, 2022
e6fd248
renamed method Graylog2Module::mapBinder to clusterConfigMapBinder
roberto-graylog Jan 10, 2022
33f1829
Removed unused dependency
roberto-graylog Jan 11, 2022
c2d5d23
Merge branch 'master' into geoip-processor-update
roberto-graylog Jan 11, 2022
57f8515
Merge branch 'master' into geoip-processor-update
roberto-graylog Jan 12, 2022
355c2c4
Updated database/vendor type labels
roberto-graylog Jan 12, 2022
578b45d
Updated defaultConfig on UI side
roberto-graylog Jan 13, 2022
193f991
Updated DB migration V20211221144300_GeoIpResolverConfigMigration to …
roberto-graylog Jan 13, 2022
4c6efcd
Updated DB migration V20211221144300_GeoIpResolverConfigMigration to …
roberto-graylog Jan 13, 2022
599ddad
Code Cleanup
roberto-graylog Jan 13, 2022
df1288d
Merge branch 'master' into geoip-processor-update
roberto-graylog Jan 13, 2022
3fad632
Merge branch 'master' into geoip-processor-update
roberto-graylog Jan 21, 2022
4b365c0
Updated GeoIpProcessor to defer filter engine creation to the first t…
roberto-graylog Jan 24, 2022
f8327c0
Updated repetitive log messages to debug in GeoIpResolverEngine & Geo…
roberto-graylog Jan 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
*/
package org.graylog.plugins.map;

import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.name.Names;
import org.graylog.plugins.map.geoip.GeoAsnInformation;
import org.graylog.plugins.map.geoip.GeoIpResolver;
import org.graylog.plugins.map.geoip.GeoIpResolverFactory;
import org.graylog.plugins.map.geoip.GeoLocationInformation;
import org.graylog.plugins.map.geoip.IpInfoIpAsnResolver;
import org.graylog.plugins.map.geoip.IpInfoLocationResolver;
import org.graylog.plugins.map.geoip.MaxMindIpAsnResolver;
import org.graylog.plugins.map.geoip.MaxMindIpLocationResolver;
import org.graylog.plugins.map.geoip.MaxmindDataAdapter;
import org.graylog.plugins.map.geoip.processor.GeoIpProcessor;
import org.graylog2.plugin.PluginModule;
Expand All @@ -28,5 +39,18 @@ protected void configure() {
MaxmindDataAdapter.class,
MaxmindDataAdapter.Factory.class,
MaxmindDataAdapter.Config.class);

//Create TypeLiterals to specify method type parameters
TypeLiteral<GeoIpResolver<GeoLocationInformation>> mmCityTl = new TypeLiteral<GeoIpResolver<GeoLocationInformation>>() {};
TypeLiteral<GeoIpResolver<GeoAsnInformation>> mmAsnTl = new TypeLiteral<GeoIpResolver<GeoAsnInformation>>() {};
TypeLiteral<GeoIpResolver<GeoLocationInformation>> ipinfoCityTl = new TypeLiteral<GeoIpResolver<GeoLocationInformation>>() {};
TypeLiteral<GeoIpResolver<GeoAsnInformation>> ipInfoAsnTl = new TypeLiteral<GeoIpResolver<GeoAsnInformation>>() {};

install(new FactoryModuleBuilder()
.implement(mmCityTl, Names.named("MAXMIND_CITY"), MaxMindIpLocationResolver.class)
.implement(mmAsnTl, Names.named("MAXMIND_ASN"), MaxMindIpAsnResolver.class)
.implement(ipinfoCityTl, Names.named("IPINFO_CITY"), IpInfoLocationResolver.class)
.implement(ipInfoAsnTl, Names.named("IPINFO_ASN"), IpInfoIpAsnResolver.class)
.build(GeoIpResolverFactory.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

package org.graylog.plugins.map.config;

public enum DatabaseVendorType {
MAXMIND(DatabaseType.MAXMIND_CITY, DatabaseType.MAXMIND_ASN),
IPINFO(DatabaseType.IPINFO_STANDARD_LOCATION, DatabaseType.IPINFO_ASN);

private final DatabaseType cityDbType;
private final DatabaseType asnDbType;

DatabaseVendorType(DatabaseType cityDbType, DatabaseType asnDbType) {
this.cityDbType = cityDbType;
this.asnDbType = asnDbType;
}

public DatabaseType getCityDbType() {
return cityDbType;
}

public DatabaseType getAsnDbType() {
return asnDbType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
*/
package org.graylog.plugins.map.config;

import com.google.auto.value.AutoValue;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;

@JsonAutoDetect
@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -31,28 +30,40 @@ public abstract class GeoIpResolverConfig {
@JsonProperty("enabled")
public abstract boolean enabled();

@JsonProperty("db_type")
public abstract DatabaseType dbType();
@JsonProperty("enforce_graylog_schema")
public abstract boolean enforceGraylogSchema();

@JsonProperty("db_vendor_type")
public abstract DatabaseVendorType databaseVendorType();

@JsonProperty("city_db_path")
public abstract String cityDbPath();

@JsonProperty("db_path")
public abstract String dbPath();
@JsonProperty("asn_db_path")
public abstract String asnDbPath();

@JsonCreator
public static GeoIpResolverConfig create(@JsonProperty("enabled") boolean enabled,
@JsonProperty("db_type") DatabaseType dbType,
@JsonProperty("db_path") String dbPath) {
public static GeoIpResolverConfig create(@JsonProperty("enabled") boolean cityEnabled,
roberto-graylog marked this conversation as resolved.
Show resolved Hide resolved
@JsonProperty("enforce_graylog_schema") boolean enforceGraylogSchema,
@JsonProperty("db_vendor_type") DatabaseVendorType databaseVendorType,
@JsonProperty("city_db_path") String cityDbPath,
@JsonProperty("asn_db_path") String asnDbPath) {
return builder()
.enabled(enabled)
.dbType(dbType)
.dbPath(dbPath)
.enabled(cityEnabled)
roberto-graylog marked this conversation as resolved.
Show resolved Hide resolved
.enforceGraylogSchema(enforceGraylogSchema)
.databaseVendorType(databaseVendorType == null ? DatabaseVendorType.MAXMIND : databaseVendorType)
.cityDbPath(cityDbPath)
.asnDbPath(asnDbPath)
.build();
}

public static GeoIpResolverConfig defaultConfig() {
return builder()
.enabled(false)
.dbType(DatabaseType.MAXMIND_CITY)
.dbPath("/etc/graylog/server/GeoLite2-City.mmdb")
.databaseVendorType(DatabaseVendorType.MAXMIND)
.enforceGraylogSchema(false)
.cityDbPath("/etc/graylog/server/GeoLite2-City.mmdb")
.asnDbPath("/etc/graylog/server/GeoLite2-ASN.mmdb")
.build();
}

Expand All @@ -63,11 +74,17 @@ public static Builder builder() {
public abstract Builder toBuilder();

@AutoValue.Builder
public static abstract class Builder {
public abstract static class Builder {
public abstract Builder enabled(boolean enabled);
public abstract Builder dbType(DatabaseType dbType);
public abstract Builder dbPath(String dbPath);

public abstract Builder enforceGraylogSchema(boolean enforce);

public abstract Builder databaseVendorType(DatabaseVendorType type);

public abstract Builder cityDbPath(String dbPath);

public abstract Builder asnDbPath(String asnDBPath);

public abstract GeoIpResolverConfig build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

package org.graylog.plugins.map.geoip;

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class GeoAsnInformation {

public abstract String organization();

public abstract String type();

public abstract String asn();

public static GeoAsnInformation create(String organization, String type, String asn) {
return new AutoValue_GeoAsnInformation(organization, type, asn);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

package org.graylog.plugins.map.geoip;

import com.codahale.metrics.Timer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.InetAddress;
import java.nio.file.Files;
import java.util.Optional;

public abstract class GeoIpResolver<V> {

private static final Logger LOG = LoggerFactory.getLogger(GeoIpResolver.class);

protected String lastError = null;
protected final Timer resolveTime;
private final boolean enabled;

GeoIpResolver(Timer resolveTime, String configPath, boolean enabled) {

this.resolveTime = resolveTime;
if (enabled) {
final File configFile = new File(configPath);
if (Files.exists(configFile.toPath())) {
this.enabled = createDataProvider(configFile);
} else {
LOG.warn("'{}' database file does not exist: {}", getClass().getName(), configPath);
this.enabled = false;
}
} else {
this.enabled = false;
}
}

public boolean isEnabled() {
return enabled;
}

abstract boolean createDataProvider(File configFile);

public Optional<V> getGeoIpData(InetAddress address) {
lastError = null;
if (!enabled || address == null) {
return Optional.empty();
}
return doGetGeoIpData(address);
}

/**
* Get the last error, if any, produced after having called {@link #getGeoIpData(InetAddress)}.
*
* @return optional error message
*/
public Optional<String> getLastError() {
return Optional.ofNullable(lastError);
}

protected abstract Optional<V> doGetGeoIpData(InetAddress address);
}
Loading