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

[Auditbeat] New system/socket dataset using kprobes tracing events #13058

Merged
merged 22 commits into from
Aug 29, 2019

Conversation

adriansr
Copy link
Contributor

@adriansr adriansr commented Jul 24, 2019

This PR replaces the original system/socket dataset which used netlink to periodically poll the system for open sockets.

In the new implementation, kprobe-based tracing is used to receive events of interest related to function calls and their arguments inside the kernel TCP/IP stack. From this stream of information the dataset constructs a model of all the network sockets in use and the processes running in the system at any given time.

This allows the dataset to produce flow-like events with information like packets and bytes counters, originator process and user, with little impact to system performance and without missing short-lived sockets or processes.

The dataset supports TCP and UDP sockets for both IPv4 and IPv6.

TODO

There is some, but please review:

Notes to reviewers

You can skip the first two commits (vendored packages):

  • update of golang.org/x/sys/unix
  • vendor of golang.org/x/sys/unix/linux/perf (in review here) with a few improvements.

@adriansr adriansr force-pushed the feature_ab_tracing branch 3 times, most recently from 5b23666 to 7d5985f Compare July 25, 2019 09:38
@adriansr adriansr force-pushed the feature_ab_tracing branch from dc3b9cc to f3b8e9f Compare August 21, 2019 23:18
This is a perf API client candidate for golang.org/x/sys/unix/linux/perf
which is currently in review at:
  https://go-review.googlesource.com/c/sys/+/168059

The Elastic fork adds some features on top of it:
 - OpenWithFlags() to pass custom flags to perf_event_open(2), necessary
   for managing our own event groups.
 - HasRecord() to peek a ring buffer without blocking. Necessary to read
   multiple rings in parallel from a single goroutine.

And also some fixes:
 - Fix bad handling of ring buffer memory.
 - Add error checking to prevent crashes due to corrupted samples.
Package tracing provides a set of tools built on top of
golang.org/x/sys/unix/linux/perf that simplify working with KProbes and
UProbes, using tracing perf channels to receive events from the kernel and
decoding of this raw events into more useful types.
@adriansr adriansr force-pushed the feature_ab_tracing branch from 8b798b0 to 05a6b32 Compare August 22, 2019 21:57
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@elastic elastic deleted a comment from houndci-bot Aug 22, 2019
@adriansr adriansr force-pushed the feature_ab_tracing branch from ae177d2 to 5a78c37 Compare August 28, 2019 18:46
// timeout.
const executorQueueSize = 1
thread := helper.NewFixedThreadExecutor(executorQueueSize)
defer thread.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Clearer now with this approach 👍

// FixedThreadExecutor runs tasks on a fixed OS thread (see runtime.LockOSThread).
type FixedThreadExecutor struct {
// TID is the OS identifier for the thread where it is running.
TID int
Copy link
Member

Choose a reason for hiding this comment

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

Supernit. Make TID a method so it is read-only.

@adriansr adriansr merged commit b1893f2 into elastic:master Aug 29, 2019
andrewkroh pushed a commit to andrewkroh/beats that referenced this pull request Aug 29, 2019
…lastic#13058)

This patch replaces the original `system/socket` dataset which used
netlink to periodically poll the system for open sockets.

In the new implementation, kprobe-based tracing is used to receive
events of interest related to function calls and their arguments
inside the kernel tcp/ip stack. From this stream of information the
dataset constructs a model of all the network sockets in use and the
processes running in the system at any given time.

This allows the dataset to produce flow-like events with information
like packets and bytes counters, originator process and user, with
little impact to system performance and without missing short-lived
sockets or processes.

The dataset is in beta.

(cherry picked from commit b1893f2)
andrewkroh added a commit that referenced this pull request Aug 29, 2019
…13058) (#13397)

This patch replaces the original `system/socket` dataset which used
netlink to periodically poll the system for open sockets.

In the new implementation, kprobe-based tracing is used to receive
events of interest related to function calls and their arguments
inside the kernel tcp/ip stack. From this stream of information the
dataset constructs a model of all the network sockets in use and the
processes running in the system at any given time.

This allows the dataset to produce flow-like events with information
like packets and bytes counters, originator process and user, with
little impact to system performance and without missing short-lived
sockets or processes.

The dataset is in beta.

(cherry picked from commit b1893f2)
adriansr added a commit to adriansr/beats that referenced this pull request Aug 30, 2019
adriansr added a commit that referenced this pull request Aug 30, 2019
adriansr added a commit to adriansr/beats that referenced this pull request Aug 30, 2019
adriansr added a commit that referenced this pull request Aug 30, 2019
adriansr added a commit to adriansr/beats that referenced this pull request Sep 4, 2019
This fixes a known problem with the system/socket dataset. Before 3.13
an extra level of indirection is needed to access IPv6 addresses from a
struct inet_sock.

Relates elastic#13058
adriansr added a commit that referenced this pull request Sep 5, 2019
This fixes a known problem with the system/socket dataset. Before 3.13
an extra level of indirection is needed to access IPv6 addresses from a
struct inet_sock.

Relates #13058
adriansr added a commit to adriansr/beats that referenced this pull request Sep 5, 2019
This fixes a known problem with the system/socket dataset. Before 3.13
an extra level of indirection is needed to access IPv6 addresses from a
struct inet_sock.

Relates elastic#13058

(cherry picked from commit dc6c013)
adriansr added a commit that referenced this pull request Sep 6, 2019
This fixes a known problem with the system/socket dataset. Before 3.13
an extra level of indirection is needed to access IPv6 addresses from a
struct inet_sock.

Relates #13058

(cherry picked from commit dc6c013)
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…lastic#13058) (elastic#13397)

This patch replaces the original `system/socket` dataset which used
netlink to periodically poll the system for open sockets.

In the new implementation, kprobe-based tracing is used to receive
events of interest related to function calls and their arguments
inside the kernel tcp/ip stack. From this stream of information the
dataset constructs a model of all the network sockets in use and the
processes running in the system at any given time.

This allows the dataset to produce flow-like events with information
like packets and bytes counters, originator process and user, with
little impact to system performance and without missing short-lived
sockets or processes.

The dataset is in beta.

(cherry picked from commit e4ae0d5)
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
elastic#13523)

This fixes a known problem with the system/socket dataset. Before 3.13
an extra level of indirection is needed to access IPv6 addresses from a
struct inet_sock.

Relates elastic#13058

(cherry picked from commit ced7862)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auditbeat enhancement review v7.4.0 x-pack Issues and pull requests for X-Pack features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants