fix(ja4ebpf): split bpf2go generate into Ja4Tc + Ja4Ssl, fix RPM systemd-rpm-macros

- Use two separate //go:generate directives (Ja4Tc for tc_capture.c, Ja4Ssl
  for uprobe_ssl.c) to avoid duplicate LICENSE symbol and multi-file clang issue
- Update loader.go to hold tcObjs/sslObjs separately with correct field names:
  UprobeSslSetFd, UprobeSslReadEntry, UretprobeSslReadExit,
  KprobeAccept4Entry, KretprobeAccept4Exit
- Add systemd-rpm-macros to all three RPM build stages (el8/el9/el10)
  so that %{_unitdir} macro resolves correctly
- RPMs now build successfully for el8, el9, el10

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
toto
2026-04-11 23:21:11 +02:00
parent a1e4c1dad5
commit 3b047b680a
155 changed files with 197011 additions and 599 deletions

View File

@ -0,0 +1,90 @@
# =============================================================================
# Stack hitch + varnish — tests d'intégration ja4ebpf
#
# Architecture :
# traffic-gen ─HTTPS→ hitch (TLS, port 443, PROXY protocol) ─HTTP→ varnish (port 6081)
# ↓
# backend HTTP (port 8080)
# ↑
# ja4ebpf (uprobe hitch/libssl + hook TC)
#
# Hitch est un TLS offloader dédié : il ne fait QUE la terminaison TLS
# et transmet le trafic cleartext + PROXY protocol header à Varnish.
# Varnish lit le PROXY header pour récupérer l'IP réelle du client.
#
# Différence clé vs nginx+varnish :
# - uprobe sur hitch (/usr/sbin/hitch ou libssl liée par hitch)
# - PROXY protocol header permet à ja4ebpf de récupérer la vraie src_ip
# même si le trafic L3 vient de hitch → varnish (127.0.0.1)
# =============================================================================
services:
clickhouse:
image: clickhouse/clickhouse-server:24.8
hostname: clickhouse
environment:
CLICKHOUSE_DB: ja4_processing
CLICKHOUSE_USER: default
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
volumes:
- ../platform/clickhouse-init.sh:/docker-entrypoint-initdb.d/00_init.sh
- ../../../shared/clickhouse/00_database.sql:/initdb-src/00_database.sql:ro
- ../../../shared/clickhouse/01_raw_tables.sql:/initdb-src/01_raw_tables.sql:ro
- ../../../shared/clickhouse/02_dictionaries.sql:/initdb-src/02_dictionaries.sql:ro
- ../../../shared/clickhouse/03_anubis_tables.sql:/initdb-src/03_anubis_tables.sql:ro
- ../../../shared/clickhouse/04_mv_http_logs.sql:/initdb-src/04_mv_http_logs.sql:ro
- ../../../shared/clickhouse/05_aggregation_tables.sql:/initdb-src/05_aggregation_tables.sql:ro
- ../../../shared/clickhouse/06_ml_tables.sql:/initdb-src/06_ml_tables.sql:ro
- ../../../shared/clickhouse/07_ai_features_view.sql:/initdb-src/07_ai_features_view.sql:ro
- ../../../shared/clickhouse/08_users.sql:/initdb-src/08_users.sql:ro
- ../../../shared/clickhouse/09_audit_table.sql:/initdb-src/09_audit_table.sql:ro
- ../../../shared/clickhouse/10_perf_indexes.sql:/initdb-src/10_perf_indexes.sql:ro
- ../../../shared/clickhouse/11_views.sql:/initdb-src/11_views.sql:ro
- ../../../shared/clickhouse/12_thesis_features.sql:/initdb-src/12_thesis_features.sql:ro
- ../../../shared/data/browser_h2.csv:/initdb-src/browser_h2.csv:ro
- ../platform/csv-stubs:/var/lib/clickhouse/user_files
ports: ["9000:9000","8123:8123"]
healthcheck:
test: ["CMD","clickhouse-client","--query","SELECT 1"]
interval: 5s
timeout: 3s
retries: 30
networks: [ja4net]
platform:
build:
context: ../../..
dockerfile: tests/integration/hitch-varnish/platform/Dockerfile
args:
BASE_IMAGE: ${PLATFORM_BASE_IMAGE:-rockylinux:9}
hostname: platform
cap_add: [NET_ADMIN, BPF, SYS_PTRACE]
privileged: true
environment:
JA4EBPF_CH_ADDR: "clickhouse:9000"
depends_on:
clickhouse:
condition: service_healthy
ports: ["443:443","80:80"]
healthcheck:
# Hitch n'expose pas de port HTTP directement.
# On passe par HTTPS (hitch → varnish → backend).
test: ["CMD","curl","-sfk","https://localhost/health"]
interval: 5s
timeout: 3s
retries: 30
networks: [ja4net]
traffic-gen:
build:
context: ../traffic-gen
hostname: traffic-gen
depends_on:
platform:
condition: service_healthy
networks: [ja4net]
networks:
ja4net:
driver: bridge

