From 15226e5c4638ed7bccc1a096b6d6dbb00b713a6d Mon Sep 17 00:00:00 2001 From: Victoria Jeffrey Date: Wed, 20 Sep 2023 08:47:12 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20ensure=20ec2=20instances=20dont?= =?UTF-8?q?=20get=20aws=20platform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/aws/provider/provider.go | 8 +++++++- providers/aws/resources/discovery_conversion.go | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/providers/aws/provider/provider.go b/providers/aws/provider/provider.go index 0d6dc78fdc..22aaf0fbc7 100644 --- a/providers/aws/provider/provider.go +++ b/providers/aws/provider/provider.go @@ -125,7 +125,9 @@ func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallba } if c, ok := conn.(*connection.AwsConnection); ok { - c.PlatformOverride = req.Asset.Platform.Name + if req.Asset.Platform != nil { + c.PlatformOverride = req.Asset.Platform.Name + } inventory, err = s.discover(c) if err != nil { return nil, err @@ -183,6 +185,10 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba } func (s *Service) detect(asset *inventory.Asset, conn plugin.Connection) error { + if len(asset.Connections) > 0 && asset.Connections[0].Type == "ssh" { + // workaround to make sure we dont assign the aws platform to ec2 instances + return nil + } if c, ok := conn.(*connection.AwsConnection); ok { asset.Id = c.Conf.Type + "://" + c.AccountId() asset.Name = c.Conf.Host diff --git a/providers/aws/resources/discovery_conversion.go b/providers/aws/resources/discovery_conversion.go index 0163a33945..781572c706 100644 --- a/providers/aws/resources/discovery_conversion.go +++ b/providers/aws/resources/discovery_conversion.go @@ -19,6 +19,7 @@ import ( awsec2ebstypes "go.mondoo.com/cnquery/providers/aws/connection/awsec2ebsconn/types" "go.mondoo.com/cnquery/providers/os/id/awsec2" "go.mondoo.com/cnquery/providers/os/id/containerid" + "go.mondoo.com/cnquery/providers/os/id/ids" ) type mqlObject struct { @@ -640,7 +641,7 @@ func SSMConnectAsset(args []string, opts map[string]string) *inventory.Asset { } asset := &inventory.Asset{} opts["instance"] = id - asset.IdDetector = []string{"aws-ec2"} + asset.IdDetector = []string{ids.IdDetector_CloudDetect} asset.Connections = []*inventory.Config{{ Type: "ssh", Host: id, @@ -668,7 +669,7 @@ func InstanceConnectAsset(args []string, opts map[string]string) *inventory.Asse } } asset := &inventory.Asset{} - asset.IdDetector = []string{"aws-ec2"} + asset.IdDetector = []string{ids.IdDetector_CloudDetect} opts["instance"] = id asset.Connections = []*inventory.Config{{ Type: "ssh",