-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start of darwin support in event monitor
- Loading branch information
1 parent
06321a2
commit a1a287b
Showing
40 changed files
with
5,696 additions
and
107 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build darwin | ||
|
||
//nolint:revive // TODO(EBPF) Fix revive linter | ||
package modules | ||
|
||
import ( | ||
"github.com/DataDog/datadog-agent/cmd/system-probe/api/module" | ||
) | ||
|
||
// All System Probe modules should register their factories here | ||
var All = []module.Factory{ | ||
EventMonitor, | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build darwin | ||
|
||
package eventmonitor | ||
|
||
import ( | ||
"net" | ||
"os" | ||
) | ||
|
||
func (m *EventMonitor) getListener() (net.Listener, error) { | ||
ln, err := net.Listen("unix", m.Config.SocketPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err = os.Chmod(m.Config.SocketPath, 0700); err != nil { | ||
return nil, err | ||
} | ||
return ln, nil | ||
} | ||
|
||
func (m *EventMonitor) init() error { | ||
// force socket cleanup of previous socket not cleanup | ||
os.Remove(m.Config.SocketPath) | ||
return nil | ||
} | ||
|
||
func (m *EventMonitor) cleanup() { | ||
os.Remove(m.Config.SocketPath) | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build darwin | ||
|
||
package consumer | ||
|
||
import ( | ||
"github.com/DataDog/datadog-agent/pkg/process/events/model" | ||
smodel "github.com/DataDog/datadog-agent/pkg/security/secl/model" | ||
) | ||
|
||
// Copy copies the necessary fields from the event received from the event monitor | ||
func (p *ProcessConsumer) Copy(event *smodel.Event) any { | ||
return &model.ProcessEvent{ | ||
EventType: model.NewEventType(event.GetEventType().String()), | ||
CollectionTime: event.GetTimestamp(), | ||
Pid: event.GetProcessPid(), | ||
ContainerID: event.GetContainerId(), | ||
Ppid: event.GetProcessPpid(), | ||
UID: event.GetProcessUid(), | ||
GID: event.GetProcessGid(), | ||
Username: event.GetProcessUser(), | ||
Group: event.GetProcessGroup(), | ||
Exe: event.GetExecFilePath(), | ||
Cmdline: event.GetProcessArgv(), | ||
ExecTime: event.GetProcessExecTime(), | ||
ExitTime: event.GetProcessExitTime(), | ||
ExitCode: event.GetExitCode(), | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
// Package probe holds probe related files | ||
package probe | ||
|
||
import ( | ||
"github.com/DataDog/datadog-agent/pkg/security/secl/model" | ||
) | ||
|
||
// FieldHandlers defines a field handlers | ||
type FieldHandlers struct { | ||
// TODO(safchain) remove this when support for multiple platform with the same build tags is available | ||
// keeping it can be dangerous as it can hide non implemented handlers | ||
model.FakeFieldHandlers | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
// Package probe holds probe related files | ||
package probe | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/security/secl/compiler/eval" | ||
"github.com/DataDog/datadog-agent/pkg/security/secl/model" | ||
) | ||
|
||
// NewDarwinModel returns a new model with some extra field validation | ||
func NewDarwinModel() *model.Model { | ||
return &model.Model{ | ||
ExtraValidateFieldFnc: func(field eval.Field, fieldValue eval.FieldValue) error { | ||
// TODO(safchain) remove this check when multiple model per platform will be supported in the SECL package | ||
if !strings.HasPrefix(field, "exec.") && | ||
!strings.HasPrefix(field, "exit.") && | ||
!strings.HasPrefix(field, "process.") { | ||
return fmt.Errorf("%s is not available with the Windows version", field) | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
// NewDarwinEvent returns a new event | ||
func NewDarwinEvent(fh *FieldHandlers) *model.Event { | ||
event := model.NewFakeEvent() | ||
event.FieldHandlers = fh | ||
return event | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build darwin | ||
|
||
// Package probe holds probe related files | ||
package probe | ||
|
||
import ( | ||
"github.com/DataDog/datadog-go/v5/statsd" | ||
) | ||
|
||
// Opts defines some probe options | ||
type Opts struct { | ||
// StatsdClient to be used for probe stats | ||
StatsdClient statsd.ClientInterface | ||
} | ||
|
||
func (o *Opts) normalize() { | ||
if o.StatsdClient == nil { | ||
o.StatsdClient = &statsd.NoOpClient{} | ||
} | ||
} |
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
Oops, something went wrong.