github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/compute/disk_encryption_no_plaintext_key.go (about) 1 package compute 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 CheckDiskEncryptionRequired = rules.Register( 12 scan.Rule{ 13 AVDID: "AVD-GCP-0037", 14 Provider: providers.GoogleProvider, 15 Service: "compute", 16 ShortCode: "disk-encryption-no-plaintext-key", 17 Summary: "The encryption key used to encrypt a compute disk has been specified in plaintext.", 18 Impact: "The encryption key should be considered compromised as it is not stored securely.", 19 Resolution: "Reference a managed key rather than include the key in raw format.", 20 Explanation: `Sensitive values such as raw encryption keys should not be included in your Terraform code, and should be stored securely by a secrets manager.`, 21 Links: []string{ 22 "https://cloud.google.com/compute/docs/disks/customer-supplied-encryption", 23 }, 24 Terraform: &scan.EngineMetadata{ 25 GoodExamples: terraformDiskEncryptionNoPlaintextKeyGoodExamples, 26 BadExamples: terraformDiskEncryptionNoPlaintextKeyBadExamples, 27 Links: terraformDiskEncryptionNoPlaintextKeyLinks, 28 RemediationMarkdown: terraformDiskEncryptionNoPlaintextKeyRemediationMarkdown, 29 }, 30 Severity: severity.Critical, 31 }, 32 func(s *state.State) (results scan.Results) { 33 for _, instance := range s.Google.Compute.Instances { 34 for _, disk := range append(instance.BootDisks, instance.AttachedDisks...) { 35 if disk.Encryption.RawKey.Len() > 0 { 36 results.Add( 37 "Instance disk has encryption key provided in plaintext.", 38 disk.Encryption.RawKey, 39 ) 40 } else { 41 results.AddPassed(&disk) 42 } 43 } 44 } 45 for _, disk := range s.Google.Compute.Disks { 46 if disk.Encryption.RawKey.Len() > 0 { 47 results.Add( 48 "Disk encryption key is supplied in plaintext.", 49 disk.Encryption.RawKey, 50 ) 51 } else { 52 results.AddPassed(&disk) 53 } 54 } 55 return 56 }, 57 )