Skip to content

Commit

Permalink
Merge pull request #139 from liamg/liamg=add-ipv6-support
Browse files Browse the repository at this point in the history
Add ipv6 support for aws security group rules
  • Loading branch information
liamg authored Jul 15, 2020
2 parents adbf997 + a7332c9 commit da4266a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/app/tfsec/aws_open_security_group_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ variable "blocks" {
`,
mustIncludeResultCode: checks.AWSOpenIngressSecurityGroupRule,
},
{
name: "check aws_security_group_rule ingress on ::/0",
source: `
resource "aws_security_group_rule" "my-rule" {
type = "ingress"
ipv6_cidr_blocks = ["::/0"]
}`,
mustIncludeResultCode: checks.AWSOpenIngressSecurityGroupRule,
},
}

for _, test := range tests {
Expand Down
10 changes: 10 additions & 0 deletions internal/app/tfsec/aws_open_security_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ variable "cidr_2" {
`,
mustIncludeResultCode: checks.AWSOpenEgressSecurityGroupInlineRule,
},
{
name: "check aws_security_group ingress on ::/0",
source: `
resource "aws_security_group" "my-group" {
ingress {
ipv6_cidr_blocks = ["0.0.0.0/0"]
}
}`,
mustIncludeResultCode: checks.AWSOpenIngressSecurityGroupInlineRule,
},
}

for _, test := range tests {
Expand Down
42 changes: 42 additions & 0 deletions internal/app/tfsec/checks/aws_open_security_group_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ func init() {

}

if ipv6CidrBlocksAttr := block.GetAttribute("ipv6_cidr_blocks"); ipv6CidrBlocksAttr != nil {

if ipv6CidrBlocksAttr.Value().IsNull() || ipv6CidrBlocksAttr.Value().LengthInt() == 0 {
return nil
}

for _, cidr := range ipv6CidrBlocksAttr.Value().AsValueSlice() {
if strings.HasSuffix(cidr.AsString(), "/0") {
return []scanner.Result{
check.NewResultWithValueAnnotation(
fmt.Sprintf("Resource '%s' defines a fully open egress security group rule.", block.Name()),
ipv6CidrBlocksAttr.Range(),
ipv6CidrBlocksAttr,
scanner.SeverityWarning,
),
}
}
}

}

return nil
},
})
Expand Down Expand Up @@ -93,6 +114,27 @@ func init() {

}

if ipv6CidrBlocksAttr := block.GetAttribute("ipv6_cidr_blocks"); ipv6CidrBlocksAttr != nil {

if ipv6CidrBlocksAttr.Value().IsNull() || ipv6CidrBlocksAttr.Value().LengthInt() == 0 {
return nil
}

for _, cidr := range ipv6CidrBlocksAttr.Value().AsValueSlice() {
if strings.HasSuffix(cidr.AsString(), "/0") {
return []scanner.Result{
check.NewResultWithValueAnnotation(
fmt.Sprintf("Resource '%s' defines a fully open egress security group rule.", block.Name()),
ipv6CidrBlocksAttr.Range(),
ipv6CidrBlocksAttr,
scanner.SeverityWarning,
),
}
}
}

}

return nil
},
})
Expand Down
37 changes: 37 additions & 0 deletions internal/app/tfsec/checks/aws_open_security_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ func init() {
return nil
}

for _, cidr := range cidrBlocksAttr.Value().AsValueSlice() {
if strings.HasSuffix(cidr.AsString(), "/0") {
results = append(results,
check.NewResult(
fmt.Sprintf("Resource '%s' defines a fully open ingress security group.", block.Name()),
cidrBlocksAttr.Range(),
scanner.SeverityWarning,
),
)
}
}
}
if cidrBlocksAttr := directionBlock.GetAttribute("ipv6_cidr_blocks"); cidrBlocksAttr != nil {

if cidrBlocksAttr.Value().IsNull() || cidrBlocksAttr.Value().LengthInt() == 0 {
return nil
}

for _, cidr := range cidrBlocksAttr.Value().AsValueSlice() {
if strings.HasSuffix(cidr.AsString(), "/0") {
results = append(results,
Expand Down Expand Up @@ -64,6 +82,25 @@ func init() {
return nil
}

for _, cidr := range cidrBlocksAttr.Value().AsValueSlice() {
if strings.HasSuffix(cidr.AsString(), "/0") {
results = append(results,
check.NewResultWithValueAnnotation(
fmt.Sprintf("Resource '%s' defines a fully open egress security group.", block.Name()),
cidrBlocksAttr.Range(),
cidrBlocksAttr,
scanner.SeverityWarning,
),
)
}
}
}
if cidrBlocksAttr := directionBlock.GetAttribute("ipv6_cidr_blocks"); cidrBlocksAttr != nil {

if cidrBlocksAttr.Value().IsNull() || cidrBlocksAttr.Value().LengthInt() == 0 {
return nil
}

for _, cidr := range cidrBlocksAttr.Value().AsValueSlice() {
if strings.HasSuffix(cidr.AsString(), "/0") {
results = append(results,
Expand Down

0 comments on commit da4266a

Please sign in to comment.