Files
ja4-platform/tests/integration/nginx/platform/entrypoint.sh
Jacquin Antoine 742f4420c0 fix(test): add ClickHouse readiness check before starting ja4ebpf
Fixed race condition where ja4ebpf would fail to connect to
ClickHouse at startup because ClickHouse HTTP port wasn't ready yet,
even though Docker healthcheck passed.

Changes:
- Add 30s wait loop with ClickHouse /ping endpoint check
- Log success message when ClickHouse is ready
- Applied to all 4 stacks: nginx, apache, nginx-varnish, hitch-varnish

Test results after fix:
- nginx: 240 rows, 175 JA4 fingerprints 
- apache: 257 rows, 191 JA4 fingerprints 
- nginx-varnish: 298 rows, 242 JA4 fingerprints 
- hitch-varnish: 247 rows, 177 JA4 fingerprints 

All L3/L4 metadata (TTL, MSS, Window), TLS fingerprinting (JA4, SNI),
and HTTP layer data are correctly captured and persisted.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-19 15:11:22 +02:00

81 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================================
# Entrypoint — stack nginx + ja4ebpf
# Ordre : nginx → ja4ebpf (uprobes sur nginx/libssl)
# =============================================================================
set -eo pipefail
log() { echo "[entrypoint:nginx] $(date +%H:%M:%S) $*"; }
NGINX_PID=""
JA4EBPF_PID=""
cleanup() {
log "Arrêt des processus…"
[ -n "$JA4EBPF_PID" ] && kill "$JA4EBPF_PID" 2>/dev/null || true
[ -n "$NGINX_PID" ] && kill "$NGINX_PID" 2>/dev/null || true
wait 2>/dev/null || true
}
trap cleanup EXIT SIGTERM SIGINT
# ── 1. Démarrage de nginx ─────────────────────────────────────────────────
log "Démarrage de nginx…"
nginx
NGINX_PID=$(cat /run/nginx/nginx.pid 2>/dev/null || pgrep nginx | head -1)
# Attendre que nginx soit opérationnel
for i in $(seq 1 20); do
if curl -sf http://localhost/health >/dev/null 2>&1; then
log "nginx opérationnel (PID $NGINX_PID)"
break
fi
sleep 0.5
done
# ── 2. Démarrage de ja4ebpf ───────────────────────────────────────────────
# Attendre que ClickHouse soit prêt (connection refused possible sinon)
log "Attente de ClickHouse (max 30s)…"
for i in $(seq 1 30); do
if curl -sf http://clickhouse:8123/ping >/dev/null 2>&1; then
log "ClickHouse est prêt (http://clickhouse:8123/ping OK)"
break
fi
if [ $i -eq 30 ]; then
log "⚠ ClickHouse toujours pas prêt après 30s, démarrage ja4ebpf quand même"
fi
sleep 1
done
log "Démarrage de ja4ebpf (attache uprobes sur libssl)…"
ja4ebpf -config /etc/ja4ebpf/config.yml &
JA4EBPF_PID=$!
log "Stack démarrée — nginx PID=$NGINX_PID ja4ebpf PID=$JA4EBPF_PID"
# Laisser ja4ebpf 3s pour détecter un échec immédiat (ex: verifier eBPF)
sleep 3
if ! kill -0 "$JA4EBPF_PID" 2>/dev/null; then
log "⚠ ja4ebpf s'est arrêté immédiatement — mode dégradé (web server seul)"
JA4EBPF_PID=""
fi
# ── 3. Supervision ────────────────────────────────────────────────────────
# nginx fonctionne en daemon : surveiller le process master via le PID file.
# ja4ebpf tourne en foreground (optionnel : ne pas quitter s'il s'arrête).
while true; do
# Vérifier que nginx est toujours en vie
if ! kill -0 "$NGINX_PID" 2>/dev/null; then
NGINX_PID=$(cat /run/nginx/nginx.pid 2>/dev/null || echo "")
if [ -z "$NGINX_PID" ] || ! kill -0 "$NGINX_PID" 2>/dev/null; then
log "nginx s'est arrêté — fin de l'entrypoint"
break
fi
fi
# ja4ebpf est optionnel : loguer si arrêté mais ne pas quitter
if [ -n "$JA4EBPF_PID" ] && ! kill -0 "$JA4EBPF_PID" 2>/dev/null; then
log "⚠ ja4ebpf s'est arrêté — web server continue sans collecte eBPF"
JA4EBPF_PID=""
fi
sleep 2
done