Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(queries): Add check for traffic direction in port queries in some providers #5313

Merged
merged 5 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CxPolicy[result] {
protocol := getProtocolList(resource.protocol)[_]

upper(resource.access) == "ALLOW"
inbound_direction(resource)
endswith(resource.source_address_prefix, "/0")
containsDestinationPort(portNumber, resource)
isTCPorUDP(protocol)
Expand Down Expand Up @@ -79,3 +80,9 @@ else = containing {
isTCPorUDP(protocol) = is {
is := upper(protocol) != "ICMP"
}

inbound_direction(resource){
upper(resource.direction) == "INBOUND"
}else{
not commonLib.valid_key(resource,"direction")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import data.generic.common as common_lib
CxPolicy[result] {
some i
resource := input.document[i].resource.alicloud_security_group_rule[name]
resource.type == "ingress"
resource.cidr_ip == "0.0.0.0/0"
isTCPorUDP(resource.ip_protocol)
resource.port_range == "1/65535"
Expand All @@ -25,6 +26,7 @@ isTCPorUDP("udp") = true
CxPolicy[result] {
some i
resource := input.document[i].resource.alicloud_security_group_rule[name]
resource.type == "ingress"
resource.cidr_ip == "0.0.0.0/0"
isGREorICMP(resource.ip_protocol)
resource.port_range == "-1/-1"
Expand All @@ -46,6 +48,7 @@ isGREorICMP("gre") = true
CxPolicy[result] {
some i
resource := input.document[i].resource.alicloud_security_group_rule[name]
resource.type == "ingress"
resource.cidr_ip == "0.0.0.0/0"
resource.ip_protocol == "all"
result := {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import data.generic.terraform as terraform_lib
CxPolicy[result] {
some i
resource := input.document[i].resource.alicloud_security_group_rule[name]
resource.type == "ingress"
resource.cidr_ip == "0.0.0.0/0"
isTCPorUDP(resource.ip_protocol)
portContent := common_lib.tcpPortsMap[port]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import data.generic.terraform as terraform_lib

CxPolicy[result] {
resource := input.document[i].resource.alicloud_security_group_rule[name]
resource.type == "ingress"
resource.cidr_ip == "0.0.0.0/0"
isTCPorUDP(resource.ip_protocol)
containsUnknownPort(resource)
Expand All @@ -26,6 +27,7 @@ isTCPorUDP("udp") = true

CxPolicy[result] {
resource := input.document[i].resource.alicloud_security_group_rule[name]
resource.type == "ingress"
resource.cidr_ip == "0.0.0.0/0"
resource.ip_protocol == "all"
resource.port_range == "-1/-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package Cx
CxPolicy[result] {
resource := input.document[i].resource.azurerm_network_security_rule[var0]
upper(resource.access) == "ALLOW"

upper(resource.direction) == "INBOUND"

isRelevantProtocol(resource.protocol)
isRelevantPort(resource.destination_port_range)
isRelevantAddressPrefix(resource.source_address_prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CxPolicy[result] {
protocol := terraLib.getProtocolList(resource.protocol)[_]

upper(resource.access) == "ALLOW"
upper(resource.direction) == "INBOUND"

endswith(resource.source_address_prefix, "/0")
terraLib.containsPort(resource, portNumber)
isTCPorUDP(protocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CxPolicy[result] {
protocol := terraLib.getProtocolList(resource.protocol)[_]

upper(resource.access) == "ALLOW"
upper(resource.direction) == "INBOUND"

isSmallPublicNetwork(resource)
terraLib.containsPort(resource, portNumber)
isTCPorUDP(protocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CxPolicy[result] {
protocol := terraLib.getProtocolList(resource.protocol)[_]

upper(resource.access) == "ALLOW"
upper(resource.direction) == "INBOUND"

commonLib.isPrivateIP(resource.source_address_prefix)
terraLib.containsPort(resource, portNumber)
isTCPorUDP(protocol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Cx
CxPolicy[result] {
resource := input.document[i].resource.azurerm_network_security_rule[var0]
upper(resource.access) == "ALLOW"
upper(resource.direction) == "INBOUND"

isRelevantProtocol(resource.protocol)
isRelevantPort(resource.destination_port_range)
Expand Down