github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/sql/pg_log_errors.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 CheckPgLogErrors = rules.Register( 13 scan.Rule{ 14 AVDID: "AVD-GCP-0018", 15 Provider: providers.GoogleProvider, 16 Service: "sql", 17 ShortCode: "pg-log-errors", 18 Summary: "Ensure that Postgres errors are logged", 19 Impact: "Loss of error logging", 20 Resolution: "Set the minimum log severity to at least ERROR", 21 Explanation: `Setting the minimum log severity too high will cause errors not to be logged`, 22 Links: []string{ 23 "https://postgresqlco.nf/doc/en/param/log_min_messages/", 24 "https://www.postgresql.org/docs/13/runtime-config-logging.html#GUC-LOG-MIN-MESSAGES", 25 }, 26 Terraform: &scan.EngineMetadata{ 27 GoodExamples: terraformPgLogErrorsGoodExamples, 28 BadExamples: terraformPgLogErrorsBadExamples, 29 Links: terraformPgLogErrorsLinks, 30 RemediationMarkdown: terraformPgLogErrorsRemediationMarkdown, 31 }, 32 Severity: severity.Low, 33 }, 34 func(s *state.State) (results scan.Results) { 35 for _, instance := range s.Google.SQL.Instances { 36 if instance.Metadata.IsUnmanaged() { 37 continue 38 } 39 if instance.DatabaseFamily() != sql.DatabaseFamilyPostgres { 40 continue 41 } 42 if instance.Settings.Flags.LogMinMessages.IsOneOf("FATAL", "PANIC", "LOG") { 43 results.Add( 44 "Database instance is not configured to log errors.", 45 instance.Settings.Flags.LogMinMessages, 46 ) 47 } else { 48 results.AddPassed(&instance) 49 } 50 51 } 52 return 53 }, 54 )