fix: never ban a trusted proxy network from any ban source
The gateway already refused to ban addresses from proxy_protocol.trusted_cidrs, but the traffic-intelligence auto-ban and the subnet monitor still did, so a trusted load balancer living inside a banned /24 (or below the reputation threshold) could be knocked out together with its clients. - TrustedProxyCidr moved to src/config/trusted.rs (the edge section file hit the 250-line gate) and gained `overlaps_prefix`: a ban is suppressed when the banned prefix intersects a trusted network. - TrafficHook::with_trusted suppresses reputation and offender bans; its ban() now reports whether the ban was installed so `ban_offenders` counts real bans. - The subnet monitor takes a MonitorSetup bundle (spawn had 8 arguments) and suppresses both userspace CIDR bans and XDP prefix bans that overlap a trusted network, logging a warning instead. - IPv4-mapped addresses are normalised in `contains` too. - Tests: overlap maths (v4/v6, /0 rejected), tracker suppression vs unrelated networks, and auto-ban skipping a trusted range while still banning public offenders.
This commit is contained in:
parent
72c1f45d62
commit
bcae8901c6
11 changed files with 300 additions and 106 deletions
|
|
@ -446,3 +446,33 @@ fn alerts_fire_only_on_state_transitions() {
|
|||
assert!(alerts[0].message.contains("attack started"));
|
||||
assert!(alerts[1].message.contains("attack ended"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auto_ban_never_targets_a_trusted_proxy_network() {
|
||||
let reputation = Arc::new(IpReputation::new());
|
||||
let blacklist = Arc::new(Blacklist::new());
|
||||
let trusted: Vec<rampart::config::TrustedProxyCidr> = vec!["10.0.0.0/8".parse().expect("trusted cidr")];
|
||||
let hook =
|
||||
TrafficHook::new(Arc::clone(&reputation), Arc::clone(&blacklist), autoban_cfg(true), 60).with_trusted(trusted);
|
||||
let inside = ip([10, 1, 2, 3]);
|
||||
|
||||
for _ in 0..6 {
|
||||
reputation.record_bad(inside);
|
||||
hook.on_connection_end(inside);
|
||||
}
|
||||
assert!(
|
||||
reputation.score(inside) <= -50,
|
||||
"reputation must fall below the threshold"
|
||||
);
|
||||
assert_eq!(hook.ban_offenders(), 0, "trusted addresses are never banned");
|
||||
|
||||
let public = ip([198, 51, 100, 9]);
|
||||
for _ in 0..6 {
|
||||
reputation.record_bad(public);
|
||||
hook.on_connection_end(public);
|
||||
}
|
||||
assert!(
|
||||
blacklist.is_blocked(public),
|
||||
"non-trusted offenders are still banned by the reputation path"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue