feat(ingress): firewall telemetry of inbound attempts (host kit --ingress)
Observation-only nftables table (prerouting -150, counters and a rate-limited log, never drops or modifies), a per-minute counters file, probe sources ingress and ingresscnt, a per-host hourly aggregate in the hub (exact totals, sampled ports/ASNs/countries, banned share by the hub's own ban state, no ban feedback loop), GET /api/v1/ingress, a Defense section, doctor check, docs EN/pt-BR and tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4143bf599e
commit
aefdcea8d2
40 files changed
+1684
-11
No files matched your search
+28
-1
@@ -4,6 +4,7 @@
|
||||
#
|
||||
# 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 --ingress # also the inbound observation (firewall telemetry)
|
||||
# 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
|
||||
@@ -13,6 +14,13 @@
|
||||
# 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.
|
||||
#
|
||||
# --ingress adds an nftables table that only counts, and logs a sample of, the new
|
||||
# inbound connection attempts reaching the host (it never drops or changes a
|
||||
# packet), a timer that writes the exact counters to /var/log/urutau/ingress.counters
|
||||
# and an rsyslog rule for /var/log/urutau/ingress.log. It is separate from
|
||||
# --enforce on purpose (observing is not blocking); combine them freely, and
|
||||
# re-run without it to leave it as is, or use --remove to undo.
|
||||
#
|
||||
# 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
|
||||
@@ -21,11 +29,13 @@ uid=${URUTAU_UID:-10001}
|
||||
|
||||
probe=0
|
||||
enforce=0
|
||||
ingress=0
|
||||
remove=0
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--probe) probe=1 ;;
|
||||
--enforce) enforce=1 ;;
|
||||
--ingress) ingress=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 ;;
|
||||
@@ -35,7 +45,9 @@ done
|
||||
[ "$(id -u)" = 0 ] || { echo "run as root" >&2; exit 1; }
|
||||
|
||||
if [ "$remove" = 1 ]; then
|
||||
systemctl disable --now urutau-egress.service urutau-containers-watch.service urutau-containers-map.timer urutau-logrotate.timer urutau-unban.path 2>/dev/null || true
|
||||
systemctl disable --now urutau-ingress.service urutau-ingress-tick.timer urutau-egress.service urutau-containers-watch.service urutau-containers-map.timer urutau-logrotate.timer urutau-unban.path 2>/dev/null || true
|
||||
rm -f /etc/systemd/system/urutau-ingress.service /etc/systemd/system/urutau-ingress-tick.service \
|
||||
/etc/systemd/system/urutau-ingress-tick.timer /usr/local/sbin/urutau-ingress-tick /etc/rsyslog.d/42-urutau-ingress.conf
|
||||
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/systemd/system/urutau-containers-watch.service /usr/local/sbin/urutau-containers-watch \
|
||||
@@ -75,6 +87,21 @@ systemctl start urutau-containers-map.service urutau-containers-map.timer
|
||||
systemctl restart urutau-containers-watch.service
|
||||
echo "egress logging on $wan: /var/log/urutau/egress.log, map: /var/log/urutau/containers.map"
|
||||
|
||||
if [ "$ingress" = 1 ]; then
|
||||
sed "s/@WAN@/$wan/g" "$here/urutau-ingress.nft" > /etc/urutau/ingress.nft
|
||||
nft -c -f /etc/urutau/ingress.nft
|
||||
install -m 0644 "$here/42-urutau-ingress.conf" /etc/rsyslog.d/42-urutau-ingress.conf
|
||||
install -m 0755 "$here/urutau-ingress-tick" /usr/local/sbin/urutau-ingress-tick
|
||||
install -m 0644 "$here/urutau-ingress.service" "$here/urutau-ingress-tick.service" "$here/urutau-ingress-tick.timer" /etc/systemd/system/
|
||||
[ -e /var/log/urutau/ingress.counters ] || install -m 0640 -o syslog -g adm /dev/null /var/log/urutau/ingress.counters 2>/dev/null || install -m 0640 -g adm /dev/null /var/log/urutau/ingress.counters
|
||||
systemctl daemon-reload
|
||||
systemctl restart rsyslog
|
||||
systemctl enable urutau-ingress.service urutau-ingress-tick.timer >/dev/null
|
||||
systemctl restart urutau-ingress.service
|
||||
systemctl start urutau-ingress-tick.timer
|
||||
echo "inbound observation on $wan: /var/log/urutau/ingress.log (sample), /var/log/urutau/ingress.counters (exact)"
|
||||
fi
|
||||
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user