-
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
[add_session_metadata processor] Enrich events with user and group names #39537
Conversation
Enrich process events with user and group names for the process, and related processes (parent, session leader, group leader, entry leader). A new cache for user and group names is added to the process DB, so that the names only need to be read once, and not on every process event that's received.
x-pack/auditbeat/processors/sessionmd/provider/procfs_provider/procfs_provider.go
Show resolved
Hide resolved
cval.name = user.Username | ||
cval.found = true | ||
} | ||
return cval.name, cval.found |
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.
If I get this correctly before we return it we should save cval
in the map right? That said, I think that the cache sure helps with the performance (especially if we are talking about LDAP-based users) but on the other hand it can affect the reliability of the data, e.g.
$ sudo useradd jane
$ sudo su jane
$ id
uid=1000(jane) gid=1001(jane) groups=1001(jane)
$ exit
$ sudo usermod -l new_jane jane
$ sudo su new_jane
$ id
uid=1000(new_jane) gid=1001(jane) groups=1001(jane)
I just renamed a user but the Id remains the same so better to search for it every-time?!?
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.
I've removed all the caching here, it turns out it has no benefit. I've also tried changing the username as the benchmarking ran, and it returned the new username immediately.
I did some benchmarking on this (with this), and I learned a few things
Here's the benchmark results of 1. My caching code, 2. user.LookupId(id) with CGO disabled, 3. user.LookupId(id) with CGO enabled, 4. Just reading
|
Profiling has shown that `user.LookupId(id)` is already very fast, and there's no need to add a cache for this data.
Pinging @elastic/sec-deployment-and-devices (Team:Security-Deployment and Devices) |
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.
nice findings @mjwolf , LGTM
Proposed commit message
Update the
add_session_metadata
processor to add user and group names to enriched events, rather than just IDs, as it was doing previously.This also renames the
UpdateDB
function toSyncDB
. Previously this function was confusing, because it didn't always update the DB. With ebpf, the DB update is done separately. By renaming and updating the func comment, it should be more clear that the function should synchronize the DB so it's ready for enriching events, either by waiting until the DB is updated, or doing the synchronization itself, as it does with procfs backend.Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Disruptive User Impact
Adding user and group names will increase event sized very slightly, it shouldn't have an impact on users.
How to test this PR locally
For process events enriched with the add_session_metadata processor, check that documents have values for these fields:
process.user.name
,process.group.name
,process.parent.user.name
,process.parent.group.name
,process.session_leader.user.name
,process.session_leader.group.name
,process.group_leader.user.name
,process.group_leader.group.name
,process.entry_leader.user.name
,process.entry_leader.group.name
.Related issues
Use cases
Screenshots
Screenshots showing session view, with user and group names for a process and related processes