github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/azure/monitor/activity_log_retention_set.go (about)

     1  package monitor
     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 CheckActivityLogRetentionSet = rules.Register(
    12  	scan.Rule{
    13  		AVDID:       "AVD-AZU-0031",
    14  		Provider:    providers.AzureProvider,
    15  		Service:     "monitor",
    16  		ShortCode:   "activity-log-retention-set",
    17  		Summary:     "Ensure the activity retention log is set to at least a year",
    18  		Impact:      "Short life activity logs can lead to missing records when investigating a breach",
    19  		Resolution:  "Set a retention period that will allow for delayed investigation",
    20  		Explanation: `The average time to detect a breach is up to 210 days, to ensure that all the information required for an effective investigation is available, the retention period should allow for delayed starts to investigating.`,
    21  		Links: []string{
    22  			"https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/platform-logs-overview",
    23  		},
    24  		Terraform: &scan.EngineMetadata{
    25  			GoodExamples:        terraformActivityLogRetentionSetGoodExamples,
    26  			BadExamples:         terraformActivityLogRetentionSetBadExamples,
    27  			Links:               terraformActivityLogRetentionSetLinks,
    28  			RemediationMarkdown: terraformActivityLogRetentionSetRemediationMarkdown,
    29  		},
    30  		Severity: severity.Medium,
    31  	},
    32  	func(s *state.State) (results scan.Results) {
    33  		for _, profile := range s.Azure.Monitor.LogProfiles {
    34  			if profile.Metadata.IsUnmanaged() {
    35  				continue
    36  			}
    37  			if profile.RetentionPolicy.Enabled.IsFalse() {
    38  				results.Add(
    39  					"Profile does not enable the log retention policy.",
    40  					profile.RetentionPolicy.Enabled,
    41  				)
    42  			} else if profile.RetentionPolicy.Days.LessThan(365) {
    43  				results.Add(
    44  					"Profile has a log retention policy of less than 1 year.",
    45  					profile.RetentionPolicy.Days,
    46  				)
    47  			} else {
    48  				results.AddPassed(&profile)
    49  			}
    50  		}
    51  		return
    52  	},
    53  )