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

[WIP][Auditbeat] auditd ECS categorization update #18028

Closed
Closed
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
56 changes: 37 additions & 19 deletions auditbeat/module/auditd/audit_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package auditd

//go:generate sh -c "go run mk_ecs_categorization.go -in ecs_categorization.yml -out z_ecs_categorization.go"

import (
"fmt"
"os"
Expand Down Expand Up @@ -473,11 +475,15 @@ func buildMetricbeatEvent(msgs []*auparse.AuditMessage, config Config) mb.Event
if eventOutcome == "fail" {
eventOutcome = "failure"
}
ecsCategorization := getECSCategorization(auditEvent.Category, auditEvent.Type)
// keep this for now, remove in 8.x
categories := append(ecsCategorization.Categories, auditEvent.Category.String())
out := mb.Event{
Timestamp: auditEvent.Timestamp,
RootFields: common.MapStr{
"event": common.MapStr{
"category": auditEvent.Category.String(),
"category": categories,
"type": ecsCategorization.Types,
"action": auditEvent.Summary.Action,
"outcome": eventOutcome,
},
Expand Down Expand Up @@ -541,7 +547,7 @@ func buildMetricbeatEvent(msgs []*auparse.AuditMessage, config Config) mb.Event

switch auditEvent.Category {
case aucoalesce.EventTypeUserLogin:
// Customize event.type / event.category to match unified values.
// Remove this call in 8.x
normalizeEventFields(out.RootFields)
// Set ECS user fields from the attempted login account.
if usernameOrID := auditEvent.Summary.Actor.Secondary; usernameOrID != "" {
Expand All @@ -559,20 +565,15 @@ func buildMetricbeatEvent(msgs []*auparse.AuditMessage, config Config) mb.Event
return out
}

func resolveUsernameOrID(userOrID string) (usr *user.User, err error) {
usr, err = user.Lookup(userOrID)
if err == nil {
// User found by name
return
}
if _, ok := err.(user.UnknownUserError); !ok {
// Lookup failed by a reason other than user not found
func normalizeEventFields(m common.MapStr) {
getFieldAsStrs := func(key string) (s []string, found bool) {
iface, err := m.GetValue(key)
if err != nil {
return
}
s, found = iface.([]string)
return
}
return user.LookupId(userOrID)
}

func normalizeEventFields(m common.MapStr) {
getFieldAsStr := func(key string) (s string, found bool) {
iface, err := m.GetValue(key)
if err != nil {
Expand All @@ -582,16 +583,33 @@ func normalizeEventFields(m common.MapStr) {
return
}

category, ok1 := getFieldAsStr("event.category")
categories, ok1 := getFieldAsStrs("event.category")
action, ok2 := getFieldAsStr("event.action")
outcome, ok3 := getFieldAsStr("event.outcome")
if !ok1 || !ok2 || !ok3 {
types, ok4 := getFieldAsStrs("event.type")
if !ok1 || !ok2 || !ok3 || !ok4 {
return
}
for _, category := range categories {
if category == "authentication" && action == "logged-in" { // USER_LOGIN
types = append(types, fmt.Sprintf("authentication_%s", outcome))
m.Put("event.type", types)
return
}
}
}

func resolveUsernameOrID(userOrID string) (usr *user.User, err error) {
usr, err = user.Lookup(userOrID)
if err == nil {
// User found by name
return
}
if category == "user-login" && action == "logged-in" { // USER_LOGIN
m.Put("event.category", "authentication")
m.Put("event.type", fmt.Sprintf("authentication_%s", outcome))
if _, ok := err.(user.UnknownUserError); !ok {
// Lookup failed by a reason other than user not found
return
}
return user.LookupId(userOrID)
}

func addUser(u aucoalesce.User, m common.MapStr) {
Expand Down
11 changes: 6 additions & 5 deletions auditbeat/module/auditd/audit_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,24 @@ func TestLoginType(t *testing.T) {

for idx, expected := range []common.MapStr{
{
"event.category": "authentication",
"event.type": "authentication_failure",
"event.category": []string{"authentication", "user-login"},
"event.type": []string{"start", "authentication_failure"},
Comment on lines +144 to +145
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these second ones (user-login and auth_failure) marked as deprecated for deletion in 8.0?

"event.outcome": "failure",
"user.name": "(invalid user)",
"user.id": nil,
"session": nil,
},
{
"event.category": "authentication",
"event.type": "authentication_success",
"event.category": []string{"authentication", "user-login"},
"event.type": []string{"start", "authentication_success"},
"event.outcome": "success",
"user.name": "adrian",
"user.audit.id": nil,
"auditd.session": nil,
},
{
"event.category": "user-login",
"event.category": []string{"authentication", "user-login"},
"event.type": []string{"info"},
"event.outcome": "success",
"user.name": "root",
"user.id": "0",
Expand Down
Loading