Skip to content

Commit

Permalink
🐛 ensure ec2 instances dont get aws platform
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Sep 20, 2023
1 parent 5400b87 commit 15226e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion providers/aws/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions providers/aws/resources/discovery_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 15226e5

Please sign in to comment.