-
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] Cherry-pick #9327 to 6.x: Login metricset #10509
Merged
Merged
Conversation
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
Adds the login metricset to the Auditbeat system module as the last of the six initial metricsets. It only works on Linux, and detects not just user logins and logouts, but also system boots and shutdowns. It works by reading the /var/log/wtmp and /var/log/btmp file (and rotated files) present on Linux systems. In reading a file, it is similar to Filebeat, except that UTMP is a binary format, so reading happens using a binary Go reader. (cherry picked from commit 1566e66)
houndci-bot
reviewed
Feb 3, 2019
cwurm
changed the title
Cherry-pick #9327 to 6.x: [Auditbeat] Login metricset
[Auditbeat] Cherry-pick #9327 to 6.x: Login metricset
Feb 3, 2019
Pinging @elastic/secops |
houndci-bot
reviewed
Feb 3, 2019
I pushed two changes:
|
andrewkroh
approved these changes
Feb 4, 2019
webmat
approved these changes
Feb 4, 2019
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of PR #9327 to 6.x branch. Original message:
This adds the
login
metricset to the Auditbeat system module. It's the last of the six initial metricsets. It only works on Linux, and detects not just user logins and logouts, but also system boots and shutdowns.It works by reading the
/var/log/wtmp
and/var/log/btmp
file (and rotated files) present on Linux systems. In reading a file, it is similar to Filebeat, except that UTMP is a binary format, so reading happens using a binary Go reader. See utmp(5) for the format of that file.The logic is roughly as follows:
login.utmp_file_pattern
andlogin.btmp_file_pattern
will contain the pattern matching the wtmp (good logins, as well as system shutdowns and boots) and btmp (bad/failed logins) files and rotated files (if desired). The defaults are/var/log/wtmp*
and/var/log/btmp*
. These are expanded usingfilepath.Glob
and the files are sorted lexicographically in reverse order (i.e./var/log/wtmp.1
will come before/var/log/wtmp
) so that we read older login records first - reading in order is required for matching login and logout records, see next steps.Fetch
it checks for new entries: Any new files are read from the beginning, while known files are read from a saved offset. To that purpose, the last offset per file is saved and persisted to disk inbeat.db
. A new file is one that has an unknown inode, but files are also read completely if theirnewSize < oldSize
for some reason (that should make it work with any potential inode reuse - very unlikely since this will never read a lot of files but still possible).LoginRecord
in the code). Boot and shutdown events are fairly straightforward, user login and logout events have to be matched using theirtty
- so there is aloginSessions
map that stores logins to enrich the logouts, and is also persisted to disk.Note: This dataset also introduces
event.origin
containing the file the event came from, e.g./var/log/wtmp.1
. In other cases, it would be something likeprocfs
ornetlink
. It's useful to know where information comes from, e.g. to know how reliable it is.