Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link to ECS service for RDS enrollment #44707

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

3 changes: 2 additions & 1 deletion api/proto/teleport/integration/v1/awsoidc_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ message DeployDatabaseServiceDeployment {
message DeployDatabaseServiceResponse {
// ClusterArn identifies the cluster where the deployment was made.
string cluster_arn = 1;
// ClusterDashboardUrl is the URL for Amazon Web Console that links directly to the Amazon ECS Cluster.
// ClusterDashboardURL is a link to the Amazon ECS cluster dashboard or a
// specific cluster service if a single deployment was requested.
string cluster_dashboard_url = 2;
}

Expand Down
26 changes: 21 additions & 5 deletions lib/integrations/awsoidc/deploydatabaseservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ type DeployDatabaseServiceResponse struct {
// ClusterARN is the Amazon ECS Cluster ARN where the task was started.
ClusterARN string

// ClusterDashboardURL is a link to the Cluster's Dashboard URL in Amazon Console.
// ClusterDashboardURL is a link to the Amazon ECS cluster dashboard or
// a specific cluster service if a single deployment was requested.
ClusterDashboardURL string
}

Expand Down Expand Up @@ -214,7 +215,7 @@ func DeployDatabaseService(ctx context.Context, clt DeployServiceClient, req Dep
)

log.DebugContext(ctx, "Upsert ECS Cluster")
cluster, err := upsertCluster(ctx, clt, req.ecsClusterName, req.ResourceCreationTags)
ecsCluster, err := upsertCluster(ctx, clt, req.ecsClusterName, req.ResourceCreationTags)
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -260,11 +261,22 @@ func DeployDatabaseService(ctx context.Context, clt DeployServiceClient, req Dep
}

return &DeployDatabaseServiceResponse{
ClusterARN: aws.ToString(cluster.ClusterArn),
ClusterDashboardURL: ecsClusterDashboardURL(req.Region, aws.ToString(cluster.ClusterName)),
ClusterARN: aws.ToString(ecsCluster.ClusterArn),
ClusterDashboardURL: deploymentURL(req.Region, aws.ToString(ecsCluster.ClusterName), req.Deployments),
}, nil
}

// deploymentURL returns a link to the service in the ECS cluster for a single
// deployment, which is the nominal case since we updated the enrollment flow
// to deploy a single VPC at a time, or a link to the ECS cluster overview
// if multiple deployments are requested.
func deploymentURL(region, ecsClusterName string, deps []DeployDatabaseServiceRequestDeployment) string {
if len(deps) == 1 {
return ecsServiceDashboardURL(region, ecsClusterName, deps[0].VPCID)
}
return ecsClusterDashboardURL(region, ecsClusterName)
}

// ecsTaskName returns the normalized ECS TaskDefinition Family
func ecsTaskName(teleportClusterName, deploymentMode, vpcid string) string {
return normalizeECSResourceName(fmt.Sprintf("%s-teleport-%s-%s", teleportClusterName, deploymentMode, vpcid))
Expand Down Expand Up @@ -294,7 +306,11 @@ func ECSDatabaseServiceDashboardURL(region, teleportClusterName, vpcID string) (
return "", trace.BadParameter("empty VPC ID")
}
ecsClusterName := normalizeECSClusterName(teleportClusterName)
return ecsServiceDashboardURL(region, ecsClusterName, vpcID), nil
}

func ecsServiceDashboardURL(region, ecsClusterName, vpcID string) string {
ecsClusterDashboard := ecsClusterDashboardURL(region, ecsClusterName)
serviceName := ecsServiceName(DatabaseServiceDeploymentMode, vpcID)
return fmt.Sprintf("%s/%s", ecsClusterDashboard, serviceName), nil
return fmt.Sprintf("%s/%s", ecsClusterDashboard, serviceName)
}
4 changes: 2 additions & 2 deletions lib/integrations/awsoidc/deploydatabaseservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func TestDeployDatabaseService(t *testing.T) {
},
)
require.NoError(t, err)
require.Equal(t, "https://us-east-1.console.aws.amazon.com/ecs/v2/clusters/cluster-name-teleport/services", resp.ClusterDashboardURL)
require.Equal(t, "https://us-east-1.console.aws.amazon.com/ecs/v2/clusters/cluster-name-teleport/services/database-service-vpc-123", resp.ClusterDashboardURL)
require.Equal(t, "ARNcluster-name-teleport", resp.ClusterARN)
require.Contains(t, mockClient.clusters, "cluster-name-teleport")
require.Contains(t, mockClient.services, "database-service-vpc-123")
Expand Down Expand Up @@ -550,7 +550,7 @@ func TestDeployDatabaseService(t *testing.T) {
},
)
require.NoError(t, err)
require.Equal(t, "https://us-east-1.console.aws.amazon.com/ecs/v2/clusters/cluster-name-teleport/services", resp.ClusterDashboardURL)
require.Equal(t, "https://us-east-1.console.aws.amazon.com/ecs/v2/clusters/cluster-name-teleport/services/database-service-vpc-123", resp.ClusterDashboardURL)
require.Equal(t, "ARNcluster-name-teleport", resp.ClusterARN)
})
}
Expand Down
Loading