Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 aws fixes; make aws ec2 instance-connect and aws ec2 ssm work #1707

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions providers/aws/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ package config
import (
"go.mondoo.com/cnquery/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/providers/aws/connection"
"go.mondoo.com/cnquery/providers/aws/connection/awsec2ebsconn"
"go.mondoo.com/cnquery/providers/aws/provider"
)

var Config = plugin.Provider{
Name: "aws",
ID: "go.mondoo.com/cnquery/providers/aws",
Version: "9.0.0",
ConnectionTypes: []string{provider.DefaultConnectionType},
ConnectionTypes: []string{provider.DefaultConnectionType, string(awsec2ebsconn.EBSConnectionType)},
vjeffrey marked this conversation as resolved.
Show resolved Hide resolved
Connectors: []plugin.Connector{
{
Name: "aws",
Use: "aws",
Short: "aws account",
MinArgs: 0,
MaxArgs: 0,
MaxArgs: 4,
Discovery: []string{
connection.DiscoveryAccounts,
connection.DiscoveryAll,
Expand Down Expand Up @@ -77,6 +78,12 @@ var Config = plugin.Provider{
Default: "",
Desc: "Endpoint URL override for authentication with the API",
},
{
Long: "no-setup",
Type: plugin.FlagType_String,
Default: "",
Desc: "Override option for EBS scanning that tells it to not create the snapshot or volume",
},
},
},
},
Expand Down
48 changes: 48 additions & 0 deletions providers/aws/connection/awsec2ebsconn/destroy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package awsec2ebsconn

import (
"context"
"time"

"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/rs/zerolog/log"
awsec2ebstypes "go.mondoo.com/cnquery/providers/aws/connection/awsec2ebsconn/types"
)

func (c *AwsEbsConnection) DetachVolumeFromInstance(ctx context.Context, volume *awsec2ebstypes.VolumeInfo) error {
log.Info().Msg("detach volume")
res, err := c.scannerRegionEc2svc.DetachVolume(ctx, &ec2.DetachVolumeInput{
Device: aws.String(c.volumeMounter.VolumeAttachmentLoc), VolumeId: &volume.Id,
InstanceId: &c.scannerInstance.Id,
})
if err != nil {
return err
}
if res.State != types.VolumeAttachmentStateDetached { // check if it's detached already
var volState types.VolumeState
for volState != types.VolumeStateAvailable {
time.Sleep(10 * time.Second)
resp, err := c.scannerRegionEc2svc.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{VolumeIds: []string{volume.Id}})
if err != nil {
return err
}
if len(resp.Volumes) == 1 {
volState = resp.Volumes[0].State

log.Info().Interface("state", volState).Msg("waiting for volume detachment completion")
}
}
}
return nil
}

func (c *AwsEbsConnection) DeleteCreatedVolume(ctx context.Context, volume *awsec2ebstypes.VolumeInfo) error {
log.Info().Msg("delete created volume")
_, err := c.scannerRegionEc2svc.DeleteVolume(ctx, &ec2.DeleteVolumeInput{VolumeId: &volume.Id})
return err
}
Loading