Skip to content
Merged
11 changes: 11 additions & 0 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ const (
// that the resource originates from.
OriginLabel = TeleportNamespace + "/origin"

// ClusterLabel is a label that identifies the current cluster when creating resources on another systems.
// Eg, when creating a resource in AWS, this label must be set as a Tag in the resource.
ClusterLabel = TeleportNamespace + "/cluster"

// ADLabel is a resource metadata label name used to identify if resource is part of Active Directory
ADLabel = TeleportNamespace + "/ad"

Expand Down Expand Up @@ -467,6 +471,13 @@ const (
// created from the Okta service.
OriginOkta = "okta"

// OriginIntegrationAWSOIDC is an origin value indicating that the resource was
// created from the AWS OIDC Integration.
OriginIntegrationAWSOIDC = "integration_awsoidc"

// IntegrationLabel is a resource metadata label name used to identify the integration name that created the resource.
IntegrationLabel = TeleportNamespace + "/integration"

// AWSAccountIDLabel is used to identify nodes by AWS account ID
// found via automatic discovery, to avoid re-running installation
// commands on the node.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.67
github.com/aws/aws-sdk-go-v2/service/athena v1.30.0
github.com/aws/aws-sdk-go-v2/service/ec2 v1.98.0
github.com/aws/aws-sdk-go-v2/service/ecs v1.27.1
github.com/aws/aws-sdk-go-v2/service/glue v1.50.0
github.com/aws/aws-sdk-go-v2/service/rds v1.44.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.33.1
Expand Down Expand Up @@ -167,6 +168,7 @@ require (
google.golang.org/grpc/examples v0.0.0-20221010194801-c67245195065
google.golang.org/protobuf v1.30.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/dnaeon/go-vcr.v3 v3.1.2
gopkg.in/ini.v1 v1.67.0
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.7 h1:yb2o8oh3Y+Gg2g+wlzrWS3p
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.7/go.mod h1:1MNss6sqoIsFGisX92do/5doiUCBrN7EjhZCS/8DUjI=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.98.0 h1:WblDV33AG9dhv0zFEPEmGtD5UECSNpKMxtdENULfR8M=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.98.0/go.mod h1:L3ZT0N/vBsw77mOAawXmRnREpEjcHd2v5Hzf7AkIH8M=
github.com/aws/aws-sdk-go-v2/service/ecs v1.27.1 h1:54QSuWR3Pot7HqBRXd+c1yF97h2bqzDBID8qFSAkTlE=
github.com/aws/aws-sdk-go-v2/service/ecs v1.27.1/go.mod h1:SB6YszwN1iKvyt/Qk+ICeKsfBxjd0CTEwwkmej9qoa0=
github.com/aws/aws-sdk-go-v2/service/glue v1.50.0 h1:GF6Lsy9g1+Ig2e1TpGygl00+oBcdYHIMyTHoKZa9VGE=
github.com/aws/aws-sdk-go-v2/service/glue v1.50.0/go.mod h1:agadckFdb7BwFqeN4CXt3yrMtoFvY/8b2F+8FNeHVOc=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1/go.mod h1:GeUru+8VzrTXV/83XyMJ80KpH8xO89VPoUileyNQ+tc=
Expand Down Expand Up @@ -2393,6 +2395,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/dnaeon/go-vcr.v3 v3.1.2 h1:F1smfXBqQqwpVifDfUBQG6zzaGjzT+EnVZakrOdr5wA=
gopkg.in/dnaeon/go-vcr.v3 v3.1.2/go.mod h1:2IMOnnlx9I6u9x+YBsM3tAMx6AlOxnJ0pWxQAzZ79Ag=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
Expand Down
29 changes: 29 additions & 0 deletions lib/integrations/awsoidc/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/gravitational/trace"
)

// AWSClientRequest contains the required fields to set up an AWS service client.
type AWSClientRequest struct {
// IntegrationName is the integration name that is going to issue an API Call.
IntegrationName string

// Token is the token used to issue the API Call.
Token string

Expand All @@ -37,10 +41,17 @@ type AWSClientRequest struct {

// Region where the API call should be made.
Region string

// httpClient used in tests.
httpClient aws.HTTPClient
}

// CheckAndSetDefaults checks if the required fields are present.
func (req *AWSClientRequest) CheckAndSetDefaults() error {
if req.IntegrationName == "" {
return trace.BadParameter("integration name is required")
}

if req.Token == "" {
return trace.BadParameter("token is required")
}
Expand All @@ -58,11 +69,19 @@ func (req *AWSClientRequest) CheckAndSetDefaults() error {

// newAWSConfig creates a new [aws.Config] using the [AWSClientRequest] fields.
func newAWSConfig(ctx context.Context, req *AWSClientRequest) (*aws.Config, error) {
if err := req.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}

cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(req.Region))
if err != nil {
return nil, trace.Wrap(err)
}

if req.httpClient != nil {
cfg.HTTPClient = req.httpClient
}

cfg.Credentials = stscreds.NewWebIdentityRoleProvider(
sts.NewFromConfig(cfg),
req.RoleARN,
Expand All @@ -82,6 +101,16 @@ func newRDSClient(ctx context.Context, req *AWSClientRequest) (*rds.Client, erro
return rds.NewFromConfig(*cfg), nil
}

// newECSClient creates an [ecs.Client] using the provided Token, RoleARN and Region.
func newECSClient(ctx context.Context, req *AWSClientRequest) (*ecs.Client, error) {
cfg, err := newAWSConfig(ctx, req)
if err != nil {
return nil, trace.Wrap(err)
}

return ecs.NewFromConfig(*cfg), nil
}

// IdentityToken is an implementation of [stscreds.IdentityTokenRetriever] for returning a static token.
type IdentityToken string

Expand Down
Loading