github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/compute/no_serial_port.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 CheckNoSerialPort = rules.Register(
    12  	scan.Rule{
    13  		AVDID:       "AVD-GCP-0032",
    14  		Provider:    providers.GoogleProvider,
    15  		Service:     "compute",
    16  		ShortCode:   "no-serial-port",
    17  		Summary:     "Disable serial port connectivity for all instances",
    18  		Impact:      "Unrestricted network access to the serial console of the instance",
    19  		Resolution:  "Disable serial port access",
    20  		Explanation: `When serial port access is enabled, the access is not governed by network security rules meaning the port can be exposed publicly.`,
    21  		Links:       []string{},
    22  		Terraform: &scan.EngineMetadata{
    23  			GoodExamples:        terraformNoSerialPortGoodExamples,
    24  			BadExamples:         terraformNoSerialPortBadExamples,
    25  			Links:               terraformNoSerialPortLinks,
    26  			RemediationMarkdown: terraformNoSerialPortRemediationMarkdown,
    27  		},
    28  		Severity: severity.Medium,
    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.EnableSerialPort.IsTrue() {
    36  				results.Add(
    37  					"Instance has serial port enabled.",
    38  					instance.EnableSerialPort,
    39  				)
    40  			} else {
    41  				results.AddPassed(&instance)
    42  			}
    43  		}
    44  		return
    45  	},
    46  )