github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/compute/no_ip_forwarding.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 CheckNoIpForwarding = rules.Register(
    12  	scan.Rule{
    13  		AVDID:       "AVD-GCP-0043",
    14  		Provider:    providers.GoogleProvider,
    15  		Service:     "compute",
    16  		ShortCode:   "no-ip-forwarding",
    17  		Summary:     "Instances should not have IP forwarding enabled",
    18  		Impact:      "Instance can send/receive packets without the explicit instance address",
    19  		Resolution:  "Disable IP forwarding",
    20  		Explanation: `Disabling IP forwarding ensures the instance can only receive packets addressed to the instance and can only send packets with a source address of the instance.`,
    21  		Links:       []string{},
    22  		Terraform: &scan.EngineMetadata{
    23  			GoodExamples:        terraformNoIpForwardingGoodExamples,
    24  			BadExamples:         terraformNoIpForwardingBadExamples,
    25  			Links:               terraformNoIpForwardingLinks,
    26  			RemediationMarkdown: terraformNoIpForwardingRemediationMarkdown,
    27  		},
    28  		Severity: severity.High,
    29  	},
    30  	func(s *state.State) (results scan.Results) {
    31  		for _, instance := range s.Google.Compute.Instances {
    32  			if instance.Metadata.IsUnmanaged() {
    33  				continue
    34  			}
    35  			if instance.CanIPForward.IsTrue() {
    36  				results.Add(
    37  					"Instance has IP forwarding allowed.",
    38  					instance.CanIPForward,
    39  				)
    40  			} else {
    41  				results.AddPassed(&instance)
    42  			}
    43  		}
    44  		return
    45  	},
    46  )