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: Make all filesets disabled in default configuration #27762

Merged
merged 6 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -84,6 +84,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Remove all alias fields pointing to ECS fields from modules. This affects the Suricata and Traefik modules. {issue}10535[10535] {pull}26627[26627]
- Add option for S3 input to work without SQS notification {issue}18205[18205] {pull}27332[27332]
- Fix Crowdstrike ingest pipeline that was creating flattened `process` fields. {issue}27622[27622] {pull}27623[27623]
- All filesets are disabled in the default configuration. {issue}17256[17256] {pull}27762[27762]

*Heartbeat*
- Remove long deprecated `watch_poll` functionality. {pull}27166[27166]
Expand Down
70 changes: 70 additions & 0 deletions dev-tools/mage/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
package mage

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/joeshaw/multierror"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

var modulesDConfigTemplate = `
Expand Down Expand Up @@ -71,3 +76,68 @@ func GenerateDirModulesD() error {
}
return nil
}

type datasetDefinition struct {
Enabled *bool
}

type moduleDefinition struct {
Name string `yaml:"module"`
Filesets map[string]datasetDefinition `yaml:",inline"`
}

// ValidateDirModulesD validates a modules.d directory containing the
// <module>.yml.disabled files. It checks that the files are valid
// yaml and conform to module definitions.
func ValidateDirModulesD() error {
_, err := loadModulesD()
return err
}

// ValidateDirModulesDDatasetsDisabled ensures that all the datasets
// are disabled by default.
func ValidateDirModulesDDatasetsDisabled() error {
cfgs, err := loadModulesD()
if err != nil {
return err
}
var errs multierror.Errors
for path, cfg := range cfgs {
// A config.yml is a list of module configurations.
for modIdx, mod := range cfg {
// A module config is a map of datasets.
for dsName, ds := range mod.Filesets {
if ds.Enabled == nil || *ds.Enabled {
var entry string
if len(cfg) > 1 {
entry = fmt.Sprintf(" (entry #%d)", modIdx+1)
}
err = fmt.Errorf("in file '%s': %s module%s dataset %s must be explicitly disabled (needs `enabled: false`)",
path, mod.Name, entry, dsName)
errs = append(errs, err)
}
}
}
}
return errs.Err()
}

func loadModulesD() (modules map[string][]moduleDefinition, err error) {
files, err := filepath.Glob("modules.d/*.disabled")
if err != nil {
return nil, err
}
modules = make(map[string][]moduleDefinition, len(files))
for _, file := range files {
contents, err := ioutil.ReadFile(file)
if err != nil {
return nil, errors.Wrapf(err, "reading %s", file)
}
var cfg []moduleDefinition
if err = yaml.Unmarshal(contents, &cfg); err != nil {
return nil, errors.Wrapf(err, "parsing %s as YAML", file)
}
modules[file] = cfg
}
return modules, nil
}
5 changes: 3 additions & 2 deletions filebeat/docs/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ configs:
include::{libbeat-dir}/tab-widgets/enable-modules-widget.asciidoc[]
--

. In the module configs under `modules.d`, change the module settings to match
your environment.
. In the module configs under `modules.d`, enable the desired datasets and
change the module settings to match your environment.
+
For example, log locations are set based on the OS. If your logs aren't in
default locations, set the `paths` variable:
Expand All @@ -97,6 +97,7 @@ default locations, set the `paths` variable:
----
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log*"] <1>
----
--
Expand Down
30 changes: 15 additions & 15 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,32 @@ filebeat.modules:
- module: elasticsearch
# Server log
server:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

gc:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

audit:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

slowlog:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

deprecation:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:
Expand All @@ -114,7 +114,7 @@ filebeat.modules:
- module: haproxy
# All logs
log:
enabled: true
enabled: false

# Set which input to use between syslog (default) or file.
#var.input:
Expand Down Expand Up @@ -191,7 +191,7 @@ filebeat.modules:
- module: kafka
# All logs
log:
enabled: true
enabled: false

# Set custom paths for Kafka. If left empty,
# Filebeat will look under /opt.
Expand All @@ -205,15 +205,15 @@ filebeat.modules:
- module: kibana
# Server logs
log:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# Audit logs
audit:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
Expand Down Expand Up @@ -281,7 +281,7 @@ filebeat.modules:
- module: nats
# All logs
log:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
Expand Down Expand Up @@ -322,9 +322,9 @@ filebeat.modules:
# #var.paths:

#------------------------------- Osquery Module -------------------------------
- module: osquery
result:
enabled: true
#- module: osquery
#result:
#enabled: true

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
Expand All @@ -339,7 +339,7 @@ filebeat.modules:
- module: pensando
# Firewall logs
dfw:
enabled: true
enabled: false
var.syslog_host: 0.0.0.0
var.syslog_port: 9001

Expand Down Expand Up @@ -384,7 +384,7 @@ filebeat.modules:
#----------------------------- Google Santa Module -----------------------------
- module: santa
log:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the the default path.
#var.paths:
Expand Down
1 change: 1 addition & 0 deletions filebeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func Update() {
// modules.d directory.
func Config() {
mg.Deps(devtools.GenerateDirModulesD, configYML)
mg.SerialDeps(devtools.ValidateDirModulesD, devtools.ValidateDirModulesDDatasetsDisabled)
}

func configYML() error {
Expand Down
4 changes: 2 additions & 2 deletions filebeat/module/apache/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
- module: apache
# Access logs
access:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# Error logs
error:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
Expand Down
2 changes: 1 addition & 1 deletion filebeat/module/auditd/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- module: auditd
log:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
Expand Down
10 changes: 5 additions & 5 deletions filebeat/module/elasticsearch/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
- module: elasticsearch
# Server log
server:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

gc:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

audit:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

slowlog:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

deprecation:
enabled: true
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:
2 changes: 1 addition & 1 deletion filebeat/module/haproxy/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- module: haproxy
# All logs
log:
enabled: true
enabled: false

# Set which input to use between syslog (default) or file.
#var.input:
Expand Down
6 changes: 3 additions & 3 deletions filebeat/module/icinga/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
- module: icinga
# Main logs
main:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# Debug logs
debug:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# Startup logs
startup:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
Expand Down
6 changes: 3 additions & 3 deletions filebeat/module/iis/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
- module: iis
# Access logs
access:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# Error logs
error:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:


2 changes: 1 addition & 1 deletion filebeat/module/kafka/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- module: kafka
# All logs
log:
enabled: true
enabled: false

# Set custom paths for Kafka. If left empty,
# Filebeat will look under /opt.
Expand Down
4 changes: 2 additions & 2 deletions filebeat/module/kibana/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
- module: kibana
# Server logs
log:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:

# Audit logs
audit:
enabled: true
enabled: false

# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
Expand Down
Loading