github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/nifcloud/rdb/specify_backup_retention.go (about) 1 package rdb 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-NIF-0009", 14 Provider: providers.NifcloudProvider, 15 Service: "rdb", 16 ShortCode: "specify-backup-retention", 17 Summary: "RDB instance should have backup retention longer than 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: `Backup retention periods should be set to a period that is a balance on cost and limiting risk.`, 21 Links: []string{ 22 "https://pfs.nifcloud.com/spec/rdb/snapshot_backup.htm", 23 }, 24 Terraform: &scan.EngineMetadata{ 25 GoodExamples: terraformSpecifyBackupRetentionGoodExamples, 26 BadExamples: terraformSpecifyBackupRetentionBadExamples, 27 Links: terraformSpecifyBackupRetentionLinks, 28 RemediationMarkdown: terraformSpecifyBackupRetentionRemediationMarkdown, 29 }, 30 Severity: severity.Medium, 31 }, 32 func(s *state.State) (results scan.Results) { 33 for _, instance := range s.Nifcloud.RDB.DBInstances { 34 if instance.Metadata.IsUnmanaged() { 35 continue 36 } 37 if instance.BackupRetentionPeriodDays.LessThan(2) { 38 results.Add( 39 "Instance has very low backup retention period.", 40 instance.BackupRetentionPeriodDays, 41 ) 42 } else { 43 results.AddPassed(&instance) 44 } 45 } 46 47 return 48 }, 49 )