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

fix(queries): add missing check in ec2 instance has public ip #5720

Merged
merged 12 commits into from
Aug 23, 2022
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package Cx

import data.generic.ansible as ansLib
import data.generic.common as common_lib

CxPolicy[result] {
task := ansLib.tasks[id][t]
modules := {"amazon.aws.ec2", "ec2"}
ec2 := task[modules[m]]
checkState(ec2)

not common_lib.valid_key(ec2, "network_interfaces")
ansLib.isAnsibleTrue(ec2.assign_public_ip)

# There is no default value for assign_public_ip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "b3de4e4c-14be-4159-b99d-9ad194365e4c",
"queryName": "EC2 Instance Has Public IP",
"queryName": "EC2 Instance Subnet Has Public IP Mapping On Launch",
"severity": "HIGH",
"category": "Networking and Firewall",
"descriptionText": "EC2 Subnet should not have MapPublicIpOnLaunch set to true",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"queryName": "EC2 Instance Has Public IP",
"queryName": "EC2 Instance Subnet Has Public IP Mapping On Launch",
cxMiguelSilva marked this conversation as resolved.
Show resolved Hide resolved
"severity": "HIGH",
"line": 7,
"fileName": "positive1.yaml"
},
{
"queryName": "EC2 Instance Has Public IP",
"queryName": "EC2 Instance Subnet Has Public IP Mapping On Launch",
"severity": "HIGH",
"line": 8,
"fileName": "positive2.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CxPolicy[result] {
resource := input.document[i].resource.aws_instance[name]

not common_lib.valid_key(resource, "associate_public_ip_address")
not common_lib.valid_key(resource, "network_interface")

result := {
"documentId": input.document[i].id,
Expand All @@ -23,7 +24,9 @@ CxPolicy[result] {
CxPolicy[result] {
module := input.document[i].module[name]
keyToCheck := common_lib.get_module_equivalent_key("aws", module.source, "aws_instance", "associate_public_ip_address")
netInterfaceKey := common_lib.get_module_equivalent_key("aws", module.source, "aws_instance", "network_interface")

not common_lib.valid_key(module, netInterfaceKey)
not common_lib.valid_key(module, keyToCheck)

result := {
Expand All @@ -42,6 +45,7 @@ CxPolicy[result] {
resource := input.document[i].resource.aws_instance[name]

isTrue(resource.associate_public_ip_address)
not common_lib.valid_key(resource, "network_interface")

result := {
"documentId": input.document[i].id,
Expand All @@ -58,7 +62,9 @@ CxPolicy[result] {
CxPolicy[result] {
module := input.document[i].module[name]
keyToCheck := common_lib.get_module_equivalent_key("aws", module.source, "aws_instance", "associate_public_ip_address")
netInterfaceKey := common_lib.get_module_equivalent_key("aws", module.source, "aws_instance", "network_interface")

not common_lib.valid_key(module, netInterfaceKey)
isTrue(module[keyToCheck])

result := {
Expand Down
Loading