Skip to content

Commit

Permalink
fix: align CIDR check rules with their title
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Pivkin <[email protected]>
  • Loading branch information
nikpivkin committed Jan 16, 2025
1 parent e9f1c40 commit cf57c76
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 88 deletions.
3 changes: 1 addition & 2 deletions avd_docs/azure/network/AVD-AZU-0047/docs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

Network security rules should not use very broad subnets.
Where possible, segments should be broken into smaller subnets.
Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
3 changes: 1 addition & 2 deletions avd_docs/azure/network/AVD-AZU-0051/docs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

Network security rules should not use very broad subnets.
Where possible, segments should be broken into smaller subnets.
Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
2 changes: 1 addition & 1 deletion avd_docs/digitalocean/compute/AVD-DIG-0001/docs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
2 changes: 1 addition & 1 deletion avd_docs/digitalocean/compute/AVD-DIG-0003/docs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Opening up ports to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that explicitly require it where possible.
Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
3 changes: 1 addition & 2 deletions avd_docs/google/compute/AVD-GCP-0027/docs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

Network security rules should not use very broad subnets.
Where possible, segments should be broken into smaller subnets and avoid using the <code>/0</code> subnet.
Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
3 changes: 1 addition & 2 deletions avd_docs/google/compute/AVD-GCP-0035/docs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

Network security rules should not use very broad subnets.
Where possible, segments should be broken into smaller subnets and avoid using the <code>/0</code> subnet.
Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
3 changes: 2 additions & 1 deletion avd_docs/kubernetes/network/AVD-KUBE-0001/docs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

You should not expose infrastructure to the public internet except where explicitly required
Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
<!-- Add Impact here -->
Expand Down
2 changes: 1 addition & 1 deletion avd_docs/nifcloud/computing/AVD-NIF-0001/docs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Opening up ports to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that explicitly require it where possible.
Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.

When publishing web applications, use a load balancer instead of publishing directly to instances.

Expand Down
2 changes: 1 addition & 1 deletion avd_docs/nifcloud/nas/AVD-NIF-0014/docs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Opening up ports to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that explicitly require it where possible.
Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
2 changes: 1 addition & 1 deletion avd_docs/nifcloud/rdb/AVD-NIF-0011/docs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Opening up ports to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that explicitly require it where possible.
Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.


### Impact
Expand Down
9 changes: 5 additions & 4 deletions checks/cloud/aws/ec2/no_public_egress_sgr.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# METADATA
# title: An egress security group rule allows traffic to /0.
# title: A security group rule should not allow egress to any IP address.
# description: |
# Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
# scope: package
Expand Down Expand Up @@ -35,13 +35,14 @@ package builtin.aws.ec2.aws0104

import rego.v1

import data.lib.net

deny contains res if {
some rule in input.aws.ec2.securitygroups[_].egressrules
some block in rule.cidrs
cidr.is_public(block.value)
cidr.count_addresses(block.value) > 1
net.cidr_allows_all_ips(block.value)
res := result.new(
"Security group rule allows egress to multiple public internet addresses.",
"Security group rule allows egress to any IP address.",
block,
)
}
6 changes: 5 additions & 1 deletion checks/cloud/aws/ec2/no_public_egress_sgr_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ test_deny_sg_with_public_egress if {
}

test_allow_sg_without_private_egress if {
inp := {"aws": {"ec2": {"securitygroups": [{"egressrules": [{"cidrs": [{"value": "10.0.0.0/16"}]}]}]}}}
inp := {"aws": {"ec2": {"securitygroups": [{"egressrules": [{"cidrs": [
{"value": "10.0.0.0/8"},
{"value": "192.168.164.0/23"},
{"value": "22.0.0.0/8"},
]}]}]}}}

test.assert_empty(check.deny) with input as inp
}
4 changes: 2 additions & 2 deletions checks/cloud/aws/ec2/no_public_ingress_acl.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# METADATA
# title: Network ACLs should not allow ingress from 0.0.0.0/0 to port 22 or port 3389.
# title: Network ACLs should not allow ingress to SSH or RDP from any IP address.
# description: |
# The Network Access Control List (NACL) function provide stateless filtering of ingress and
# egress network traffic to AWS resources. It is recommended that no NACL allows
Expand Down Expand Up @@ -56,7 +56,7 @@ deny contains res if {
some block in rule.cidrs
net.cidr_allows_all_ips(block.value)
res := result.new(
"Network ACL rule allows ingress from public internet.",
"Network ACL rule allows ingress from any IP address.",
block,
)
}
Expand Down
4 changes: 2 additions & 2 deletions checks/cloud/aws/ec2/no_public_ingress_sgr.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# METADATA
# title: Security groups should not allow ingress from 0.0.0.0/0 or ::/0 to port 22 or port 3389.
# title: Security groups should not allow ingress to SSH or RDP from any IP address.
# description: |
# Security groups provide stateful filtering of ingress and egress network traffic to AWS
# resources. It is recommended that no security group allows unrestricted ingress access to
Expand Down Expand Up @@ -53,7 +53,7 @@ deny contains res if {
some block in rule.cidrs
net.cidr_allows_all_ips(block.value)
res := result.new(
"Security group rule allows ingress from public internet.",
"Security group rule allows ingress from any IP address.",
block,
)
}
9 changes: 5 additions & 4 deletions checks/cloud/azure/network/disable_rdp_from_internet.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# METADATA
# title: RDP access should not be accessible from the Internet, should be blocked on port 3389
# title: A security group should not allow ingress to the RDP port from any IP address.
# description: |
# RDP access can be configured on either the network security group or in the network security group rule.
# RDP access should not be permitted from the internet (*, 0.0.0.0, /0, internet, any). Consider using the Azure Bastion Service.
Expand Down Expand Up @@ -32,6 +32,8 @@ package builtin.azure.network.azure0048

