github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/aws/rds/specify_backup_retention.go (about) 1 package rds 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 CheckBackupRetentionSpecified = rules.Register( 12 scan.Rule{ 13 AVDID: "AVD-AWS-0077", 14 Provider: providers.AWSProvider, 15 Service: "rds", 16 ShortCode: "specify-backup-retention", 17 Summary: "RDS Cluster and RDS instance should have backup retention longer than default 1 day", 18 Impact: "Potential loss of data and short opportunity for recovery", 19 Resolution: "Explicitly set the retention period to greater than the default", 20 Explanation: `RDS backup retention for clusters defaults to 1 day, this may not be enough to identify and respond to an issue. Backup retention periods should be set to a period that is a balance on cost and limiting risk.`, 21 Links: []string{ 22 "https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithAutomatedBackups.html#USER_WorkingWithAutomatedBackups.BackupRetention", 23 }, 24 Terraform: &scan.EngineMetadata{ 25 GoodExamples: terraformSpecifyBackupRetentionGoodExamples, 26 BadExamples: terraformSpecifyBackupRetentionBadExamples, 27 Links: terraformSpecifyBackupRetentionLinks, 28 RemediationMarkdown: terraformSpecifyBackupRetentionRemediationMarkdown, 29 }, 30 CloudFormation: &scan.EngineMetadata{ 31 GoodExamples: cloudFormationSpecifyBackupRetentionGoodExamples, 32 BadExamples: cloudFormationSpecifyBackupRetentionBadExamples, 33 Links: cloudFormationSpecifyBackupRetentionLinks, 34 RemediationMarkdown: cloudFormationSpecifyBackupRetentionRemediationMarkdown, 35 }, 36 Severity: severity.Medium, 37 }, 38 func(s *state.State) (results scan.Results) { 39 for _, cluster := range s.AWS.RDS.Clusters { 40 41 if cluster.Metadata.IsUnmanaged() { 42 continue 43 } 44 if !cluster.ReplicationSourceARN.IsEmpty() { 45 continue 46 } 47 if cluster.BackupRetentionPeriodDays.LessThan(2) { 48 results.Add( 49 "Cluster has very low backup retention period.", 50 cluster.BackupRetentionPeriodDays, 51 ) 52 } else { 53 results.AddPassed(&cluster) 54 } 55 } 56 for _, instance := range s.AWS.RDS.Instances { 57 if instance.Metadata.IsUnmanaged() { 58 continue 59 } 60 if !instance.ReplicationSourceARN.IsEmpty() { 61 continue 62 } 63 if instance.BackupRetentionPeriodDays.LessThan(2) { 64 results.Add( 65 "Instance has very low backup retention period.", 66 instance.BackupRetentionPeriodDays, 67 ) 68 } else { 69 results.AddPassed(&instance) 70 } 71 } 72 73 return 74 }, 75 )