Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sniffer
temp
.vscode
Comment thread
dwertent marked this conversation as resolved.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
install-deps:
./deps/install_dependencies.sh

build:
go build -o sniffer .
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# sniffer
## sniffer

1. Run minikube:

```
minikube start
```

2. Run Sniffer:

```
sudo SNIFFER_CONFIG=./configuration/SnifferConfigurationFile.json ./sniffer
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[TODO]: We should replace the env prefix.

@slashben Do we have a new name for the sniffer?

```

## Limitations:
1. This feature is using EBPF technology that is implemented only on linux.
2. the linux kernel version that supported it 4.14


## Debugging
# file for vscode:
```
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {
"SNIFFER_CONFIG": "${workspaceFolder}/configuration/SnifferConfigurationFile.json"
},
"console": "integratedTerminal",
"asRoot": true
}
]
}

```
16 changes: 16 additions & 0 deletions deps/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

sudo apt install git curl clang-12 -y

mkdir dependencies
pwd

git clone git@github.com:kubescape/ebpf-engine.git deps/dependencies/kubescape_ebpf_engine_sc
cd deps/dependencies/kubescape_ebpf_engine_sc
./install_dependencies.sh
mkdir build && cd ./build
cmake ..
make all
cd ../../../
cp deps/dependencies/kubescape_ebpf_engine_sc/deps/dependencies/falco-libs/build/driver/bpf/probe.o ../resources/ebpf/kernel_obj.o
cp deps/dependencies/kubescape_ebpf_engine_sc/build/main ../resources/ebpf/sniffer
41 changes: 41 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module sniffer

go 1.19

require github.com/kubescape/go-logger v0.0.8

require (
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/uptrace/opentelemetry-go-extra/otelutil v0.1.18 // indirect
github.com/uptrace/opentelemetry-go-extra/otelzap v0.1.18 // indirect
github.com/uptrace/uptrace-go v1.11.8 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.37.0 // indirect
go.opentelemetry.io/otel v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.34.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.34.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.11.2 // indirect
go.opentelemetry.io/otel/metric v0.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.11.2 // indirect
go.opentelemetry.io/otel/sdk/metric v0.34.0 // indirect
go.opentelemetry.io/otel/trace v1.11.2 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20230106154932-a12b697841d9 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
480 changes: 480 additions & 0 deletions go.sum

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions internal/config/config_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config

import "io"

type ConfigClient interface {
// global configuration
GetConfigurationData() (io.Reader, error)
ParseConfiguration(data io.Reader) error
}
5 changes: 5 additions & 0 deletions internal/validator/validator_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package validator

type ValidatorClient interface {
CheckPrerequisites() error
}
5 changes: 5 additions & 0 deletions internal/version/version_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package version

type VersionClient interface {
GetVersion() string
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package main

func main() {
}
8 changes: 8 additions & 0 deletions pkg/accumulator/accumulator_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package accumulator

type AcccumulatorClient interface {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[TODO]: I'm not sure this interface name makes sense to me.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
type AcccumulatorClient interface {
type AccumulatorClient interface {

[Required]: CHECK TYPOS BEFORE YOU PUSH!!!!!!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

// this function StartAccumulator will store the data from the ebpf engine
StartAccumulator() error
StartContainerAccumulator() error
StopContainerAccumulator() error
}
7 changes: 7 additions & 0 deletions pkg/conthandler/container_aggregator_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package conthandler

type ContainerAggregatorClient interface {
StartAggregate(containerID string) error
StopAggregate(containerID string) error
ListContainerRealTimeFiles(containerID string) []string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no need for error here? (maybe not...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the ListContainerRealTimeFiles is a getter function, error will be handled during the file monitor process

}
5 changes: 5 additions & 0 deletions pkg/conthandler/container_main_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package conthandler

type ContainerMainHandlerClient interface {
StartMainHandler() error
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[TODO]: I dont see a reason of wrapping the main function in an interface. What other options are there to run here?

}
5 changes: 5 additions & 0 deletions pkg/conthandler/container_watcher_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package conthandler

type ContainerWatcherClient interface {
StartWatchedOnNewContainers() error
}
9 changes: 9 additions & 0 deletions pkg/ebpfeng/ebpf_engine_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ebpfeng

import ebpfev "sniffer/pkg/ebpfev/v1"

type EbpfEngineClient interface {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Question]: I'm not sure it is right to have the Client as part of an interface name

StartEbpfEngine() error
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[TODO]: I don't see any need in repeating the fact that this is EbpfEngine. How about GetData instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

GetData(chan *ebpfev.EventData)
GetEbpfEngineError() error
}
16 changes: 16 additions & 0 deletions pkg/ebpfev/event_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ebpfev
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Required]: This package should be nested under v1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


import (
"time"
)

type EventClient interface {
GetEventTimestamp() time.Time
GetEventContainerID() string
GetEventPPID() string
GetEventPID() string
GetEventSyscallOp() string
GetEventSyscallArgs() string
GetEventEXE() string
GetEventCMD() string
}
52 changes: 52 additions & 0 deletions pkg/ebpfev/v1/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ebpfev

import "time"

type EventData struct {
timestamp time.Time
containerID string
ppid string
pid string
syscallOp string
syscallArgs string
exe string
cmd string
}

func CreateKernelEvent(timestamp *time.Time, containerID string, ppid string, pid string, syscallOp string, syscallArgs string, exe string, cmd string) *EventData {
return &EventData{
timestamp: *timestamp,
containerID: containerID,
ppid: ppid,
pid: pid,
syscallOp: syscallOp,
syscallArgs: syscallArgs,
exe: exe,
cmd: cmd,
}
}

func (ev *EventData) GetEventTimestamp() time.Time {
return ev.timestamp
}
func (ev *EventData) GetEventContainerID() string {
return ev.containerID
}
func (ev *EventData) GetEventPPID() string {
return ev.ppid
}
func (ev *EventData) GetEventPID() string {
return ev.pid
}
func (ev *EventData) GetEventSyscallOp() string {
return ev.syscallOp
}
func (ev *EventData) GetEventSyscallArgs() string {
return ev.syscallArgs
}
func (ev *EventData) GetEventEXE() string {
return ev.exe
}
func (ev *EventData) GetEventCMD() string {
return ev.cmd
}
7 changes: 7 additions & 0 deletions pkg/sbom/sbom_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package sbom
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Required]: See my comment above regarding "nesting" datastructures in "version" packages


type SBOMClient interface {
GetSBOM(imageID string) error
FilterSBOM(sbomFileRelevantMap map[string]bool) error
StoreFilterSBOM() error
}
7 changes: 7 additions & 0 deletions pkg/strageclient/storage_client_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package storageclient

type StorageClient interface {
GetData(key string) (interface{}, error)
PutData(key string, data interface{}) error
PostData(key string, data interface{}) error
}