Skip to content

Commit

Permalink
✨ Add AWS VPC Endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Marius Kimmina <[email protected]>
  • Loading branch information
mariuskimmina committed Sep 22, 2023
1 parent 6cd174f commit bb75eb5
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 0 deletions.
18 changes: 18 additions & 0 deletions providers/aws/resources/aws.lr
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ private aws.vpc @defaults("arn isDefault") {
isDefault bool
// Region the VPC exists in
region string
// A list of endpoints for the VPC
endpoints() []aws.vpc.endpoint
// A list of flowlogs for the VPC
flowLogs() []aws.vpc.flowlog
// List of route tables for the VPC
Expand All @@ -62,6 +64,22 @@ private aws.vpc.routetable @defaults("id") {
routes []dict
}

// Amazon Virtual Private Cloud (VPC) Endpoint
private aws.vpc.endpoint @defaults("id") {
// Unique ID of the endpoint
id string
// type of the endpoint
type string
// VPC the endpoint exists in
vpc string
// The name of the endpoint service
serviceName string
// The policy document associated with the endpoint, if applicable.
policyDocument string
// the subnets for the (interface) endpoint
subnets []string
}

// Amazon Virtual Private Cloud (VPC) Flow Log
private aws.vpc.flowlog @defaults("id region status") {
// Unique ID of the flow log
Expand Down
143 changes: 143 additions & 0 deletions providers/aws/resources/aws.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions providers/aws/resources/aws.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,8 @@ resources:
aws.vpc:
fields:
arn: {}
endpoints:
min_mondoo_version: 9.0.0
flowLogs: {}
id: {}
isDefault: {}
Expand All @@ -1433,6 +1435,19 @@ resources:
platform:
name:
- aws
aws.vpc.endpoint:
fields:
id: {}
policyDocument: {}
serviceName: {}
subnets: {}
type: {}
vpc: {}
is_private: true
min_mondoo_version: 9.0.0
platform:
name:
- aws
aws.vpc.flowlog:
fields:
id: {}
Expand Down
44 changes: 44 additions & 0 deletions providers/aws/resources/aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,50 @@ func (a *mqlAws) getVpcs(conn *connection.AwsConnection) []*jobpool.Job {
return tasks
}

func (a *mqlAwsVpc) endpoints() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
vpc := a.Id.Data

svc := conn.Ec2(a.Region.Data)
ctx := context.Background()
endpoints := []interface{}{}
filterKeyVal := "vpc-id"
nextToken := aws.String("no_token_to_start_with")
params := &ec2.DescribeVpcEndpointsInput{Filters: []vpctypes.Filter{{Name: &filterKeyVal, Values: []string{vpc}}}}
for nextToken != nil {
endpointsRes, err := svc.DescribeVpcEndpoints(ctx, params)
if err != nil {
return nil, err
}
nextToken = endpointsRes.NextToken
if endpointsRes.NextToken != nil {
params.NextToken = nextToken
}

for _, endpoint := range endpointsRes.VpcEndpoints {
var subnetIds []interface{}
for _, subnet := range endpoint.SubnetIds {
subnetIds = append(subnetIds, subnet)
}
mqlEndpoint, err := CreateResource(a.MqlRuntime, "aws.vpc.endpoint",
map[string]*llx.RawData{
"id": llx.StringData(*endpoint.VpcEndpointId),
"type": llx.StringData(string(endpoint.VpcEndpointType)),
"vpc": llx.StringData(*endpoint.VpcId),
"serviceName": llx.StringData(*endpoint.ServiceName),
"policyDocument": llx.StringData(*endpoint.PolicyDocument),
"subnets": llx.ArrayData(subnetIds, types.String),
},
)
if err != nil {
return nil, err
}
endpoints = append(endpoints, mqlEndpoint)
}
}
return endpoints, nil
}

func (a *mqlAwsVpc) flowLogs() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
vpc := a.Id.Data
Expand Down

0 comments on commit bb75eb5

Please sign in to comment.