Skip to content

Commit

Permalink
feat: add aws services (#1367)
Browse files Browse the repository at this point in the history
* feat: add aws services

* fix: links

Signed-off-by: Azanul <azanulhaque@gmail.com>

* fix: tidy

Signed-off-by: Azanul <azanulhaque@gmail.com>

* fix: lint

Signed-off-by: Azanul <azanulhaque@gmail.com>

---------

Signed-off-by: Azanul <azanulhaque@gmail.com>
Co-authored-by: Azanul <azanulhaque@gmail.com>
Co-authored-by: Azanul Haque <42029519+Azanul@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 8, 2024
1 parent 512a905 commit 3fdd340
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 21 deletions.
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0
github.com/BurntSushi/toml v1.2.1
github.com/aws/aws-sdk-go-v2 v1.25.1
github.com/aws/aws-sdk-go-v2 v1.25.2
github.com/aws/aws-sdk-go-v2/config v1.25.3
github.com/aws/aws-sdk-go-v2/service/apigateway v1.20.2
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.35.1
Expand All @@ -37,8 +37,11 @@ require (
github.com/aws/aws-sdk-go-v2/service/eks v1.33.1
github.com/aws/aws-sdk-go-v2/service/elasticache v1.32.2
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.24.2
github.com/aws/aws-sdk-go-v2/service/firehose v1.28.1
github.com/aws/aws-sdk-go-v2/service/iam v1.27.2
github.com/aws/aws-sdk-go-v2/service/kafka v1.30.1
github.com/aws/aws-sdk-go-v2/service/kinesis v1.22.2
github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2 v1.23.1
github.com/aws/aws-sdk-go-v2/service/kms v1.26.2
github.com/aws/aws-sdk-go-v2/service/lambda v1.48.0
github.com/aws/aws-sdk-go-v2/service/pricing v1.23.2
Expand All @@ -48,6 +51,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sns v1.25.2
github.com/aws/aws-sdk-go-v2/service/sqs v1.28.1
github.com/aws/aws-sdk-go-v2/service/sts v1.25.3
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.47.0
github.com/civo/civogo v0.3.24
github.com/digitalocean/godo v1.97.0
github.com/elazarl/go-bindata-assetfs v1.0.1
Expand Down Expand Up @@ -106,8 +110,8 @@ require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.16.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.3 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.27.1
Expand Down
20 changes: 14 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/apache/arrow/go/v11 v11.0.0 h1:hqauxvFQxww+0mEU/2XHG6LT7eZternCZq+A5Y
github.com/apache/arrow/go/v11 v11.0.0/go.mod h1:Eg5OsL5H+e299f7u5ssuXsuHQVEGC4xei5aX110hRiI=
github.com/apache/thrift v0.16.0 h1:qEy6UW60iVOlUy+b9ZR0d5WzUWYGOo4HfopoyBaNmoY=
github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU=
github.com/aws/aws-sdk-go-v2 v1.25.1 h1:P7hU6A5qEdmajGwvae/zDkOq+ULLC9tQBTwqqiwFGpI=
github.com/aws/aws-sdk-go-v2 v1.25.1/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo=
github.com/aws/aws-sdk-go-v2 v1.25.2 h1:/uiG1avJRgLGiQM9X3qJM8+Qa6KRGK5rRPuXE0HUM+w=
github.com/aws/aws-sdk-go-v2 v1.25.2/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.1 h1:ZY3108YtBNq96jNZTICHxN1gSBSbnvIdYwwqnvCV4Mc=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.1/go.mod h1:t8PYl/6LzdAqsU4/9tz28V/kU+asFePvpOMkdul0gEQ=
github.com/aws/aws-sdk-go-v2/config v1.25.3 h1:E4m9LbwJOoncDNt3e9MPLbz/saxWcGUlZVBydydD6+8=
Expand All @@ -72,10 +72,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.16.2 h1:0sdZ5cwfOAipTzZ7eOL0gw4LAhk/
github.com/aws/aws-sdk-go-v2/credentials v1.16.2/go.mod h1:sDdvGhXrSVT5yzBDR7qXz+rhbpiMpUYfF3vJ01QSdrc=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.4 h1:9wKDWEjwSnXZre0/O3+ZwbBl1SmlgWYBbrTV10X/H1s=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.4/go.mod h1:t4i+yGHMCcUNIX1x7YVYa6bH/Do7civ5I6cG/6PMfyA=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1 h1:evvi7FbTAoFxdP/mixmP7LIYzQWAmzBcwNB/es9XPNc=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1/go.mod h1:rH61DT6FDdikhPghymripNUCsf+uVF4Cnk4c4DBKH64=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.1 h1:RAnaIrbxPtlXNVI/OIlh1sidTQ3e1qM6LRjs7N0bE0I=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.1/go.mod h1:nbgAGkH5lk0RZRMh6A4K/oG6Xj11eC/1CyDow+DUAFI=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 h1:bNo4LagzUKbjdxE0tIcR9pMzLR2U/Tgie1Hq1HQ3iH8=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2/go.mod h1:wRQv0nN6v9wDXuWThpovGQjqF1HFdcgWjporw14lS8k=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 h1:EtOU5jsPdIQNP+6Q2C5e3d65NKT1PeCiQk+9OdzO12Q=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2/go.mod h1:tyF5sKccmDz0Bv4NrstEr+/9YkSPJHrcO7UsUKf7pWM=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1 h1:uR9lXYjdPX0xY+NhvaJ4dD8rpSRz5VY81ccIIoNG+lw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.3 h1:lMwCXiWJlrtZot0NJTjbC8G9zl+V3i68gBTBBvDeEXA=
Expand Down Expand Up @@ -120,6 +120,8 @@ github.com/aws/aws-sdk-go-v2/service/elasticache v1.32.2 h1:3V4GHH05PtNsDjXlKXVb
github.com/aws/aws-sdk-go-v2/service/elasticache v1.32.2/go.mod h1:p5/Vq+5NiyqnyQyH5JVK3lrHDygbiQiqdCNaDT018I8=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.24.2 h1:4pOJ+1slB9s36rDsHvnbUd93SZZ4+Z/FdX5f1TKOiQk=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.24.2/go.mod h1:NatT0jYQo0MfgZnIX8ReNWnbsl4rbQjuS+uci1KNkck=
github.com/aws/aws-sdk-go-v2/service/firehose v1.28.1 h1:MUpdcOKpTyPt6F3rgHZVs2o9sqpfMW1KEFsSeRw7srs=
github.com/aws/aws-sdk-go-v2/service/firehose v1.28.1/go.mod h1:Y4zm0U9Yl0wt9JOhgt97YeQe/st7UHDbSjvLd1j3Bp8=
github.com/aws/aws-sdk-go-v2/service/iam v1.27.2 h1:Z3a5I5kKGsuVW4kbrtHVnLGUHpEpo19zFyo6dzP2WCM=
github.com/aws/aws-sdk-go-v2/service/iam v1.27.2/go.mod h1:CYRyr95Q57xVvrcKJu3vw4jVVCZhmY1SyugM+EWXlzI=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.0 h1:a33HuFlO0KsveiP90IUJh8Xr/cx9US2PqkSroaLc+o8=
Expand All @@ -132,8 +134,12 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.0 h1:SHN/umDLT
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.0/go.mod h1:l8gPU5RYGOFHJqWEpPMoRTP0VoaWQSkJdKo+hwWnnDA=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.3 h1:KV0z2RDc7euMtg8aUT1czv5p29zcLlXALNFsd3jkkEc=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.3/go.mod h1:KZgs2ny8HsxRIRbDwgvJcHHBZPOzQr/+NtGwnP+w2ec=
github.com/aws/aws-sdk-go-v2/service/kafka v1.30.1 h1:oxzvFQDz9+IG6x8ONYdE5bSU+GnTJaUEcH6gBbyiz2Q=
github.com/aws/aws-sdk-go-v2/service/kafka v1.30.1/go.mod h1:sMIuF773eHxQ/sGAHTWG01xPqpyBD77gNlc0QabBvPk=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.22.2 h1:kav618UT9BH3kNhEXWo5YPphWBzcxLHp/VKmgXXqM34=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.22.2/go.mod h1:pDjJUf6yTIRPsSLDdVI2oR6A9Iv12P1NOL5KaJ9AeRI=
github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2 v1.23.1 h1:WRCH3UutBCpD7aZpLM6kqOz8eGBwF1nRDkWSGxphROI=
github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2 v1.23.1/go.mod h1:7g00ITXbKeUZE5G7HUcQ1u33bWPvVl+Q0V16kB/zK9E=
github.com/aws/aws-sdk-go-v2/service/kms v1.26.2 h1:cd6qixgKwsu4i1oT14brIYx9qZaXX/9CFrBncxYr7OY=
github.com/aws/aws-sdk-go-v2/service/kms v1.26.2/go.mod h1:SBBCPcfsuNkvXnW4sDzoPNeow6xOaU6g2xTfj1dfxo4=
github.com/aws/aws-sdk-go-v2/service/lambda v1.48.0 h1:Q1ajPX+B64b/OyxuaSDBjqOMmVrpNLhPfTFghpU783k=
Expand Down Expand Up @@ -170,6 +176,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.20.0 h1:/XiEU7VIFcVWRDQLabyrSjBo
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.20.0/go.mod h1:dWqm5G767qwKPuayKfzm4rjzFmVjiBFbOJrpSPnAMDs=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.3 h1:M2w4kiMGJCCM6Ljmmx/l6mmpfa3gPJVpBencfnsgvqs=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.3/go.mod h1:4EqRHDCKP78hq3zOnmFXu5k0j4bXbRFfCh/zQ6KnEfQ=
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.47.0 h1:mazKH8eHoNR8qYgu2dcwff3e/GsNTQ5ZPL5os3Rv7wg=
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.47.0/go.mod h1:UUrkvVfyLEVsyo5qQxBfb047u+3owYtxGzOxNIrwpPo=
github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw=
github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
Expand Down
8 changes: 8 additions & 0 deletions policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"ec2:DescribeSnapshots",
"ec2:DescribeSpotInstanceRequests",
"ec2:DescribeSubnets",
"ec2:DescribeTransitGatewayVpcAttachments",
"ec2:DescribeVolumes",
"ec2:DescribeVpcEndpoints",
"ec2:DescribeVpcPeeringConnections",
Expand All @@ -52,6 +53,13 @@
"elasticloadbalancing:DescribeTags",
"elasticloadbalancing:DescribeListeners",
"elasticloadbalancing:DescribeTargetGroups",
"kafka:ListClustersV2",
"kinesisanalytics:ListApplication",
"firehose:ListDeliveryStreams",
"ec2:DescribeNatGateways",
"ec2:DescribeTransitGatewayPeeringAttachments",
"WAFV2:ListWebACLs",
"sns:ListSubscriptions",
"iam:ListGroups",
"iam:ListInstanceProfiles",
"iam:ListOpenIDConnectProviders",
Expand Down
13 changes: 13 additions & 0 deletions providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"

"github.com/tailwarden/komiser/providers/aws/apigateway"
"github.com/tailwarden/komiser/providers/aws/cloudfront"
"github.com/tailwarden/komiser/providers/aws/cloudtrail"
Expand All @@ -27,8 +28,11 @@ import (
"github.com/tailwarden/komiser/providers/aws/eks"
"github.com/tailwarden/komiser/providers/aws/elasticache"
"github.com/tailwarden/komiser/providers/aws/elb"
"github.com/tailwarden/komiser/providers/aws/firehose"
"github.com/tailwarden/komiser/providers/aws/iam"
"github.com/tailwarden/komiser/providers/aws/kafka"
"github.com/tailwarden/komiser/providers/aws/kinesis"
"github.com/tailwarden/komiser/providers/aws/kinesisanalytics"
"github.com/tailwarden/komiser/providers/aws/kms"
"github.com/tailwarden/komiser/providers/aws/lambda"
"github.com/tailwarden/komiser/providers/aws/lightsail"
Expand All @@ -44,6 +48,7 @@ import (
"github.com/tailwarden/komiser/providers/aws/sqs"
"github.com/tailwarden/komiser/providers/aws/systemsmanager"
awsUtils "github.com/tailwarden/komiser/providers/aws/utils"
"github.com/tailwarden/komiser/providers/aws/wafv2"
"github.com/tailwarden/komiser/utils"

"github.com/uptrace/bun"
Expand Down Expand Up @@ -123,6 +128,14 @@ func listOfSupportedServices() []providers.FetchDataFunction {
cloudtrail.Trails,
datasync.Agents,
secretsmanager.Secrets,
ec2.TransitGatewayPeeringAttachments,
ec2.TransitGatewayVpcAttachments,
firehose.DeliveryStreams,
kinesisanalytics.KinesisAnalytics,
kafka.Kafka,
ec2.NatGateways,
sns.Subscriptions,
wafv2.WebAcls,
}
}

Expand Down
63 changes: 63 additions & 0 deletions providers/aws/ec2/nat_gateways.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ec2

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
)

func NatGateways(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
var config ec2.DescribeNatGatewaysInput
resources := make([]models.Resource, 0)
ec2Client := ec2.NewFromConfig(*client.AWSClient)

for {
output, err := ec2Client.DescribeNatGateways(ctx, &config)
if err != nil {
return resources, err
}

for _, natGateways := range output.NatGateways {
tags := make([]models.Tag, 0)
for _, tag := range natGateways.Tags {
tags = append(tags, models.Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}

resources = append(resources, models.Resource{
Provider: "AWS",
Account: client.Name,
Service: "Nat Gateway",
Region: client.AWSClient.Region,
ResourceId: *natGateways.NatGatewayId,
Cost: 0,
Name: *natGateways.NatGatewayId,
FetchedAt: time.Now(),
Tags: tags,
Link: fmt.Sprintf("https:/%s.console.aws.amazon.com/vpc/home?region=%s#NatGateway:natGatewayId=%s", client.AWSClient.Region, client.AWSClient.Region, *natGateways.NatGatewayId),
})
}
if aws.ToString(output.NextToken) == "" {
break
}

config.NextToken = output.NextToken
}
log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "Nat Gateway",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}
63 changes: 63 additions & 0 deletions providers/aws/ec2/transit_peering_attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ec2

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
)

func TransitGatewayPeeringAttachments(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
var config ec2.DescribeTransitGatewayPeeringAttachmentsInput
resources := make([]models.Resource, 0)
ec2Client := ec2.NewFromConfig(*client.AWSClient)

for {
output, err := ec2Client.DescribeTransitGatewayPeeringAttachments(ctx, &config)
if err != nil {
return resources, err
}

for _, tAttachment := range output.TransitGatewayPeeringAttachments {
tags := make([]models.Tag, 0)
for _, tag := range tAttachment.Tags {
tags = append(tags, models.Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}

resources = append(resources, models.Resource{
Provider: "AWS",
Account: client.Name,
Service: "Transit Gateway Peering Attachments",
Region: client.AWSClient.Region,
ResourceId: *tAttachment.TransitGatewayAttachmentId,
Cost: 0,
Name: *tAttachment.TransitGatewayAttachmentId,
FetchedAt: time.Now(),
Tags: tags,
Link: fmt.Sprintf("https:/%s.console.aws.amazon.com/vpc/home?region=%s#TransitGatewayAttachment:transitGatewayAttachmentId=%s", client.AWSClient.Region, client.AWSClient.Region, *tAttachment.TransitGatewayAttachmentId),
})
}
if aws.ToString(output.NextToken) == "" {
break
}

config.NextToken = output.NextToken
}
log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "Transit Gateway Peering Attachments",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}
63 changes: 63 additions & 0 deletions providers/aws/ec2/transit_vpc_attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ec2

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
)

func TransitGatewayVpcAttachments(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
var config ec2.DescribeTransitGatewayVpcAttachmentsInput
resources := make([]models.Resource, 0)
ec2Client := ec2.NewFromConfig(*client.AWSClient)

for {
output, err := ec2Client.DescribeTransitGatewayVpcAttachments(ctx, &config)
if err != nil {
return resources, err
}

for _, tAttachment := range output.TransitGatewayVpcAttachments {
tags := make([]models.Tag, 0)
for _, tag := range tAttachment.Tags {
tags = append(tags, models.Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}

resources = append(resources, models.Resource{
Provider: "AWS",
Account: client.Name,
Service: "Transit Gateway Vpc Attachments",
Region: client.AWSClient.Region,
ResourceId: *tAttachment.TransitGatewayAttachmentId,
Cost: 0,
Name: *tAttachment.TransitGatewayAttachmentId,
FetchedAt: time.Now(),
Tags: tags,
Link: fmt.Sprintf("https:/%s.console.aws.amazon.com/vpc/home?region=%s#TransitGatewayAttachment:transitGatewayAttachmentId=%s", client.AWSClient.Region, client.AWSClient.Region, *tAttachment.TransitGatewayAttachmentId),
})
}
if aws.ToString(output.NextToken) == "" {
break
}

config.NextToken = output.NextToken
}
log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "Transit Gateway Vpc Attachments",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}
Loading

0 comments on commit 3fdd340

Please sign in to comment.