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

Add kernel.failure_mode config option #4516

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha1...master[Check the HEAD d

*Metricbeat*
- Add random startup delay to each metricset to avoid the thundering herd problem. {issue}4010[4010]

- Add the ability to configure audit rules to the kernel module. {pull}4482[4482]
- Add the ability to configure kernel's audit failure mode. {pull}4516[4516]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ SOFTWARE.
--------------------------------------------------------------------
Dependency: github.com/elastic/go-libaudit
Version: v0.0.3
Revision: b2d37f9d37d8e2a81bf69b5fae3c1f49bf6a14bf
Revision: 01c7fd0956dbe3fea61047c330de4c1e06b6427d
License type (autodetected): Apache License 2.0
./vendor/github.com/elastic/go-libaudit/LICENSE:
--------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions metricbeat/metricbeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ metricbeat.modules:
enabled: false
metricsets: ["kernel"]
kernel.resolve_ids: true
kernel.failure_mode: silent
kernel.backlog_limit: 8196
kernel.rate_limit: 0
kernel.include_raw_message: false
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/audit/_meta/config.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
enabled: false
metricsets: ["kernel"]
kernel.resolve_ids: true
kernel.failure_mode: silent
kernel.backlog_limit: 8196
kernel.rate_limit: 0
kernel.include_raw_message: false
Expand Down
9 changes: 9 additions & 0 deletions metricbeat/module/audit/kernel/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ is example showing all configuration options with their default values.
- module: audit
metricsets: ["kernel"]
kernel.resolve_ids: true
kernel.failure_mode: silent
kernel.backlog_limit: 8196
kernel.rate_limit: 0
kernel.include_raw_message: false
Expand All @@ -52,6 +53,14 @@ is example showing all configuration options with their default values.
*`kernel.resolve_ids`*:: This boolean setting enables the resolution of UIDs and
GIDs to their associated names. The default value is true.

*`kernel.failure_mode`*:: This determines the kernel's behavior on critical
failures such as errors sending events to Metricbeat, the backlog limit was
exceeded, the kernel ran out of memory, or the rate limit was exceeded. The
options are `silent`, `log`, or `panic`. `silent` basically makes the kernel
ignore the errors, `log` makes the kernel write the audit messages using
`printk` so they show up in system's syslog, and `panic` causes the kernel to
panic to prevent use of the machine. Metricbeat's default is `silent`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this description sounds like log would be a good choice for the default as well? Or do you think it might spam the kernel logs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spam to the kernel logs was my main motivation for choosing silent over log for the default value.


*`kernel.backlog_limit`*:: This controls the maximum number of audit messages
that will be buffered by kernel.

Expand Down
12 changes: 9 additions & 3 deletions metricbeat/module/audit/kernel/audit_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ func (ms *MetricSet) initClient() error {
}
debugf("%v audit status from kernel at start: status=%+v", logPrefix, status)

if status.Enabled == 0 {
if err = ms.client.SetEnabled(true, libaudit.NoWait); err != nil {
return errors.Wrap(err, "failed to enable auditing in the kernel")
if fm, _ := ms.config.failureMode(); status.Failure != fm {
if err = ms.client.SetFailure(libaudit.FailureMode(fm), libaudit.NoWait); err != nil {
return errors.Wrap(err, "failed to set audit failure mode in kernel")
}
}

Expand All @@ -163,6 +163,12 @@ func (ms *MetricSet) initClient() error {
}
}

if status.Enabled == 0 {
if err = ms.client.SetEnabled(true, libaudit.NoWait); err != nil {
return errors.Wrap(err, "failed to enable auditing in the kernel")
}
}

if err := ms.client.SetPID(libaudit.NoWait); err != nil {
return errors.Wrap(err, "failed to set audit PID")
}
Expand Down
5 changes: 3 additions & 2 deletions metricbeat/module/audit/kernel/audit_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func TestData(t *testing.T) {

func getConfig() map[string]interface{} {
return map[string]interface{}{
"module": "audit",
"metricsets": []string{"kernel"},
"module": "audit",
"metricsets": []string{"kernel"},
"kernel.failure_mode": "log",
"kernel.audit_rules": `
-w /etc/passwd -p wa -k auth
-a always,exit -F arch=b64 -S execve -k exec
Expand Down
25 changes: 24 additions & 1 deletion metricbeat/module/audit/kernel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// Config defines the kernel metricset's possible configuration options.
type Config struct {
ResolveIDs bool `config:"kernel.resolve_ids"` // Resolve UID/GIDs to names.
FailureMode string `config:"kernel.failure_mode"` // Failure mode for the kernel (silent, log, panic).
BacklogLimit uint32 `config:"kernel.backlog_limit"` // Max number of message to buffer in the kernel.
RateLimit uint32 `config:"kernel.rate_limit"` // Rate limit in messages/sec of messages from kernel.
RawMessage bool `config:"kernel.include_raw_message"` // Include the list of raw audit messages in the event.
Expand All @@ -29,8 +30,16 @@ type auditRule struct {

// Validate validates the rules specified in the config.
func (c Config) Validate() error {
var errs multierror.Errors
_, err := c.rules()
return err
if err != nil {
errs = append(errs, err)
}
_, err = c.failureMode()
if err != nil {
errs = append(errs, err)
}
return errs.Err()
}

// Rules returns a list of rules specified in the config.
Expand Down Expand Up @@ -77,8 +86,22 @@ func (c Config) rules() ([]auditRule, error) {
return auditRules, nil
}

func (c Config) failureMode() (uint32, error) {
switch strings.ToLower(c.FailureMode) {
case "silent":
return 0, nil
case "log":
return 1, nil
case "panic":
return 2, nil
default:
return 0, errors.Errorf("invalid kernel.failure_mode '%v' (use silent, log, or panic)", c.FailureMode)
}
}

var defaultConfig = Config{
ResolveIDs: true,
FailureMode: "silent",
BacklogLimit: 8192,
RateLimit: 0,
RawMessage: false,
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/audit/kernel/config_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ kernel.audit_rules: |
t.Log(err)
}

func TestConfigValidateFailureMode(t *testing.T) {
config := defaultConfig
config.FailureMode = "boom"
err := config.Validate()
assert.Error(t, err)
t.Log(err)
}

func parseConfig(t testing.TB, yaml string) (Config, error) {
c, err := common.NewConfigWithYAML([]byte(yaml), "")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/elastic/go-libaudit/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/elastic/go-libaudit/audit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,40 +290,40 @@
"revisionTime": "2016-08-05T00:47:13Z"
},
{
"checksumSHA1": "MfmdLoBh0b2JUUyS2QLu2fcGYIQ=",
"checksumSHA1": "5cppdt4ZlFpURXuZ7QeBQvdhmKQ=",
"path": "github.com/elastic/go-libaudit",
"revision": "b2d37f9d37d8e2a81bf69b5fae3c1f49bf6a14bf",
"revisionTime": "2017-06-08T23:02:06Z",
"revision": "01c7fd0956dbe3fea61047c330de4c1e06b6427d",
"revisionTime": "2017-06-15T21:41:34Z",
"version": "v0.0.3",
"versionExact": "v0.0.3"
},
{
"checksumSHA1": "Ca2OhodWbbke1v+cctf9y/HdwZM=",
"path": "github.com/elastic/go-libaudit/aucoalesce",
"revision": "b2d37f9d37d8e2a81bf69b5fae3c1f49bf6a14bf",
"revisionTime": "2017-06-08T23:02:06Z",
"revision": "01c7fd0956dbe3fea61047c330de4c1e06b6427d",
"revisionTime": "2017-06-15T21:41:34Z",
"version": "v0.0.3",
"versionExact": "v0.0.3"
},
{
"checksumSHA1": "9hp7icHi638Ye1yXSgmoyy/HvW4=",
"path": "github.com/elastic/go-libaudit/auparse",
"revision": "b2d37f9d37d8e2a81bf69b5fae3c1f49bf6a14bf",
"revisionTime": "2017-06-08T23:02:06Z",
"revision": "01c7fd0956dbe3fea61047c330de4c1e06b6427d",
"revisionTime": "2017-06-15T21:41:34Z",
"version": "v0.0.3",
"versionExact": "v0.0.3"
},
{
"checksumSHA1": "H0rnscnKHbkjmXc4whC3gtIPR0c=",
"path": "github.com/elastic/go-libaudit/rule",
"revision": "b2d37f9d37d8e2a81bf69b5fae3c1f49bf6a14bf",
"revisionTime": "2017-06-08T23:02:06Z"
"revision": "01c7fd0956dbe3fea61047c330de4c1e06b6427d",
"revisionTime": "2017-06-15T21:41:34Z"
},
{
"checksumSHA1": "36UaYid29Kyhrsa5D8N6BoM8dVw=",
"path": "github.com/elastic/go-libaudit/rule/flags",
"revision": "b2d37f9d37d8e2a81bf69b5fae3c1f49bf6a14bf",
"revisionTime": "2017-06-08T23:02:06Z"
"revision": "01c7fd0956dbe3fea61047c330de4c1e06b6427d",
"revisionTime": "2017-06-15T21:41:34Z"
},
{
"checksumSHA1": "3jizmlZPCyo6FAZY8Trk9jA8NH4=",
Expand Down