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

[Filebeat] Add network.direction by specifying internal_networks to gcp module #23081

Merged
merged 5 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add top_level_domain enrichment for suricata/eve fileset. {pull}23046[23046]
- Add top_level_domain enrichment for zeek/dns fileset. {pull}23046[23046]
- Add `network.direction` to netflow/log fileset. {pull}23052[23052]
- Add `network.direction` override by specifying `internal_networks` in gcp module. {pull}23081[23081]

*Heartbeat*

Expand Down
3 changes: 3 additions & 0 deletions libbeat/docs/processors-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ endif::[]
ifndef::no_add_locale_processor[]
include::{libbeat-processors-dir}/add_locale/docs/add_locale.asciidoc[]
endif::[]
ifndef::no_add_network_direction_processor[]
include::{libbeat-processors-dir}/actions/docs/add_network_direction.asciidoc[]
endif::[]
ifndef::no_add_observer_metadata_processor[]
include::{libbeat-processors-dir}/add_observer_metadata/docs/add_observer_metadata.asciidoc[]
endif::[]
Expand Down
2 changes: 2 additions & 0 deletions libbeat/processors/actions/add_network_direction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import (
"github.com/elastic/beats/v7/libbeat/conditions"
"github.com/elastic/beats/v7/libbeat/processors"
"github.com/elastic/beats/v7/libbeat/processors/checks"
jsprocessor "github.com/elastic/beats/v7/libbeat/processors/script/javascript/module/processor"
)

func init() {
processors.RegisterPlugin("add_network_direction",
checks.ConfigChecked(NewAddNetworkDirection,
checks.RequireFields("source", "destination", "target", "internal_networks"),
checks.AllowedFields("source", "destination", "target", "internal_networks")))
jsprocessor.RegisterPlugin("AddNetworkDirection", NewAddNetworkDirection)
}

const (
Expand Down
19 changes: 19 additions & 0 deletions x-pack/filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,16 @@ filebeat.modules:
# the subscription.
var.credentials_file: ${path.config}/gcp-service-account-xyz.json

# Set internal networks. This is used to classify network.direction based
# off of what networks are considered "internal" either base off of a CIDR
# block or named network conditions. If this is not specified, then traffic
# direction is determined by whether it is between source and destination
# instance information rather than IP.
#
# For a full list of network conditions see:
# https://www.elastic.co/guide/en/beats/filebeat/current/defining-processors.html#condition-network
#var.internal_networks: [ "private" ]

firewall:
enabled: true

Expand All @@ -861,6 +871,15 @@ filebeat.modules:
# the subscription.
var.credentials_file: ${path.config}/gcp-service-account-xyz.json

# Set internal networks. This is used to classify network.direction based
# off of what networks are considered "internal" either base off of a CIDR
# block or named network conditions. If this is not specified, then traffic
# is taken from the direction data in the rule_details event payload.
#
# For a full list of network conditions see:
# https://www.elastic.co/guide/en/beats/filebeat/current/defining-processors.html#condition-network
#var.internal_networks: [ "private" ]

audit:
enabled: true

Expand Down
19 changes: 19 additions & 0 deletions x-pack/filebeat/module/gcp/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
# the subscription.
var.credentials_file: ${path.config}/gcp-service-account-xyz.json

# Set internal networks. This is used to classify network.direction based
# off of what networks are considered "internal" either base off of a CIDR
# block or named network conditions. If this is not specified, then traffic
# direction is determined by whether it is between source and destination
# instance information rather than IP.
#
# For a full list of network conditions see:
# https://www.elastic.co/guide/en/beats/filebeat/current/defining-processors.html#condition-network
#var.internal_networks: [ "private" ]

firewall:
enabled: true

Expand All @@ -35,6 +45,15 @@
# the subscription.
var.credentials_file: ${path.config}/gcp-service-account-xyz.json

# Set internal networks. This is used to classify network.direction based
# off of what networks are considered "internal" either base off of a CIDR
# block or named network conditions. If this is not specified, then traffic
# is taken from the direction data in the rule_details event payload.
#
# For a full list of network conditions see:
# https://www.elastic.co/guide/en/beats/filebeat/current/defining-processors.html#condition-network
#var.internal_networks: [ "private" ]

audit:
enabled: true

Expand Down
3 changes: 3 additions & 0 deletions x-pack/filebeat/module/gcp/firewall/config/input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ processors:
params:
debug: {{ .debug }}
keep_original_message: {{ .keep_original_message }}
{{ if .internal_networks }}
internal_networks: {{ .internal_networks | tojson }}
{{ end }}
file: ${path.home}/module/gcp/firewall/config/pipeline.js
- add_fields:
target: ''
Expand Down
16 changes: 12 additions & 4 deletions x-pack/filebeat/module/gcp/firewall/config/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function PipelineBuilder(pipelineName, debug) {
}
}

