github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/sql/enable_pg_temp_file_logging.go (about) 1 package sql 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/providers/google/sql" 7 "github.com/khulnasoft-lab/defsec/pkg/scan" 8 "github.com/khulnasoft-lab/defsec/pkg/severity" 9 "github.com/khulnasoft-lab/defsec/pkg/state" 10 ) 11 12 var CheckEnablePgTempFileLogging = rules.Register( 13 scan.Rule{ 14 AVDID: "AVD-GCP-0014", 15 Provider: providers.GoogleProvider, 16 Service: "sql", 17 ShortCode: "enable-pg-temp-file-logging", 18 Summary: "Temporary file logging should be enabled for all temporary files.", 19 Impact: "Use of temporary files will not be logged", 20 Resolution: "Enable temporary file logging for all files", 21 Explanation: `Temporary files are not logged by default. To log all temporary files, a value of ` + "`" + `0` + "`" + ` should set in the ` + "`" + `log_temp_files` + "`" + ` flag - as all files greater in size than the number of bytes set in this flag will be logged.`, 22 Links: []string{ 23 "https://postgresqlco.nf/doc/en/param/log_temp_files/", 24 }, 25 Terraform: &scan.EngineMetadata{ 26 GoodExamples: terraformEnablePgTempFileLoggingGoodExamples, 27 BadExamples: terraformEnablePgTempFileLoggingBadExamples, 28 Links: terraformEnablePgTempFileLoggingLinks, 29 RemediationMarkdown: terraformEnablePgTempFileLoggingRemediationMarkdown, 30 }, 31 Severity: severity.Medium, 32 }, 33 func(s *state.State) (results scan.Results) { 34 for _, instance := range s.Google.SQL.Instances { 35 if instance.Metadata.IsUnmanaged() { 36 continue 37 } 38 if instance.DatabaseFamily() != sql.DatabaseFamilyPostgres { 39 continue 40 } 41 if instance.Settings.Flags.LogTempFileSize.LessThan(0) { 42 results.Add( 43 "Database instance has temporary file logging disabled.", 44 instance.Settings.Flags.LogTempFileSize, 45 ) 46 } else if instance.Settings.Flags.LogTempFileSize.GreaterThan(0) { 47 results.Add( 48 "Database instance has temporary file logging disabled for files of certain sizes.", 49 instance.Settings.Flags.LogTempFileSize, 50 ) 51 } else { 52 results.AddPassed(&instance) 53 } 54 } 55 return 56 }, 57 )