-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Auditbeat] Login dataset: Add event category and type #11339
Conversation
Pinging @elastic/secops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -58,6 +98,7 @@ func TestFailedLogins(t *testing.T) { | |||
config["login.wtmp_file_pattern"] = "" | |||
config["login.btmp_file_pattern"] = "../../../tests/files/btmp_ubuntu1804" | |||
f := mbtest.NewReportingMetricSetV2(t, config) | |||
defer f.(*MetricSet).utmpReader.bucket.DeleteBucket() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added? IIUC the data directory is removed in between tests so the whole DB gets deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, but for some reason that does not cause it to be re-read. Copy pasting one of the test functions causes the second one to fail, every time. I turned on debug logging and it still has the data written in the first function.
I didn't find out exactly why this happens, but I suspect it's because we use a sync.Once
here, and the data path will never get re-resolved:
beats/auditbeat/datastore/datastore.go
Lines 35 to 47 in d36eb5a
// OpenBucket returns a new Bucket that stores data in {path.data}/beat.db. | |
// The returned Bucket must be closed when finished to ensure all resources | |
// are released. | |
func OpenBucket(name string) (Bucket, error) { | |
initDatastoreOnce.Do(func() { | |
ds = &boltDatastore{ | |
path: paths.Resolve(paths.Data, "beat.db"), | |
mode: 0600, | |
} | |
}) | |
return ds.OpenBucket(name) | |
} |
This only really matters in tests as far as I can see, so I didn't dig deeper into it but just added the DeleteBucket()
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that's what it is. OpenBucket
uses the singleton instance and the DB path is only ever initialized once. The singleton instance is closed when all the users (metricsets) close their buckets. But when it gets reused again it still will have the original path so our cleanup has no effect.
One option would be to have a package global function that the metricsets use to open a bucket. That fn handle could be swapped for testing purposes. We use this pattern in a few places. For example
var openBucket = datastore.OpenBucket
Then for testing swap in a different func.
openBucket = func(name string) (Bucket, error) {
return datastore.New(paths.Join(testDir, "beat.db"), 0600).OpenBucket(name)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we could do that separately. Merging this for now.
Adds `event.category: authentication` and `event.type: authentication_success` (or `authentication_failure`). (cherry picked from commit 09a8fa8)
Adds
event.category: authentication
andevent.type: authentication_success
(orauthentication_failure
).I also took the opportunity to add another unit test for a successful login.