network.rego
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Network helpers ==============================================================
# Shared ingress rule extraction and port/CIDR checks for CMP and NCD packages.

package common.network

ingress_rules(rc) := rc.change.after.ingress if rc.type == "aws_security_group"

ingress_rules(rc) := [rc.change.after] if rc.type == "aws_vpc_security_group_ingress_rule"

unrestricted_cidr(rule) if rule.cidr_blocks[_] == "0.0.0.0/0"
unrestricted_cidr(rule) if rule.ipv6_cidr_blocks[_] == "::/0"
unrestricted_cidr(rule) if rule.cidr_ipv4 == "0.0.0.0/0"
unrestricted_cidr(rule) if rule.cidr_ipv6 == "::/0"

port_in_range(port, rule) if {
	rule.from_port <= port
	rule.to_port >= port
}