View File

@ -0,0 +1,54 @@
# =============================================================================
# Platform hitch + varnish — Rocky Linux 9
# hitch (TLS, PROXY protocol) → Varnish (HTTP cache) → backend HTTP
# =============================================================================
FROM golang:1.24-bookworm AS go-builder
RUN apt-get update && apt-get install -y clang llvm libbpf-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /build
COPY go.work go.work.sum* ./
COPY shared/go/ja4common/go.mod shared/go/ja4common/go.sum* ./shared/go/ja4common/
COPY services/ja4ebpf/go.mod services/ja4ebpf/go.sum* ./services/ja4ebpf/
RUN cd services/ja4ebpf && go mod download 2>/dev/null; true
COPY shared/go/ja4common/ ./shared/go/ja4common/
COPY services/ja4ebpf/ ./services/ja4ebpf/
WORKDIR /build/services/ja4ebpf
RUN GOWORK=off go generate ./internal/loader/ && \
GOWORK=off CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -ldflags="-s -w" -o /out/ja4ebpf ./cmd/ja4ebpf/
# ── Runtime : hitch + varnish + backend + ja4ebpf ────────────────────────────
ARG BASE_IMAGE=rockylinux:9
FROM ${BASE_IMAGE}
# hitch est dans EPEL ; varnish dans le dépôt officiel Rocky
RUN dnf install -y epel-release && \
dnf install -y hitch varnish openssl curl python3 && \
dnf clean all
COPY --from=go-builder /out/ja4ebpf /usr/local/bin/ja4ebpf
# Certificat TLS auto-signé pour hitch
RUN openssl req -x509 -nodes -days 365 \
-subj "/CN=platform.test" \
-newkey rsa:2048 \
-keyout /tmp/hitch.key \
-out /tmp/hitch.crt && \
# hitch attend un fichier PEM concaténé (clé + certificat)
cat /tmp/hitch.key /tmp/hitch.crt > /etc/hitch/hitch.pem && \
chmod 600 /etc/hitch/hitch.pem && \
mkdir -p /var/www/html /run/varnish && \
echo '{"status":"ok","stack":"hitch-varnish"}' > /var/www/html/health
COPY tests/integration/hitch-varnish/platform/hitch.conf /etc/hitch/hitch.conf
COPY tests/integration/hitch-varnish/platform/varnish.vcl /etc/varnish/default.vcl
COPY tests/integration/hitch-varnish/platform/ja4ebpf.yml /etc/ja4ebpf/config.yml
COPY tests/integration/hitch-varnish/platform/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 80 443
CMD ["/entrypoint.sh"]

View File

