Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
8f927c3
add unknown container
notshivansh Jul 25, 2025
000e003
Merge pull request #112 from akto-api-security/hotfix/fix_no_containers
notshivansh Jul 25, 2025
a6816ff
update version
notshivansh Aug 13, 2025
e9fa4a7
Merge pull request #114 from akto-api-security/hotfix/fix_vuln
notshivansh Aug 13, 2025
a2b0968
add chunk encoding and debug logs
notshivansh Aug 18, 2025
99ae18a
attempt
notshivansh Aug 18, 2025
5c5892b
remove debug logs
notshivansh Aug 20, 2025
d853d48
make limit configurable
notshivansh Aug 20, 2025
99bd902
increase chunk limit
notshivansh Aug 20, 2025
8535a4f
reduce default limit
notshivansh Aug 20, 2025
73f3b8d
Merge pull request #116 from akto-api-security/feature/chunk_encoding
notshivansh Aug 21, 2025
b6629c4
Adding sasl auth in kafka for agent
Ark2307 Sep 1, 2025
176250e
Fixing compilation errors
Ark2307 Sep 2, 2025
2383fe0
adding missing import
Ark2307 Sep 2, 2025
7be7762
Merge pull request #118 from akto-api-security/feature/sasl_auth_kafk…
Ark2307 Sep 2, 2025
c53c2e3
enable threat events push by default
ayushaga14 Sep 30, 2025
b0eb594
remove file logging enabled check on debug urls
ayushaga14 Sep 30, 2025
b4a365b
Merge pull request #124 from akto-api-security/enable-threat-ebpf
ayushaga14 Sep 30, 2025
66d67b3
update script
notshivansh Oct 3, 2025
bdee800
configurable
notshivansh Oct 3, 2025
40c453d
add override
notshivansh Oct 3, 2025
9ab2ed5
take in mb
notshivansh Oct 3, 2025
cdce6c0
Merge pull request #125 from akto-api-security/feature/mem_check
notshivansh Oct 3, 2025
8d4d02a
add go mem limit.
notshivansh Oct 3, 2025
9c7b15c
set go mem limit as 50% of mem threshold
ayushaga14 Oct 5, 2025
e63a15c
set go mem limit as 50% of mem threshold
ayushaga14 Oct 5, 2025
d4eae05
Merge pull request #127 from akto-api-security/feature/mem_check
ayushaga14 Oct 5, 2025
f746861
push source in threat payload
ayushaga14 Nov 19, 2025
c4e2f74
Merge pull request #131 from akto-api-security/fix/push-source-threat
ayushaga14 Nov 19, 2025
6e84665
remove the payload printing
gauravakto Nov 27, 2025
ac26129
Merge pull request #133 from akto-api-security/fix/remove-sample
gauravakto Nov 27, 2025
c4a70ce
exit on kafka error threshold
notshivansh Dec 16, 2025
9895ea7
make optional config changes
notshivansh Dec 16, 2025
5f93245
increase default threshold
notshivansh Dec 16, 2025
9a03ba8
increase threshold
notshivansh Dec 16, 2025
45e40a4
Merge pull request #137 from akto-api-security/feature/kafka_err_restart
notshivansh Dec 16, 2025
d73dfb5
kafka reconnect
notshivansh Dec 24, 2025
e4ada9c
refactor parseAndProduce
gauravakto Dec 25, 2025
20a705c
Merge pull request #140 from akto-api-security/feat/partial-requests
gauravakto Dec 25, 2025
d784ad1
use empty bodies on failures
gauravakto Dec 25, 2025
04e6abe
Merge pull request #141 from akto-api-security/feat/best-effort-disco…
gauravakto Dec 25, 2025
cf4a711
increase and reset timer
gauravakto Dec 25, 2025
c5a88e3
default don't reconnect
notshivansh Dec 26, 2025
bb536cf
add max 10MB limit
gauravakto Dec 26, 2025
b110a01
Merge pull request #142 from akto-api-security/feat/handle-longer-res…
gauravakto Dec 27, 2025
e4feeae
Merge pull request #139 from akto-api-security/feature/kafka_reconnect
notshivansh Dec 29, 2025
1f9ee08
Feature/communicate kafka (#144)
kural-akto Jan 12, 2026
dd96fba
feat: add kafka header
abhijeet-akto Jan 14, 2026
1484955
chore: add check
abhijeet-akto Jan 14, 2026
98933fb
Merge pull request #147 from akto-api-security/abhi/feat/kafka-header
abhijeet-akto Jan 14, 2026
83ce73d
Feature/communicate kafka v2 (#148)
kural-akto Jan 16, 2026
39a588b
Don't resolve pod labels for envoy process Ids. (#134)
gauravakto Jan 19, 2026
fc675cd
Feature/pod profiling (#149)
kural-akto Jan 22, 2026
0f3b91e
added dest ip in the payload
kural-akto Feb 3, 2026
3ab791b
Merge pull request #150 from akto-api-security/fix/add_dest_ip
Ark2307 Feb 4, 2026
eec0615
reduce log level
gauravakto Feb 18, 2026
04a3376
Merge pull request #152 from akto-api-security/fix/mute-logs
notshivansh Feb 18, 2026
9681477
Allow sequence to start from anywehre
gauravakto Feb 20, 2026
1cdd406
Merge pull request #153 from akto-api-security/feat/capture-all-requq…
notshivansh Feb 20, 2026
1dd2c51
Preserve environment variables across process restarts
gauravakto Feb 27, 2026
b9b3b57
change in consumer message type
kural-akto Mar 2, 2026
54bef1c
changes for fix in consumer group id and revert some untested changes
kural-akto Mar 2, 2026
43d4e9b
commit offset manually before processing the message as there is os.e…
kural-akto Mar 2, 2026
0c34412
Merge pull request #158 from akto-api-security/fix/restart-preserver-…
notshivansh Mar 3, 2026
d882fb7
use global transport
ayushaga14 Mar 13, 2026
f0196ca
Merge pull request #173 from akto-api-security/kafka-conn-fix
ayushaga14 Mar 16, 2026
e114475
updated GO image
harshithb3304 Mar 16, 2026
7553d85
updated go version
harshithb3304 Mar 16, 2026
0b50be5
updated Go version
harshithb3304 Mar 17, 2026
b34c0c8
updated script
harshithb3304 Mar 17, 2026
8632c42
updated logs
harshithb3304 Mar 17, 2026
c51de90
shifted to debug
harshithb3304 Mar 17, 2026
1e872d6
updated logs
harshithb3304 Mar 17, 2026
318a864
update code
harshithb3304 Mar 17, 2026
224f19e
updated logs
harshithb3304 Mar 17, 2026
4a56ad5
Merge pull request #176 from akto-api-security/feature/goprocs
notshivansh Mar 17, 2026
701b753
added env read (#175)
harshithb3304 Mar 18, 2026
a51841d
Pre-fill existing connections of kube processes (#169)
gauravakto Mar 23, 2026
b066170
use flag for sequence check
gauravakto Mar 23, 2026
60fbbce
spell fix
gauravakto Mar 23, 2026
5b07f0c
Merge pull request #179 from akto-api-security/fix/put-seq-check-in-flag
notshivansh Mar 23, 2026
c1feb8c
Enhance ebpf-run.sh with new environment variables and improved loggi…
krngrover94 Mar 27, 2026
b613140
Merge pull request #181 from akto-api-security/hide-SIGSEGV-error-logs
notshivansh Mar 27, 2026
999902d
fix cgroup file locations (#186)
gauravakto Apr 23, 2026
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
59 changes: 50 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ on:
options:
- legacy
- ebpf
default: legacy
default: legacy
Architecture:
description: "The target architecture(s) for the Docker image."
required: true
type: choice
options:
- both
- arm64
- amd64
default: both

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down Expand Up @@ -82,11 +91,19 @@ jobs:
ECR_REPOSITORY: akto-api-security
REGISTRY_ALIAS: p7q3h0z2
IMAGE_TAG: ${{ github.event.inputs.Tag }}
ARCH_INPUT: ${{ github.event.inputs.Architecture }}
run: |
# Build a docker container and push it to DockerHub
docker buildx create --use
echo "Building and Pushing image to ECR..."
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$REGISTRY_ALIAS/mirror-api-logging:$IMAGE_TAG . --push
if [ "$ARCH_INPUT" == "arm64" ]; then
PLATFORM="linux/arm64/v8"
elif [ "$ARCH_INPUT" == "amd64" ]; then
PLATFORM="linux/amd64"
else
PLATFORM="linux/arm64/v8,linux/amd64"
fi
echo "Building and Pushing image to ECR with platform: $PLATFORM"
docker buildx build --platform $PLATFORM -t $ECR_REGISTRY/$REGISTRY_ALIAS/mirror-api-logging:$IMAGE_TAG . --push
echo "::set-output name=image::$ECR_REGISTRY/$REGISTRY_ALIAS/mirror-api-logging:$IMAGE_TAG"

- name: Build, tag, and push the image to Amazon ECR -ebpf
Expand All @@ -97,11 +114,19 @@ jobs:
ECR_REPOSITORY: akto-api-security
REGISTRY_ALIAS: p7q3h0z2
IMAGE_TAG: ${{ github.event.inputs.EbpfTag }}
ARCH_INPUT: ${{ github.event.inputs.Architecture }}
run: |
# Build a docker container and push it to DockerHub
docker buildx create --use
echo "Building and Pushing image to ECR..."
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$REGISTRY_ALIAS/mirror-api-logging:$IMAGE_TAG -f Dockerfile.eBPF . --push
if [ "$ARCH_INPUT" == "arm64" ]; then
PLATFORM="linux/arm64/v8"
elif [ "$ARCH_INPUT" == "amd64" ]; then
PLATFORM="linux/amd64"
else
PLATFORM="linux/arm64/v8,linux/amd64"
fi
echo "Building and Pushing image to ECR with platform: $PLATFORM"
docker buildx build --platform $PLATFORM -t $ECR_REGISTRY/$REGISTRY_ALIAS/mirror-api-logging:$IMAGE_TAG -f Dockerfile.eBPF . --push
echo "::set-output name=image::$ECR_REGISTRY/$REGISTRY_ALIAS/mirror-api-logging:$IMAGE_TAG"

build-docker:
Expand Down Expand Up @@ -136,11 +161,19 @@ jobs:
env:
ECR_REGISTRY: aktosecurity
IMAGE_TAG: ${{ github.event.inputs.Tag }}
ARCH_INPUT: ${{ github.event.inputs.Architecture }}
run: |
# Build a docker container and push it to DockerHub
docker buildx create --use
echo "Building and Pushing image to DockerHub..."
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/mirror-api-logging:$IMAGE_TAG . --push
if [ "$ARCH_INPUT" == "arm64" ]; then
PLATFORM="linux/arm64/v8"
elif [ "$ARCH_INPUT" == "amd64" ]; then
PLATFORM="linux/amd64"
else
PLATFORM="linux/arm64/v8,linux/amd64"
fi
echo "Building and Pushing image to DockerHub with platform: $PLATFORM"
docker buildx build --platform $PLATFORM -t $ECR_REGISTRY/mirror-api-logging:$IMAGE_TAG . --push
echo "::set-output name=image::$ECR_REGISTRY/mirror-api-logging:$IMAGE_TAG"

- name: Build, tag, and push the image to DockerHub - ebpf
Expand All @@ -149,9 +182,17 @@ jobs:
env:
ECR_REGISTRY: aktosecurity
IMAGE_TAG: ${{ github.event.inputs.EbpfTag }}
ARCH_INPUT: ${{ github.event.inputs.Architecture }}
run: |
# Build a docker container and push it to DockerHub
docker buildx create --use
echo "Building and Pushing image to DockerHub..."
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/mirror-api-logging:$IMAGE_TAG -f Dockerfile.eBPF . --push
if [ "$ARCH_INPUT" == "arm64" ]; then
PLATFORM="linux/arm64/v8"
elif [ "$ARCH_INPUT" == "amd64" ]; then
PLATFORM="linux/amd64"
else
PLATFORM="linux/arm64/v8,linux/amd64"
fi
echo "Building and Pushing image to DockerHub with platform: $PLATFORM"
docker buildx build --platform $PLATFORM -t $ECR_REGISTRY/mirror-api-logging:$IMAGE_TAG -f Dockerfile.eBPF . --push
echo "::set-output name=image::$ECR_REGISTRY/mirror-api-logging:$IMAGE_TAG"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ mirroring-api-logging
.idea/
**/.vscode/
temp
**temp
**temp
data-*
4 changes: 2 additions & 2 deletions Dockerfile.eBPF
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM alpine:3.21 AS base
FROM alpine:3.22 AS base

USER root
RUN apk add bcc-tools bcc-dev bcc-doc linux-headers build-base

FROM base AS builder

# Install Go based on architecture
ARG GO_VERSION=1.24.3
ARG GO_VERSION=1.25.8
ARG TARGETARCH

RUN if [ "$TARGETARCH" = "arm64" ]; then \
Expand Down
170 changes: 162 additions & 8 deletions ebpf-run.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/bin/sh

LOG_FILE="/tmp/dump.log"
LOG_FILE=${LOG_FILE:-/tmp/dump.log}
MAX_LOG_SIZE=${MAX_LOG_SIZE:-10485760} # Default to 10 MB if not set (10 MB = 10 * 1024 * 1024 bytes)
CHECK_INTERVAL=60 # Check interval in seconds
CHECK_INTERVAL=${CHECK_INTERVAL:-60}
CHECK_INTERVAL_MEM=${CHECK_INTERVAL_MEM:-5} # Check interval in seconds (configurable via env)
MEMORY_THRESHOLD=${MEMORY_THRESHOLD:-85} # Kill process at this % memory usage (configurable via env)
GOMEMLIMIT_PERCENT=${GOMEMLIMIT_PERCENT:-60} # GOMEMLIMIT as % of container memory limit (configurable via env)
AKTO_SUPPRESS_TRACE=${AKTO_SUPPRESS_TRACE:-true}
CRASH_RESTART_BACKOFF_SECONDS=${CRASH_RESTART_BACKOFF_SECONDS:-10}

# Function to rotate the log file
rotate_log() {
Expand All @@ -14,6 +19,39 @@ rotate_log() {
fi
}

# Function to check memory usage and kill process if threshold exceeded
check_memory_and_kill() {
# Resolve container's cgroup path (needed when hostPID: true shifts cgroup root)
CGROUP_BASE=$(cut -d: -f3 /proc/self/cgroup | head -1)

# Get current memory usage in bytes
if [ -f "/sys/fs/cgroup${CGROUP_BASE}/memory.current" ]; then
# cgroup v2 with hostPID
CURRENT_MEM=$(cat "/sys/fs/cgroup${CGROUP_BASE}/memory.current")
elif [ -f /sys/fs/cgroup/memory.current ]; then
# cgroup v2 normal
CURRENT_MEM=$(cat /sys/fs/cgroup/memory.current)
elif [ -f "/sys/fs/cgroup${CGROUP_BASE}/memory.usage_in_bytes" ]; then
# cgroup v1 with hostPID
CURRENT_MEM=$(cat "/sys/fs/cgroup${CGROUP_BASE}/memory.usage_in_bytes")
elif [ -f /sys/fs/cgroup/memory/memory.usage_in_bytes ]; then
# cgroup v1 normal
CURRENT_MEM=$(cat /sys/fs/cgroup/memory/memory.usage_in_bytes)
else
return
fi

# Calculate percentage used
PERCENT_USED=$((CURRENT_MEM * 100 / MEM_LIMIT_BYTES))

echo "Memory usage: ${PERCENT_USED}% (${CURRENT_MEM} / ${MEM_LIMIT_BYTES} bytes)"

if [ "$PERCENT_USED" -ge "$MEMORY_THRESHOLD" ]; then
echo "Memory threshold ${MEMORY_THRESHOLD}% exceeded (${PERCENT_USED}%), killing ebpf-logging process"
pkill -9 ebpf-logging
fi
}

# Start monitoring in the background
if [[ "${ENABLE_LOGS}" == "false" ]]; then
while true; do
Expand All @@ -22,12 +60,128 @@ if [[ "${ENABLE_LOGS}" == "false" ]]; then
done &
fi

while :
do
if [[ "${ENABLE_LOGS}" == "false" ]]; then
./ebpf-logging >> "$LOG_FILE" 2>&1
# 1. Check if MEM_LIMIT is provided as env variable
if [ -z "$MEM_LIMIT" ]; then
# Resolve container's cgroup path (needed when hostPID: true shifts cgroup root)
CGROUP_BASE=$(cut -d: -f3 /proc/self/cgroup | head -1)

# Not provided, detect and read cgroup memory limits
if [ -f "/sys/fs/cgroup${CGROUP_BASE}/memory.max" ]; then
# cgroup v2 with hostPID
MEM_LIMIT_BYTES=$(cat "/sys/fs/cgroup${CGROUP_BASE}/memory.max")
elif [ -f /sys/fs/cgroup/memory.max ]; then
# cgroup v2 normal
MEM_LIMIT_BYTES=$(cat /sys/fs/cgroup/memory.max)
elif [ -f "/sys/fs/cgroup${CGROUP_BASE}/memory.limit_in_bytes" ]; then
# cgroup v1 with hostPID
MEM_LIMIT_BYTES=$(cat "/sys/fs/cgroup${CGROUP_BASE}/memory.limit_in_bytes")
elif [ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
# cgroup v1 normal
MEM_LIMIT_BYTES=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
else
# Fallback to free -b (bytes) if cgroup file not found
echo "Neither cgroup v2 nor v1 memory file found, defaulting to free -b"
MEM_LIMIT_BYTES=$(free -b | awk '/Mem:/ {print $2}')
fi

# 2. Handle edge cases: "max" (cgroup v2) or 9223372036854775807 (cgroup v1 INT64_MAX) mean no limit
if [ "$MEM_LIMIT_BYTES" = "max" ] || [ "$MEM_LIMIT_BYTES" = "9223372036854775807" ]; then
echo "Cgroup memory limit is unlimited, defaulting to free memory"
MEM_LIMIT_BYTES=$(free -b | awk '/Mem:/ {print $2}')
fi

# 3. Convert the memory limit from bytes to MB (integer division)
MEM_LIMIT_MB=$((MEM_LIMIT_BYTES / 1024 / 1024))
else
./ebpf-logging
# MEM_LIMIT provided as env variable, treat as MB
echo "Using MEM_LIMIT from environment variable: ${MEM_LIMIT} MB"
MEM_LIMIT_MB=$MEM_LIMIT
# Convert MB to bytes for calculations
MEM_LIMIT_BYTES=$((MEM_LIMIT * 1024 * 1024))
fi
sleep 2

echo "Using container memory limit: ${MEM_LIMIT_MB} MB"

# Set GOMEMLIMIT for the Go process
GOMEMLIMIT_MB=$((MEM_LIMIT_MB * GOMEMLIMIT_PERCENT / 100))
export GOMEMLIMIT="${GOMEMLIMIT_MB}MiB"
echo "Setting GOMEMLIMIT to: ${GOMEMLIMIT} (${GOMEMLIMIT_PERCENT}% of ${MEM_LIMIT_MB} MB)"

# ENABLE_LOGS (same intent as always):
# false -> append ebpf stdout+stderr to LOG_FILE (2>&1), not primary container streams.
# true (or anything else) -> ebpf inherits container stdout/stderr (kubectl logs).
# AKTO_SUPPRESS_TRACE=true -> optional stderr-only SIGSEGV/cgo filter; when off, file mode matches legacy exactly.
run_ebpf_once() {
log_to_file=false
[[ "${ENABLE_LOGS}" == "false" ]] && log_to_file=true

# Legacy path: single merged stream, no FIFO.
if [ "${AKTO_SUPPRESS_TRACE}" != "true" ]; then
if [ "$log_to_file" = "true" ]; then
./ebpf-logging >> "$LOG_FILE" 2>&1
else
./ebpf-logging
fi
return $?
fi

# Filter path: stderr only through awk; stdout unchanged. FIFO connects ebpf stderr -> awk reader.
ERRPIPE="/tmp/ebpf-stderr-$$"
rm -f "$ERRPIPE"
if ! mkfifo "$ERRPIPE"; then
return 1
fi

to_logfile=0
[ "$log_to_file" = "true" ] && to_logfile=1

awk -v to_logfile="$to_logfile" -v logf="$LOG_FILE" '
BEGIN { quiet = 0 }
/^SIGSEGV:/ || /^signal arrived during cgo execution/ {
if (!quiet) {
msg = "SIGSEGV/cgo crash (multi-line trace suppressed; set AKTO_SUPPRESS_TRACE=false for full output)"
if (to_logfile) print msg >> logf
else print msg > "/dev/stderr"
}
quiet = 1
next
}
quiet { next }
{
if (to_logfile) print >> logf
else print > "/dev/stderr"
}
' < "$ERRPIPE" &
AWKPID=$!

if [ "$log_to_file" = "true" ]; then
./ebpf-logging >> "$LOG_FILE" 2>"$ERRPIPE"
else
./ebpf-logging 2>"$ERRPIPE"
fi
ebpf_exit=$?
wait "$AWKPID" 2>/dev/null
rm -f "$ERRPIPE"
return "$ebpf_exit"
}

# Start memory monitoring in the background
while true; do
check_memory_and_kill
sleep "$CHECK_INTERVAL_MEM"
done &

while :
do
# Source environment file if it exists (contains vars set by processCommandMessage)
if [ -f /ebpf/.env ]; then
set -a
source /ebpf/.env
set +a
fi

run_ebpf_once
ebpf_exit=$?

sleep "${CRASH_RESTART_BACKOFF_SECONDS}"
done
3 changes: 2 additions & 1 deletion ebpf/bpfwrapper/eventCallbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func SocketDataEventCallback(inputChan chan []byte, connectionFactory *connectio
"data", dataStr,
"rc", event.Attr.ReadEventsCount,
"wc", event.Attr.WriteEventsCount,
"ssl", event.Attr.Ssl)
"ssl", event.Attr.Ssl,
"bytesSent", bytesSent)
}
}
Loading
Loading