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
8fc98bb
commit c69d03b
Showing
9 changed files
with
278 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package msk | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/parser" | ||
"github.com/aquasecurity/defsec/provider/aws/msk" | ||
"github.com/aquasecurity/defsec/types" | ||
) | ||
|
||
func Adapt(cfFile parser.FileContext) msk.MSK { | ||
return msk.MSK{ | ||
Clusters: getClusters(cfFile), | ||
} | ||
} | ||
|
||
func getClusters(ctx parser.FileContext) (clusters []msk.Cluster) { | ||
for _, clusterResource := range ctx.GetResourceByType("AWS::MSK::Cluster") { | ||
|
||
var cluster msk.Cluster | ||
|
||
if brokerProp := clusterResource.GetProperty("EncryptionInfo.EncryptionInTransit.ClientBroker"); brokerProp.IsString() { | ||
cluster.EncryptionInTransit.ClientBroker = brokerProp.AsStringValue() | ||
} else { | ||
cluster.EncryptionInTransit.ClientBroker = types.StringDefault("TLS", clusterResource.Metadata()) | ||
} | ||
|
||
if logsProp := clusterResource.GetProperty("LoggingInfo.BrokerLogs"); logsProp.IsNotNil() { | ||
if cloudwatchProp := logsProp.GetProperty("CloudWatchLogs"); cloudwatchProp.IsNotNil() { | ||
if enableProp := cloudwatchProp.GetProperty("Enabled"); enableProp.IsBool() { | ||
cluster.Logging.Broker.Cloudwatch.Enabled = enableProp.AsBoolValue() | ||
} else { | ||
cluster.Logging.Broker.Cloudwatch.Enabled = types.BoolDefault(false, cloudwatchProp.Metadata()) | ||
} | ||
} else { | ||
cluster.Logging.Broker.Cloudwatch.Enabled = types.BoolDefault(false, logsProp.Metadata()) | ||
} | ||
|
||
if firehoseProp := logsProp.GetProperty("Firehose"); firehoseProp.IsNotNil() { | ||
if enableProp := firehoseProp.GetProperty("Enabled"); enableProp.IsBool() { | ||
cluster.Logging.Broker.Firehose.Enabled = enableProp.AsBoolValue() | ||
} else { | ||
cluster.Logging.Broker.Firehose.Enabled = types.BoolDefault(false, firehoseProp.Metadata()) | ||
} | ||
} else { | ||
cluster.Logging.Broker.Firehose.Enabled = types.BoolDefault(false, logsProp.Metadata()) | ||
} | ||
|
||
if s3Prop := logsProp.GetProperty("S3"); s3Prop.IsNotNil() { | ||
if enableProp := s3Prop.GetProperty("Enabled"); enableProp.IsBool() { | ||
cluster.Logging.Broker.S3.Enabled = enableProp.AsBoolValue() | ||
} else { | ||
cluster.Logging.Broker.S3.Enabled = types.BoolDefault(false, s3Prop.Metadata()) | ||
} | ||
} else { | ||
cluster.Logging.Broker.S3.Enabled = types.BoolDefault(false, logsProp.Metadata()) | ||
} | ||
|
||
} else { | ||
cluster.Logging.Broker.Cloudwatch.Enabled = types.BoolDefault(false, clusterResource.Metadata()) | ||
cluster.Logging.Broker.Firehose.Enabled = types.BoolDefault(false, clusterResource.Metadata()) | ||
cluster.Logging.Broker.S3.Enabled = types.BoolDefault(false, clusterResource.Metadata()) | ||
} | ||
|
||
clusters = append(clusters, cluster) | ||
} | ||
return clusters | ||
} |
42 changes: 42 additions & 0 deletions
42
internal/app/cfsec/rules/aws/msk/enable_in_transit_encryption_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,42 @@ | ||
package rds | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/rule" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
"github.com/aquasecurity/defsec/rules/aws/msk" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example | ||
Resources: | ||
Cluster: | ||
Type: AWS::MSK::Cluster | ||
Properties: | ||
EncryptionInfo: | ||
EncryptionInTransit: | ||
ClientBroker: "TLS_PLAINTEXT" | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Good example | ||
Resources: | ||
Cluster: | ||
Type: AWS::MSK::Cluster | ||
Properties: | ||
EncryptionInfo: | ||
EncryptionInTransit: | ||
ClientBroker: "TLS" | ||
`, | ||
}, | ||
Base: msk.CheckEnableInTransitEncryption, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/msk/enable_in_transit_encryption_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 rds | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/test" | ||
) | ||
|
||
func Test_MSK_InTransit_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-msk-enable-in-transit-encryption" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_MSK_InTransit_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-msk-enable-in-transit-encryption" | ||
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,46 @@ | ||
package rds | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/rule" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
"github.com/aquasecurity/defsec/rules/aws/msk" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example | ||
Resources: | ||
Cluster: | ||
Type: AWS::MSK::Cluster | ||
Properties: | ||
LoggingInfo: | ||
BrokerLogs: | ||
CloudWatchLogs: | ||
Enabled: false | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Good example | ||
Resources: | ||
Cluster: | ||
Type: AWS::MSK::Cluster | ||
Properties: | ||
LoggingInfo: | ||
BrokerLogs: | ||
S3: | ||
Enabled: true | ||
`, | ||
}, | ||
Base: msk.CheckEnableLogging, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/msk/enable_logging_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 rds | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/test" | ||
) | ||
|
||
func Test_MSK_Logs_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-msk-enable-logging" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_MSK_Logs_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-msk-enable-logging" | ||
test.RunPassingExamplesTest(t, expectedCode) | ||
} |
42 changes: 42 additions & 0 deletions
42
vendor/github.com/aquasecurity/defsec/rules/aws/msk/enable_in_transit_encryption.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
vendor/github.com/aquasecurity/defsec/rules/aws/msk/enable_logging.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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