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
@@ -0,0 +1,75 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/ingress"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registerUserRoute("GET /api/v1/ingress", func(s *Server) http.HandlerFunc { return s.ingressAPI })
|
||||
}
|
||||
|
||||
type ingressOut struct {
|
||||
Hosts []string `json:"hosts"`
|
||||
ingress.Report
|
||||
}
|
||||
|
||||
// ingressAPI: GET /api/v1/ingress?range=24h&host=all|<name>[,<name>]. The
|
||||
// firewall telemetry of the hosts that send it: exact totals from the host kit
|
||||
// counters, the details (ports, origins, banned share) from its sampled log.
|
||||
// Only the probes of this hub are covered (the telemetry is not relayed to
|
||||
// peers).
|
||||
func (s *Server) ingressAPI(w http.ResponseWriter, r *http.Request) {
|
||||
rg, ok := s.rangeOf(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
host := strings.TrimSpace(r.URL.Query().Get("host"))
|
||||
if len(host) > 64*maxHostSel {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "bad host"})
|
||||
return
|
||||
}
|
||||
var all []string
|
||||
if s.opt.Nodes != nil {
|
||||
all = s.opt.Nodes.Hosts()
|
||||
}
|
||||
var names []string
|
||||
switch host {
|
||||
case "", "all":
|
||||
names = all
|
||||
default:
|
||||
for _, n := range strings.Split(host, ",") {
|
||||
n = strings.TrimSpace(n)
|
||||
if n == "" {
|
||||
continue
|
||||
}
|
||||
if !contains(all, n) {
|
||||
writeJSON(w, http.StatusNotFound, map[string]string{"error": "unknown host"})
|
||||
return
|
||||
}
|
||||
names = append(names, n)
|
||||
}
|
||||
}
|
||||
aggs := make([]*ingress.Agg, 0, len(names))
|
||||
for _, n := range names {
|
||||
if a := s.opt.Nodes.Ingress(n); a != nil {
|
||||
aggs = append(aggs, a)
|
||||
}
|
||||
}
|
||||
from, to := rg.Bounds(s.opt.Store.Now().Unix())
|
||||
if names == nil {
|
||||
names = []string{}
|
||||
}
|
||||
writeJSON(w, 200, ingressOut{Hosts: names, Report: ingress.ReportOf(aggs, from, to)})
|
||||
}
|
||||
|
||||
func contains(l []string, s string) bool {
|
||||
for _, x := range l {
|
||||
if x == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user