github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/aws/msk/enable_logging.go (about)

     1  package msk
     2  
     3  import (
     4  	"github.com/khulnasoft-lab/defsec/internal/rules"
     5  	"github.com/khulnasoft-lab/defsec/pkg/providers"
     6  	"github.com/khulnasoft-lab/defsec/pkg/scan"
     7  	"github.com/khulnasoft-lab/defsec/pkg/severity"
     8  	"github.com/khulnasoft-lab/defsec/pkg/state"
     9  )
    10  
    11  var CheckEnableLogging = rules.Register(
    12  	scan.Rule{
    13  		AVDID:       "AVD-AWS-0074",
    14  		Provider:    providers.AWSProvider,
    15  		Service:     "msk",
    16  		ShortCode:   "enable-logging",
    17  		Summary:     "Ensure MSK Cluster logging is enabled",
    18  		Impact:      "Without logging it is difficult to trace issues",
    19  		Resolution:  "Enable logging",
    20  		Explanation: `Managed streaming for Kafka can log to Cloud Watch, Kinesis Firehose and S3, at least one of these locations should be logged to`,
    21  		Links: []string{
    22  			"https://docs.aws.amazon.com/msk/latest/developerguide/msk-logging.html",
    23  		},
    24  		Terraform: &scan.EngineMetadata{
    25  			GoodExamples:        terraformEnableLoggingGoodExamples,
    26  			BadExamples:         terraformEnableLoggingBadExamples,
    27  			Links:               terraformEnableLoggingLinks,
    28  			RemediationMarkdown: terraformEnableLoggingRemediationMarkdown,
    29  		},
    30  		CloudFormation: &scan.EngineMetadata{
    31  			GoodExamples:        cloudFormationEnableLoggingGoodExamples,
    32  			BadExamples:         cloudFormationEnableLoggingBadExamples,
    33  			Links:               cloudFormationEnableLoggingLinks,
    34  			RemediationMarkdown: cloudFormationEnableLoggingRemediationMarkdown,
    35  		},
    36  		Severity: severity.Medium,
    37  	},
    38  	func(s *state.State) (results scan.Results) {
    39  		for _, cluster := range s.AWS.MSK.Clusters {
    40  			brokerLogging := cluster.Logging.Broker
    41  
    42  			if brokerLogging.S3.Enabled.IsTrue() {
    43  				results.AddPassed(&cluster, "S3 Logging is enabled")
    44  				continue
    45  			}
    46  
    47  			if brokerLogging.Firehose.Enabled.IsTrue() {
    48  				results.AddPassed(&cluster, "Firehose Logging is enabled")
    49  				continue
    50  			}
    51  
    52  			if brokerLogging.Cloudwatch.Enabled.IsTrue() {
    53  				results.AddPassed(&cluster, "Cloudwatch Logging is enabled")
    54  				continue
    55  			}
    56  
    57  			results.Add(
    58  				"Cluster does not ship logs to any service.",
    59  				brokerLogging.Cloudwatch.Enabled,
    60  			)
    61  		}
    62  		return
    63  	},
    64  )