function FirewallProcessor(keep_original_message, debug) {
function FirewallProcessor(keep_original_message, debug, internalNetworks) {
var builder = new PipelineBuilder("firewall", debug);

// The pub/sub input writes the Stackdriver LogEntry object into the message
Expand Down Expand Up @@ -313,17 +313,25 @@ function FirewallProcessor(keep_original_message, debug) {
event.AppendTo("related.ip", event.Get("destination.ip"));
});

var chain = builder.Build();
if (internalNetworks) {
builder.Add("addNetworkDirection", processor.AddNetworkDirection({
source: "source.ip",
destination: "destination.ip",
target: "network.direction",
internal_networks: internalNetworks,
}))
}

return {
process: chain.Run
process: builder.Build().Run
};
}

var firewall;

// Register params from configuration.
function register(params) {
firewall = new FirewallProcessor(params.keep_original_message, params.debug);
firewall = new FirewallProcessor(params.keep_original_message, params.debug, params.internal_networks);
}

function process(evt) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gcp/firewall/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var:
default: false
- name: tags
default: [forwarded]
- name: internal_networks

ingest_pipeline: ingest/pipeline.yml
input: config/input.yml
Expand Down
3 changes: 3 additions & 0 deletions x-pack/filebeat/module/gcp/vpcflow/config/input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ processors:
file: ${path.home}/module/gcp/vpcflow/config/pipeline.js
params:
keep_original_message: {{ .keep_original_message }}
{{ if .internal_networks }}
internal_networks: {{ .internal_networks | tojson }}
{{ end }}
- add_fields:
target: ''
fields:
Expand Down
18 changes: 13 additions & 5 deletions x-pack/filebeat/module/gcp/vpcflow/config/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

function VPCFlow(keep_original_message) {
function VPCFlow(keep_original_message, internalNetworks) {
var processor = require("processor");

// The pub/sub input writes the Stackdriver LogEntry object into the message
Expand Down Expand Up @@ -239,19 +239,27 @@ function VPCFlow(keep_original_message) {
.Add(setNetworkTransport)
.Add(setNetworkDirection)
.Add(setNetworkType)
.Add(setRelatedIP)
.Build();
.Add(setRelatedIP);

if (internalNetworks) {
pipeline = pipeline.AddNetworkDirection({
source: "source.ip",
destination: "destination.ip",
target: "network.direction",
internal_networks: internalNetworks,
})
}

return {
process: pipeline.Run,
process: pipeline.Build().Run,
};
}

var vpcflow;

// Register params from configuration.
function register(params) {
vpcflow = new VPCFlow(params.keep_original_message);
vpcflow = new VPCFlow(params.keep_original_message, params.internal_networks);
}

function process(evt) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/filebeat/module/gcp/vpcflow/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var:
default: false
- name: tags
default: [forwarded]
- name: internal_networks

ingest_pipeline: ingest/pipeline.yml
input: config/input.yml
Expand Down
19 changes: 19 additions & 0 deletions x-pack/filebeat/modules.d/gcp.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
# the subscription.
var.credentials_file: ${path.config}/gcp-service-account-xyz.json

# Set internal networks. This is used to classify network.direction based
# off of what networks are considered "internal" either base off of a CIDR
# block or named network conditions. If this is not specified, then traffic
# direction is determined by whether it is between source and destination
# instance information rather than IP.
#
# For a full list of network conditions see:
# https://www.elastic.co/guide/en/beats/filebeat/current/defining-processors.html#condition-network
#var.internal_networks: [ "private" ]

firewall:
enabled: true

Expand All @@ -38,6 +48,15 @@
# the subscription.
var.credentials_file: ${path.config}/gcp-service-account-xyz.json

# Set internal networks. This is used to classify network.direction based
# off of what networks are considered "internal" either base off of a CIDR
# block or named network conditions. If this is not specified, then traffic
# is taken from the direction data in the rule_details event payload.
#
# For a full list of network conditions see:
# https://www.elastic.co/guide/en/beats/filebeat/current/defining-processors.html#condition-network
#var.internal_networks: [ "private" ]

audit:
enabled: true

Expand Down