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
c69d03b
commit ce7af87
Showing
14 changed files
with
320 additions
and
49 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,46 @@ | ||
package mq | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/parser" | ||
"github.com/aquasecurity/defsec/provider/aws/mq" | ||
"github.com/aquasecurity/defsec/types" | ||
) | ||
|
||
func Adapt(cfFile parser.FileContext) mq.MQ { | ||
return mq.MQ{ | ||
Brokers: getBrokers(cfFile), | ||
} | ||
} | ||
|
||
func getBrokers(ctx parser.FileContext) (brokers []mq.Broker) { | ||
for _, brokerResource := range ctx.GetResourceByType("AWS::AmazonMQ::Broker") { | ||
|
||
var broker mq.Broker | ||
broker.Metadata = brokerResource.Metadata() | ||
|
||
if publicProp := brokerResource.GetProperty("PubliclyAccessible"); publicProp.IsBool() { | ||
broker.PublicAccess = publicProp.AsBoolValue() | ||
} else { | ||
broker.PublicAccess = types.BoolDefault(false, brokerResource.Metadata()) | ||
} | ||
|
||
if logsProp := brokerResource.GetProperty("Logs"); logsProp.IsNotNil() { | ||
if auditProp := logsProp.GetProperty("Audit"); auditProp.IsBool() { | ||
broker.Logging.Audit = auditProp.AsBoolValue() | ||
} else { | ||
broker.Logging.Audit = types.BoolDefault(false, logsProp.Metadata()) | ||
} | ||
if generalProp := logsProp.GetProperty("General"); generalProp.IsBool() { | ||
broker.Logging.General = generalProp.AsBoolValue() | ||
} else { | ||
broker.Logging.General = types.BoolDefault(false, logsProp.Metadata()) | ||
} | ||
} else { | ||
broker.Logging.Audit = types.BoolDefault(false, brokerResource.Metadata()) | ||
broker.Logging.General = types.BoolDefault(false, brokerResource.Metadata()) | ||
} | ||
|
||
brokers = append(brokers, broker) | ||
} | ||
return brokers | ||
} |
41 changes: 41 additions & 0 deletions
41
internal/app/cfsec/rules/aws/mq/enable_audit_logging_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,41 @@ | ||
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/mq" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example | ||
Resources: | ||
Broker: | ||
Type: AWS::AmazonMQ::Broker | ||
Properties: | ||
Logs: | ||
Audit: false | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Good example | ||
Resources: | ||
Broker: | ||
Type: AWS::AmazonMQ::Broker | ||
Properties: | ||
Logs: | ||
Audit: true | ||
`, | ||
}, | ||
Base: mq.CheckEnableAuditLogging, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/mq/enable_audit_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_MQ_AuditLogs_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-mq-enable-audit-logging" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_MQ_AuditLogs_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-mq-enable-audit-logging" | ||
test.RunPassingExamplesTest(t, expectedCode) | ||
} |
41 changes: 41 additions & 0 deletions
41
internal/app/cfsec/rules/aws/mq/enable_general_logging_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,41 @@ | ||
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/mq" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example | ||
Resources: | ||
Broker: | ||
Type: AWS::AmazonMQ::Broker | ||
Properties: | ||
Logs: | ||
General: false | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Good example | ||
Resources: | ||
Broker: | ||
Type: AWS::AmazonMQ::Broker | ||
Properties: | ||
Logs: | ||
General: true | ||
`, | ||
}, | ||
Base: mq.CheckEnableGeneralLogging, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/mq/enable_general_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_MQ_GeneralLogs_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-mq-enable-audit-logging" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_MQ_GeneralLogs_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-mq-enable-audit-logging" | ||
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 rds | ||
|
||
import ( | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/rule" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
"github.com/aquasecurity/defsec/rules/aws/mq" | ||
) | ||
|
||
func init() { | ||
scanner.RegisterCheckRule(rule.Rule{ | ||
|
||
BadExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Bad example | ||
Resources: | ||
Broker: | ||
Type: AWS::AmazonMQ::Broker | ||
Properties: | ||
PubliclyAccessible: true | ||
`, | ||
}, | ||
|
||
GoodExample: []string{ | ||
`--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Good example | ||
Resources: | ||
Broker: | ||
Type: AWS::AmazonMQ::Broker | ||
Properties: | ||
PubliclyAccessible: false | ||
`, | ||
}, | ||
Base: mq.CheckNoPublicAccess, | ||
}) | ||
} |
17 changes: 17 additions & 0 deletions
17
internal/app/cfsec/rules/aws/mq/no_public_access_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_MQ_Public_FailureExamples(t *testing.T) { | ||
expectedCode := "aws-mq-no-public-access" | ||
test.RunFailureExamplesTest(t, expectedCode) | ||
} | ||
|
||
func Test_MQ_Public_SuccessExamples(t *testing.T) { | ||
expectedCode := "aws-mq-no-public-access" | ||
test.RunPassingExamplesTest(t, expectedCode) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
vendor/github.com/aquasecurity/defsec/rules/aws/mq/enable_audit_logging.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
vendor/github.com/aquasecurity/defsec/rules/aws/mq/enable_general_logging.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
vendor/github.com/aquasecurity/defsec/rules/aws/mq/no_public_access.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.