Skip to content

Commit

Permalink
add ListVPCs to AWS OIDC integration service (#44313)
Browse files Browse the repository at this point in the history
* add ListVPCs to AWS OIDC integration service

* add databasevpcs endpoint for AWS OIDC integration

* set DescribeVpcs page size to 100
  • Loading branch information
GavinFrazar authored Jul 26, 2024
1 parent 8e9cfc6 commit 6c24047
Show file tree
Hide file tree
Showing 13 changed files with 1,433 additions and 647 deletions.
897 changes: 574 additions & 323 deletions api/gen/proto/go/teleport/integration/v1/awsoidc_service.pb.go

Large diffs are not rendered by default.

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

37 changes: 36 additions & 1 deletion api/proto/teleport/integration/v1/awsoidc_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ service AWSOIDCService {
// https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSubnets.html
rpc ListSubnets(ListSubnetsRequest) returns (ListSubnetsResponse);

// ListVPCs returns a list of AWS VPCs.
// It uses the following API:
// https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcs.html
rpc ListVPCs(ListVPCsRequest) returns (ListVPCsResponse);

// DeployDatabaseService deploys a Database Services to Amazon ECS.
rpc DeployDatabaseService(DeployDatabaseServiceRequest) returns (DeployDatabaseServiceResponse);

Expand Down Expand Up @@ -262,7 +267,7 @@ message ListSubnetsRequest {

// Subnet is a representation of an AWS VPC subnet.
message Subnet {
// Name is the subnet name.
// Name is the subnet name. Can be empty.
string name = 1;
// ID is the subnet ID.
string id = 2;
Expand All @@ -279,6 +284,36 @@ message ListSubnetsResponse {
string next_token = 2;
}

// ListVPCsRequest is a request for a paginated list of AWS VPCs.
message ListVPCsRequest {
// Integration is the AWS OIDC Integration name.
// Required.
string integration = 1;
// Region is the AWS Region
// Required.
string region = 2;
// NextToken is the token to be used to fetch the next page.
// If empty, the first page is fetched.
string next_token = 3;
}

// VPC is a representation of an AWS VPC.
message VPC {
// Name is the VPC name. Can be empty.
string name = 1;
// ID is the VPC ID.
string id = 2;
}

// ListVPCsResponse contains a page of AWS VPCs.
message ListVPCsResponse {
// VPCs contains the page of VPCs.
repeated VPC vpcs = 1;
// NextToken is used for pagination.
// If non-empty, it can be used to request the next page.
string next_token = 2;
}

// DeployDatabaseServiceRequest is a request to deploy .
message DeployDatabaseServiceRequest {
// Integration is the AWS OIDC Integration name.
Expand Down
42 changes: 42 additions & 0 deletions lib/auth/integration/integrationv1/awsoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,3 +716,45 @@ func (s *AWSOIDCService) ListSubnets(ctx context.Context, req *integrationpb.Lis
NextToken: resp.NextToken,
}, nil
}

// ListVPCs returns a list of AWS VPCs.
func (s *AWSOIDCService) ListVPCs(ctx context.Context, req *integrationpb.ListVPCsRequest) (*integrationpb.ListVPCsResponse, error) {
authCtx, err := s.authorizer.Authorize(ctx)
if err != nil {
return nil, trace.Wrap(err)
}

if err := authCtx.CheckAccessToKind(types.KindIntegration, types.VerbUse); err != nil {
return nil, trace.Wrap(err)
}

awsClientReq, err := s.awsClientReq(ctx, req.Integration, req.Region)
if err != nil {
return nil, trace.Wrap(err)
}

awsClient, err := awsoidc.NewListVPCsClient(ctx, awsClientReq)
if err != nil {
return nil, trace.Wrap(err)
}

resp, err := awsoidc.ListVPCs(ctx, awsClient, awsoidc.ListVPCsRequest{
NextToken: req.NextToken,
})
if err != nil {
return nil, trace.Wrap(err)
}

vpcs := make([]*integrationpb.VPC, 0, len(resp.VPCs))
for _, s := range resp.VPCs {
vpcs = append(vpcs, &integrationpb.VPC{
Name: s.Name,
Id: s.ID,
})
}

return &integrationpb.ListVPCsResponse{
Vpcs: vpcs,
NextToken: resp.NextToken,
}, nil
}
Loading

0 comments on commit 6c24047

Please sign in to comment.