github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/gke/enable_private_cluster.go (about) 1 package gke 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 CheckEnablePrivateCluster = rules.Register( 12 scan.Rule{ 13 AVDID: "AVD-GCP-0059", 14 Provider: providers.GoogleProvider, 15 Service: "gke", 16 ShortCode: "enable-private-cluster", 17 Summary: "Clusters should be set to private", 18 Impact: "Nodes may be exposed to the public internet", 19 Resolution: "Enable private cluster", 20 Explanation: `Enabling private nodes on a cluster ensures the nodes are only available internally as they will only be assigned internal addresses.`, 21 Links: []string{}, 22 Terraform: &scan.EngineMetadata{ 23 GoodExamples: terraformEnablePrivateClusterGoodExamples, 24 BadExamples: terraformEnablePrivateClusterBadExamples, 25 Links: terraformEnablePrivateClusterLinks, 26 RemediationMarkdown: terraformEnablePrivateClusterRemediationMarkdown, 27 }, 28 Severity: severity.Medium, 29 }, 30 func(s *state.State) (results scan.Results) { 31 for _, cluster := range s.Google.GKE.Clusters { 32 if cluster.Metadata.IsUnmanaged() { 33 continue 34 } 35 if cluster.PrivateCluster.EnablePrivateNodes.IsFalse() { 36 results.Add( 37 "Cluster does not have private nodes.", 38 cluster.PrivateCluster.EnablePrivateNodes, 39 ) 40 } else { 41 results.AddPassed(&cluster) 42 } 43 44 } 45 return 46 }, 47 )