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,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);
}