import rego.v1

import data.lib.net

deny contains res if {
some group in input.azure.network.securitygroups
some rule in group.rules
Expand All @@ -41,10 +43,9 @@ deny contains res if {
some ports in rule.destinationports
port_range_includes(ports.start, ports.end, 3389)
some ip in rule.sourceaddresses
cidr.is_public(ip.value)
cidr.count_addresses(ip.value) > 1
net.cidr_allows_all_ips(ip.value)
res := result.new(
"Security group rule allows ingress to RDP port from multiple public internet addresses.",
"Security group rule allows ingress to RDP port from any IP address.",
ip,
)
}
Expand Down
11 changes: 6 additions & 5 deletions checks/cloud/azure/network/no_public_egress.rego
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# METADATA
# title: An outbound network security rule allows traffic to /0.
# title: A security rule should not allow egress to any IP address.
# description: |
# Network security rules should not use very broad subnets.
# Where possible, segments should be broken into smaller subnets.
# Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
# scope: package
# schemas:
# - input: schema["cloud"]
Expand Down Expand Up @@ -31,12 +30,14 @@ package builtin.azure.network.azure0051

import rego.v1

import data.lib.net

deny contains res if {
some group in input.azure.network.securitygroups
some rule in group.rules
rule.outbound.value
rule.allow.value
some addr in rule.destinationaddresses
cidr.is_public(addr.value)
res := result.new("Security group rule allows egress to public internet.", addr)
net.cidr_allows_all_ips(addr.value)
res := result.new("Security group rule allows egress to any IP address.", addr)
}
11 changes: 11 additions & 0 deletions checks/cloud/azure/network/no_public_egress_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ test_deny_outbound_rule_with_wildcard_destination_address if {
count(res) == 1
}

test_deny_outbound_rule_with_public_destination_address if {
inp := {"azure": {"network": {"securitygroups": [{"rules": [{
"allow": {"value": true},
"outbound": {"value": true},
"destinationaddresses": [{"value": "0.0.0.0/0"}],
}]}]}}}

res := check.deny with input as inp
count(res) == 1
}

test_allow_outbound_rule_with_private_destination_address if {
inp := {"azure": {"network": {"securitygroups": [{"rules": [{
"allow": {"value": true},
Expand Down
12 changes: 6 additions & 6 deletions checks/cloud/azure/network/no_public_ingress.rego
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# METADATA
# title: An inbound network security rule allows traffic from /0.
# title: A security group rule should not allow ingress from any IP address.
# description: |
# Network security rules should not use very broad subnets.
# Where possible, segments should be broken into smaller subnets.
# Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
# scope: package
# schemas:
# - input: schema["cloud"]
Expand Down Expand Up @@ -31,13 +30,14 @@ package builtin.azure.network.azure0047

import rego.v1

import data.lib.net

deny contains res if {
some group in input.azure.network.securitygroups
some rule in group.rules
not rule.outbound.value
rule.allow.value
some addr in rule.sourceaddresses
cidr.is_public(addr.value)
cidr.count_addresses(addr.value) > 1
res := result.new("Security group rule allows ingress from public internet.", addr)
net.cidr_allows_all_ips(addr.value)
res := result.new("Security group rule allows ingress from any IP address.", addr)
}
9 changes: 5 additions & 4 deletions checks/cloud/azure/network/ssh_blocked_from_internet.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# METADATA
# title: SSH access should not be accessible from the Internet, should be blocked on port 22
# title: Security group should not allow ingress to SSH port from any IP address.
# description: |
# SSH access can be configured on either the network security group or in the network security group rule.
# SSH access should not be permitted from the internet (*, 0.0.0.0, /0, internet, any)
Expand Down Expand Up @@ -30,6 +30,8 @@ package builtin.azure.network.azure0050

import rego.v1

import data.lib.net

deny contains res if {
some group in input.azure.network.securitygroups
some rule in group.rules
Expand All @@ -39,10 +41,9 @@ deny contains res if {
some ports in rule.destinationports
port_range_includes(ports.start, ports.end, 22)
some ip in rule.sourceaddresses
cidr.is_public(ip.value)
cidr.count_addresses(ip.value) > 1
net.cidr_allows_all_ips(ip.value)
res := result.new(
"Security group rule allows ingress to SSH port from multiple public internet addresses.",
"Security group rule allows ingress to SSH port from any IP address.",
ip,
)
}
Expand Down
11 changes: 6 additions & 5 deletions checks/cloud/digitalocean/compute/no_public_egress.rego
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# METADATA
# title: The firewall has an outbound rule with open access
# title: A firewall rule should not allow egress to any IP address.
# description: |
# Opening up ports to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that explicitly require it where possible.
# Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
# scope: package
# schemas:
# - input: schema["cloud"]
Expand Down Expand Up @@ -30,12 +30,13 @@ package builtin.digitalocean.compute.digitalocean0003

import rego.v1

import data.lib.net

deny contains res if {
some address in input.digitalocean.compute.firewalls[_].outboundrules[_].destinationaddresses
cidr.is_public(address.value)
cidr.count_addresses(address.value) > 1
net.cidr_allows_all_ips(address.value)
res := result.new(
"Egress rule allows access to multiple public addresses.",
"Firewall rule allows egress traffic to any IP address.",
address,
)
}
11 changes: 6 additions & 5 deletions checks/cloud/digitalocean/compute/no_public_ingress.rego
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# METADATA
# title: The firewall has an inbound rule with open access
# title: A firewall rule should not allow ingress from any IP address.
# description: |
# Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
# Opening up ports to allow connections from the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
# scope: package
# schemas:
# - input: schema["cloud"]
Expand Down Expand Up @@ -30,12 +30,13 @@ package builtin.digitalocean.compute.digitalocean0001

import rego.v1

import data.lib.net

deny contains res if {
some address in input.digitalocean.compute.firewalls[_].inboundrules[_].sourceaddresses
cidr.is_public(address.value)
cidr.count_addresses(address.value) > 1
net.cidr_allows_all_ips(address.value)
res := result.new(
"Ingress rule allows access from multiple public addresses.",
"Firewall rule allows ingress from any IP address.",
address,
)
}
12 changes: 6 additions & 6 deletions checks/cloud/google/compute/no_public_egress.rego
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# METADATA
# title: An outbound firewall rule allows traffic to /0.
# title: A firewall rule should not allow egress to any IP address.
# description: |
# Network security rules should not use very broad subnets.
# Where possible, segments should be broken into smaller subnets and avoid using the <code>/0</code> subnet.
# Opening up ports to connect out to the public internet is generally to be avoided. You should restrict access to IP addresses or ranges that are explicitly required where possible.
# scope: package
# schemas:
# - input: schema["cloud"]
Expand Down Expand Up @@ -31,16 +30,17 @@ package builtin.google.compute.google0035

import rego.v1

import data.lib.net

deny contains res if {
some network in input.google.compute.networks
some rule in network.firewall.egressrules
rule.firewallrule.isallow.value
rule.firewallrule.enforced.value
some destination in rule.destinationranges
cidr.is_public(destination.value)
cidr.count_addresses(destination.value) > 1
net.cidr_allows_all_ips(destination.value)
res := result.new(
"Firewall rule allows egress traffic to multiple addresses on the public internet.",
"Firewall rule allows egress traffic to any IP address.",
destination,
)
}
2 changes: 1 addition & 1 deletion checks/cloud/google/compute/no_public_egress_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_deny_egress_rule_with_multiple_public_destinations if {
count(res) == 1
}

test_allow_egress_rule_with_public_destination if {
test_allow_egress_rule_with_private_destination if {
inp := {"google": {"compute": {"networks": [{"firewall": {"egressrules": [{
"firewallrule": {
"isallow": {"value": true},
Expand Down
Loading

0 comments on commit cf57c76

Please sign in to comment.