Skip to content

Commit

Permalink
Use stsutils.NewFromConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
codingllama committed Feb 6, 2025
1 parent 4ad68bc commit 0cc9899
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/auth/join_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ import (
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"github.com/aws/aws-sdk-go-v2/service/ec2"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/digitorus/pkcs7"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/aws/stsutils"
)

type ec2Client interface {
Expand Down Expand Up @@ -96,7 +96,7 @@ func checkInstanceRunning(ctx context.Context, instanceID, region, IAMRole strin

// assume the configured IAM role if necessary
if IAMRole != "" {
stsClient := sts.NewFromConfig(awsClientConfig)
stsClient := stsutils.NewFromConfig(awsClientConfig)
creds := stscreds.NewAssumeRoleProvider(stsClient, IAMRole)
awsClientConfig.Credentials = aws.NewCredentialsCache(creds)
}
Expand Down
5 changes: 3 additions & 2 deletions lib/integrations/awsoidc/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/gravitational/trace"

awsutils "github.com/gravitational/teleport/api/utils/aws"
"github.com/gravitational/teleport/lib/utils/aws/stsutils"
)

// AWSClientRequest contains the required fields to set up an AWS service client.
Expand Down Expand Up @@ -92,7 +93,7 @@ func newAWSConfig(ctx context.Context, req *AWSClientRequest) (*aws.Config, erro
}

cfg.Credentials = stscreds.NewWebIdentityRoleProvider(
sts.NewFromConfig(cfg),
stsutils.NewFromConfig(cfg),
req.RoleARN,
IdentityToken(req.Token),
)
Expand Down Expand Up @@ -136,7 +137,7 @@ func newSTSClient(ctx context.Context, req *AWSClientRequest) (*sts.Client, erro
return nil, trace.Wrap(err)
}

return sts.NewFromConfig(*cfg), nil
return stsutils.NewFromConfig(*cfg), nil
}

// newEC2Client creates an [ec2.Client] using the provided Token, RoleARN and Region.
Expand Down
3 changes: 2 additions & 1 deletion lib/integrations/awsoidc/deployservice_iam_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
awslib "github.com/gravitational/teleport/lib/cloud/aws"
"github.com/gravitational/teleport/lib/integrations/awsoidc/tags"
awslibutils "github.com/gravitational/teleport/lib/utils/aws"
"github.com/gravitational/teleport/lib/utils/aws/stsutils"
)

var taskRoleDescription = "Used by Teleport Database Service deployed in Amazon ECS."
Expand Down Expand Up @@ -142,7 +143,7 @@ func NewDeployServiceIAMConfigureClient(ctx context.Context, region string) (Dep

return &defaultDeployServiceIAMConfigureClient{
Client: iam.NewFromConfig(cfg),
stsClient: sts.NewFromConfig(cfg),
stsClient: stsutils.NewFromConfig(cfg),
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion lib/integrations/awsoidc/idp_iam_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
awslib "github.com/gravitational/teleport/lib/cloud/aws"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/integrations/awsoidc/tags"
"github.com/gravitational/teleport/lib/utils/aws/stsutils"
)

const (
Expand Down Expand Up @@ -161,7 +162,7 @@ func NewIdPIAMConfigureClient(ctx context.Context) (IdPIAMConfigureClient, error
httpClient: httpClient,
awsConfig: cfg,
Client: iam.NewFromConfig(cfg),
stsClient: sts.NewFromConfig(cfg),
stsClient: stsutils.NewFromConfig(cfg),
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions lib/integrations/externalauditstorage/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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/sts"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
Expand All @@ -38,6 +37,7 @@ import (
"github.com/gravitational/teleport/api/types/externalauditstorage"
"github.com/gravitational/teleport/lib/modules"
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/utils/aws/stsutils"
)

const (
Expand Down Expand Up @@ -111,7 +111,7 @@ func (o *Options) setDefaults(ctx context.Context, region string) error {
if err != nil {
return trace.Wrap(err)
}
o.stsClient = sts.NewFromConfig(cfg)
o.stsClient = stsutils.NewFromConfig(cfg)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions tool/teleport/common/integration_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/aws/aws-sdk-go-v2/service/glue"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/gravitational/trace"

ecatypes "github.com/gravitational/teleport/api/types/externalauditstorage"
Expand All @@ -41,6 +40,7 @@ import (
"github.com/gravitational/teleport/lib/integrations/samlidp"
"github.com/gravitational/teleport/lib/integrations/samlidp/samlidpconfig"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/aws/stsutils"
)

func onIntegrationConfDeployService(ctx context.Context, params config.IntegrationConfDeployServiceIAM) error {
Expand Down Expand Up @@ -202,7 +202,7 @@ func onIntegrationConfExternalAuditCmd(ctx context.Context, params easconfig.Ext

clt := &awsoidc.DefaultConfigureExternalAuditStorageClient{
Iam: iam.NewFromConfig(cfg),
Sts: sts.NewFromConfig(cfg),
Sts: stsutils.NewFromConfig(cfg),
}
return trace.Wrap(awsoidc.ConfigureExternalAuditStorage(ctx, clt, params))
}
Expand Down

0 comments on commit 0cc9899

Please sign in to comment.