@ -0,0 +1,120 @@
#!/usr/bin/env bash
# =============================================================================
# Entrypoint — stack hitch + varnish + backend HTTP + ja4ebpf
# Ordre : backend → varnish → hitch → ja4ebpf
# =============================================================================
set -eo pipefail
log() { echo "[entrypoint:hitch-varnish] $(date +%H:%M:%S) $*"; }
BACKEND_PID="" VARNISH_PID="" HITCH_PID="" JA4EBPF_PID=""
cleanup() {
log "Arrêt des processus…"
for pid in "$JA4EBPF_PID" "$HITCH_PID" "$VARNISH_PID" "$BACKEND_PID"; do
[ -n "$pid" ] && kill "$pid" 2>/dev/null || true
done
wait 2>/dev/null || true
}
trap cleanup EXIT SIGTERM SIGINT
# ── 1. Backend HTTP simple (port 8080) ────────────────────────────────────────
log "Démarrage du backend HTTP (port 8080)…"
python3 -c "
import http.server, socketserver, json
class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a): pass
def do_GET(self):
body = json.dumps({'status':'ok','backend':'hitch-varnish','path':self.path}).encode()
self.send_response(200)
self.send_header('Content-Type','application/json')
self.send_header('Content-Length', len(body))
self.end_headers()
self.wfile.write(body)
def do_POST(self):
n = int(self.headers.get('Content-Length',0))
self.rfile.read(n)
body = b'{\"result\":\"accepted\"}'
self.send_response(200)
self.send_header('Content-Type','application/json')
self.send_header('Content-Length', len(body))
self.end_headers()
self.wfile.write(body)
with socketserver.TCPServer(('127.0.0.1', 8080), H) as s:
s.serve_forever()
" &
BACKEND_PID=$!
sleep 1
log "Backend démarré (PID $BACKEND_PID)"
# ── 2. Démarrage de Varnish (port 6081, avec PROXY protocol activé) ───────────
# L'option "-a 127.0.0.1:6081,PROXY" indique à Varnish d'accepter le PROXY header
# envoyé par hitch pour récupérer la vraie IP du client.
log "Démarrage de Varnish (port 6081, PROXY protocol)…"
varnishd \
-F \
-f /etc/varnish/default.vcl \
-a "127.0.0.1:6081,PROXY" \
-s malloc,64m \
-T 127.0.0.1:6082 &
VARNISH_PID=$!
for i in $(seq 1 30); do
if varnishadm -T 127.0.0.1:6082 status 2>/dev/null | grep -q "Child in state running"; then
log "Varnish opérationnel (PID $VARNISH_PID)"; break
fi
sleep 0.5
done
# ── 3. Démarrage de hitch (port 443) ──────────────────────────────────────────
log "Démarrage de hitch (port 443, TLS + PROXY protocol)…"
hitch --config=/etc/hitch/hitch.conf &
HITCH_PID=$!
# Attendre que hitch soit opérationnel (accepte les connexions TLS)
for i in $(seq 1 20); do
if curl -skf https://127.0.0.1/health >/dev/null 2>&1; then
log "hitch opérationnel (PID $HITCH_PID)"; break
fi
sleep 0.5
done
# Exposition d'un port HTTP 80 simple pour le healthcheck Docker
# (hitch gère uniquement HTTPS — on ajoute un mini-serveur HTTP pour /health)
python3 -c "
import http.server, socketserver, json
class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a): pass
def do_GET(self):
body = json.dumps({'status':'ok','stack':'hitch-varnish'}).encode()
self.send_response(200)
self.send_header('Content-Type','application/json')
self.send_header('Content-Length',len(body))
self.end_headers()
self.wfile.write(body)
with socketserver.TCPServer(('0.0.0.0',80), H) as s:
s.serve_forever()
" &
# ── 4. Démarrage de ja4ebpf ───────────────────────────────────────────────────
log "Démarrage de ja4ebpf (uprobes hitch/libssl + hook TC eth0)…"
ja4ebpf -config /etc/ja4ebpf/config.yml &
JA4EBPF_PID=$!
log "Stack complète — backend=$BACKEND_PID varnish=$VARNISH_PID hitch=$HITCH_PID ja4ebpf=$JA4EBPF_PID"
# ── 5. Supervision ────────────────────────────────────────────────────────────
while true; do
for pid_var in BACKEND_PID VARNISH_PID HITCH_PID JA4EBPF_PID; do
pid="${!pid_var}"
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then
log "$pid_var (PID $pid) s'est arrêté — fin"
exit 1
fi
done
sleep 2
done

View File

@ -0,0 +1,33 @@
# hitch.conf — TLS offloader hitch
# Terminaison TLS sur port 443, transmission à Varnish (port 6081) via PROXY protocol.
# Le PROXY protocol permet à Varnish de connaître la vraie IP source du client.
# Réf: https://hitch-tls.org/
# Adresse et port d'écoute TLS
frontend = "[*]:443"
# Backend Varnish (HTTP cleartext + PROXY protocol header)
backend = "[127.0.0.1]:6081"
# Fichier PEM : clé privée + certificat (concaténés)
pem-file = "/etc/hitch/hitch.pem"
# Activation du PROXY protocol v1 (texte) vers le backend
write-proxy-v1 = on
# Protocoles TLS acceptés
tls-protos = TLSv1.2 TLSv1.3
# Suites de chiffrement variées pour générer des JA4 distincts
ciphers = "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256"
# ALPN : activer h2 pour HTTP/2 (si Varnish supporte)
alpn-protos = "h2,http/1.1"
# Nombre de workers (= nombre de cœurs pour les tests)
workers = 2
# Répertoire de travail
daemon = off
log-level = 1
syslog = off

