github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/compute/no_public_ip.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 CheckInstancesDoNotHavePublicIPs = rules.Register( 12 scan.Rule{ 13 AVDID: "AVD-GCP-0031", 14 Provider: providers.GoogleProvider, 15 Service: service, 16 ShortCode: "no-public-ip", 17 Summary: "Instances should not have public IP addresses", 18 Impact: "Direct exposure of an instance to the public internet", 19 Resolution: "Remove public IP", 20 Explanation: `Instances should not be publicly exposed to the internet`, 21 Terraform: &scan.EngineMetadata{ 22 GoodExamples: terraformNoPublicIpGoodExamples, 23 BadExamples: terraformNoPublicIpBadExamples, 24 Links: terraformNoPublicIpLinks, 25 RemediationMarkdown: terraformNoPublicIpRemediationMarkdown, 26 }, 27 Severity: severity.High, 28 Links: []string{ 29 "https://cloud.google.com/compute/docs/ip-addresses#externaladdresses", 30 }, 31 }, 32 func(s *state.State) (results scan.Results) { 33 for _, instance := range s.Google.Compute.Instances { 34 for _, networkInterface := range instance.NetworkInterfaces { 35 if networkInterface.HasPublicIP.IsTrue() { 36 results.Add( 37 "Instance has a public IP allocated.", 38 networkInterface.HasPublicIP, 39 ) 40 } else { 41 results.AddPassed(&networkInterface) 42 } 43 } 44 45 } 46 return results 47 }, 48 )