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>
103 lines
5.2 KiB
Bash
103 lines
5.2 KiB
Bash
#!/bin/sh
|
|
# Urutau host kit: egress logging (nftables + rsyslog), the container map and,
|
|
# optionally, the fail2ban jail of the "second firewall".
|
|
#
|
|
# sudo sh install.sh # egress logging + container map
|
|
# sudo sh install.sh --enforce # also the fail2ban jail for URUTAU_ENFORCE=on
|
|
# sudo sh install.sh --probe # a probe host: the kit above, no hub on this machine
|
|
# sudo sh install.sh --probe --enforce # probe host that also applies the hub's bans
|
|
# sudo sh install.sh --remove # undo everything
|
|
#
|
|
# --probe is for servers that run only the Urutau probe (deploy/probe): the
|
|
# probe dials out to the hub, so nothing here opens or needs a port. It also
|
|
# prepares /var/log/urutau-enforce (owned by the probe's uid) so the probe can
|
|
# append the hub's decisions; the fail2ban jail still needs --enforce.
|
|
#
|
|
# Idempotent. Urutau itself never gets privileges: it only reads these logs and
|
|
# writes its ban decisions to /var/log/urutau-enforce/decisions.log.
|
|
set -eu
|
|
here=$(cd "$(dirname "$0")" && pwd)
|
|
uid=${URUTAU_UID:-10001}
|
|
|
|
probe=0
|
|
enforce=0
|
|
remove=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--probe) probe=1 ;;
|
|
--enforce) enforce=1 ;;
|
|
--remove) remove=1 ;;
|
|
-h | --help) awk 'NR > 1 { if (!/^#/) exit; sub(/^# ?/, ""); print }' "$0"; exit 0 ;;
|
|
*) echo "unknown option: $arg (see --help)" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
[ "$(id -u)" = 0 ] || { echo "run as root" >&2; exit 1; }
|
|
|
|
if [ "$remove" = 1 ]; then
|
|
systemctl disable --now urutau-egress.service urutau-containers-map.timer urutau-logrotate.timer urutau-unban.path 2>/dev/null || true
|
|
rm -f /etc/systemd/system/urutau-egress.service /etc/systemd/system/urutau-containers-map.service \
|
|
/etc/systemd/system/urutau-containers-map.timer /usr/local/sbin/urutau-containers-map \
|
|
/etc/rsyslog.d/41-urutau-egress.conf /etc/logrotate.d/urutau-egress \
|
|
/etc/fail2ban/jail.d/urutau.local /etc/fail2ban/filter.d/urutau.conf /etc/fail2ban/action.d/urutau-allports.conf \
|
|
/etc/systemd/system/urutau-logrotate.service /etc/systemd/system/urutau-logrotate.timer \
|
|
/etc/systemd/system/urutau-unban.path /etc/systemd/system/urutau-unban.service /usr/local/sbin/urutau-unban
|
|
rm -rf /etc/urutau
|
|
systemctl daemon-reload
|
|
systemctl restart rsyslog
|
|
fail2ban-client reload >/dev/null 2>&1 || true
|
|
echo "removed (logs under /var/log/urutau kept)"
|
|
exit 0
|
|
fi
|
|
|
|
wan=${URUTAU_WAN:-$(ip -o route get 1.1.1.1 | sed -n 's/.* dev \([^ ]*\).*/\1/p')}
|
|
[ -n "$wan" ] || { echo "cannot detect the uplink interface; set URUTAU_WAN" >&2; exit 1; }
|
|
case "$wan" in *[!A-Za-z0-9_.-]*) echo "bad interface name: $wan" >&2; exit 1 ;; esac
|
|
|
|
install -d -m 0750 -o syslog -g adm /var/log/urutau 2>/dev/null || install -d -m 0750 -g adm /var/log/urutau
|
|
install -d -m 0755 /etc/urutau
|
|
sed "s/@WAN@/$wan/g" "$here/urutau-egress.nft" > /etc/urutau/egress.nft
|
|
nft -c -f /etc/urutau/egress.nft
|
|
|
|
install -m 0644 "$here/41-urutau-egress.conf" /etc/rsyslog.d/41-urutau-egress.conf
|
|
install -m 0644 "$here/urutau.logrotate" /etc/logrotate.d/urutau-egress
|
|
install -m 0755 "$here/urutau-containers-map" /usr/local/sbin/urutau-containers-map
|
|
install -m 0644 "$here/urutau-egress.service" "$here/urutau-containers-map.service" \
|
|
"$here/urutau-containers-map.timer" "$here/urutau-logrotate.service" "$here/urutau-logrotate.timer" /etc/systemd/system/
|
|
systemctl daemon-reload
|
|
systemctl restart rsyslog
|
|
systemctl enable urutau-egress.service urutau-containers-map.timer urutau-logrotate.timer >/dev/null
|
|
systemctl start urutau-logrotate.timer
|
|
systemctl restart urutau-egress.service
|
|
systemctl start urutau-containers-map.service urutau-containers-map.timer
|
|
echo "egress logging on $wan: /var/log/urutau/egress.log, map: /var/log/urutau/containers.map"
|
|
|
|
if [ "$probe" = 1 ] && [ "$enforce" = 0 ]; then
|
|
# The probe appends the hub's decisions here even when the jail is not
|
|
# installed yet, so the files must exist and belong to the probe's uid.
|
|
install -d -m 0750 -o "$uid" -g adm /var/log/urutau-enforce
|
|
for f in decisions.log unban.log; do
|
|
[ -e "/var/log/urutau-enforce/$f" ] || install -m 0640 -o "$uid" -g adm /dev/null "/var/log/urutau-enforce/$f"
|
|
done
|
|
fi
|
|
|
|
if [ "$enforce" = 1 ]; then
|
|
install -d -m 0750 -o "$uid" -g adm /var/log/urutau-enforce
|
|
[ -e /var/log/urutau-enforce/decisions.log ] || install -m 0640 -o "$uid" -g adm /dev/null /var/log/urutau-enforce/decisions.log
|
|
install -m 0644 "$here/fail2ban-filter-urutau.conf" /etc/fail2ban/filter.d/urutau.conf
|
|
install -m 0644 "$here/fail2ban-action-urutau.conf" /etc/fail2ban/action.d/urutau-allports.conf
|
|
install -m 0644 "$here/fail2ban-jail-urutau.local" /etc/fail2ban/jail.d/urutau.local
|
|
[ -e /var/log/urutau-enforce/unban.log ] || install -m 0640 -o "$uid" -g adm /dev/null /var/log/urutau-enforce/unban.log
|
|
install -m 0755 "$here/urutau-unban" /usr/local/sbin/urutau-unban
|
|
install -m 0644 "$here/urutau-unban.path" "$here/urutau-unban.service" /etc/systemd/system/
|
|
systemctl daemon-reload
|
|
systemctl enable --now urutau-unban.path >/dev/null
|
|
fail2ban-client -t >/dev/null
|
|
fail2ban-client reload
|
|
echo "fail2ban jail 'urutau' on; the probe container mounts /var/log/urutau-enforce:/logs/enforce (rw)"
|
|
fi
|
|
|
|
if [ "$probe" = 1 ]; then
|
|
echo "probe host ready: create the probe on the hub (urutau probes create <name>) and start deploy/probe/docker-compose.yml"
|
|
fi
|