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 check for public addresses #100

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions avd_docs/aws/ec2/AVD-AWS-0107/Terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Set a more restrictive cidr range
cidr_blocks = ["10.0.0.0/16"]
}

```
```hcl
resource "aws_security_group_rule" "another_good_example" {
type = "ingress"
cidr_blocks = ["1.2.3.4/24"]
}

```
```hcl
resource "aws_security_group_rule" "allow_partner_rsync" {
Expand Down
2 changes: 1 addition & 1 deletion checks/cloud/aws/ec2/no_public_ingress_sgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var CheckNoPublicIngressSgr = rules.Register(
for _, rule := range group.IngressRules {
var failed bool
for _, block := range rule.CIDRs {
if cidr.IsPublic(block.Value()) && cidr.CountAddresses(block.Value()) > 1 {
if cidr.IsPublic(block.Value()) && (cidr.CountAddresses(block.Value()) == 255*255*255*255 || cidr.CountAddresses(block.Value()) == 0xffffffffffffffff) {
failed = true
results.Add(
"Security group rule allows ingress from public internet.",
Expand Down
6 changes: 6 additions & 0 deletions checks/cloud/aws/ec2/no_public_ingress_sgr.tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ var terraformNoPublicIngressSgrGoodExamples = []string{
}
`,
`
resource "aws_security_group_rule" "another_good_example" {
type = "ingress"
cidr_blocks = ["1.2.3.4/24"]
}
`,
`
resource "aws_security_group_rule" "allow_partner_rsync" {
type = "ingress"
security_group_id = aws_security_group.….id
Expand Down
21 changes: 20 additions & 1 deletion checks/cloud/aws/ec2/no_public_ingress_sgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCheckNoPublicIngressSgr(t *testing.T) {
expected bool
}{
{
name: "AWS VPC ingress security group rule with wildcard address",
name: "AWS VPC ingress security group rule with wildcard address (0.0.0.0/0)",
input: ec2.EC2{
SecurityGroups: []ec2.SecurityGroup{
{
Expand All @@ -38,6 +38,25 @@ func TestCheckNoPublicIngressSgr(t *testing.T) {
},
expected: true,
},
{
name: "AWS VPC ingress security group rule with public address (/24)",
input: ec2.EC2{
SecurityGroups: []ec2.SecurityGroup{
{
Metadata: trivyTypes.NewTestMetadata(),
IngressRules: []ec2.SecurityGroupRule{
{
Metadata: trivyTypes.NewTestMetadata(),
CIDRs: []trivyTypes.StringValue{
trivyTypes.String("1.2.3.4/24", trivyTypes.NewTestMetadata()),
},
},
},
},
},
},
expected: false,
},
{
name: "AWS VPC ingress security group rule with private address",
input: ec2.EC2{
Expand Down