From b0760900ba1cb6f190a00cba16d5dc2b1500fc79 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sun, 21 Jan 2024 03:30:29 -0800 Subject: [PATCH] Add discovery for aws-rds-dbcluster (#3027) RDS clusters are very important and should be scanned as their own assets with checks applied to those assets. This starts that process. Signed-off-by: Tim Smith --- providers/aws/config/config.go | 1 + providers/aws/connection/platform.go | 2 ++ providers/aws/resources/discovery.go | 28 +++++++++++++++++++ .../aws/resources/discovery_conversion.go | 3 ++ 4 files changed, 34 insertions(+) diff --git a/providers/aws/config/config.go b/providers/aws/config/config.go index c7fa1e3ae7..651bb1fa6d 100644 --- a/providers/aws/config/config.go +++ b/providers/aws/config/config.go @@ -38,6 +38,7 @@ var Config = plugin.Provider{ resources.DiscoveryS3Buckets, resources.DiscoveryCloudtrailTrails, resources.DiscoveryRdsDbInstances, + resources.DiscoveryRdsDbClusters, resources.DiscoveryVPCs, resources.DiscoverySecurityGroups, resources.DiscoveryIAMUsers, diff --git a/providers/aws/connection/platform.go b/providers/aws/connection/platform.go index a956b00b0f..705191cb7e 100644 --- a/providers/aws/connection/platform.go +++ b/providers/aws/connection/platform.go @@ -34,6 +34,8 @@ func getTitleForPlatformName(name string) string { return "AWS CloudTrail Trail" case "aws-rds-dbinstance": return "AWS RDS DB Instance" + case "aws-rds-dbcluster": + return "AWS RDS DB Cluster" case "aws-dynamodb-table": return "AWS DynamoDB Table" case "aws-redshift-cluster": diff --git a/providers/aws/resources/discovery.go b/providers/aws/resources/discovery.go index 6778021af2..69a73196a4 100644 --- a/providers/aws/resources/discovery.go +++ b/providers/aws/resources/discovery.go @@ -33,6 +33,7 @@ const ( DiscoveryS3Buckets = "s3-buckets" DiscoveryCloudtrailTrails = "cloudtrail-trails" DiscoveryRdsDbInstances = "rds-dbinstances" + DiscoveryRdsDbClusters = "rds-dbclusters" DiscoveryVPCs = "vpcs" DiscoverySecurityGroups = "security-groups" DiscoveryIAMUsers = "iam-users" @@ -71,6 +72,7 @@ var AllAPIResources = []string{ DiscoveryS3Buckets, DiscoveryCloudtrailTrails, DiscoveryRdsDbInstances, + DiscoveryRdsDbClusters, DiscoveryVPCs, DiscoverySecurityGroups, DiscoveryIAMUsers, @@ -525,6 +527,32 @@ func discover(runtime *plugin.Runtime, awsAccount *mqlAwsAccount, target string, } assetList = append(assetList, MqlObjectToAsset(accountId, m, conn)) } + case DiscoveryRdsDbClusters: + res, err := NewResource(runtime, "aws.rds", map[string]*llx.RawData{}) + if err != nil { + return nil, err + } + + r := res.(*mqlAwsRds) + + clusters := r.GetDbClusters() + if clusters == nil { + return assetList, nil + } + + for i := range clusters.Data { + f := clusters.Data[i].(*mqlAwsRdsDbcluster) + + tags := mapStringInterfaceToStringString(f.Tags.Data) + m := mqlObject{ + name: f.Id.Data, labels: tags, + awsObject: awsObject{ + account: accountId, region: f.Region.Data, arn: f.Arn.Data, + id: f.Id.Data, service: "rds", objectType: "dbcluster", + }, + } + assetList = append(assetList, MqlObjectToAsset(accountId, m, conn)) + } case DiscoveryVPCs: res, err := NewResource(runtime, "aws", map[string]*llx.RawData{}) if err != nil { diff --git a/providers/aws/resources/discovery_conversion.go b/providers/aws/resources/discovery_conversion.go index 99e8dfaa24..6d3768850c 100644 --- a/providers/aws/resources/discovery_conversion.go +++ b/providers/aws/resources/discovery_conversion.go @@ -111,6 +111,9 @@ func getPlatformName(awsObject awsObject) string { if awsObject.objectType == "dbinstance" { return "aws-rds-dbinstance" } + if awsObject.objectType == "dbcluster" { + return "aws-rds-dbcluster" + } case "dynamodb": if awsObject.objectType == "table" { return "aws-dynamodb-table"