github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/google/compute/enable_shielded_vm_vtpm.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 CheckEnableShieldedVMVTPM = rules.Register(
    12  	scan.Rule{
    13  		AVDID:       "AVD-GCP-0041",
    14  		Provider:    providers.GoogleProvider,
    15  		Service:     "compute",
    16  		ShortCode:   "enable-shielded-vm-vtpm",
    17  		Summary:     "Instances should have Shielded VM VTPM enabled",
    18  		Impact:      "Unable to prevent unwanted system state modification",
    19  		Resolution:  "Enable Shielded VM VTPM",
    20  		Explanation: `The virtual TPM provides numerous security measures to your VM.`,
    21  		Links: []string{
    22  			"https://cloud.google.com/blog/products/identity-security/virtual-trusted-platform-module-for-shielded-vms-security-in-plaintext",
    23  		},
    24  		Terraform: &scan.EngineMetadata{
    25  			GoodExamples:        terraformEnableShieldedVmVtpmGoodExamples,
    26  			BadExamples:         terraformEnableShieldedVmVtpmBadExamples,
    27  			Links:               terraformEnableShieldedVmVtpmLinks,
    28  			RemediationMarkdown: terraformEnableShieldedVmVtpmRemediationMarkdown,
    29  		},
    30  		Severity: severity.Medium,
    31  	},
    32  	func(s *state.State) (results scan.Results) {
    33  		for _, instance := range s.Google.Compute.Instances {
    34  			if instance.Metadata.IsUnmanaged() {
    35  				continue
    36  			}
    37  			if instance.ShieldedVM.VTPMEnabled.IsFalse() {
    38  				results.Add(
    39  					"Instance does not have VTPM for shielded VMs enabled.",
    40  					instance.ShieldedVM.VTPMEnabled,
    41  				)
    42  			} else {
    43  				results.AddPassed(&instance)
    44  			}
    45  		}
    46  		return
    47  	},
    48  )