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

[Draft] Addition to anupam tarian detector integration #74

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
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
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
9 changes: 8 additions & 1 deletion Dockerfile-node-agent
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# FROM cgr.dev/chainguard/static:latest
FROM cgr.dev/chainguard/static@sha256:2ea44d9bdd177a07e6fba8a60f7d45cb8a7358586a5f740187866566e6df310d

ARG KERNEL_VERSION_MAJOR
ARG KERNEL_VERSION_MINOR
ARG KERNEL_VERSION_PATCH

ENV LINUX_VERSION_MAJOR=$KERNEL_VERSION_MAJOR
ENV LINUX_VERSION_MINOR=$KERNEL_VERSION_MINOR
ENV LINUX_VERSION_PATCH=$KERNEL_VERSION_PATCH

COPY ./tarian-node-agent .

ENTRYPOINT ["./tarian-node-agent"]
Expand Down
42 changes: 11 additions & 31 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,20 @@ 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

# extracts the major, minor, and patch version numbers of the kernel version
KERNEL_VERSION = $(word 1, $(subst -, ,$(shell uname -r)))
KV_S = $(subst ., ,$(KERNEL_VERSION))
KV_MAJOR = $(word 1,$(KV_S))
KV_MINOR = $(word 2,$(KV_S))
KV_PATCH = $(word 3,$(KV_S))


# output

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

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

# vmlinux header file

.PHONY: vmlinuxh
Expand All @@ -88,22 +85,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 +97,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 All @@ -132,7 +112,7 @@ local-images: build
docker build -f Dockerfile-server -t localhost:5000/tarian-server dist/tarian-server_linux_amd64/ && docker push localhost:5000/tarian-server
docker build -f Dockerfile-cluster-agent -t localhost:5000/tarian-cluster-agent dist/tarian-cluster-agent_linux_amd64/ && docker push localhost:5000/tarian-cluster-agent
docker build -f Dockerfile-pod-agent -t localhost:5000/tarian-pod-agent dist/tarian-pod-agent_linux_amd64/ && docker push localhost:5000/tarian-pod-agent
docker build -f Dockerfile-node-agent -t localhost:5000/tarian-node-agent dist/tarian-node-agent_linux_amd64/ && docker push localhost:5000/tarian-node-agent
docker build --build-arg KERNEL_VERSION_MAJOR=$(KV_MAJOR) --build-arg KERNEL_VERSION_MINOR=$(KV_MINOR) --build-arg KERNEL_VERSION_PATCH=$(KV_PATCH) -f Dockerfile-node-agent -t localhost:5000/tarian-node-agent dist/tarian-node-agent_linux_amd64/ && docker push localhost:5000/tarian-node-agent
docker build -f Dockerfile-tarianctl -t localhost:5000/tarianctl dist/tarianctl_linux_amd64/ && docker push localhost:5000/tarianctl

push-local-images:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ spec:
mountPath: /sys/fs/bpf
mountPropagation: Bidirectional
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: LINUX_VERSION_MAJOR
value: "6"
- name: LINUX_VERSION_MINOR
value: "5"
- name: LINUX_VERSION_PATCH
value: "0"
serviceAccountName: {{ .Release.Name }}-node-sa
volumes:
- name: host-proc
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
8 changes: 8 additions & 0 deletions cmd/tarian-node-agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"os/signal"
"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"
Expand Down Expand Up @@ -65,8 +66,15 @@
return fmt.Errorf("host proc is not mounted: %w", err)
}

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

Check warning on line 71 in cmd/tarian-node-agent/cmd/run.go

View check run for this annotation

Codecov / codecov/patch

cmd/tarian-node-agent/cmd/run.go#L69-L71

Added lines #L69 - L71 were not covered by tests

addr := c.clusterAgentHost + ":" + c.clusterAgentPort
agent := nodeagent.NewNodeAgent(c.logger, addr)
/*if err != nil {
return fmt.Errorf("error while creating tarian-node-agent: %w", err)
}*/

Check warning on line 77 in cmd/tarian-node-agent/cmd/run.go

View check run for this annotation

Codecov / codecov/patch

cmd/tarian-node-agent/cmd/run.go#L75-L77

Added lines #L75 - L77 were not covered by tests
agent.EnableAddConstraint(c.enableAddConstraint)
agent.SetNodeName(c.nodeNmae)

Expand Down
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
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
15 changes: 11 additions & 4 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 All @@ -31,10 +32,16 @@ spec:
mountPath: /sys/fs/bpf
mountPropagation: Bidirectional
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: LINUX_VERSION_MAJOR
value: "6"
- name: LINUX_VERSION_MINOR
value: "5"
- name: LINUX_VERSION_PATCH
value: "0"
serviceAccountName: tarian-node-agent
volumes:
- name: host-proc
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