github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/internal/adapters/cloudformation/aws/ec2/launch_configuration.go (about) 1 package ec2 2 3 import ( 4 "github.com/khulnasoft-lab/defsec/pkg/providers/aws/ec2" 5 "github.com/khulnasoft-lab/defsec/pkg/scanners/cloudformation/parser" 6 "github.com/khulnasoft-lab/defsec/pkg/types" 7 ) 8 9 func getLaunchConfigurations(file parser.FileContext) (launchConfigurations []ec2.LaunchConfiguration) { 10 launchConfigResources := file.GetResourcesByType("AWS::AutoScaling::LaunchConfiguration") 11 12 for _, r := range launchConfigResources { 13 14 launchConfig := ec2.LaunchConfiguration{ 15 Metadata: r.Metadata(), 16 Name: r.GetStringProperty("Name"), 17 AssociatePublicIP: r.GetBoolProperty("AssociatePublicIpAddress"), 18 MetadataOptions: ec2.MetadataOptions{ 19 Metadata: r.Metadata(), 20 HttpTokens: types.StringDefault("optional", r.Metadata()), 21 HttpEndpoint: types.StringDefault("enabled", r.Metadata()), 22 }, 23 UserData: r.GetStringProperty("UserData", ""), 24 } 25 26 if opts := r.GetProperty("MetadataOptions"); opts.IsNotNil() { 27 launchConfig.MetadataOptions = ec2.MetadataOptions{ 28 Metadata: opts.Metadata(), 29 HttpTokens: opts.GetStringProperty("HttpTokens", "optional"), 30 HttpEndpoint: opts.GetStringProperty("HttpEndpoint", "enabled"), 31 } 32 } 33 34 blockDevices := getBlockDevices(r) 35 for i, device := range blockDevices { 36 copyDevice := device 37 if i == 0 { 38 launchConfig.RootBlockDevice = copyDevice 39 continue 40 } 41 launchConfig.EBSBlockDevices = append(launchConfig.EBSBlockDevices, device) 42 } 43 44 launchConfigurations = append(launchConfigurations, launchConfig) 45 46 } 47 return launchConfigurations 48 }