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

Cherry-pick #18034 to 7.x: [Auditbeat] Add system module login dataset ECS categorization fields #18251

Merged
merged 3 commits into from
May 5, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix memory leak on when we miss socket close kprobe events. {pull}17500[17500]
- Add system module process dataset ECS categorization fields. {pull}18032[18032]
- Add system module user dataset ECS categorization fields. {pull}18035[18035]
- Add system module login dataset ECS categorization fields. {pull}18034[18034]

*Filebeat*

Expand Down
20 changes: 15 additions & 5 deletions x-pack/auditbeat/module/system/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (ms *MetricSet) loginEvent(loginRecord *LoginRecord) mb.Event {

if loginRecord.Username != "" {
event.RootFields.Put("user.name", loginRecord.Username)

event.RootFields.Put("related.user", []string{loginRecord.Username})
if loginRecord.UID != -1 {
event.RootFields.Put("user.id", loginRecord.UID)
}
Expand All @@ -194,6 +194,7 @@ func (ms *MetricSet) loginEvent(loginRecord *LoginRecord) mb.Event {

if loginRecord.IP != nil {
event.RootFields.Put("source.ip", loginRecord.IP)
event.RootFields.Put("related.ip", []string{loginRecord.IP.String()})
}

if loginRecord.Hostname != "" && loginRecord.Hostname != loginRecord.IP.String() {
Expand All @@ -202,13 +203,22 @@ func (ms *MetricSet) loginEvent(loginRecord *LoginRecord) mb.Event {

switch loginRecord.Type {
case userLoginRecord:
event.RootFields.Put("event.category", "authentication")
event.RootFields.Put("event.category", []string{"authentication"})
event.RootFields.Put("event.outcome", "success")
event.RootFields.Put("event.type", "authentication_success")
event.RootFields.Put("event.type", []string{"start", "authentication_success"})
case userLoginFailedRecord:
event.RootFields.Put("event.category", "authentication")
event.RootFields.Put("event.category", []string{"authentication"})
event.RootFields.Put("event.outcome", "failure")
event.RootFields.Put("event.type", "authentication_failure")
event.RootFields.Put("event.type", []string{"start", "authentication_failure"})
case userLogoutRecord:
event.RootFields.Put("event.category", []string{"authentication"})
event.RootFields.Put("event.type", []string{"end"})
case bootRecord:
event.RootFields.Put("event.category", []string{"host"})
event.RootFields.Put("event.type", []string{"start"})
case shutdownRecord:
event.RootFields.Put("event.category", []string{"host"})
event.RootFields.Put("event.type", []string{"end"})
}

return event
Expand Down
24 changes: 14 additions & 10 deletions x-pack/auditbeat/module/system/login/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func TestWtmp(t *testing.T) {

// utmpdump: [7] [14962] [ts/2] [vagrant ] [pts/2 ] [10.0.2.2 ] [10.0.2.2 ] [2019-01-24T09:51:51,367964+00:00]
checkFieldValue(t, events[0].RootFields, "event.kind", "event")
checkFieldValue(t, events[0].RootFields, "event.category", "authentication")
checkFieldValue(t, events[0].RootFields, "event.category", []string{"authentication"})
checkFieldValue(t, events[0].RootFields, "event.type", []string{"start", "authentication_success"})
checkFieldValue(t, events[0].RootFields, "event.action", "user_login")
checkFieldValue(t, events[0].RootFields, "event.outcome", "success")
checkFieldValue(t, events[0].RootFields, "event.type", "authentication_success")
checkFieldValue(t, events[0].RootFields, "process.pid", 14962)
checkFieldValue(t, events[0].RootFields, "source.ip", "10.0.2.2")
checkFieldValue(t, events[0].RootFields, "user.name", "vagrant")
Expand Down Expand Up @@ -123,10 +123,14 @@ func TestWtmp(t *testing.T) {
}

checkFieldValue(t, events[0].RootFields, "event.kind", "event")
checkFieldValue(t, events[0].RootFields, "event.category", []string{"authentication"})
checkFieldValue(t, events[0].RootFields, "event.type", []string{"end"})
checkFieldValue(t, events[0].RootFields, "event.action", "user_logout")
checkFieldValue(t, events[0].RootFields, "process.pid", 14962)
checkFieldValue(t, events[0].RootFields, "source.ip", "10.0.2.2")
checkFieldValue(t, events[0].RootFields, "related.ip", []string{"10.0.2.2"})
checkFieldValue(t, events[0].RootFields, "user.name", "vagrant")
checkFieldValue(t, events[0].RootFields, "related.user", []string{"vagrant"})
checkFieldValue(t, events[0].RootFields, "user.terminal", "pts/2")
}

Expand Down Expand Up @@ -156,10 +160,10 @@ func TestBtmp(t *testing.T) {

// utmpdump: [6] [03307] [ ] [root ] [ssh:notty ] [10.0.2.2 ] [10.0.2.2 ] [2019-02-20T17:42:26,000000+0000]
checkFieldValue(t, events[0].RootFields, "event.kind", "event")
checkFieldValue(t, events[0].RootFields, "event.category", "authentication")
checkFieldValue(t, events[0].RootFields, "event.category", []string{"authentication"})
checkFieldValue(t, events[0].RootFields, "event.type", []string{"start", "authentication_failure"})
checkFieldValue(t, events[0].RootFields, "event.action", "user_login")
checkFieldValue(t, events[0].RootFields, "event.outcome", "failure")
checkFieldValue(t, events[0].RootFields, "event.type", "authentication_failure")
checkFieldValue(t, events[0].RootFields, "process.pid", 3307)
checkFieldValue(t, events[0].RootFields, "source.ip", "10.0.2.2")
checkFieldValue(t, events[0].RootFields, "user.id", 0)
Expand All @@ -171,10 +175,10 @@ func TestBtmp(t *testing.T) {
// The second UTMP entry in the btmp test file is a duplicate of the first, this is what Ubuntu 18.04 generates.
// utmpdump: [6] [03307] [ ] [root ] [ssh:notty ] [10.0.2.2 ] [10.0.2.2 ] [2019-02-20T17:42:26,000000+0000]
checkFieldValue(t, events[1].RootFields, "event.kind", "event")
checkFieldValue(t, events[0].RootFields, "event.category", "authentication")
checkFieldValue(t, events[0].RootFields, "event.category", []string{"authentication"})
checkFieldValue(t, events[0].RootFields, "event.type", []string{"start", "authentication_failure"})
checkFieldValue(t, events[1].RootFields, "event.action", "user_login")
checkFieldValue(t, events[1].RootFields, "event.outcome", "failure")
checkFieldValue(t, events[0].RootFields, "event.type", "authentication_failure")
checkFieldValue(t, events[1].RootFields, "process.pid", 3307)
checkFieldValue(t, events[1].RootFields, "source.ip", "10.0.2.2")
checkFieldValue(t, events[1].RootFields, "user.id", 0)
Expand All @@ -185,10 +189,10 @@ func TestBtmp(t *testing.T) {

// utmpdump: [7] [03788] [/0 ] [elastic ] [pts/0 ] [ ] [0.0.0.0 ] [2019-02-20T17:45:08,447344+0000]
checkFieldValue(t, events[2].RootFields, "event.kind", "event")
checkFieldValue(t, events[0].RootFields, "event.category", "authentication")
checkFieldValue(t, events[0].RootFields, "event.category", []string{"authentication"})
checkFieldValue(t, events[0].RootFields, "event.type", []string{"start", "authentication_failure"})
checkFieldValue(t, events[2].RootFields, "event.action", "user_login")
checkFieldValue(t, events[2].RootFields, "event.outcome", "failure")
checkFieldValue(t, events[0].RootFields, "event.type", "authentication_failure")
checkFieldValue(t, events[2].RootFields, "process.pid", 3788)
checkFieldValue(t, events[2].RootFields, "source.ip", "0.0.0.0")
checkFieldValue(t, events[2].RootFields, "user.name", "elastic")
Expand All @@ -198,10 +202,10 @@ func TestBtmp(t *testing.T) {

// utmpdump: [7] [03788] [/0 ] [UNKNOWN ] [pts/0 ] [ ] [0.0.0.0 ] [2019-02-20T17:45:15,765318+0000]
checkFieldValue(t, events[3].RootFields, "event.kind", "event")
checkFieldValue(t, events[0].RootFields, "event.category", "authentication")
checkFieldValue(t, events[0].RootFields, "event.category", []string{"authentication"})
checkFieldValue(t, events[0].RootFields, "event.type", []string{"start", "authentication_failure"})
checkFieldValue(t, events[3].RootFields, "event.action", "user_login")
checkFieldValue(t, events[3].RootFields, "event.outcome", "failure")
checkFieldValue(t, events[0].RootFields, "event.type", "authentication_failure")
checkFieldValue(t, events[3].RootFields, "process.pid", 3788)
checkFieldValue(t, events[3].RootFields, "source.ip", "0.0.0.0")
contains, err := events[3].RootFields.HasKey("user.id")
Expand Down