Skip to content

Commit

Permalink
Filebeat: Make all filesets disabled in default configuration (elasti…
Browse files Browse the repository at this point in the history
…c#27762)

What does this PR do?

Changes the default configuration for Filebeat's filesets to make them
disabled by default (enabled: false).

Adds a check to the config and update targets of mage to check that
default configurations have an explicit disable:

> error: in file 'modules.d/checkpoint.yml.disabled': checkpoint module
> dataset firewall must be explicitly disabled (needs enabled: false)

Why is it important?

The previous default of having all filesets enabled, paired with
the configuration loader enabling all non-explicitly-disabled
filesets (changed in elastic#27526) has been causing trouble for our users
for quite some time.
  • Loading branch information
adriansr authored and wiwen committed Nov 1, 2021
1 parent c63d8f0 commit 51f1a50
Show file tree
Hide file tree
Showing 146 changed files with 560 additions and 486 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix Crowdstrike ingest pipeline that was creating flattened `process` fields. {issue}27622[27622] {pull}27623[27623]
- Rename `log.path` to `log.file.path` in filestream to be consistent with `log` input and ECS. {pull}27761[27761]
- Only filesets that are explicitly configured will be enabled. {issue}17256[17256] {pull}27526[27526]
- 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 @@ -105,6 +105,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

0 comments on commit 51f1a50

Please sign in to comment.