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

tarian-detector integration and existing ebpf code removal #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0cc8bd6
ci: update .deepsource.toml
deepsource-io[bot] Feb 8, 2024
6d0e3e2
ci: update .deepsource.toml
deepsource-io[bot] Feb 8, 2024
bf27b19
Merge branch 'kube-tarian:main' into main
kumari-anupam Feb 15, 2024
3250efa
tarian-detector integration
kumari-anupam Feb 9, 2024
7222a34
tarian-detector dev branch intgration
kumari-anupam Feb 22, 2024
0c92a53
reverting unwanted file changes
kumari-anupam Feb 22, 2024
5529847
rebase tarian-detector code integration
kumari-anupam Feb 25, 2024
466a195
fixed controller-runtime admission decode error
kumari-anupam Feb 25, 2024
b1a819a
code cleanup
kumari-anupam Feb 26, 2024
36304b4
replaced existing ebpf with tarian-detector
kumari-anupam Mar 3, 2024
36d7e0e
code cleanup
kumari-anupam Mar 3, 2024
c2a4b26
removed existing ebpf code
kumari-anupam Mar 6, 2024
941c87f
fixed lint and unit tests
kumari-anupam Mar 6, 2024
f6cc4cd
fixed lint
kumari-anupam Mar 7, 2024
304d1f8
remove 3rdparty/libbpf and fixed nodeagent running issue
kumari-anupam Mar 9, 2024
bbeba85
workaround: node-agent/tarian-detector needs libelf-dev
andylibrian Mar 9, 2024
4f845d9
fix Anupam's code
andylibrian Mar 9, 2024
82e5793
initial work on removing loopValidateProcesses
andylibrian Mar 10, 2024
118fbdf
attempt to fix CI - 1
andylibrian Mar 11, 2024
0389c26
attempt to fix CI - 2
andylibrian Mar 11, 2024
f871b26
attempt to fix CI - 3
andylibrian Mar 11, 2024
60fed95
attempt to fix CI - 4
andylibrian Mar 14, 2024
7f9f7a6
attempt to fix CI - 5
andylibrian Mar 16, 2024
f977532
Fix tarian-node-agent issue running on cgr static image
andylibrian Mar 16, 2024
9fb2ec1
adding tarian-detection event to dgraph store
kumari-anupam Mar 18, 2024
60c9336
removed duplicate added function from nodeagent
kumari-anupam Mar 19, 2024
3cc4472
removing ebpf code added while resolving merge conflict
kumari-anupam Mar 19, 2024
f600cc4
removed 3rdparty directory
kumari-anupam Mar 19, 2024
21b65df
fixed dgraph_schema
kumari-anupam Mar 21, 2024
f761883
updated dgraph query to ignore tarian-detection event
kumari-anupam Mar 23, 2024
70448ac
k8s node linux kernel major version inside daemonset
kumari-anupam Mar 27, 2024
80b9db7
added script to set node kernel version for k8s-test
kumari-anupam Mar 28, 2024
7847832
fixed typo in previous commit
kumari-anupam Mar 29, 2024
85731b0
removed kernel-script
kumari-anupam Mar 29, 2024
120d150
linux kernel info of runnnig node using go syscall
kumari-anupam Apr 3, 2024
e12aa43
fixed alert manager indefinite call
kumari-anupam Apr 8, 2024
60ce8ad
fixed code
kumari-anupam Apr 9, 2024
1be78b7
added goroutine to ready the events from queue
kumari-anupam Apr 22, 2024
fa7f11a
upgraded x/net pkg version to v0.23.0
kumari-anupam Apr 22, 2024
6a88e16
added retry logic to publish the event
kumari-anupam Apr 22, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@938f6e2f7550e542bd78f3b9e8812665db109e02 # @v1.1.0
make bin/protoc bin/goreleaser
bash ./dev/run-kind-registry.sh
make ebpf generate
make generate
./bin/goreleaser release --snapshot --rm-dist
make push-local-images
cp dist/tarianctl_linux_amd64/tarianctl ./bin/
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
run: |
set -x
sudo apt update && sudo apt install -y jq pkg-config libelf-dev clang
make ebpf

- name: Run unit tests
run: make unit-test
Expand Down Expand Up @@ -131,7 +130,7 @@ jobs:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@938f6e2f7550e542bd78f3b9e8812665db109e02 # @v1.1.0
make bin/protoc bin/goreleaser
bash ./dev/run-kind-registry.sh
make ebpf generate
make generate
./bin/goreleaser release --snapshot --rm-dist
make push-local-images
cp dist/tarianctl_linux_amd64/tarianctl ./bin/
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/vendor
/.local
/.vscode
/pkg/**/capture_exec.bpf.o
/pkg/tarianpb/api.pb.go
/pkg/tarianpb/types.pb.go
coverage.xml
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
run:
timeout: 10m
concurrency: 4
skip-files:
- pkg/nodeagent/ebpf/exec.go

