From 405a999d9b93193d027bb7e8a9f8e80e2b975d9f Mon Sep 17 00:00:00 2001 From: Preslav Gerchev Date: Thu, 14 Nov 2024 10:13:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Revert=20SSM=20improvement=20to?= =?UTF-8?q?=20fix=20panic.=20(#4855)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Preslav --- .../aws/resources/discovery_conversion.go | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/providers/aws/resources/discovery_conversion.go b/providers/aws/resources/discovery_conversion.go index 2ab30794a0..0266a79699 100644 --- a/providers/aws/resources/discovery_conversion.go +++ b/providers/aws/resources/discovery_conversion.go @@ -306,13 +306,14 @@ func addConnectionInfoToEc2Asset(instance *mqlAwsEc2Instance, accountId string, info.image = &instance.GetImage().Data.Id.Data } addMondooLabels(info, asset) - imageName := "" - if instance.GetImage().Data != nil { - imageName = instance.GetImage().Data.Name.Data - } - probableUsername := getProbableUsernameFromImageName(imageName) + // if there is a public ip & it is running, we assume ssh is an option if instance.PublicIp.Data != "" && instance.State.Data == string(types.InstanceStateNameRunning) { + imageName := "" + if instance.GetImage().Data != nil { + imageName = instance.GetImage().Data.Name.Data + } + probableUsername := getProbableUsernameFromImageName(imageName) asset.Connections = []*inventory.Config{{ Type: "ssh", Host: instance.PublicIp.Data, @@ -330,15 +331,16 @@ func addConnectionInfoToEc2Asset(instance *mqlAwsEc2Instance, accountId string, "instance": instance.InstanceId.Data, }, }} - } - // if the ssm agent indicates it is online, we assume ssm is an option - if instance.GetSsm() != nil && instance.GetSsm().Data != nil && len(instance.GetSsm().Data.(map[string]interface{})["InstanceInformationList"].([]interface{})) > 0 { - if instance.GetSsm().Data.(map[string]interface{})["InstanceInformationList"].([]interface{})[0].(map[string]interface{})["PingStatus"] == "Online" { - asset.Connections[0].Credentials = append(asset.Connections[0].Credentials, &vault.Credential{ - User: probableUsername, - Type: vault.CredentialType_aws_ec2_ssm_session, - }) - asset.Labels[MondooSsmConnection] = "Online" + + // if the ssm agent indicates it is online, we assume ssm is an option + if instance.GetSsm() != nil && instance.GetSsm().Data != nil && len(instance.GetSsm().Data.(map[string]interface{})["InstanceInformationList"].([]interface{})) > 0 { + if instance.GetSsm().Data.(map[string]interface{})["InstanceInformationList"].([]interface{})[0].(map[string]interface{})["PingStatus"] == "Online" { + asset.Connections[0].Credentials = append(asset.Connections[0].Credentials, &vault.Credential{ + User: probableUsername, + Type: vault.CredentialType_aws_ec2_ssm_session, + }) + asset.Labels[MondooSsmConnection] = "Online" + } } } return asset