This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f7e2f8
commit 1e47106
Showing
17 changed files
with
425 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package redshift | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/parser" | ||
"github.com/aquasecurity/defsec/provider/aws/redshift" | ||
"github.com/aquasecurity/defsec/types" | ||
) | ||
|
||
func Adapt(cfFile parser.FileContext) redshift.Redshift { | ||
return redshift.Redshift{ | ||
Clusters: getClusters(cfFile), | ||
SecurityGroups: getSecurityGroups(cfFile), | ||
} | ||
} | ||
|
||
func getClusters(ctx parser.FileContext) (clusters []redshift.Cluster) { | ||
for _, clusterResource := range ctx.GetResourceByType("AWS::Redshift::Cluster") { | ||
var cluster redshift.Cluster | ||
if subnetProp := clusterResource.GetProperty("ClusterSubnetGroupName"); subnetProp.IsString() { | ||
cluster.SubnetGroupName = subnetProp.AsStringValue() | ||
} else { | ||
cluster.SubnetGroupName = types.StringDefault("", clusterResource.Metadata()) | ||
} | ||
if encryptedProp := clusterResource.GetProperty("Encrypted"); encryptedProp.IsBool() { | ||
cluster.Encryption.Enabled = encryptedProp.AsBoolValue() | ||
} else { | ||
cluster.Encryption.Enabled = types.BoolDefault(false, clusterResource.Metadata()) | ||
} | ||
if keyProp := clusterResource.GetProperty("KmsKeyId"); keyProp.IsString() { | ||
cluster.Encryption.KMSKeyID = keyProp.AsStringValue() | ||
} else { | ||
cluster.Encryption.KMSKeyID = types.StringDefault("", clusterResource.Metadata()) | ||
} | ||
clusters = append(clusters, cluster) | ||
} | ||
return clusters | ||
} | ||
|
||
func getSecurityGroups(ctx parser.FileContext) (groups []redshift.SecurityGroup) { | ||
for _, groupResource := range ctx.GetResourceByType("AWS::Redshift::ClusterSecurityGroup") { | ||
var group redshift.SecurityGroup | ||
if descProp := groupResource.GetProperty("Description"); descProp.IsString() { | ||
group.Description = descProp.AsStringValue() | ||
} else { | ||
group.Description = types.StringDefault("", groupResource.Metadata()) | ||
} | ||
groups = append(groups, group) | ||
} | ||
return groups | ||
} |
39 changes: 39 additions & 0 deletions
39
internal/app/cfsec/rules/aws/redshift/add_description_to_security_group_rule.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package redshift | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/rule" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
"github.com/aquasecurity/defsec/rules/aws/redshift" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example of redshift sgr | ||
Resources: | ||
Queue: | ||
Type: AWS::Redshift::ClusterSecurityGroup | ||
Properties: | ||
Description: "" | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Good example of redshift sgr | ||
Resources: | ||
Queue: | ||
Type: AWS::Redshift::ClusterSecurityGroup | ||
Properties: | ||
Description: "Disallow bad stuff" | ||
`, | ||
}, | ||
Base: redshift.CheckAddDescriptionToSecurityGroup, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/redshift/add_description_to_security_group_rule_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package redshift | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/test" | ||
) | ||
|
||
func Test_Redshift_AddDescriptionToSecurityGroup_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-add-description-to-security-group" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_Redshift_AddDescriptionToSecurityGroup_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-add-description-to-security-group" | ||
test.RunPassingExamplesTest(t, expectedCode) | ||
} |
39 changes: 39 additions & 0 deletions
39
internal/app/cfsec/rules/aws/redshift/encryption_customer_key_rule.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package redshift | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/rule" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
"github.com/aquasecurity/defsec/rules/aws/redshift" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example of redshift cluster | ||
Resources: | ||
Queue: | ||
Type: AWS::Redshift::Cluster | ||
Properties: | ||
Encrypted: true | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example of redshift cluster | ||
Resources: | ||
Queue: | ||
Type: AWS::Redshift::Cluster | ||
Properties: | ||
Encrypted: true | ||
KmsKeyId: "something" | ||
`, | ||
}, | ||
Base: redshift.CheckEncryptionCustomerKey, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/redshift/encryption_customer_key_rule_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package redshift | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/test" | ||
) | ||
|
||
func Test_Redshift_EncryptionCustomerKey_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-encryption-customer-key" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_Redshift_EncryptionCustomerKey_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-encryption-customer-key" | ||
test.RunPassingExamplesTest(t, expectedCode) | ||
} |
35 changes: 35 additions & 0 deletions
35
internal/app/cfsec/rules/aws/redshift/no_classic_resources_rule.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package redshift | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/rule" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
"github.com/aquasecurity/defsec/rules/aws/redshift" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example of redshift sgr | ||
Resources: | ||
Queue: | ||
Type: AWS::Redshift::ClusterSecurityGroup | ||
Properties: | ||
Description: "" | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Good example of redshift sgr | ||
Resources: | ||
`, | ||
}, | ||
Base: redshift.CheckNoClassicResources, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/redshift/no_classic_resources_rule_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package redshift | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/test" | ||
) | ||
|
||
func Test_Redshift_NoClassicResources_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-no-classic-resources" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_Redshift_NoClassicResources_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-no-classic-resources" | ||
test.RunPassingExamplesTest(t, expectedCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package redshift | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/rule" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
"github.com/aquasecurity/defsec/rules/aws/redshift" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example of redshift cluster | ||
Resources: | ||
Queue: | ||
Type: AWS::Redshift::Cluster | ||
Properties: | ||
ClusterSubnetGroupName: "" | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example of redshift cluster | ||
Resources: | ||
Queue: | ||
Type: AWS::Redshift::Cluster | ||
Properties: | ||
ClusterSubnetGroupName: "my-subnet-group" | ||
`, | ||
}, | ||
Base: redshift.CheckUsesVPC, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/redshift/use_vpc_rule_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package redshift | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/test" | ||
) | ||
|
||
func Test_Redshift_UseVPC_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-use-vpc" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_Redshift_UseVPC_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-redshift-use-vpc" | ||
test.RunPassingExamplesTest(t, expectedCode) | ||
} |
37 changes: 37 additions & 0 deletions
37
...or/github.com/aquasecurity/defsec/rules/aws/redshift/add_description_to_security_group.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
vendor/github.com/aquasecurity/defsec/rules/aws/redshift/encryption_customer_key.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.