linters:
disable-all: true
Expand Down
3 changes: 1 addition & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
env:
- CONTAINER_REGISTRY={{ if index .Env "CONTAINER_REGISTRY" }}{{ .Env.CONTAINER_REGISTRY }}{{ else }}localhost:5000{{ end }}
- CGO_CFLAGS=-I{{ abs .ModulePath }}/output -Wno-unknown-attributes
- CGO_LDFLAGS=-lelf -lz {{ abs .ModulePath}}/output/libbpf.a
builds:
- id: tarian-server
main: ./cmd/tarian-server/
Expand Down Expand Up @@ -39,7 +38,7 @@ builds:
main: ./cmd/tarian-node-agent/
binary: tarian-node-agent
env:
- CC=clang
- CGO_ENABLED=0
goos:
- linux
goarch:
Expand Down
1 change: 0 additions & 1 deletion 3rdparty/libbpf
Submodule libbpf deleted from 2cd2d0
1 change: 0 additions & 1 deletion Dockerfile-node-agent
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# FROM cgr.dev/chainguard/static:latest
FROM cgr.dev/chainguard/static@sha256:2ea44d9bdd177a07e6fba8a60f7d45cb8a7358586a5f740187866566e6df310d

COPY ./tarian-node-agent .
Expand Down
32 changes: 2 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,12 @@ default: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ eBPF

BASEDIR = $(abspath ./)
OUTPUT = ./output
ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g')

LIBBPF_SRC = $(abspath ./3rdparty/libbpf/src)
LIBBPF_OBJ = $(abspath $(OUTPUT)/libbpf.a)
LIBBPF_OBJDIR = $(abspath $(OUTPUT)/libbpf)
LIBBPF_DESTDIR = $(abspath $(OUTPUT))

CC = gcc
CLANG = clang
GO = go
CFLAGS = -g -O2 -Wall -fpie
LDFLAGS =
Expand All @@ -60,16 +53,12 @@ CGO_LDFLAGS_DYN = "-lelf -lz -lbpf"
BTFFILE = /sys/kernel/btf/vmlinux
BPFTOOL = $(shell which bpftool || /bin/false)
VMLINUXH = $(OUTPUT)/vmlinux.h
NODEAGENT_EBPF_DIR = pkg/nodeagent/ebpf

# output

$(OUTPUT):
mkdir -p $(OUTPUT)

$(OUTPUT)/libbpf:
mkdir -p $(OUTPUT)/libbpf

# vmlinux header file

.PHONY: vmlinuxh
Expand All @@ -88,22 +77,7 @@ $(VMLINUXH): $(OUTPUT)
echo "INFO: generating $(VMLINUXH) from $(BTFFILE)"; \
$(BPFTOOL) btf dump file $(BTFFILE) format c > $(VMLINUXH); \
fi

# libbpf

