-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kernel.audit_rules config option to set audit rules (#4482)
* Update go-libaudit to get the ability to set audit rules * Add kernel.audit_rules config option to set audit rules
- Loading branch information
1 parent
6bc3d4b
commit e443859
Showing
40 changed files
with
5,991 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package kernel | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigValidate(t *testing.T) { | ||
data := ` | ||
kernel.audit_rules: | | ||
# Comments and empty lines are ignored. | ||
-w /etc/passwd -p wa -k auth | ||
-a always,exit -F arch=b64 -S execve -k exec` | ||
|
||
config, err := parseConfig(t, data) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
rules, err := config.rules() | ||
if err != nil { | ||
t.Fatal() | ||
} | ||
assert.EqualValues(t, []string{ | ||
"-w /etc/passwd -p wa -k auth", | ||
"-a always,exit -F arch=b64 -S execve -k exec", | ||
}, commands(rules)) | ||
} | ||
|
||
func TestConfigValidateWithError(t *testing.T) { | ||
data := ` | ||
kernel.audit_rules: | | ||
-x bad -F flag | ||
-a always,exit -w /etc/passwd | ||
-a always,exit -F arch=b64 -S fake -k exec` | ||
|
||
_, err := parseConfig(t, data) | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
t.Log(err) | ||
} | ||
|
||
func TestConfigValidateWithDuplicates(t *testing.T) { | ||
data := ` | ||
kernel.audit_rules: | | ||
-w /etc/passwd -p rwxa -k auth | ||
-w /etc/passwd -k auth` | ||
|
||
_, err := parseConfig(t, data) | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
t.Log(err) | ||
} | ||
|
||
func parseConfig(t testing.TB, yaml string) (Config, error) { | ||
c, err := common.NewConfigWithYAML([]byte(yaml), "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
config := defaultConfig | ||
err = c.Unpack(&config) | ||
return config, err | ||
} | ||
|
||
func commands(rules []auditRule) []string { | ||
var cmds []string | ||
for _, r := range rules { | ||
cmds = append(cmds, r.flags) | ||
} | ||
return cmds | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
vendor/github.com/elastic/go-libaudit/aucoalesce/coalesce.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.