View File

@ -0,0 +1,41 @@
# Configuration ja4ebpf — stack hitch + varnish
#
# Architecture TLS : hitch est le seul processus qui fait SSL_read.
# Il lie libssl.so.3 dynamiquement (package openssl sur Rocky Linux 9).
# ja4ebpf attache son uprobe sur libssl.so.3 pour capturer les données
# déchiffrées que hitch transmet à Varnish via PROXY protocol.
#
# Différence clé vs nginx :
# - Le processus qui appelle SSL_read est /usr/sbin/hitch (pas nginx)
# - Le PROXY protocol header est dans le flux cleartext hitch→varnish,
# pas dans les données capturées par SSL_read
# - src_ip est récupérée via le hook TC (TCP SYN du client vers hitch:443)
interface: eth0
ssl_probes:
# hitch lie libssl.so.3 de Rocky Linux 9.
# On peut aussi essayer directement le binaire hitch si OpenSSL est statique.
- executable: /usr/lib64/libssl.so.3
symbol: SSL_read
# Fallback : hitch peut lier une version différente selon le packaging
- executable: /usr/sbin/hitch
symbol: SSL_read
clickhouse:
addr: "clickhouse:9000"
database: "ja4_logs"
table: "http_logs_raw"
username: "default"
password: ""
tls: false
batch_size: 100
flush_every: "1s"
timeouts:
session_expiry: "500ms"
slowloris: "10s"
log:
level: "info"
format: "json"

View File

@ -0,0 +1,55 @@
vcl 4.1;
# =============================================================================
# varnish.vcl — Stack hitch + varnish
# Varnish reçoit le trafic de hitch avec le PROXY protocol header.
# accept_from est limité à 127.0.0.1 (hitch tourne en local).
# =============================================================================
# Activation du PROXY protocol : Varnish récupère la vraie IP client depuis
# le header PROXY envoyé par hitch.
# (configuré via -a "...PROXY" dans la ligne de commande varnishd)
backend default {
.host = "127.0.0.1";
.port = "8080";
.probe = {
.url = "/health";
.interval = 5s;
.timeout = 2s;
.window = 3;
.threshold = 2;
}
}
sub vcl_recv {
# Normalisation URL
if (req.url ~ "//") {
set req.url = regsuball(req.url, "//+", "/");
}
# Ne pas cacher les mutations
if (req.method != "GET" && req.method != "HEAD") {
return (pass);
}
return (hash);
}
sub vcl_backend_response {
set beresp.ttl = 5s;
set beresp.grace = 10s;
}
sub vcl_deliver {
# En-têtes de debug pour les tests
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
# Indique que Varnish a traité la requête (vérifiable dans les tests)
set resp.http.Via = "1.1 varnish (Varnish/hitch-varnish-test)";
# Expose l'IP client vue par Varnish (après PROXY protocol de hitch)
set resp.http.X-Client-IP = client.ip;
return (deliver);
}

View File

