Files
Lucas RayanandClaude Sonnet 5.5 aefdcea8d2 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>
2026-11-23 09:09:16 -03:00

109 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Local verification: runs the same checks as CI before pushing. Anything the
# machine lacks (go, node, docker, govulncheck) is skipped with a warning.
#
# scripts/check.sh fast: gofmt, go vet, i18n, scripts, workflows, compose
# scripts/check.sh --full also runs go test -race and govulncheck
# scripts/check.sh --ui also renders every route and fails on horizontal overflow
# (needs Chrome and puppeteer-core; skipped when missing)
#
# CI takes minutes per run; almost everything that breaks it is caught here
# in seconds.
set -uo pipefail
cd "$(dirname "$0")/.."
full=0
ui=0
for a in "$@"; do
[ "$a" = "--full" ] && full=1
[ "$a" = "--ui" ] && ui=1
done
failures=()
step() { # step "name" command...
local name="$1"; shift
printf '\n\033[1m== %s\033[0m\n' "$name"
if "$@"; then printf '\033[32mok\033[0m %s\n' "$name"; else printf '\033[31mFAILED\033[0m %s\n' "$name"; failures+=("$name"); fi
}
skip() { printf '\n\033[33mskipped\033[0m %s (%s)\n' "$1" "$2"; }
if command -v go >/dev/null; then
step "formatting (gofmt)" bash -c 'out=$(gofmt -l .); [ -z "$out" ] || { echo "$out"; exit 1; }'
step "go vet" go vet ./...
else
skip "gofmt and go vet" "go not installed"
fi
if command -v node >/dev/null; then
step "UI translation coverage" node scripts/check-ui-i18n.mjs
else
skip "UI translation coverage" "node not installed"
fi
if [ "$ui" = 1 ]; then
if command -v go >/dev/null && command -v node >/dev/null; then
bin="$(mktemp -d)/urutau"
if go build -o "$bin" ./cmd/urutau; then step "UI layout (no horizontal overflow)" node scripts/ui-overflow.mjs "$bin"; else skip "UI layout" "build failed"; fi
else
skip "UI layout" "go or node not installed"
fi
fi
step "bash script syntax" bash -c 'for f in scripts/*.sh .githooks/*; do bash -n "$f" || exit 1; done'
step "host kit shell syntax" bash -c 'for f in deploy/host/install.sh deploy/host/urutau-ingress-tick deploy/host/urutau-containers-map deploy/host/urutau-containers-watch deploy/host/urutau-unban; do sh -n "$f" || exit 1; done'
# nftables syntax of the host kit tables, validated in a throwaway network
# namespace (no root needed); skipped when nft or unshare cannot do it.
if command -v nft >/dev/null && unshare -rn true 2>/dev/null; then
step "host kit nftables syntax" bash -c 'for f in deploy/host/urutau-egress.nft deploy/host/urutau-ingress.nft; do
t=$(mktemp); sed "s/@WAN@/eth0/g" "$f" > "$t"
unshare -rn nft -c -f "$t" || { rm -f "$t"; exit 1; }
rm -f "$t"
# the observation table must never decide the fate of a packet
if [ "$f" = deploy/host/urutau-ingress.nft ] && grep -Eq "^[^#]*[[:space:]](drop|accept|reject|queue|dnat|snat|masquerade|redirect|ct mark set|meta mark set)([[:space:]]|$)" "$f"; then
echo "$f: the ingress table must only count and log" >&2; exit 1
fi
done'
else
skip "host kit nftables syntax" "nft or unprivileged namespaces not available"
fi
if python3 -c 'import yaml' 2>/dev/null; then
step "workflows and templates (valid YAML)" python3 -c "
import glob, yaml
for f in glob.glob('.gitea/**/*.yml', recursive=True):
yaml.safe_load(open(f))
"
else
skip "workflows and templates (valid YAML)" "PyYAML missing: pip install pyyaml"
fi
step "docs links" python3 scripts/check-docs-links.py
step "brand assets" test -s logo.png
if command -v docker >/dev/null && docker compose version >/dev/null 2>&1; then
step "docker compose config (hub)" docker compose config --quiet
step "docker compose config (probe)" env URUTAU_HUB=https://hub.example.org URUTAU_PROBE_NAME=check docker compose -f deploy/probe/docker-compose.yml config --quiet
else
skip "docker compose config" "docker compose not available"
fi
if [ "$full" = 1 ]; then
if command -v go >/dev/null; then
step "tests (go test -race)" go test -race ./...
if command -v govulncheck >/dev/null; then
step "dependency audit (govulncheck)" govulncheck ./...
else
skip "govulncheck" "install: go install golang.org/x/vuln/cmd/govulncheck@latest"
fi
else
skip "tests and govulncheck" "go not installed"
fi
fi
printf '\n'
if [ ${#failures[@]} -eq 0 ]; then
printf '\033[32mall checks passed\033[0m: ready to push.\n'
else
printf '\033[31mfailed:\033[0m %s\n' "${failures[*]}"
exit 1
fi