Each server runs an ultralight probe (scratch image, ~7 MiB RSS) that tails the logs, ships raw lines to the hub over HTTPS with an on-disk spool, and applies enforce decisions locally. The hub keeps one node per probe (primary node = the 1.x data dir, unchanged), does all analysis and serves the UI. Peer federation is removed. 'urutau import' brings 1.x data dirs in with hash and count verification. UI: probes page, host qualified incidents, IPs never wrap, egress heatmap labels, live and replay globes no longer auto-rotate, replay repeat, live traffic metrics. BREAKING CHANGE: URUTAU_PEERS, URUTAU_PEER_* and /api/v1/peer/* are gone; log path variables move from the hub to the probe. See docs/migration-2.0.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
142 lines
8.1 KiB
Bash
Executable File
142 lines
8.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regenerates the screenshots in docs/img from the real Urutau dashboard.
|
|
#
|
|
# Nothing in the pictures is real: scripts/screenshots/demo writes a DEMO geolocation
|
|
# database (MMDB, city + asn) that maps sub-ranges of the reserved documentation addresses
|
|
# (198.18.0.0/15, 203.0.113.0/24, 198.51.100.0/24, 192.0.2.0/24, 2001:db8::/32) to real
|
|
# cities, plus 30 days of synthetic Traefik / auth.log / fail2ban.log files for two servers
|
|
# (edge-1, edge-2) with domains under example.com/.org/.net. One hub (port 18880) and two
|
|
# probes (edge-1 and edge-2, which read the files and push them to the hub over loopback)
|
|
# serve them, new events keep arriving while the pages are captured (so the live map has
|
|
# arcs), and headless Chrome takes the pictures.
|
|
#
|
|
# scripts/screenshots.sh # writes docs/img
|
|
# OUT=/tmp/img scripts/screenshots.sh # writes elsewhere
|
|
#
|
|
# Variables: ONLY (comma list of page ids to capture), OUT, HUB_PORT (18880), LOGIN_PORT (18882), CHROME,
|
|
# PUPPETEER_CORE (default: newest Chrome in ~/.cache/puppeteer and puppeteer-core in
|
|
# ~/.claude/tools/node_modules). Needs go, node, curl, openssl and Chrome. No network use.
|
|
# Idempotent: it builds into a temporary directory, kills what it started (by PID) when done
|
|
# and overwrites the same file names. oxipng/pngquant are used when installed.
|
|
set -euo pipefail
|
|
|
|
root=$(cd "$(dirname "$0")/.." && pwd)
|
|
out=${OUT:-$root/docs/img}
|
|
hub_port=${HUB_PORT:-18880}
|
|
login_port=${LOGIN_PORT:-18882}
|
|
|
|
work=$(mktemp -d)
|
|
pids=()
|
|
cleanup() {
|
|
for p in "${pids[@]}"; do kill "$p" 2>/dev/null || true; done
|
|
for p in "${pids[@]}"; do wait "$p" 2>/dev/null || true; done
|
|
rm -rf "$work"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
for port in "$hub_port" "$login_port"; do
|
|
if curl -fsS -m 1 "http://127.0.0.1:$port/api/health" >/dev/null 2>&1; then
|
|
echo "port $port is already in use; stop that instance first" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
export TZ=UTC
|
|
# Hidden demo-only switch: reserved ranges count as public for the second firewall (see internal/enforce/policy.go).
|
|
export URUTAU_DEMO_RESERVED_PUBLIC=1
|
|
mkdir -p "$out" "$work/bin"
|
|
(cd "$root" && go build -trimpath -o "$work/bin/urutau" ./cmd/urutau && go build -o "$work/bin/demo" ./scripts/screenshots/demo)
|
|
urutau="$work/bin/urutau"
|
|
demo="$work/bin/demo"
|
|
|
|
# Demo geolocation base and logs (relative to "now").
|
|
"$demo" geo "$work/geo"
|
|
"$demo" logs "$work/hub/logs" edge-1 1
|
|
"$demo" logs "$work/peer/logs" edge-2 2
|
|
"$demo" egress "$work/hub/egress"
|
|
"$demo" check "$work"/hub/logs/* "$work"/peer/logs/* "$work"/hub/egress/* # fails on any IP outside the reserved ranges
|
|
|
|
# The hub reads no file. Probes edge-1 (the hub's own name, so its data lives in the
|
|
# data-dir root) and edge-2 are registered offline, before the hub starts, and each
|
|
# prints its token once.
|
|
mkdir -p "$work/hub/data"
|
|
probe_token() { # probe_token name: registers the probe and prints its urp_ token
|
|
"$urutau" probes create --data-dir "$work/hub/data" "$1" | grep -o 'urp_[A-Za-z0-9_-]\{43\}' | head -n1
|
|
}
|
|
tok1=$(probe_token edge-1)
|
|
tok2=$(probe_token edge-2)
|
|
[ -n "$tok1" ] && [ -n "$tok2" ] || { echo "could not create the demo probes (urutau probes create)" >&2; exit 1; }
|
|
|
|
"$urutau" serve --name edge-1 --bind "127.0.0.1:$hub_port" --data-dir "$work/hub/data" \
|
|
--geo-dir "$work/geo" --geo-update 0 --insecure-no-auth \
|
|
--enforce observe --egress on --egress-workloads "ciberlab=name:ciberlab:scanner" \
|
|
--location "50.1109,8.6821,edge-1" > "$work/hub.log" 2>&1 &
|
|
pids+=($!)
|
|
|
|
start_probe() { # start_probe name token dir [env...]
|
|
local name=$1 token=$2 dir=$3; shift 3
|
|
mkdir -p "$dir/state" "$dir/enforce"
|
|
env URUTAU_HUB="http://127.0.0.1:$hub_port" URUTAU_PROBE_NAME="$name" URUTAU_PROBE_TOKEN="$token" \
|
|
URUTAU_STATE_DIR="$dir/state" URUTAU_TRAEFIK_LOG="$dir/logs/access.log" URUTAU_AUTH_LOG="$dir/logs/auth.log" \
|
|
URUTAU_FAIL2BAN_LOG="$dir/logs/fail2ban.log" URUTAU_PROBE_LOG= URUTAU_EGRESS_LOG= URUTAU_EGRESS_CONTAINERS= URUTAU_RESOLV= \
|
|
URUTAU_ENFORCE_LOG="$dir/enforce/decisions.log" URUTAU_ENFORCE_UNBAN_LOG="$dir/enforce/unban.log" "$@" \
|
|
"$urutau" probe > "$dir.probe.log" 2>&1 &
|
|
pids+=($!)
|
|
}
|
|
# The hub must be answering before the probes dial it.
|
|
for _ in $(seq 1 150); do curl -fsS "http://127.0.0.1:$hub_port/api/health" >/dev/null 2>&1 && break; sleep 0.2; done
|
|
start_probe edge-1 "$tok1" "$work/hub" URUTAU_EGRESS_LOG="$work/hub/egress/egress.log" URUTAU_EGRESS_CONTAINERS="$work/hub/egress/containers.map"
|
|
start_probe edge-2 "$tok2" "$work/peer" URUTAU_LOCATION="39.0438,-77.4874,edge-2"
|
|
|
|
# A third, short-lived instance with authentication on, only for the login page.
|
|
mkdir -p "$work/login/data"
|
|
URUTAU_TOKEN=$(openssl rand -base64 48 | tr -d '\n') "$urutau" serve --name edge-1 \
|
|
--bind "127.0.0.1:$login_port" --data-dir "$work/login/data" \
|
|
--geo-dir "$work/geo" --geo-update 0 > "$work/login.log" 2>&1 &
|
|
pids+=($!)
|
|
|
|
for port in "$hub_port" "$login_port"; do
|
|
ok=0
|
|
for _ in $(seq 1 150); do
|
|
curl -fsS "http://127.0.0.1:$port/api/health" >/dev/null 2>&1 && { ok=1; break; }
|
|
sleep 0.2
|
|
done
|
|
[ "$ok" = 1 ] || { echo "instance on port $port did not start:" >&2; tail -20 "$work"/*.log "$work"/*/*.probe.log "$work"/*.probe.log >&2; exit 1; }
|
|
done
|
|
# wait until the hub has read the backfill (the request counter stops growing)
|
|
prev=-1
|
|
for _ in $(seq 1 240); do
|
|
n=$(curl -fsS "http://127.0.0.1:$hub_port/api/v1/summary?range=30d" 2>/dev/null | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{console.log(JSON.parse(s).totals.requests||0)}catch{console.log(0)}})' || echo 0)
|
|
[ "${n:-0}" -gt 1000 ] && [ "$n" = "$prev" ] && break
|
|
prev=$n
|
|
sleep 1
|
|
done
|
|
|
|
# Demo incident tickets (manual ones; the egress/enforce detections may add automatic ones).
|
|
inc() { curl -fsS -X "$1" -H 'Content-Type: application/json' -d "$3" "http://127.0.0.1:$hub_port/api/v1/incidents$2"; }
|
|
idof() { node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log(JSON.parse(s).id))'; }
|
|
i1=$(inc POST "" '{"title":"Multi-vector attacker 203.0.113.45 hitting edge-1","detail":"SSH brute force followed by web probing of /wp-login.php and /.env from the same address.","severity":"high","host":"edge-1","tags":["brute-force","web-probe"],"author":"ana"}' | idof)
|
|
inc POST "/$i1/comments" '{"text":"Confirmed in the replay: SSH password guessing, then the probe wave starts 40 minutes later.","author":"ana"}' >/dev/null
|
|
inc POST "/$i1/comments" '{"text":"Address added to the second firewall in observe mode; waiting for the next window before enforcing.","author":"bruno"}' >/dev/null
|
|
inc PATCH "/$i1" '{"status":"investigating","assignee":"ana","author":"ana"}' >/dev/null
|
|
i2=$(inc POST "" '{"title":"Unusual outbound connections from the scanner workload","detail":"The ciberlab scanner opened connections to many hosts on port 445.","severity":"medium","host":"edge-1","tags":["egress"],"author":"bruno"}' | idof)
|
|
inc PATCH "/$i2" '{"status":"true_positive","verdict":"Expected: scheduled scan of the lab range.","author":"bruno"}' >/dev/null
|
|
i3=$(inc POST "" '{"title":"Spike of 404s on example.org","detail":"A crawler walked a list of old URLs.","severity":"low","host":"edge-2","tags":["crawler"],"author":"ana"}' | idof)
|
|
inc PATCH "/$i3" '{"status":"false_positive","verdict":"Search engine crawler.","author":"ana"}' >/dev/null
|
|
inc POST "" '{"title":"Review the fail2ban ban time on edge-2","detail":"Repeat offenders return after the ban expires.","severity":"info","host":"edge-2","tags":["hardening"],"author":"bruno"}' >/dev/null
|
|
|
|
# New events keep arriving while the pages are captured.
|
|
"$demo" live 900 "$work/hub/logs:edge-1" "$work/peer/logs:edge-2" > "$work/live.log" 2>&1 &
|
|
pids+=($!)
|
|
sleep 6
|
|
|
|
if [ -n "${TABLES_ONLY:-}" ]; then
|
|
# mobile table check (375x812) instead of the documentation pictures: TABLES_ONLY=1 OUT=/tmp/x scripts/screenshots.sh
|
|
node "$root/scripts/screenshots/tables.mjs" "http://127.0.0.1:$hub_port" "$out"; exit $?
|
|
fi
|
|
node "$root/scripts/screenshots/shots.mjs" "http://127.0.0.1:$hub_port" "http://127.0.0.1:$login_port" "$out"
|
|
|
|
if command -v oxipng >/dev/null; then oxipng -q -o 3 --strip safe "$out"/*.png
|
|
elif command -v pngquant >/dev/null; then for f in "$out"/*.png; do pngquant --quality 90-100 --force --output "$f" "$f"; done; fi
|
|
echo "screenshots written to $out"
|