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:
Lucas RayanandClaude Sonnet 5.5 committed 2026-11-23 09:09:16 -03:00
1 parent 4143bf599e
commit aefdcea8d2
40 files changed
+1684 -11

No files matched your search

+125 -4
View File
@@ -126,7 +126,34 @@
'df.en.reason.port-scan': 'Scanning many network ports on the server',
'df.en.reason.known-attacker': 'Known attacker returning (hostile verdict)',
'df.en.reason.neighbor-campaign': 'Part of a campaign: several neighbours in the same network range were already banned',
'df.en.error': 'Could not load the second firewall data.'
'df.en.error': 'Could not load the second firewall data.',
'df.fw.title': 'Firewall: inbound attempts',
'df.fw.hint': 'New connection attempts that reached this host from the internet, counted by the firewall before any ban drops them. What a provider firewall (for example a cloud security list) blocks earlier never gets here.',
'df.fw.lead': '{n} inbound attempts {range}',
'df.fw.lead.sub': 'The totals are exact (counters of the host kit). Ports and origins come from a sample of {r} of them.',
'df.fw.kpi.total': 'Attempts',
'df.fw.kpi.total.sub': '{n} per hour on average',
'df.fw.kpi.closed': 'To closed ports',
'df.fw.kpi.closed.sub': '{n} to ports nothing serves',
'df.fw.kpi.banned': 'From banned sources',
'df.fw.kpi.banned.sub': 'about {n} attempts; estimated from the sample',
'df.fw.kpi.ratio': 'Sampled',
'df.fw.kpi.ratio.sub': '{n} logged attempts of the total',
'df.fw.hourly': 'Attempts per hour',
'df.fw.hourly.closed': 'Closed ports',
'df.fw.hourly.open': 'Served ports',
'df.fw.ports': 'Top destination ports',
'df.fw.ports.hint': 'Sampled. A red bar is a port this host does not serve.',
'df.fw.asns': 'Top origin networks',
'df.fw.asns.hint': 'Sampled, by the ASN of the source address.',
'df.fw.ccs': 'Top origin countries',
'df.fw.ccs.hint': 'Sampled, by the country of the source address.',
'df.fw.sampled': 'Sampled: these details cover about {r} of the attempts; the totals above are exact.',
'df.fw.banned.note': 'Banned means the source was in a jail (fail2ban or Urutau) when its attempt was logged. Those attempts are dropped by the firewall and never count as new evidence against the address.',
'df.fw.none': 'No inbound telemetry yet',
'df.fw.none.sub': 'Install the host kit with "sudo sh deploy/host/install.sh --ingress" and let the probe send ingress.log and ingress.counters.',
'df.fw.nodata': 'No attempts counted in this window',
'df.fw.error': 'Could not load the firewall data.'
},
'pt-BR': {
'df.title': 'Defesa',
@@ -243,7 +270,34 @@
'df.en.reason.port-scan': 'Varredura de muitas portas de rede do servidor',
'df.en.reason.known-attacker': 'Atacante conhecido voltando (veredito hostil)',
'df.en.reason.neighbor-campaign': 'Parte de uma campanha: vários vizinhos da mesma faixa de rede já foram banidos',
'df.en.error': 'Não foi possível carregar os dados do segundo firewall.'
'df.en.error': 'Não foi possível carregar os dados do segundo firewall.',
'df.fw.title': 'Firewall: tentativas de entrada',
'df.fw.hint': 'Tentativas novas de conexão que chegaram a este host pela internet, contadas pelo firewall antes de qualquer banimento descartá-las. O que um firewall do provedor (por exemplo uma lista de segurança na nuvem) barra antes nunca chega aqui.',
'df.fw.lead': '{n} tentativas de entrada {range}',
'df.fw.lead.sub': 'Os totais são exatos (contadores do kit do host). Portas e origens vêm de uma amostra de {r} delas.',
'df.fw.kpi.total': 'Tentativas',
'df.fw.kpi.total.sub': '{n} por hora em média',
'df.fw.kpi.closed': 'Para portas fechadas',
'df.fw.kpi.closed.sub': '{n} para portas em que nada escuta',
'df.fw.kpi.banned': 'De origens banidas',
'df.fw.kpi.banned.sub': 'cerca de {n} tentativas; estimado pela amostra',
'df.fw.kpi.ratio': 'Amostrado',
'df.fw.kpi.ratio.sub': '{n} tentativas registradas do total',
'df.fw.hourly': 'Tentativas por hora',
'df.fw.hourly.closed': 'Portas fechadas',
'df.fw.hourly.open': 'Portas com serviço',
'df.fw.ports': 'Portas de destino mais visadas',
'df.fw.ports.hint': 'Amostrado. Barra vermelha é uma porta que este host não serve.',
'df.fw.asns': 'Redes de origem mais frequentes',
'df.fw.asns.hint': 'Amostrado, pelo ASN do endereço de origem.',
'df.fw.ccs': 'Países de origem mais frequentes',
'df.fw.ccs.hint': 'Amostrado, pelo país do endereço de origem.',
'df.fw.sampled': 'Amostrado: estes detalhes cobrem cerca de {r} das tentativas; os totais acima são exatos.',
'df.fw.banned.note': 'Banida quer dizer que a origem estava numa jaula (fail2ban ou Urutau) quando a tentativa foi registrada. Essas tentativas são descartadas pelo firewall e nunca contam como nova evidência contra o endereço.',
'df.fw.none': 'Ainda sem telemetria de entrada',
'df.fw.none.sub': 'Instale o kit do host com "sudo sh deploy/host/install.sh --ingress" e deixe a sonda enviar ingress.log e ingress.counters.',
'df.fw.nodata': 'Nenhuma tentativa contada nesta janela',
'df.fw.error': 'Não foi possível carregar os dados do firewall.'
}
});
@@ -465,8 +519,75 @@
});
}
var fwData = null, fwSeq = 0, fwBox = null;
function ratioTxt(r) { var v = (r || 0) * 100; return (v > 0 && v < 10 ? v.toFixed(1) : Math.round(v)) + '%'; }
function paintFirewall() {
if (!fwBox) return;
clear(fwBox);
if (!fwData) return;
var d = fwData, tt = d.totals || {}, sm = d.sample || {}, range = U.rangeLabel({ inline: true });
var head = el('div', { class: 'df-en-head' });
head.appendChild(el('h2', { class: 'df-en-title' }, t('df.fw.title')));
head.appendChild(el('p', { class: 'hint' }, t('df.fw.hint')));
fwBox.appendChild(head);
if (!d.enabled) { fwBox.appendChild(U.ui.empty(t('df.fw.none'), t('df.fw.none.sub'))); return; }
if (!tt.attempts) { fwBox.appendChild(U.ui.empty(t('df.fw.nodata'))); return; }
fwBox.appendChild(U.ui.lead(t('df.fw.lead', { n: nf(tt.attempts), range: range }), t('df.fw.lead.sub', { r: ratioTxt(sm.ratio) }), 'info'));
var kp = el('div', { class: 'grid-12 df-kpis' });
function k(node) { node.classList.add('span-3'); kp.appendChild(node); }
k(U.ui.metric(t('df.fw.kpi.total'), nf(tt.attempts), { sub: t('df.fw.kpi.total.sub', { n: nf(Math.round(tt.per_hour || 0)) }) }));
k(U.ui.metric(t('df.fw.kpi.closed'), pctTxt(tt.closed_pct || 0), { sub: t('df.fw.kpi.closed.sub', { n: nf(tt.closed || 0) }) }));
k(U.ui.metric(t('df.fw.kpi.banned'), pctTxt(sm.banned_pct || 0), { sub: t('df.fw.kpi.banned.sub', { n: nf(sm.banned_est || 0) }), tone: (sm.banned_pct || 0) >= 50 ? 'warn' : 'neutral' }));
k(U.ui.metric(t('df.fw.kpi.ratio'), ratioTxt(sm.ratio), { sub: t('df.fw.kpi.ratio.sub', { n: nf(sm.logged || 0) }) }));
fwBox.appendChild(kp);
var grid = el('div', { class: 'grid-12' });
var hours = d.hourly || [];
var hp = U.ui.panel({ title: t('df.fw.hourly'), cls: 'span-12' });
if (U.charts && U.charts.stackedArea && hours.length) {
var step = 3600, start = hours[0].t, last = hours[hours.length - 1].t;
var n = Math.min(MAX_BUCKETS, Math.floor((last - start) / step) + 1);
if (n < 2) { n = 2; }
var cl = new Array(n).fill(0), op = new Array(n).fill(0);
hours.forEach(function (h) { var i = Math.round((h.t - start) / step); if (i >= 0 && i < n) { cl[i] += h.closed; op[i] += h.open; } });
hp.body.appendChild(U.charts.stackedArea([{ key: 'closed', label: t('df.fw.hourly.closed'), values: cl }, { key: 'open', label: t('df.fw.hourly.open'), values: op }], step, { start: start, title: t('df.fw.hourly') }));
} else hp.body.appendChild(U.ui.empty(t('df.fw.nodata')));
grid.appendChild(hp);
function barsPanel(title, hint, rows, cls) {
var p = U.ui.panel({ title: title, hint: hint, cls: cls });
if (!rows.length) p.body.appendChild(U.ui.empty(t('df.fw.nodata')));
else if (U.charts && U.charts.bars) p.body.appendChild(U.charts.bars(rows, { title: title, format: nf }));
grid.appendChild(p);
}
barsPanel(t('df.fw.ports'), t('df.fw.ports.hint'), (d.ports || []).slice(0, 10).map(function (p) {
return { key: p.proto + '/' + p.port, label: p.proto + '/' + p.port, value: p.n, color: p.served ? '--viz-1' : '--danger' };
}), 'span-4');
barsPanel(t('df.fw.asns'), t('df.fw.asns.hint'), (d.asns || []).slice(0, 10).map(function (a) {
return { key: a.asn, label: a.asn + (a.org ? ' ' + a.org : ''), value: a.n };
}), 'span-4');
barsPanel(t('df.fw.ccs'), t('df.fw.ccs.hint'), (d.countries || []).slice(0, 10).map(function (c) {
return { key: c.cc, label: (U.fmt.flag ? U.fmt.flag(c.cc) + ' ' : '') + c.cc, value: c.n };
}), 'span-4');
fwBox.appendChild(grid);
fwBox.appendChild(el('p', { class: 'hint' }, t('df.fw.sampled', { r: ratioTxt(sm.ratio) })));
fwBox.appendChild(el('p', { class: 'hint' }, t('df.fw.banned.note')));
}
function loadFirewall() {
var my = ++fwSeq;
U.api('/api/v1/ingress', Object.assign(U.rangeParams(), ctx && ctx.host && ctx.host !== 'all' ? { host: ctx.host } : {})).then(function (d) {
if (!alive || my !== fwSeq) return;
fwData = d; paintFirewall();
}).catch(function () {
if (!alive || my !== fwSeq || fwData || !fwBox) return;
clear(fwBox);
fwBox.appendChild(el('div', { class: 'state-error' }, el('strong', null, t('df.fw.error'))));
});
}
function load() {
loadEnforce();
loadFirewall();
var my = ++seq;
U.api('/api/v1/defense', Object.assign(U.rangeParams(), ctx && ctx.host && ctx.host !== 'all' ? { host: ctx.host } : {})).then(function (d) {
if (!alive || my !== seq) return;
@@ -481,10 +602,10 @@
U.registerPage({
id: 'defense', group: 'operate', titleKey: 'df.title',
icon: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M12 3l8 3v6c0 4.5-3.2 7.8-8 9-4.8-1.2-8-4.5-8-9V6z"/><path d="M9 12l2 2 4-4"/></svg>',
mount: function (node, cx) { root = el('div', { class: 'df-page' }); node.appendChild(root); enBox = el('div', { class: 'df-page df-en' }); node.appendChild(enBox); ctx = cx; alive = true; data = null; enData = null; paint(); load(); },
mount: function (node, cx) { root = el('div', { class: 'df-page' }); node.appendChild(root); enBox = el('div', { class: 'df-page df-en' }); node.appendChild(enBox); fwBox = el('div', { class: 'df-page df-en' }); node.appendChild(fwBox); ctx = cx; alive = true; data = null; enData = null; fwData = null; paint(); load(); },
update: function (cx) { ctx = cx; load(); },
refresh: function () { load(); },
unmount: function () { alive = false; seq++; enSeq++; if (root && root.parentNode) root.parentNode.removeChild(root); if (enBox && enBox.parentNode) enBox.parentNode.removeChild(enBox); root = null; enBox = null; data = null; enData = null; }
unmount: function () { alive = false; seq++; enSeq++; fwSeq++; if (root && root.parentNode) root.parentNode.removeChild(root); if (enBox && enBox.parentNode) enBox.parentNode.removeChild(enBox); if (fwBox && fwBox.parentNode) fwBox.parentNode.removeChild(fwBox); root = null; enBox = null; fwBox = null; data = null; enData = null; fwData = null; }
});
return true;
}