github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/azure/database/retention_period_set.go (about) 1 package database 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 CheckRetentionPeriodSet = rules.Register( 12 scan.Rule{ 13 AVDID: "AVD-AZU-0025", 14 Provider: providers.AzureProvider, 15 Service: "database", 16 ShortCode: "retention-period-set", 17 Summary: "Database auditing rentention period should be longer than 90 days", 18 Impact: "Short logging retention could result in missing valuable historical information", 19 Resolution: "Set retention periods of database auditing to greater than 90 days", 20 Explanation: `When Auditing is configured for a SQL database, if the retention period is not set, the retention will be unlimited. 21 22 If the retention period is to be explicitly set, it should be set for no less than 90 days.`, 23 Links: []string{ 24 "https://docs.microsoft.com/en-us/azure/azure-sql/database/auditing-overview", 25 }, 26 Terraform: &scan.EngineMetadata{ 27 GoodExamples: terraformRetentionPeriodSetGoodExamples, 28 BadExamples: terraformRetentionPeriodSetBadExamples, 29 Links: terraformRetentionPeriodSetLinks, 30 RemediationMarkdown: terraformRetentionPeriodSetRemediationMarkdown, 31 }, 32 Severity: severity.Medium, 33 }, 34 func(s *state.State) (results scan.Results) { 35 for _, server := range s.Azure.Database.MSSQLServers { 36 for _, policy := range server.ExtendedAuditingPolicies { 37 if policy.RetentionInDays.LessThan(90) && policy.RetentionInDays.NotEqualTo(0) { 38 results.Add( 39 "Server has a retention period of less than 90 days.", 40 policy.RetentionInDays, 41 ) 42 } else { 43 results.AddPassed(&policy) 44 } 45 } 46 } 47 return 48 }, 49 )