From 0f04f4bd7a745ddbec629d0a5cac52f2478deae8 Mon Sep 17 00:00:00 2001 From: vjeffrey Date: Fri, 2 Feb 2024 15:28:22 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20crash=20on=20aws.iam.virtu?= =?UTF-8?q?alMfaDevices=20&=20logGroup.metricsFilters=20alarms=20failure?= =?UTF-8?q?=20(#3190)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 fix crash on aws.iam.virtualMfaDevices * 🐛 fix aws cloudwatch logs metrics alarms initialization * set the error for the virtualmfadevice --- providers/aws/resources/aws_cloudwatch.go | 2 +- providers/aws/resources/aws_ec2.go | 2 +- providers/aws/resources/aws_iam.go | 36 +++++++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/providers/aws/resources/aws_cloudwatch.go b/providers/aws/resources/aws_cloudwatch.go index f4c7912fd7..ecfa5506fa 100644 --- a/providers/aws/resources/aws_cloudwatch.go +++ b/providers/aws/resources/aws_cloudwatch.go @@ -431,7 +431,7 @@ func (a *mqlAwsCloudwatchMetric) alarms() ([]interface{}, error) { } res := []interface{}{} for _, alarm := range alarmsResp.MetricAlarms { - mqlAlarm, err := CreateResource(a.MqlRuntime, "aws.cloudwatch.metricsalarm", + mqlAlarm, err := NewResource(a.MqlRuntime, "aws.cloudwatch.metricsalarm", map[string]*llx.RawData{"arn": llx.StringData(convert.ToString(alarm.AlarmArn))}) if err != nil { return nil, err diff --git a/providers/aws/resources/aws_ec2.go b/providers/aws/resources/aws_ec2.go index 5e89d719e2..ddf61a974c 100644 --- a/providers/aws/resources/aws_ec2.go +++ b/providers/aws/resources/aws_ec2.go @@ -748,7 +748,7 @@ func (a *mqlAwsEc2) gatherInstanceInfo(instances []ec2types.Reservation, imdsvVe if err == nil { args["image"] = llx.ResourceData(mqlImage, mqlImage.MqlName()) } else { - log.Error().Err(err).Msg("cannot find image") + // this is a common case, logging the error here only creates confusion args["image"] = llx.NilData } } else { diff --git a/providers/aws/resources/aws_iam.go b/providers/aws/resources/aws_iam.go index a4d4d169d5..1a32b3fa68 100644 --- a/providers/aws/resources/aws_iam.go +++ b/providers/aws/resources/aws_iam.go @@ -288,7 +288,9 @@ func (a *mqlAwsIam) virtualMfaDevices() ([]interface{}, error) { devicesResp, err := svc.ListVirtualMFADevices(ctx, &iam.ListVirtualMFADevicesInput{}) if err != nil { - return nil, errors.Wrap(err, "could not gather aws iam virtual-mfa-devices") + log.Error().Err(err).Msg("cannot gather virtual mfa devices info") + a.VirtualMfaDevices = plugin.TValue[[]interface{}]{Error: err, State: plugin.StateIsSet} + return nil, nil } // note: adding pagination to this call results in Throttling: Rate exceeded error @@ -721,23 +723,25 @@ func initAwsIamUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[ ctx := context.Background() if args["name"] != nil { - username := args["name"].Value.(string) - resp, err := svc.GetUser(ctx, &iam.GetUserInput{ - UserName: &username, - }) - if err != nil { - return nil, nil, err - } + if usr, ok := args["name"].Value.(string); ok { + username := usr + resp, err := svc.GetUser(ctx, &iam.GetUserInput{ + UserName: &username, + }) + if err != nil { + return nil, nil, err + } - usr := resp.User - args["arn"] = llx.StringDataPtr(usr.Arn) - args["id"] = llx.StringDataPtr(usr.UserId) - args["name"] = llx.StringDataPtr(usr.UserName) - args["createDate"] = llx.TimeDataPtr(usr.CreateDate) - args["passwordLastUsed"] = llx.TimeDataPtr(usr.PasswordLastUsed) - args["tags"] = llx.MapData(iamTagsToMap(usr.Tags), types.String) + usr := resp.User + args["arn"] = llx.StringDataPtr(usr.Arn) + args["id"] = llx.StringDataPtr(usr.UserId) + args["name"] = llx.StringDataPtr(usr.UserName) + args["createDate"] = llx.TimeDataPtr(usr.CreateDate) + args["passwordLastUsed"] = llx.TimeDataPtr(usr.PasswordLastUsed) + args["tags"] = llx.MapData(iamTagsToMap(usr.Tags), types.String) - return args, nil, nil + return args, nil, nil + } } return args, nil, nil