$(LIBBPF_OBJ): $(LIBBPF_SRC) $(wildcard $(LIBBPF_SRC)/*.[ch]) | $(OUTPUT)/libbpf
CC="$(CC)" CFLAGS="$(CFLAGS)" LD_FLAGS="$(LDFLAGS)" \
$(MAKE) -C $(LIBBPF_SRC) \
BUILD_STATIC_ONLY=1 \
OBJDIR=$(LIBBPF_OBJDIR) \
DESTDIR=$(LIBBPF_DESTDIR) \
INCLUDEDIR= LIBDIR= UAPIDIR= install

libbpfgo-static: $(VMLINUXH) | $(LIBBPF_OBJ)

$(NODEAGENT_EBPF_DIR)/capture_exec.bpf.o: vmlinuxh libbpfgo-static ## Build eBPF object
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -c $(NODEAGENT_EBPF_DIR)/c/capture_exec.bpf.c -o $@


##@ Development

generate: bin/controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand All @@ -115,9 +89,7 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) go vet ./...

ebpf: $(NODEAGENT_EBPF_DIR)/capture_exec.bpf.o

build: bin/goreleaser generate proto ebpf ## Build binaries and copy to ./bin/
build: bin/goreleaser generate proto ## Build binaries and copy to ./bin/
./bin/goreleaser build --single-target --snapshot --rm-dist --single-target
cp dist/*/tarian* ./bin/

Expand Down
1 change: 1 addition & 0 deletions cmd/tarian-node-agent/cmd/mount_debugfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// https://man7.org/linux/man-pages/man2/statfs.2.html
const DebugFSMagic = 0x64626720

// DebugFSRoot is the location of the DebugFS filesystem
const DebugFSRoot = "/sys/kernel/debug"

func isDebugFsMounted() bool {
Expand Down
61 changes: 61 additions & 0 deletions cmd/tarian-node-agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"

"github.com/cilium/ebpf/rlimit"
"github.com/kube-tarian/tarian/cmd/tarian-node-agent/cmd/flags"
"github.com/kube-tarian/tarian/pkg/log"
"github.com/kube-tarian/tarian/pkg/nodeagent"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// Uname contains system uname information.
type Uname struct {
ub syscall.Utsname
}

type runCommand struct {
globalFlags *flags.GlobalFlags
logger *logrus.Logger
Expand Down Expand Up @@ -65,6 +72,15 @@ func (c *runCommand) run(_ *cobra.Command, args []string) error {
return fmt.Errorf("host proc is not mounted: %w", err)
}

if err := c.setLinuxKernelVersion(); err != nil {
c.logger.WithError(err).Error("failed to set linux kernel version")
return fmt.Errorf("failed to set linux kernel version: %w", err)
}

if err := rlimit.RemoveMemlock(); err != nil {
c.logger.Fatal(err)
}

addr := c.clusterAgentHost + ":" + c.clusterAgentPort
agent := nodeagent.NewNodeAgent(c.logger, addr)
agent.EnableAddConstraint(c.enableAddConstraint)
Expand All @@ -86,3 +102,48 @@ func (c *runCommand) run(_ *cobra.Command, args []string) error {

return nil
}

// setLinuxKernelVersion sets the Linux kernel version by parsing the uname information.
func (c *runCommand) setLinuxKernelVersion() error {
u := &Uname{}
err := syscall.Uname(&u.ub)

if err != nil {
c.logger.WithField("error while making syscall to get linux kernel version, err: ", err)
return fmt.Errorf("error while making syscall to get linux kernel version: %w", err)
}

linuxKernelVersion := charsToString(u.ub.Release[:])
strArr := strings.Split(linuxKernelVersion, ".")
if len(strArr) < 3 {
c.logger.WithField("version", linuxKernelVersion).Fatal("invalid linux kernel version")
return fmt.Errorf("invalid linux kernel version: %s", linuxKernelVersion)
}
majorVersion := strArr[0]
minorVersion := strArr[1]
patch := strArr[2]
// Split to get the patch version
strArr = strings.Split(patch, "-")
patchVersion := strArr[0]
os.Setenv("LINUX_VERSION_MAJOR", majorVersion)
os.Setenv("LINUX_VERSION_MINOR", minorVersion)
os.Setenv("LINUX_VERSION_PATCH", patchVersion)

return nil
}

// charsToString converts an array of int8 to a string.
//
// ca []int8: the array of int8 to be converted.
// string: the resulting string from the conversion.
func charsToString(ca []int8) string {
s := make([]byte, len(ca))
var i int
for ; i < len(ca); i++ {
if ca[i] == 0 {
break
}
s[i] = uint8(ca[i])
}
return string(s[0:i])
}
1 change: 0 additions & 1 deletion cmd/tarianctl/cmd/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (globalFlags *GlobalFlags) ValidateGlobalFlags() error {
func (globalFlags *GlobalFlags) GetFlagValuesFromEnvVar(logger *logrus.Logger) {
// Read environment variable for "server-address" flag
if globalFlags.ServerAddr == defaultServerAddress || globalFlags.ServerAddr == "" {
fmt.Println("here")
if serverAddressEnv := os.Getenv(tarianServerAddressEnv); serverAddressEnv != "" {
logger.Debugf("Setting server address from environment variable, TARIAN_SERVER_ADDRESS=%s", serverAddressEnv)
globalFlags.ServerAddr = serverAddressEnv
Expand Down
6 changes: 6 additions & 0 deletions cmd/tarianctl/cmd/get/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func eventsTableOutput(events []*tarianpb.Event, logger *logrus.Logger) {
evt.WriteString("pod deleted")
}

if e.GetType() == tarianpb.EventTypeDetection {
detectionEventStr := fmt.Sprintf("detection: %s: %s", t.GetDetectionDataType(), t.GetDetectionData())
evt.WriteString("tarian detection event\n")
evt.WriteString(detectionEventStr)
}

evt.WriteString("\n")

table.Append(
Expand Down
1 change: 1 addition & 0 deletions dev/config/tarian-cluster-agent/tarian-cluster-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spec:
image: localhost:5000/tarian-cluster-agent:latest
args:
- --log-level=debug
- --log-formatter=json
- run
- "--server-address=tarian-server:80"
- --enable-add-constraint
Expand Down
1 change: 1 addition & 0 deletions dev/config/tarian-node-agent/tarian-node-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ spec:
image: localhost:5000/tarian-node-agent:latest
args:
- --log-level=debug
- --log-formatter=json
- run
- --cluster-agent-host=tarian-cluster-agent.tarian-system.svc
- --cluster-agent-port=80
Expand Down
2 changes: 1 addition & 1 deletion dev/config/tarian-server/tarian-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
- name: tarian-server
image: "localhost:5000/tarian-server:latest"
args:
- "--log-formatter=text"
- "--log-formatter=json"
- "--log-level=debug"
- run
- "--alertmanager-address=http://alertmanager:9093"
Expand Down
Loading
Loading