Skip to content

Commit

Permalink
Merge pull request #7098 from Checkmarx/tf_bug_security_groups
Browse files Browse the repository at this point in the history
fix(query): security groups not used query with false positive in aws_elasticache_instance resources
  • Loading branch information
cx-andrep committed Jun 26, 2024
2 parents 6855628 + a237c72 commit 9453cb9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ is_used(securityGroupName, doc, resource) {
contains(securityGroupUsed, sprintf("aws_security_group.%s", [securityGroupName]))
}

# check security groups assigned to aws_elasticache_instance resources
is_used(securityGroupName, doc, resource) {
[path, value] := walk(doc)
securityGroupUsed := value.security_group_ids[_]
contains(securityGroupUsed, sprintf("aws_security_group.%s", [securityGroupName]))
}

# check security groups assigned to aws_instance resources
is_used(securityGroupName, doc, resource) {
[path, value] := walk(doc)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "aws_security_group" "example" {
name = "example"
description = "Allow Redis traffic"
vpc_id = data.aws_vpc.selected.id

ingress {

from_port = 6379
to_port = 6379
protocol = "tcp"
cidr_blocks = [data.aws_vpc.selected.cidr_block]
}
}

resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "Example"
parameter_group_name = "default.redis6.x"
engine = "redis"
engine_version = "6.x"
automatic_failover_enabled = false

security_group_ids = [aws_security_group.example.id]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource "aws_security_group" "example" {
name = "example"
description = "Allow Redis traffic"
vpc_id = data.aws_vpc.selected.id

ingress {

from_port = 6379
to_port = 6379
protocol = "tcp"
cidr_blocks = [data.aws_vpc.selected.cidr_block]
}
}

resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "Example"
parameter_group_name = "default.redis6.x"
engine = "redis"
engine_version = "6.x"
automatic_failover_enabled = false

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
"severity": "INFO",
"line": 21,
"filename": "positive4.tf"
},
{
"queryName": "Security Group Not Used",
"severity": "INFO",
"line": 1,
"filename": "positive5.tf"
}
]

0 comments on commit 9453cb9

Please sign in to comment.