@ -0,0 +1,102 @@
#!/usr/bin/env bash
# =============================================================================
# run-tests.sh — Tests d'intégration stack hitch + varnish + ja4ebpf
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export STACK_NAME="hitch-varnish"
export COMPOSE_FILE="$SCRIPT_DIR/docker-compose.yml"
for arg in "$@"; do
case "$arg" in
--no-down) export KEEP_UP=true ;;
--build-only) export BUILD_ONLY=true ;;
esac
done
source "$SCRIPT_DIR/../lib/run-stack-tests.sh"
# ── Vérifications spécifiques hitch+varnish ───────────────────────────────────
stack_verify_extra() {
# Vérifie que hitch est bien en cours d'exécution
local hitch_pid
hitch_pid=$(docker compose -f "$COMPOSE_FILE" exec -T platform \
pgrep -x hitch 2>/dev/null | head -1 || echo "")
[ -n "$hitch_pid" ] && pass "Processus hitch actif (PID $hitch_pid)" \
|| fail "Processus hitch introuvable"
# Vérifie Varnish
local varnish_pid
varnish_pid=$(docker compose -f "$COMPOSE_FILE" exec -T platform \
pgrep -x varnishd 2>/dev/null | head -1 || echo "")
[ -n "$varnish_pid" ] && pass "Processus varnishd actif (PID $varnish_pid)" \
|| fail "Processus varnishd introuvable"
# Vérifie que ja4ebpf tourne
local ja4_pid
ja4_pid=$(docker compose -f "$COMPOSE_FILE" exec -T platform \
pgrep -x ja4ebpf 2>/dev/null | head -1 || echo "")
[ -n "$ja4_pid" ] && pass "ja4ebpf actif (PID $ja4_pid)" \
|| fail "ja4ebpf introuvable"
# Vérifie la présence du header Via Varnish (trafic bien routé hitch→varnish)
local via_hdr
via_hdr=$(docker compose -f "$COMPOSE_FILE" exec -T platform \
curl -skI https://localhost/ 2>/dev/null | grep -i "^Via:" | tr -d '\r' || echo "")
if echo "$via_hdr" | grep -qi "varnish"; then
pass "Header Via: varnish — trafic routé hitch→Varnish→backend"
else
warn "Header Via varnish absent ('$via_hdr')"
fi
# Vérifie X-Client-IP : doit être non-vide (Varnish récupère l'IP via PROXY protocol)
local client_ip_hdr
client_ip_hdr=$(docker compose -f "$COMPOSE_FILE" exec -T platform \
curl -skI https://localhost/ 2>/dev/null | grep -i "^X-Client-IP:" | tr -d '\r' || echo "")
if [ -n "$client_ip_hdr" ]; then
pass "PROXY protocol actif : X-Client-IP visible ('$client_ip_hdr')"
else
warn "X-Client-IP absent — PROXY protocol peut-être désactivé dans Varnish"
fi
# Vérifie ALPN h2 côté hitch (hitch supporte HTTP/2 via ALPN)
local http_ver
http_ver=$(docker compose -f "$COMPOSE_FILE" exec -T platform \
curl -sk --http2 -w "%{http_version}" -o /dev/null https://localhost/ 2>/dev/null || echo "")
if [ "$http_ver" = "2" ]; then
pass "HTTP/2 ALPN négocié par hitch (h2)"
else
warn "HTTP/2 non négocié (version: '$http_ver') — ALPN hitch peut nécessiter Varnish ≥ 6.0"
fi
# Vérification clé : dans la stack hitch+varnish, les uprobes sont sur hitch.
# ja4ebpf doit avoir capturé des requêtes depuis le processus hitch.
# On vérifie que des lignes avec method != '' existent (uprobe SSL_read actif).
local l7_from_hitch
l7_from_hitch=$(ch_query "SELECT count() FROM ja4_logs.http_logs_raw WHERE method != ''")
if [ "${l7_from_hitch:-0}" -gt 0 ] 2>/dev/null; then
pass "L7 capturé via uprobe hitch : $l7_from_hitch requêtes HTTP"
else
warn "Aucune requête L7 — uprobe hitch/libssl peut-être non attaché"
log " Vérifier : les uprobes nécessitent que hitch soit compilé avec des symboles"
log " Debug : docker compose exec platform ja4ebpf -config /etc/ja4ebpf/config.yml --dry-run"
fi
# Vérifie que le fingerprint JA4 est cohérent avec la config TLS de hitch
# (TLSv1.2 + TLSv1.3, suites ECDHE, ALPN h2+http/1.1)
local ja4_sample
ja4_sample=$(ch_query "SELECT ja4 FROM ja4_logs.http_logs_raw WHERE ja4 != '' LIMIT 1" 2>/dev/null || echo "")
if [ -n "$ja4_sample" ]; then
# JA4 format : t{ver}{sni}{cc}{ec}_{hash}_{hash}
# Avec TLS 1.3 négocié via hitch → doit commencer par tt13
if echo "$ja4_sample" | grep -qE "^tt1[23]"; then
pass "JA4 cohérent avec config hitch TLS 1.2/1.3 : $ja4_sample"
else
warn "JA4 inattendu pour hitch TLS config : $ja4_sample"
fi
fi
}
run_all_phases