Audit IPv4 CIDR allow/deny rules for overlap, shadowing, and risky network ranges in pure MoonBit
moon run ./cmd/mainmoon run ./examples/gateway
moon run ./examples/cloudmoon check
moon build
moon testlet ruleset = @cidr.parse_rules([
"allow 10.0.0.0/8 internal network",
"deny 10.1.2.0/24 blocked subnet",
"allow 192.168.1.99/24 host bits will be normalized",
"deny 0.0.0.0/0 default deny",
])
let report = ruleset.audit()
println(report.text_report())
let ip = @cidr.IPv4::parse("10.1.2.9").unwrap()
println(ruleset.decide(ip).summary())[critical] too_wide_allow R1: allow rule covers a very wide network: 10.0.0.0/8
[critical] shadowed_rule R2 related=R1: rule is already covered by earlier allow rule R1
[info] non_canonical_cidr R3: input 192.168.1.99/24 was normalized to 192.168.1.0/24
[critical] global_deny R4: deny rule blocks the entire IPv4 spacefn AddressRange::new(first : IPv4, last : IPv4, source_count? : Int) -> Result[AddressRange, String]pub struct Decision {
matched : Bool
action : RuleAction
rule_id : String
block : String
} derive(Eq, Debug)pub struct Finding {
kind : FindingKind
severity : Severity
rule_id : String
related_rule_id : String
message : String
} derive(Eq, Debug)fn Finding::new(kind : FindingKind, severity : Severity, rule_id : String, message : String, related_rule_id? : String) -> Findingfn GatePolicy::new(name : String, max_critical : Int, max_warning : Int, max_risk_score : Int, allow_parse_errors? : Bool) -> Result[GatePolicy, String]pub struct GateResult {
policy : GatePolicy
passed : Bool
risk_score : Int
reasons : Array[GateReason]
} derive(Debug)pub struct ImportIssue {
line : Int
level : ImportIssueLevel
code : String
message : String
input : String
} derive(Eq, Debug)fn ImportIssue::new(line : Int, level : ImportIssueLevel, code : String, message : String, input : String) -> ImportIssuepub struct ImportReport {
format : ImportFormat
source_count : Int
rules : Array[Rule]
issues : Array[ImportIssue]
} derive(Debug)pub struct Rule {
id : String
action : RuleAction
block : CidrBlock
source_block : String
note : String
} derive(Eq, Debug)fn Rule::new(id : String, action : RuleAction, block : CidrBlock, source_block? : String, note? : String) -> Rulepub struct RuleChange {
kind : RuleChangeKind
before_id : String
after_id : String
block : String
message : String
} derive(Eq, Debug)fn RuleChange::new(kind : RuleChangeKind, before_id : String, after_id : String, block : String, message : String) -> RuleChangefn RuleSet::evaluate_gate(self : RuleSet, audit_policy : AuditPolicy, gate_policy : GatePolicy) -> GateResultAudit IPv4 CIDR allow/deny rules for overlap, shadowing, and risky network ranges in pure MoonBit