-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathenforce_cidr.rego
52 lines (45 loc) · 1.28 KB
/
enforce_cidr.rego
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Enforces the denial of CIDR 0.0.0.0/0 in security groups
package terraform
import input.tfplan as tfplan
# Add CIDRS that should be disallowed
invalid_cidrs = [
"0.0.0.0/0"
]
array_contains(arr, elem) {
arr[_] = elem
}
# Checks security groups embdedded ingress rules
deny[reason] {
r := tfplan.resource_changes[_]
r.type == "aws_security_group"
in := r.change.after.ingress[_]
invalid := invalid_cidrs[_]
array_contains(in.cidr_blocks,invalid)
reason := sprintf(
"%-40s :: security group invalid ingress CIDR %s",
[r.address,invalid]
)
}
# Checks security groups embdedded egress rules
deny[reason] {
r := tfplan.resource_changes[_]
r.type == "aws_security_group"
eg := r.change.after.egress[_]
invalid := invalid_cidrs[_]
array_contains(eg.cidr_blocks,invalid)
reason := sprintf(
"%-40s :: security group invalid egress CIDR %s",
[r.address,invalid]
)
}
# Checks security groups rules
deny[reason] {
r := tfplan.resource_changes[_]
r.type == "aws_security_group_rule"
invalid := invalid_cidrs[_]
array_contains(r.change.after.cidr_blocks,invalid)
reason := sprintf(
"%-40s :: security group rule invalid CIDR %s",
[r.address,invalid]
)
}